#include "FloodFillImageFilter.h" #include #include #include // ------------------------------------------------------------------------- cpPlugins::BasicFilters::FloodFillImageFilter:: FloodFillImageFilter( ) : Superclass( ) { this->SetNumberOfInputs( 1 ); this->SetNumberOfOutputs( 1 ); this->_MakeOutput< cpPlugins::Interface::Image >( 0 ); double seed[ 3 ] = { double( 0 ) }; this->m_Parameters->ConfigureAsPoint( "Seed", 3, seed ); this->m_Parameters->ConfigureAsUint( "InsideValue", 0 ); this->m_Parameters->ConfigureAsUint( "OutsideValue", 255 ); } // ------------------------------------------------------------------------- cpPlugins::BasicFilters::FloodFillImageFilter:: ~FloodFillImageFilter( ) { } // ------------------------------------------------------------------------- std::string cpPlugins::BasicFilters::FloodFillImageFilter:: _GenerateData( ) { cpPlugins::Interface::Image* image = this->GetInput< cpPlugins::Interface::Image >( 0 ); if( image == NULL ) return( "FloodFillImageFilter: No input image." ); itk::DataObject* itk_image = NULL; std::string r = ""; cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 ); else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 ); else r = "FloodFillImageFilter: Input image type not supported."; return( r ); } // ------------------------------------------------------------------------- template< class I > std::string cpPlugins::BasicFilters::FloodFillImageFilter:: _GD0( itk::DataObject* image ) { return( this->_RealGD< I, itk::Image< unsigned char, I::ImageDimension > >( image ) ); } // ------------------------------------------------------------------------- template< class I, class R = float > class cpPlugins_BasicFilters_FloodFillImageFilter_Function : public itk::ImageFunction< I, bool, R > { public: typedef cpPlugins_BasicFilters_FloodFillImageFilter_Function Self; typedef itk::ImageFunction< I, bool, R > Superclass; typedef itk::SmartPointer< Self > Pointer; typedef itk::SmartPointer< const Self > ConstPointer; typedef typename Superclass::PointType TPoint; typedef typename Superclass::IndexType TIndex; typedef typename Superclass::ContinuousIndexType TCIndex; public: itkNewMacro( Self ); itkTypeMacro( cpPlugins_BasicFilters_FloodFillImageFilter_Function, itkImageFunction ); public: virtual bool Evaluate( const TPoint& point ) const { return( true ); } virtual bool EvaluateAtIndex( const TIndex& index ) const { return( true ); } virtual bool EvaluateAtContinuousIndex( const TCIndex& index ) const { return( true ); } protected: cpPlugins_BasicFilters_FloodFillImageFilter_Function( ) : Superclass( ) { } virtual ~cpPlugins_BasicFilters_FloodFillImageFilter_Function( ) { } private: // Purposely not implemented cpPlugins_BasicFilters_FloodFillImageFilter_Function( const Self& other ); Self& operator=( const Self& other ); }; // ------------------------------------------------------------------------- template< class I, class O > inline std::string cpPlugins::BasicFilters::FloodFillImageFilter:: _RealGD( itk::DataObject* image ) { typedef typename O::PixelType _OP; typedef cpPlugins_BasicFilters_FloodFillImageFilter_Function< I > _F; typedef itk::FloodFilledImageFunctionConditionalConstIterator< I, _F > _It; typename I::PointType pseed; pseed = this->m_Parameters->GetPoint< typename I::PointType >( "Seed", I::ImageDimension ); _OP in_val = _OP( this->m_Parameters->GetUint( "InsideValue" ) ); _OP out_val = _OP( this->m_Parameters->GetUint( "OutsideValue" ) ); const I* in = dynamic_cast< const I* >( image ); typename I::IndexType seed; in->TransformPhysicalPointToIndex( pseed, seed ); typename O::Pointer out = O::New( ); out->SetLargestPossibleRegion( in->GetLargestPossibleRegion( ) ); out->SetRequestedRegion( in->GetRequestedRegion( ) ); out->SetBufferedRegion( in->GetBufferedRegion( ) ); out->SetOrigin( in->GetOrigin( ) ); out->SetDirection( in->GetDirection( ) ); out->SetSpacing( in->GetSpacing( ) ); out->Allocate( ); out->FillBuffer( out_val ); typename _F::Pointer f = _F::New( ); _It i( in, f ); i.AddSeed( seed ); for( i.GoToBegin( ); !i.IsAtEnd( ); ++i ) out->SetPixel( i.GetIndex( ), in_val ); // Connect output cpPlugins::Interface::Image* out_port = this->GetOutput< cpPlugins::Interface::Image >( 0 ); if( out_port != NULL ) { out_port->SetITK< O >( out ); return( "" ); } else return( "FloodFillImageFilter: output not correctly created." ); } // eof - $RCSfile$