1 #include <Plugins/ImageRegionGrow.h>
2 #include <cpInstances/Image.h>
3 #include <cpInstances/Image_Demanglers.h>
5 #include <fpa/Image/RegionGrow.h>
6 #include <vtkPolyData.h>
8 // -------------------------------------------------------------------------
9 fpaPlugins::ImageRegionGrow::
13 typedef cpPlugins::BaseObjects::DataObject _TData;
14 typedef cpInstances::Image _TMST;
16 this->_ConfigureInput< _TData >( "GrowFunction", true, false );
18 this->m_Parameters.ConfigureAsInt( "InsideValue", 1 );
19 this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 );
20 this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" );
23 // -------------------------------------------------------------------------
24 fpaPlugins::ImageRegionGrow::
29 // -------------------------------------------------------------------------
30 void fpaPlugins::ImageRegionGrow::
33 auto o = this->GetInputData( "Input" );
34 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
35 this->_Error( "Invalid input image." );
38 // -------------------------------------------------------------------------
39 template< class _TImage >
40 void fpaPlugins::ImageRegionGrow::
41 _GD0( _TImage* image )
43 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
44 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
45 if( rtype == "char" ) this->_GD1< _TImage, char >( image );
46 if( rtype == "uchar" ) this->_GD1< _TImage, unsigned char >( image );
47 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
48 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
49 if( rtype == "short" ) this->_GD1< _TImage, short >( image );
50 if( rtype == "ushort" ) this->_GD1< _TImage, unsigned short >( image );
51 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
52 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
53 if( rtype == "int" ) this->_GD1< _TImage, int >( image );
54 if( rtype == "uint" ) this->_GD1< _TImage, unsigned int >( image );
55 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
56 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
57 if( rtype == "long" ) this->_GD1< _TImage, long >( image );
58 if( rtype == "ulong" ) this->_GD1< _TImage, unsigned long >( image );
59 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
62 // -------------------------------------------------------------------------
63 template< class _TInputImage, class _TOutputPixel >
64 void fpaPlugins::ImageRegionGrow::
65 _GD1( _TInputImage* image )
67 std::cout << "--------------> again <-----------------" << std::endl;
70 itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
72 typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter;
73 typedef typename _TFilter::TGrowFunction _TGrow;
74 typedef typename _TFilter::TNeighborhoodFunction _TNeighborhood;
77 auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" );
78 auto grow = this->GetInputData< _TGrow >( "GrowFunction" );
81 auto filter = this->_CreateITK< _TFilter >( );
82 filter->SetInput( image );
83 filter->SetGrowFunction( grow );
84 filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) );
85 filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) );
86 filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) );
89 auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
92 typename _TInputImage::PointType pnt;
93 typename _TInputImage::IndexType idx;
95 ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3;
97 for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
100 seeds->GetPoint( i, buf );
102 for( unsigned int d = 0; d < dim; ++d )
105 if( image->TransformPhysicalPointToIndex( pnt, idx ) )
106 filter->AddSeed( idx, 0 );
114 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );