From: Leonardo Florez-Valencia Date: Sun, 17 Apr 2016 23:02:11 +0000 (-0500) Subject: ... X-Git-Tag: v0.1~184 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=a7f80b65169919125a6f1ae1c62c430c18321453;p=cpPlugins.git ... --- diff --git a/lib/cpPlugins_Instances/ScalarImagesBaseFilters.i b/lib/cpPlugins_Instances/ScalarImagesBaseFilters.i index 4820938..5b5ebb5 100644 --- a/lib/cpPlugins_Instances/ScalarImagesBaseFilters.i +++ b/lib/cpPlugins_Instances/ScalarImagesBaseFilters.i @@ -9,6 +9,9 @@ d #itk_filters=ImageToImage;InPlaceImage i cpPlugins_Instances/ScalarImages.h t itk{#itk_filters}Filter.h +t itkCastImageFilter.h +t itkImageAlgorithm.h +t itkUnaryFunctorImageFilter.h * ===================== * = Base filter types = @@ -17,4 +20,10 @@ c itk::{#itk_filters}Filter< itk::Image< #inputs, #dims >, itk::Image< #outputs, c itk::{#itk_filters}Filter< itk::Image< #pixels, 3 >, itk::Image< #pixels, 2 > > c itk::{#itk_filters}Filter< itk::Image< #pixels, 2 >, itk::Image< #pixels, 3 > > +* ================== +* = Simple filters = +* ================== + +c itk::CastImageFilter< itk::Image< #inputs, #dims >, itk::Image< #outputs, #dims > > + * eof - $RCSfile$ diff --git a/plugins/cpPluginsImageFilters/CastImageFilter.cxx b/plugins/cpPluginsImageFilters/CastImageFilter.cxx new file mode 100644 index 0000000..0743b2a --- /dev/null +++ b/plugins/cpPluginsImageFilters/CastImageFilter.cxx @@ -0,0 +1,93 @@ +#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( "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$ diff --git a/plugins/cpPluginsImageFilters/CastImageFilter.h b/plugins/cpPluginsImageFilters/CastImageFilter.h new file mode 100644 index 0000000..d9760b0 --- /dev/null +++ b/plugins/cpPluginsImageFilters/CastImageFilter.h @@ -0,0 +1,47 @@ +#ifndef __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__ +#define __CPPLUGINSIMAGEFILTERS__CASTIMAGEFILTER__H__ + +#include +#include + +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$