1 #include "ImageRegionGrow.h"
3 #include <cpPlugins/Interface/Image.h>
4 #include <cpPlugins/Interface/PointList.h>
6 #include <fpaPlugins/GrowFunction.h>
8 #include <fpa/Image/RegionGrow.h>
9 #include <fpa/Image/Functors/RegionGrowAllBelongsFunction.h>
11 #include <vtkRenderWindow.h>
12 #include <vtkRenderWindowInteractor.h>
14 // -------------------------------------------------------------------------
15 fpaPlugins::ImageRegionGrow::
19 this->_AddInput( "Input" );
20 this->_AddInput( "GrowFunction" );
21 this->_AddInput( "Seeds" );
22 this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
24 this->m_Parameters->ConfigureAsBool( "VisualDebug" );
25 this->m_Parameters->ConfigureAsBool( "StopAtOneFront" );
26 this->m_Parameters->ConfigureAsReal( "InsideValue" );
27 this->m_Parameters->ConfigureAsReal( "OutsideValue" );
29 this->m_Parameters->SetBool( "VisualDebug", false );
30 this->m_Parameters->SetBool( "StopAtOneFront", false );
31 this->m_Parameters->SetReal( "InsideValue", 1 );
32 this->m_Parameters->SetReal( "OutsideValue", 0 );
34 std::vector< std::string > orders;
35 orders.push_back( "1" );
36 orders.push_back( "2" );
37 this->m_Parameters->ConfigureAsChoices( "NeighborhoodOrder", orders );
38 this->m_Parameters->SetSelectedChoice( "NeighborhoodOrder", "1" );
41 // -------------------------------------------------------------------------
42 fpaPlugins::ImageRegionGrow::
47 // -------------------------------------------------------------------------
48 std::string fpaPlugins::ImageRegionGrow::
52 this->GetInputData< cpPlugins::Interface::Image >( "Input" );
54 return( "fpaPlugins::ImageRegionGrow: No input image." );
56 itk::DataObject* image = NULL;
58 cpPlugins_Image_Demangle_AllScalarTypes( 2, input, image, r, _GD0 );
59 else cpPlugins_Image_Demangle_AllScalarTypes( 3, input, image, r, _GD0 );
60 else r = "fpaPlugins::ImageRegionGrow: Input image type not supported.";
64 // -------------------------------------------------------------------------
66 std::string fpaPlugins::ImageRegionGrow::
67 _GD0( itk::DataObject* data )
69 typedef unsigned char _TOutPixel;
70 typedef itk::Image< _TOutPixel, I::ImageDimension > _TOut;
71 typedef fpa::Image::RegionGrow< I, _TOut > _TFilter;
72 typedef typename _TFilter::TGrowingFunction _TFunctor;
73 typedef typename I::PointType _TPoint;
76 this->GetInputData< cpPlugins::Interface::PointList >( "Seeds" );
78 return( "fpaPlugins::ImageRegionGrow: No given seeds." );
79 I* image = dynamic_cast< I* >( data );
81 // Create filter and connect input
82 _TFilter* filter = this->_CreateITK< _TFilter >( );
83 filter->SetInput( image );
85 // Connect grow functor (or create a tautology)
86 typename _TFunctor::Pointer functor;
87 auto functor_wrapper =
88 this->GetInputData< cpPlugins::Interface::DataObject >( "GrowFunction" );
89 if( functor_wrapper != NULL )
90 functor = functor_wrapper->GetITK< _TFunctor >( );
91 if( functor.IsNull( ) )
93 fpa::Image::Functors::RegionGrowAllBelongsFunction< I >::New( );
94 filter->SetGrowingFunction( functor );
96 // Set numeric parameters
97 Superclass::TParameters* params = this->m_Parameters;
98 std::string order = params->GetSelectedChoice( "NeighborhoodOrder" );
99 filter->SetNeighborhoodOrder( order[ 0 ] - '0' );
100 filter->SetStopAtOneFront( params->GetBool( "StopAtOneFront" ) );
101 filter->SetInsideValue( _TOutPixel( params->GetReal( "InsideValue" ) ) );
102 filter->SetOutsideValue( _TOutPixel( params->GetReal( "OutsideValue" ) ) );
105 filter->ClearSeeds( );
106 for( unsigned int s = 0; s < seeds->GetNumberOfPoints( ); ++s )
108 _TPoint pnt = seeds->GetPoint< _TPoint >( s );
109 typename I::IndexType idx;
110 if( image->TransformPhysicalPointToIndex( pnt, idx ) )
111 filter->AddSeed( idx, 0 );
116 this->_ConfigureDebugger( filter );
118 this->_DeconfigureDebugger( filter );
122 this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
125 out->SetITK< _TOut >( filter->GetOutput( ) );
129 return( "fpaPlugins::ImageRegionGrow: output not correctly created." );