#include #include #include // ------------------------------------------------------------------------- cpPluginsImageFilters::CastImageFilter:: CastImageFilter( ) : Superclass( ) { this->_AddInput( "Input" ); this->_AddOutput< cpPlugins::Image >( "Output" ); std::vector< std::string > choices; choices.push_back( "char" ); choices.push_back( "short" ); choices.push_back( "int" ); choices.push_back( "long" ); choices.push_back( "uchar" ); choices.push_back( "ushort" ); choices.push_back( "uint" ); choices.push_back( "ulong" ); choices.push_back( "float" ); choices.push_back( "double" ); this->m_Parameters.ConfigureAsChoices( "CastType", choices ); this->m_Parameters.SetSelectedChoice( "CastType", "uchar" ); } // ------------------------------------------------------------------------- cpPluginsImageFilters::CastImageFilter:: ~CastImageFilter( ) { } // ------------------------------------------------------------------------- void cpPluginsImageFilters::CastImageFilter:: _GenerateData( ) { auto image = this->GetInputData< itk::DataObject >( "Input" ); cpPlugins_Image_Demangle_Pixel_AllScalars ( _GD0, image, 1 ); else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 2 ); else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 ); else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 4 ); else this->_Error( "No valid input image." ); } // ------------------------------------------------------------------------- template< class _TInputImage > void cpPluginsImageFilters::CastImageFilter:: _GD0( _TInputImage* image ) { auto out = this->m_Parameters.GetSelectedChoice( "CastType" ); if( out == "char" ) this->_GD1< _TInputImage, char >( image ); else if( out == "short" ) this->_GD1< _TInputImage, short >( image ); else if( out == "int" ) this->_GD1< _TInputImage, int >( image ); else if( out == "long" ) this->_GD1< _TInputImage, long >( image ); else if( out == "float" ) this->_GD1< _TInputImage, float >( image ); else if( out == "double" ) this->_GD1< _TInputImage, double >( image ); else if( out == "uchar" ) this->_GD1< _TInputImage, unsigned char >( image ); else if( out == "ushort" ) this->_GD1< _TInputImage, unsigned short >( image ); else if( out == "uint" ) this->_GD1< _TInputImage, unsigned int >( image ); else if( out == "ulong" ) this->_GD1< _TInputImage, unsigned long >( image ); else this->_Error( "Invalid output casting type." ); } // ------------------------------------------------------------------------- template< class _TInputImage, class _TOutputPixel > void cpPluginsImageFilters::CastImageFilter:: _GD1( _TInputImage* image ) { typedef itk::Image< _TOutputPixel, _TInputImage::ImageDimension > _TOutputImage; typedef itk::CastImageFilter< _TInputImage, _TOutputImage > _TFilter; // Configure filter auto filter = this->_CreateITK< _TFilter >( ); filter->SetInput( image ); filter->Update( ); // Connect output this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); } // eof - $RCSfile$