]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/RegionGrow.cxx
...
[FrontAlgorithms.git] / plugins / ImageAlgorithms / RegionGrow.cxx
1 #include <ImageAlgorithms/RegionGrow.h>
2 #include <cpInstances/DataObjects/Image.h>
3
4 #include <fpa/Image/RegionGrow.h>
5
6 // -------------------------------------------------------------------------
7 fpaPluginsImageAlgorithms::RegionGrow::
8 RegionGrow( )
9   : Superclass( )
10 {
11   typedef cpPlugins::Pipeline::DataObject _TData;
12
13   this->_ConfigureInput< _TData >( "GrowFunction", true, false );
14   this->m_Parameters.ConfigureAsInt( "InsideValue", 1 );
15   this->m_Parameters.ConfigureAsInt( "OutsideValue", 0 );
16   this->m_Parameters.ConfigureAsIntTypesChoices( "ResultType" );
17 }
18
19 // -------------------------------------------------------------------------
20 fpaPluginsImageAlgorithms::RegionGrow::
21 ~RegionGrow( )
22 {
23 }
24
25 // -------------------------------------------------------------------------
26 void fpaPluginsImageAlgorithms::RegionGrow::
27 _GenerateData( )
28 {
29   auto o = this->GetInputData( "Input" );
30   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
31     this->_Error( "Invalid input image." );
32 }
33
34 // -------------------------------------------------------------------------
35 template< class _TImage >
36 void fpaPluginsImageAlgorithms::RegionGrow::
37 _GD0( _TImage* image )
38 {
39   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
40   if( rtype == "char" )        this->_GD1< _TImage, char >( image );
41   else if( rtype == "uchar" )  this->_GD1< _TImage, unsigned char >( image );
42   else if( rtype == "short" )  this->_GD1< _TImage, short >( image );
43   else if( rtype == "ushort" ) this->_GD1< _TImage, unsigned short >( image );
44   else if( rtype == "int" )    this->_GD1< _TImage, int >( image );
45   else if( rtype == "uint" )   this->_GD1< _TImage, unsigned int >( image );
46   else if( rtype == "long" )   this->_GD1< _TImage, long >( image );
47   else if( rtype == "ulong" )  this->_GD1< _TImage, unsigned long >( image );
48   else                         this->_GD1< _TImage, char >( image );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class _TInputImage, class _TOutputPixel >
53 void fpaPluginsImageAlgorithms::RegionGrow::
54 _GD1( _TInputImage* image )
55 {
56   typedef
57     itk::Image< _TOutputPixel, _TInputImage::ImageDimension >
58     _TOutputImage;
59   typedef fpa::Image::RegionGrow< _TInputImage, _TOutputImage > _TFilter;
60   typedef typename _TFilter::TGrowFunction                      _TGrow;
61
62   _TOutputPixel i_val = _TOutputPixel( this->m_Parameters.GetInt( "InsideValue" ) );
63   _TOutputPixel o_val = _TOutputPixel( this->m_Parameters.GetInt( "OutsideValue" ) );
64
65   auto filter = this->_CreateITK< _TFilter >( );
66   std::vector< typename _TInputImage::IndexType > seeds;
67   this->_ConfigureFilter( filter, image, seeds );
68   filter->ClearSeeds( );
69   for( auto seed : seeds )
70     filter->AddSeed( seed, i_val );
71   filter->SetGrowFunction( this->GetInputData< _TGrow >( "GrowFunction" ) );
72   filter->SetInsideValue( i_val );
73   filter->SetOutsideValue( o_val );
74   filter->Update( );
75   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
76 }
77
78 // eof - $RCSfile$