1 #include <ImageAlgorithms/MoriRegionGrow.h>
2 #include <cpInstances/DataObjects/Image.h>
4 #include <fpa/Image/MoriRegionGrow.h>
6 // -------------------------------------------------------------------------
7 fpaPluginsImageAlgorithms::MoriRegionGrow::
11 typedef cpPlugins::Pipeline::DataObject _TData;
12 typedef cpInstances::DataObjects::Image _TImage;
14 this->_ConfigureInput< _TImage >( "Input", true, false );
15 this->_ConfigureInput< _TData >( "Seed", true, false );
16 this->_ConfigureOutput< _TImage >( "Output" );
17 this->_ConfigureOutput< _TImage >( "AuxiliaryOutput" );
19 this->m_Parameters.ConfigureAsInt( "InsideValue", 1 );
20 this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 );
21 this->m_Parameters.ConfigureAsReal( "Step", 1 );
22 this->m_Parameters.ConfigureAsReal( "Lower", 0 );
23 this->m_Parameters.ConfigureAsReal( "Upper", 1 );
24 this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" );
27 // -------------------------------------------------------------------------
28 fpaPluginsImageAlgorithms::MoriRegionGrow::
33 // -------------------------------------------------------------------------
34 void fpaPluginsImageAlgorithms::MoriRegionGrow::
37 auto o = this->GetInputData( "Input" );
38 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
39 this->_Error( "Invalid input image." );
42 // -------------------------------------------------------------------------
43 template< class _TImage >
44 void fpaPluginsImageAlgorithms::MoriRegionGrow::
45 _GD0( _TImage* image )
47 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
48 if( rtype == "char" ) this->_GD1< _TImage, char >( image );
49 else if( rtype == "uchar" ) this->_GD1< _TImage, unsigned char >( image );
50 else if( rtype == "short" ) this->_GD1< _TImage, short >( image );
51 else if( rtype == "ushort" ) this->_GD1< _TImage, unsigned short >( image );
52 else if( rtype == "int" ) this->_GD1< _TImage, int >( image );
53 else if( rtype == "uint" ) this->_GD1< _TImage, unsigned int >( image );
54 else if( rtype == "long" ) this->_GD1< _TImage, long >( image );
55 else if( rtype == "ulong" ) this->_GD1< _TImage, unsigned long >( image );
56 else this->_GD1< _TImage, char >( image );
59 // -------------------------------------------------------------------------
60 template< class _TInputImage, class _TOutputPixel >
61 void fpaPluginsImageAlgorithms::MoriRegionGrow::
62 _GD1( _TInputImage* image )
66 itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
68 typedef fpa::Image::MoriRegionGrow< _TInputImage, _TOutputImage > _TFilter;
70 auto filter = this->_CreateITK< _TFilter >( );
71 filter->SetInput( image );
72 filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) );
73 filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) );
74 filter->SetStep( this->m_Parameters.GetReal( "Step" ) );
75 filter->SetLower( this->m_Parameters.GetReal( "Lower" ) );
76 filter->SetUpper( this->m_Parameters.GetReal( "Upper" ) );
79 auto seeds = this->GetInputData< vtkPolyData >( "Seed" );
82 typename _TInputImage::PointType pnt;
83 typename _TInputImage::IndexType idx;
85 ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3;
86 if( seeds->GetNumberOfPoints( ) > 0 )
89 seeds->GetPoint( 0, buf );
91 for( unsigned int d = 0; d < dim; ++d )
94 if( image->TransformPhysicalPointToIndex( pnt, idx ) )
95 filter->SetSeed( idx );
98 this->_Error( "No given seeds." );
101 this->_Error( "No given seeds." );
104 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
105 this->GetOutput( "AuxiliaryOutput" )->SetITK( filter->GetAuxiliaryImage( ) );