TuttleOFX
1
|
00001 #include "ImageStatisticsPlugin.hpp" 00002 #include "ImageStatisticsProcess.hpp" 00003 #include "ImageStatisticsDefinitions.hpp" 00004 00005 #include <boost/numeric/conversion/cast.hpp> 00006 00007 #include <tuttle/plugin/interact/InteractInfos.hpp> 00008 #include <tuttle/plugin/numeric/rectOp.hpp> 00009 00010 #include <boost/gil/gil_all.hpp> 00011 00012 namespace tuttle { 00013 namespace plugin { 00014 namespace imageStatistics { 00015 00016 ImageStatisticsPlugin::ImageStatisticsPlugin( OfxImageEffectHandle handle ) 00017 : ImageEffectGilPlugin( handle ) 00018 { 00019 _paramCoordinateSystem = fetchChoiceParam( kParamCoordinateSystem ); 00020 _paramRectCenter = fetchDouble2DParam( kParamRectCenter ); 00021 _paramRectSize = fetchDouble2DParam( kParamRectSize ); 00022 _paramChooseOutput = fetchChoiceParam( kParamChooseOutput ); 00023 00024 _paramOutputAverage = fetchRGBAParam( kParamOutputAverage ); 00025 _paramOutputVariance = fetchRGBAParam( kParamOutputVariance ); 00026 _paramOutputChannelMin = fetchRGBAParam( kParamOutputChannelMin ); 00027 _paramOutputChannelMax = fetchRGBAParam( kParamOutputChannelMax ); 00028 _paramOutputLuminosityMin = fetchRGBAParam( kParamOutputLuminosityMin ); 00029 _paramOutputLuminosityMax = fetchRGBAParam( kParamOutputLuminosityMax ); 00030 _paramOutputKurtosis = fetchRGBAParam( kParamOutputKurtosis ); 00031 _paramOutputSkewness = fetchRGBAParam( kParamOutputSkewness ); 00032 00033 _paramOutputAverageHSL = fetchDouble3DParam( kParamOutputAverageHSL ); 00034 _paramOutputChannelMinHSL = fetchDouble3DParam( kParamOutputChannelMinHSL ); 00035 _paramOutputChannelMaxHSL = fetchDouble3DParam( kParamOutputChannelMaxHSL ); 00036 _paramOutputLuminosityMinHSL = fetchDouble3DParam( kParamOutputLuminosityMinHSL ); 00037 _paramOutputLuminosityMaxHSL = fetchDouble3DParam( kParamOutputLuminosityMaxHSL ); 00038 _paramOutputKurtosisHSL = fetchDouble3DParam( kParamOutputKurtosisHSL ); 00039 _paramOutputSkewnessHSL = fetchDouble3DParam( kParamOutputSkewnessHSL ); 00040 } 00041 00042 ImageStatisticsProcessParams ImageStatisticsPlugin::getProcessParams( const OfxRectI& srcRod ) const 00043 { 00044 ImageStatisticsProcessParams params; 00045 OfxPointD rectCenter = _paramRectCenter->getValue(); 00046 OfxPointD rectSize = _paramRectSize->getValue(); 00047 00048 rectSize.x = std::abs( rectSize.x ); 00049 rectSize.y = std::abs( rectSize.y ); 00050 if( _paramCoordinateSystem->getValue() == eParamCoordinateSystemNormalized ) 00051 { 00052 OfxPointD projectSize = this->getProjectSize(); 00053 rectCenter *= projectSize; 00054 rectSize *= projectSize; 00055 } 00056 00057 params._rect.x1 = boost::numeric_cast<int>( rectCenter.x - rectSize.x ); 00058 params._rect.y1 = boost::numeric_cast<int>( rectCenter.y - rectSize.y ); 00059 params._rect.x2 = boost::numeric_cast<int>( std::ceil( rectCenter.x + rectSize.x ) ); 00060 params._rect.y2 = boost::numeric_cast<int>( std::ceil( rectCenter.y + rectSize.y ) ); 00061 params._rect = rectanglesIntersection( params._rect, srcRod ); 00062 params._chooseOutput = static_cast<EParamChooseOutput>( _paramChooseOutput->getValue() ); 00063 00064 return params; 00065 } 00066 00067 void ImageStatisticsPlugin::getRegionsOfInterest( const OFX::RegionsOfInterestArguments& args, OFX::RegionOfInterestSetter& rois ) 00068 { 00069 OfxRectI srcRealRoi = getProcessParams( _clipSrc->getPixelRod( args.time ) )._rect; // we need the selected rectangle 00070 OfxRectD srcRealRoiD; 00071 00072 srcRealRoiD.x1 = srcRealRoi.x1; 00073 srcRealRoiD.y1 = srcRealRoi.y1; 00074 srcRealRoiD.x2 = srcRealRoi.x2; 00075 srcRealRoiD.y2 = srcRealRoi.y2; 00076 // TUTTLE_LOG_VAR( TUTTLE_INFO, srcRealRoiD ); 00077 00078 rois.setRegionOfInterest( *_clipSrc, srcRealRoiD ); 00079 } 00080 00081 /** 00082 * @brief The overridden render function 00083 * @param[in] args Rendering parameters 00084 */ 00085 void ImageStatisticsPlugin::render( const OFX::RenderArguments& args ) 00086 { 00087 // instantiate the render code based on the pixel depth of the dst clip 00088 OFX::EBitDepth bitDepth = _clipDst->getPixelDepth(); 00089 OFX::EPixelComponent components = _clipDst->getPixelComponents(); 00090 00091 switch( components ) 00092 { 00093 case OFX::ePixelComponentRGBA: 00094 { 00095 switch( bitDepth ) 00096 { 00097 case OFX::eBitDepthFloat: 00098 { 00099 doGilRender<ImageStatisticsProcess, false, boost::gil::rgba_layout_t, boost::gil::bits32f>( *this, args ); 00100 return; 00101 } 00102 case OFX::eBitDepthUByte: 00103 case OFX::eBitDepthUShort: 00104 case OFX::eBitDepthNone: 00105 case OFX::eBitDepthCustom: 00106 { 00107 BOOST_THROW_EXCEPTION( exception::Unsupported() 00108 << exception::user() + "Bit depth (" + mapBitDepthEnumToString(bitDepth) + ") not recognized by the plugin." ); 00109 } 00110 } 00111 break; 00112 } 00113 case OFX::ePixelComponentRGB: 00114 case OFX::ePixelComponentAlpha: 00115 case OFX::ePixelComponentCustom: 00116 case OFX::ePixelComponentNone: 00117 { 00118 BOOST_THROW_EXCEPTION( exception::Unsupported() 00119 << exception::user() + "Pixel components (" + mapPixelComponentEnumToString(components) + ") not supported by the plugin." ); 00120 } 00121 } 00122 BOOST_THROW_EXCEPTION( exception::Unknown() ); 00123 } 00124 00125 void ImageStatisticsPlugin::changedParam( const OFX::InstanceChangedArgs& args, const std::string& paramName ) 00126 { 00127 if( paramName == kParamCoordinateSystem ) 00128 { 00129 OfxPointD projectSize = this->getProjectSize(); 00130 OfxPointD rectCenter = _paramRectCenter->getValue(); 00131 OfxPointD rectSize = _paramRectSize->getValue(); 00132 switch( _paramCoordinateSystem->getValue() ) 00133 { 00134 case eParamCoordinateSystemCanonical: 00135 { 00136 rectCenter *= projectSize; 00137 rectSize *= projectSize; 00138 break; 00139 } 00140 case eParamCoordinateSystemNormalized: 00141 { 00142 rectCenter /= projectSize; 00143 rectSize /= projectSize; 00144 break; 00145 } 00146 default: 00147 BOOST_THROW_EXCEPTION( exception::Value() << exception::user( "Unrecognized coordinate system option." ) ); 00148 } 00149 _paramRectCenter->setValue( rectCenter ); 00150 _paramRectSize->setValue( rectSize ); 00151 } 00152 } 00153 00154 } 00155 } 00156 }