]> Creatis software - FrontAlgorithms.git/blob - plugins/Plugins/ImageRegionGrow.cxx
...
[FrontAlgorithms.git] / plugins / Plugins / ImageRegionGrow.cxx
1 #include <Plugins/ImageRegionGrow.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4
5 #include <fpa/Image/RegionGrow.h>
6 #include <vtkPolyData.h>
7
8 // -------------------------------------------------------------------------
9 fpaPlugins::ImageRegionGrow::
10 ImageRegionGrow( )
11   : Superclass( )
12 {
13   typedef cpPlugins::BaseObjects::DataObject _TData;
14   typedef cpPlugins::DataObjects::Image      _TMST;
15
16   this->_ConfigureInput< _TData >( "GrowFunction", true, false );
17
18   this->m_Parameters.ConfigureAsInt( "InsideValue", 1 );
19   this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 );
20   this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" );
21 }
22
23 // -------------------------------------------------------------------------
24 fpaPlugins::ImageRegionGrow::
25 ~ImageRegionGrow( )
26 {
27 }
28
29 // -------------------------------------------------------------------------
30 void fpaPlugins::ImageRegionGrow::
31 _GenerateData( )
32 {
33   auto o = this->GetInputData( "Input" );
34   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
35     this->_Error( "Invalid input image." );
36 }
37
38 // -------------------------------------------------------------------------
39 template< class _TImage >
40 void fpaPlugins::ImageRegionGrow::
41 _GD0( _TImage* image )
42 {
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
60 }
61
62 // -------------------------------------------------------------------------
63 template< class _TInputImage, class _TOutputPixel >
64 void fpaPlugins::ImageRegionGrow::
65 _GD1( _TInputImage* image )
66 {
67   typedef
68     itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
69     _TOutputImage;
70   typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter;
71   typedef typename _TFilter::TGrowFunction           _TGrow;
72   typedef typename _TFilter::TNeighborhoodFunction   _TNeighborhood;
73
74   // Get functors
75   auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" );
76   auto grow = this->GetInputData< _TGrow >( "GrowFunction" );
77
78   // Configure filter
79   auto filter = this->_CreateITK< _TFilter >( );
80   filter->SetInput( image );
81   filter->SetGrowFunction( grow );
82   filter->SetInsideValue( this->m_Parameters.GetInt( "InsideValue" ) );
83   filter->SetOutsideValue( this->m_Parameters.GetInt( "OutsideValue" ) );
84   filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) );
85
86   // Assign seeds
87   auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
88   if( seeds != NULL )
89   {
90     typename _TInputImage::PointType pnt;
91     typename _TInputImage::IndexType idx;
92     unsigned int dim =
93       ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3;
94
95     for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
96     {
97       double buf[ 3 ];
98       seeds->GetPoint( i, buf );
99       pnt.Fill( 0 );
100       for( unsigned int d = 0; d < dim; ++d )
101         pnt[ d ] = buf[ d ];
102
103       if( image->TransformPhysicalPointToIndex( pnt, idx ) )
104         filter->AddSeed( idx, 0 );
105
106     } // rof
107
108   } // fi
109
110   // Assign outputs
111   filter->Update( );
112   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
113 }
114
115 // eof - $RCSfile$