--- /dev/null
+#include <cpPluginsImageFilters/CastImageFilter.h>
+#include <cpPlugins/Image.h>
+#include <cpPlugins_Instances/ScalarImagesBaseFilters.h>
+
+// -------------------------------------------------------------------------
+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( "Input" )->GetITK< itk::DataObject >( );
+ 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->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__
+#define __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__
+
+#include <plugins/cpPluginsImageFilters/cpPluginsImageFilters_Export.h>
+#include <cpPlugins/ProcessObject.h>
+
+namespace cpPluginsImageFilters
+{
+ /**
+ */
+ class cpPluginsImageFilters_EXPORT CastImageFilter
+ : public cpPlugins::ProcessObject
+ {
+ public:
+ typedef CastImageFilter Self;
+ typedef cpPlugins::ProcessObject Superclass;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+
+ public:
+ itkNewMacro( Self );
+ itkTypeMacro( CastImageFilter, cpPlugins::ProcessObject );
+ cpPlugins_Id_Macro( CastImageFilter, ImageFilters );
+
+ protected:
+ CastImageFilter( );
+ virtual ~CastImageFilter( );
+
+ virtual void _GenerateData( ) ITK_OVERRIDE;
+
+ template< class _TInputImage >
+ inline void _GD0( _TInputImage* image );
+
+ template< class _TInputImage, class _TOutputPixel >
+ inline void _GD1( _TInputImage* image );
+
+ private:
+ // Purposely not implemented
+ CastImageFilter( const Self& );
+ Self& operator=( const Self& );
+ };
+
+} // ecapseman
+
+#endif // __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__
+
+// eof - $RCSfile$