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