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 double seed[ 3 ] = { double( 0 ) };
17 this->m_Parameters->ConfigureAsPoint( "Seed", 3, seed );
18 this->m_Parameters->ConfigureAsUint( "InsideValue", 0 );
19 this->m_Parameters->ConfigureAsUint( "OutsideValue", 255 );
22 // -------------------------------------------------------------------------
23 cpPlugins::BasicFilters::FloodFillImageFilter::
24 ~FloodFillImageFilter( )
28 // -------------------------------------------------------------------------
29 std::string cpPlugins::BasicFilters::FloodFillImageFilter::
32 cpPlugins::Interface::Image* image =
33 this->GetInput< cpPlugins::Interface::Image >( 0 );
35 return( "FloodFillImageFilter: No input image." );
37 itk::DataObject* itk_image = NULL;
39 cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
40 else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
41 else r = "FloodFillImageFilter: Input image type not supported.";
45 // -------------------------------------------------------------------------
47 std::string cpPlugins::BasicFilters::FloodFillImageFilter::
48 _GD0( itk::DataObject* image )
51 this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >(
57 // -------------------------------------------------------------------------
58 template< class I, class R = float >
59 class cpPlugins_BasicFilters_FloodFillImageFilter_Function
60 : public itk::ImageFunction< I, bool, R >
63 typedef cpPlugins_BasicFilters_FloodFillImageFilter_Function Self;
64 typedef itk::ImageFunction< I, bool, R > Superclass;
65 typedef itk::SmartPointer< Self > Pointer;
66 typedef itk::SmartPointer< const Self > ConstPointer;
68 typedef typename Superclass::PointType TPoint;
69 typedef typename Superclass::IndexType TIndex;
70 typedef typename Superclass::ContinuousIndexType TCIndex;
75 cpPlugins_BasicFilters_FloodFillImageFilter_Function,
80 virtual bool Evaluate( const TPoint& point ) const
84 virtual bool EvaluateAtIndex( const TIndex& index ) const
88 virtual bool EvaluateAtContinuousIndex( const TCIndex& index ) const
94 cpPlugins_BasicFilters_FloodFillImageFilter_Function( )
98 virtual ~cpPlugins_BasicFilters_FloodFillImageFilter_Function( )
103 // Purposely not implemented
104 cpPlugins_BasicFilters_FloodFillImageFilter_Function( const Self& other );
105 Self& operator=( const Self& other );
108 // -------------------------------------------------------------------------
109 template< class I, class O >
110 inline std::string cpPlugins::BasicFilters::FloodFillImageFilter::
111 _RealGD( itk::DataObject* image )
113 typedef typename O::PixelType _OP;
114 typedef cpPlugins_BasicFilters_FloodFillImageFilter_Function< I > _F;
115 typedef itk::FloodFilledImageFunctionConditionalConstIterator< I, _F > _It;
117 typename I::PointType pseed;
118 pseed = this->m_Parameters->GetPoint< typename I::PointType >(
119 "Seed", I::ImageDimension
121 _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) );
122 _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) );
124 const I* in = dynamic_cast< const I* >( image );
125 typename I::IndexType seed;
126 in->TransformPhysicalPointToIndex( pseed, seed );
128 typename O::Pointer out = O::New( );
129 out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) );
130 out->SetRequestedRegion( in->GetRequestedRegion( ) );
131 out->SetBufferedRegion( in->GetBufferedRegion( ) );
132 out->SetOrigin( in->GetOrigin( ) );
133 out->SetDirection( in->GetDirection( ) );
134 out->SetSpacing( in->GetSpacing( ) );
136 out->FillBuffer( out_val );
138 typename _F::Pointer f = _F::New( );
142 for( i.GoToBegin( ); !i.IsAtEnd( ); ++i )
143 out->SetPixel( i.GetIndex( ), in_val );
146 cpPlugins::Interface::Image* out_port =
147 this->GetOutput< cpPlugins::Interface::Image >( 0 );
148 if( out_port != NULL )
150 out_port->SetITK< O >( out );
154 return( "FloodFillImageFilter: output not correctly created." );