]> Creatis software - FrontAlgorithms.git/blob - lib/fpaPlugins/ImageRegionGrow.cxx
Plugins updated
[FrontAlgorithms.git] / lib / fpaPlugins / ImageRegionGrow.cxx
1 #include "ImageRegionGrow.h"
2
3 #include <cpPlugins/Interface/Image.h>
4 #include <fpa/Image/RegionGrow.h>
5 #include <fpa/Image/Functors/RegionGrowAllBelongsFunction.h>
6
7 // -------------------------------------------------------------------------
8 fpaPlugins::ImageRegionGrow::
9 ImageRegionGrow( )
10   : Superclass( )
11 {
12   this->_AddInput( "Input" );
13   this->_AddInput( "GrowFunction" );
14   this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
15
16   this->m_Parameters->ConfigureAsBool( "VisualDebug" );
17   this->m_Parameters->ConfigureAsBool( "StopAtOneFront" );
18   this->m_Parameters->ConfigureAsReal( "InsideValue" );
19   this->m_Parameters->ConfigureAsReal( "OutsideValue" );
20   this->m_Parameters->ConfigureAsPointList( "Seeds" );
21
22   this->m_Parameters->SetBool( "VisualDebug", false );
23   this->m_Parameters->SetBool( "StopAtOneFront", false );
24   this->m_Parameters->SetReal( "InsideValue", 1 );
25   this->m_Parameters->SetReal( "OutsideValue", 0 );
26
27   std::vector< std::string > orders;
28   orders.push_back( "1" );
29   orders.push_back( "2" );
30   this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders );
31 }
32
33 // -------------------------------------------------------------------------
34 fpaPlugins::ImageRegionGrow::
35 ~ImageRegionGrow( )
36 {
37 }
38
39 // -------------------------------------------------------------------------
40 std::string fpaPlugins::ImageRegionGrow::
41 _GenerateData( )
42 {
43   cpPlugins::Interface::Image* input =
44     this->GetInput< cpPlugins::Interface::Image >( "Input" );
45   if( input == NULL )
46     return( "fpaPlugins::ImageRegionGrow: No input image." );
47
48   itk::DataObject* image = NULL;
49   std::string r = "";
50   cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 );
51   else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 );
52   else r = "fpaPlugins::ImageRegionGrow: Input image type not supported.";
53   return( r );
54 }
55
56 // -------------------------------------------------------------------------
57 template< class I >
58 std::string fpaPlugins::ImageRegionGrow::
59 _GD0( itk::DataObject* data )
60 {
61   typedef unsigned char                               _TOutPixel;
62   typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut;
63   typedef fpa::Image::RegionGrow< I, _TOut >          _TFilter;
64   typedef typename _TFilter::TGrowingFunction         _TFunctor;
65   typedef typename I::PointType                       _TPoint;
66
67   I* image = dynamic_cast< I* >( data );
68
69   // Create filter and connect input
70   _TFilter* filter = this->_CreateITK< _TFilter >( );
71   filter->SetInput( image );
72
73   // Connect grow functor (or create a tautology)
74   typename _TFunctor::Pointer functor;
75   cpPlugins::Interface::DataObject* functor_wrapper =
76     this->GetInput< cpPlugins::Interface::DataObject >( "GrowFunction" );
77   if( functor_wrapper != NULL )
78     functor = functor_wrapper->GetITK< _TFunctor >( );
79   if( functor.IsNull( ) )
80     functor =
81       fpa::Image::Functors::RegionGrowAllBelongsFunction< I >::New( );
82
83   // Set numeric parameters
84   Superclass::TParameters* params = this->m_Parameters;
85   std::string order = params->GetSelectedChoice( "NeighborhoodOrder" );
86   filter->SetNeighborhoodOrder( order[ 0 ] - '0' );
87   filter->SetStopAtOneFront( params->GetBool( "StopAtOneFront" ) );
88   filter->SetInsideValue( _TOutPixel( params->GetReal( "InsideValue" ) ) );
89   filter->SetOutsideValue( _TOutPixel( params->GetReal( "OutsideValue" ) ) );
90
91   // Assign seeds
92   std::vector< _TPoint > seeds =
93     params->GetPointList< _TPoint >( "Seeds", I::ImageDimension );
94   for( auto sIt = seeds.begin( ); sIt != seeds.end( ); ++sIt )
95   {
96     typename I::IndexType idx;
97     if( image->TransformPhysicalPointToIndex( *sIt, idx ) )
98       filter->AddSeed( idx, 0 );
99
100   } // rof
101
102   // Connect visual debugger
103   /* TODO
104      this->m_Parameters->ConfigureAsBool( "VisualDebug", false );
105    */
106
107   // Go!!!
108   filter->Update( );
109
110   // Connect output
111   cpPlugins::Interface::Image* out =
112     this->GetOutput< cpPlugins::Interface::Image >( "Output" );
113   if( out != NULL )
114   {
115     out->SetITK< _TOut >( filter->GetOutput( ) );
116     return( "" );
117   }
118   else
119     return( "fpaPlugins::ImageRegionGrow: output not correctly created." );
120 }
121
122 // eof - $RCSfile$