1 #include "ImageRegionGrow.h"
3 #include <cpPlugins/Interface/Image.h>
4 #include <fpa/Image/RegionGrow.h>
5 #include <fpa/Image/Functors/RegionGrowAllBelongsFunction.h>
7 // -------------------------------------------------------------------------
8 fpaPlugins::ImageRegionGrow::
12 this->_AddInput( "Input" );
13 this->_AddInput( "GrowFunction" );
14 this->_MakeOutput< cpPlugins::Interface::Image >( "Output" );
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" );
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 );
27 std::vector< std::string > orders;
28 orders.push_back( "1" );
29 orders.push_back( "2" );
30 this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders );
33 // -------------------------------------------------------------------------
34 fpaPlugins::ImageRegionGrow::
39 // -------------------------------------------------------------------------
40 std::string fpaPlugins::ImageRegionGrow::
43 cpPlugins::Interface::Image* input =
44 this->GetInput< cpPlugins::Interface::Image >( "Input" );
46 return( "fpaPlugins::ImageRegionGrow: No input image." );
48 itk::DataObject* image = NULL;
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.";
56 // -------------------------------------------------------------------------
58 std::string fpaPlugins::ImageRegionGrow::
59 _GD0( itk::DataObject* data )
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;
67 I* image = dynamic_cast< I* >( data );
69 // Create filter and connect input
70 _TFilter* filter = this->_CreateITK< _TFilter >( );
71 filter->SetInput( image );
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( ) )
81 fpa::Image::Functors::RegionGrowAllBelongsFunction< I >::New( );
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" ) ) );
92 std::vector< _TPoint > seeds =
93 params->GetPointList< _TPoint >( "Seeds", I::ImageDimension );
94 for( auto sIt = seeds.begin( ); sIt != seeds.end( ); ++sIt )
96 typename I::IndexType idx;
97 if( image->TransformPhysicalPointToIndex( *sIt, idx ) )
98 filter->AddSeed( idx, 0 );
102 // Connect visual debugger
104 this->m_Parameters->ConfigureAsBool( "VisualDebug", false );
111 cpPlugins::Interface::Image* out =
112 this->GetOutput< cpPlugins::Interface::Image >( "Output" );
115 out->SetITK< _TOut >( filter->GetOutput( ) );
119 return( "fpaPlugins::ImageRegionGrow: output not correctly created." );