]> Creatis software - FrontAlgorithms.git/blob - lib/fpaPlugins/ImageRegionGrow.cxx
...
[FrontAlgorithms.git] / lib / fpaPlugins / ImageRegionGrow.cxx
1 #include "ImageRegionGrow.h"
2
3 #include <cpPlugins/Interface/Image.h>
4 #include <fpaPlugins/GrowFunction.h>
5 #include <fpa/Image/RegionGrow.h>
6 #include <fpa/Image/Functors/RegionGrowAllBelongsFunction.h>
7
8 // -------------------------------------------------------------------------
9 fpaPlugins::ImageRegionGrow::
10 ImageRegionGrow( )
11   : Superclass( )
12 {
13   this->_AddInput( "GrowFunction", false );
14
15   this->m_Parameters->ConfigureAsReal( "InsideValue" );
16   this->m_Parameters->ConfigureAsReal( "OutsideValue" );
17
18   this->m_Parameters->SetReal( "InsideValue", 1 );
19   this->m_Parameters->SetReal( "OutsideValue", 0 );
20 }
21
22 // -------------------------------------------------------------------------
23 fpaPlugins::ImageRegionGrow::
24 ~ImageRegionGrow( )
25 {
26 }
27
28 // -------------------------------------------------------------------------
29 std::string fpaPlugins::ImageRegionGrow::
30 _GenerateData( )
31 {
32   auto input = this->GetInputData( "Input" );
33   itk::DataObject* image = NULL;
34   std::string r = "";
35   cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 );
36   else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 );
37   else r = "fpaPlugins::ImageRegionGrow: Input image type not supported.";
38   return( r );
39 }
40
41 // -------------------------------------------------------------------------
42 template< class I >
43 std::string fpaPlugins::ImageRegionGrow::
44 _GD0( itk::DataObject* data )
45 {
46   typedef unsigned char                               _TOutPixel;
47   typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut;
48   typedef fpa::Image::RegionGrow< I, _TOut >          _TFilter;
49   typedef typename _TFilter::TGrowingFunction         _TFunctor;
50
51   // Create filter
52   _TFilter* filter = this->_ConfigureFilter< _TFilter >( );
53
54   // Connect grow functor (or create a tautology)
55   typename _TFunctor::Pointer functor;
56   auto functor_wrapper = this->GetInputData( "GrowFunction" );
57   if( functor_wrapper != NULL )
58     functor = functor_wrapper->GetITK< _TFunctor >( );
59   if( functor.IsNull( ) )
60     functor =
61       fpa::Image::Functors::RegionGrowAllBelongsFunction< I >::New( );
62   filter->SetGrowingFunction( functor );
63
64   // Set numeric parameters
65   filter->SetInsideValue(
66     _TOutPixel( this->m_Parameters->GetReal( "InsideValue" ) )
67     );
68   filter->SetOutsideValue(
69     _TOutPixel( this->m_Parameters->GetReal( "OutsideValue" ) )
70     );
71
72   // Go!!!
73   this->_ExecuteFilter( filter );
74   return( "" );
75 }
76
77 // eof - $RCSfile$