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