]> 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 =
33     this->GetInputData< cpPlugins::Interface::Image >( "Input" );
34   itk::DataObject* image = NULL;
35   std::string r = "";
36   cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 );
37   else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 );
38   else r = "fpaPlugins::ImageRegionGrow: Input image type not supported.";
39   return( r );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class I >
44 std::string fpaPlugins::ImageRegionGrow::
45 _GD0( itk::DataObject* data )
46 {
47   typedef unsigned char                               _TOutPixel;
48   typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut;
49   typedef fpa::Image::RegionGrow< I, _TOut >          _TFilter;
50   typedef typename _TFilter::TGrowingFunction         _TFunctor;
51
52   // Create filter
53   _TFilter* filter = this->_ConfigureFilter< _TFilter >( );
54
55   // Connect grow functor (or create a tautology)
56   typename _TFunctor::Pointer functor;
57   auto functor_wrapper =
58     this->GetInputData< cpPlugins::Interface::DataObject >( "GrowFunction" );
59   if( functor_wrapper != NULL )
60     functor = functor_wrapper->GetITK< _TFunctor >( );
61   if( functor.IsNull( ) )
62     functor =
63       fpa::Image::Functors::RegionGrowAllBelongsFunction< I >::New( );
64   filter->SetGrowingFunction( functor );
65
66   // Set numeric parameters
67   filter->SetInsideValue(
68     _TOutPixel( this->m_Parameters->GetReal( "InsideValue" ) )
69     );
70   filter->SetOutsideValue(
71     _TOutPixel( this->m_Parameters->GetReal( "OutsideValue" ) )
72     );
73
74   // Go!!!
75   this->_ExecuteFilter( filter );
76   return( "" );
77 }
78
79 // eof - $RCSfile$