1 #include "FloodFillImageFilter.h"
2 #include <cpPlugins/Interface/Image.h>
4 #include <itkFloodFilledImageFunctionConditionalConstIterator.h>
5 #include <itkImageFunction.h>
7 // -------------------------------------------------------------------------
8 cpPlugins::BasicFilters::FloodFillImageFilter::
9 FloodFillImageFilter( )
12 this->SetNumberOfInputs( 1 );
13 this->SetNumberOfOutputs( 1 );
14 this->_MakeOutput< cpPlugins::Interface::Image >( 0 );
16 using namespace cpPlugins::Interface;
17 this->m_DefaultParameters.Configure( Parameters::Point, "Seed" );
18 this->m_DefaultParameters.Configure( Parameters::Real, "InsideValue" );
19 this->m_DefaultParameters.Configure( Parameters::Real, "OutsideValue" );
20 this->m_DefaultParameters.SetValueAsPoint( "Seed", 3, 0, 0, 0 );
21 this->m_DefaultParameters.SetValueAsReal( "InsideValue", 255 );
22 this->m_DefaultParameters.SetValueAsReal( "OutsideValue", 0 );
23 this->m_Parameters = this->m_DefaultParameters;
26 // -------------------------------------------------------------------------
27 cpPlugins::BasicFilters::FloodFillImageFilter::
28 ~FloodFillImageFilter( )
32 // -------------------------------------------------------------------------
33 std::string cpPlugins::BasicFilters::FloodFillImageFilter::
36 cpPlugins::Interface::Image* image =
37 this->GetInput< cpPlugins::Interface::Image >( 0 );
39 return( "FloodFillImageFilter: No input image." );
41 itk::DataObject* itk_image = NULL;
43 cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
44 else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
45 else r = "FloodFillImageFilter: Input image type not supported.";
49 // -------------------------------------------------------------------------
51 std::string cpPlugins::BasicFilters::FloodFillImageFilter::
52 _GD0( itk::DataObject* image )
55 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
61 // -------------------------------------------------------------------------
62 template< class I, class R = float >
63 class cpPlugins_BasicFilters_FloodFillImageFilter_Function
64 : public itk::ImageFunction< I, bool, R >
67 typedef cpPlugins_BasicFilters_FloodFillImageFilter_Function Self;
68 typedef itk::ImageFunction< I, bool, R > Superclass;
69 typedef itk::SmartPointer< Self > Pointer;
70 typedef itk::SmartPointer< const Self > ConstPointer;
72 typedef typename Superclass::PointType TPoint;
73 typedef typename Superclass::IndexType TIndex;
74 typedef typename Superclass::ContinuousIndexType TCIndex;
79 cpPlugins_BasicFilters_FloodFillImageFilter_Function,
84 virtual bool Evaluate( const TPoint& point ) const
88 virtual bool EvaluateAtIndex( const TIndex& index ) const
92 virtual bool EvaluateAtContinuousIndex( const TCIndex& index ) const
98 cpPlugins_BasicFilters_FloodFillImageFilter_Function( )
102 virtual ~cpPlugins_BasicFilters_FloodFillImageFilter_Function( )
107 // Purposely not implemented
108 cpPlugins_BasicFilters_FloodFillImageFilter_Function( const Self& other );
109 Self& operator=( const Self& other );
112 // -------------------------------------------------------------------------
113 template< class I, class O >
114 inline std::string cpPlugins::BasicFilters::FloodFillImageFilter::
115 _RealGD( itk::DataObject* image )
117 typedef typename O::PixelType _OP;
118 typedef cpPlugins_BasicFilters_FloodFillImageFilter_Function< I > _F;
119 typedef itk::FloodFilledImageFunctionConditionalConstIterator< I, _F > _It;
121 typename I::PointType pseed;
122 pseed = this->m_Parameters.GetValueAsPoint< typename I::PointType >( "Seed" );
123 _OP in_val = _OP( this->m_Parameters.GetValueAsReal( "InsideValue" ) );
124 _OP out_val = _OP( this->m_Parameters.GetValueAsReal( "OutsideValue" ) );
126 const I* in = dynamic_cast< const I* >( image );
127 typename I::IndexType seed;
128 in->TransformPhysicalPointToIndex( pseed, seed );
130 typename O::Pointer out = O::New( );
131 out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
132 out->SetRequestedRegion( in->GetRequestedRegion( ) );
133 out->SetBufferedRegion( in->GetBufferedRegion( ) );
134 out->SetOrigin( in->GetOrigin( ) );
135 out->SetDirection( in->GetDirection( ) );
136 out->SetSpacing( in->GetSpacing( ) );
138 out->FillBuffer( out_val );
140 typename _F::Pointer f = _F::New( );
144 for( i.GoToBegin( ); !i.IsAtEnd( ); ++i )
145 out->SetPixel( i.GetIndex( ), in_val );
148 cpPlugins::Interface::Image* out_port =
149 this->GetOutput< cpPlugins::Interface::Image >( 0 );
150 if( out_port != NULL )
152 out_port->SetITK< O >( out );
156 return( "FloodFillImageFilter: output not correctly created." );