1 #include "RegionGrow.h"
2 #include <cpPlugins/Pipeline/Functor.h>
3 #include <cpInstances/DataObjects/Image.h>
5 #include <fpa/Image/RegionGrow.h>
7 // -------------------------------------------------------------------------
8 fpaPlugins_ImageAlgorithms::RegionGrow::
12 typedef cpPlugins::Pipeline::DataObject _TFunctor;
13 typedef cpInstances::DataObjects::Image _TMST;
15 this->_ConfigureInput< _TFunctor >( "GrowFunction", true, false );
16 this->m_Parameters.ConfigureAsInt( "InsideValue", 1 );
17 this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 );
18 this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" );
21 // -------------------------------------------------------------------------
22 fpaPlugins_ImageAlgorithms::RegionGrow::
27 // -------------------------------------------------------------------------
28 void fpaPlugins_ImageAlgorithms::RegionGrow::
31 auto o = this->GetInputData( "Input" );
32 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
33 this->_Error( "Invalid input image." );
36 // -------------------------------------------------------------------------
37 template< class _TImage >
38 void fpaPlugins_ImageAlgorithms::RegionGrow::
39 _GD0( _TImage* image )
41 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
42 if( rtype == "char" ) this->_GD1< _TImage, char >( image );
43 else if( rtype == "uchar" ) this->_GD1< _TImage, unsigned char >( image );
44 else if( rtype == "short" ) this->_GD1< _TImage, short >( image );
45 else if( rtype == "ushort" ) this->_GD1< _TImage, unsigned short >( image );
46 else if( rtype == "int" ) this->_GD1< _TImage, int >( image );
47 else if( rtype == "uint" ) this->_GD1< _TImage, unsigned int >( image );
48 else if( rtype == "long" ) this->_GD1< _TImage, long >( image );
49 else if( rtype == "ulong" ) this->_GD1< _TImage, unsigned long >( image );
50 else this->_GD1< _TImage, char >( image );
53 // -------------------------------------------------------------------------
54 template< class _TInputImage, class _TOutputPixel >
55 void fpaPlugins_ImageAlgorithms::RegionGrow::
56 _GD1( _TInputImage* image )
58 typedef cpPlugins::Pipeline::Functor _TFunctor;
59 typedef itk::Image< _TOutputPixel, _TInputImage::ImageDimension > _TOutputImage;
60 typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter;
61 typedef typename _TFilter::TGrowFunction _TGrowFunction;
64 auto filter = this->_CreateITK< _TFilter >( );
65 std::vector< typename _TInputImage::IndexType > seeds;
66 this->_ConfigureFilter( filter, image, seeds );
68 // Instantiate functors
69 auto growfunc = this->GetInputData< _TFunctor >( "GrowFunction" );
70 if( growfunc != NULL )
72 growfunc->Instantiate( filter );
73 auto growfunc_functor = growfunc->GetFunctor< _TGrowFunction >( );
74 if( growfunc_functor != NULL )
75 filter->SetGrowFunction( growfunc_functor );
79 // Finish filter's configuration
80 filter->ClearSeeds( );
81 for( auto seed : seeds )
82 filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) );
84 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );