]> Creatis software - FrontAlgorithms.git/blob - plugins/Plugins/ImageRegionGrow.cxx
50562123a1caf7cd50163f088aae4a31169aa2f6
[FrontAlgorithms.git] / plugins / Plugins / ImageRegionGrow.cxx
1 #include <Plugins/ImageRegionGrow.h>
2 #include <cpInstances/Image.h>
3 #include <cpInstances/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 cpInstances::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   std::cout << "--------------> again <-----------------" << std::endl;
68
69   typedef
70     itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
71     _TOutputImage;
72   typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter;
73   typedef typename _TFilter::TGrowFunction           _TGrow;
74   typedef typename _TFilter::TNeighborhoodFunction   _TNeighborhood;
75
76   // Get functors
77   auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" );
78   auto grow = this->GetInputData< _TGrow >( "GrowFunction" );
79
80   // Configure filter
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" ) );
87
88   // Assign seeds
89   auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
90   if( seeds != NULL )
91   {
92     typename _TInputImage::PointType pnt;
93     typename _TInputImage::IndexType idx;
94     unsigned int dim =
95       ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3;
96
97     for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
98     {
99       double buf[ 3 ];
100       seeds->GetPoint( i, buf );
101       pnt.Fill( 0 );
102       for( unsigned int d = 0; d < dim; ++d )
103         pnt[ d ] = buf[ d ];
104
105       if( image->TransformPhysicalPointToIndex( pnt, idx ) )
106         filter->AddSeed( idx, 0 );
107
108     } // rof
109
110   } // fi
111
112   // Assign outputs
113   filter->Update( );
114   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
115 }
116
117 // eof - $RCSfile$