From: Leonardo Flórez-Valencia Date: Thu, 10 Nov 2016 17:14:04 +0000 (-0500) Subject: CastImageFilter added. X-Git-Tag: v0.1~53 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=cpPlugins.git;a=commitdiff_plain;h=d74a07c7e0854fcfe2b0189805b992785f3631e8 CastImageFilter added. --- diff --git a/plugins/ImageGenericFilters/CastImageFilter.cxx b/plugins/ImageGenericFilters/CastImageFilter.cxx new file mode 100644 index 0000000..31626a5 --- /dev/null +++ b/plugins/ImageGenericFilters/CastImageFilter.cxx @@ -0,0 +1,78 @@ +#include +#include +#include + +#include + +// ------------------------------------------------------------------------- +cpPluginsImageGenericFilters::CastImageFilter:: +CastImageFilter( ) + : Superclass( ) +{ + typedef cpPlugins::DataObjects::Image _TImage; + this->_ConfigureInput< _TImage >( "Input", true, false ); + this->_ConfigureOutput< _TImage >( "Output" ); + this->m_Parameters.ConfigureAsScalarTypesChoices( "CastType" ); +} + +// ------------------------------------------------------------------------- +cpPluginsImageGenericFilters::CastImageFilter:: +~CastImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +void cpPluginsImageGenericFilters::CastImageFilter:: +_GenerateData( ) +{ + auto o = this->GetInputData( "Input" ); + cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 ) + this->_Error( "Invalid input image." ); +} + +// ------------------------------------------------------------------------- +template< class _TInput > +void cpPluginsImageGenericFilters::CastImageFilter:: +_GD0( _TInput* input ) +{ + std::string out_res = + this->m_Parameters.GetSelectedChoice( "CastType" ); +#ifdef cpPlugins_CONFIG_INTEGER_TYPES_char + if( out_res == "char" ) this->_GD1< _TInput, char >( input ); + if( out_res == "uchar" ) this->_GD1< _TInput, unsigned char >( input ); +#endif // cpPlugins_CONFIG_INTEGER_TYPES_char +#ifdef cpPlugins_CONFIG_INTEGER_TYPES_short + if( out_res == "short" ) this->_GD1< _TInput, short >( input ); + if( out_res == "ushort" ) this->_GD1< _TInput, unsigned short >( input ); +#endif // cpPlugins_CONFIG_INTEGER_TYPES_short +#ifdef cpPlugins_CONFIG_INTEGER_TYPES_int + if( out_res == "int" ) this->_GD1< _TInput, int >( input ); + if( out_res == "uint" ) this->_GD1< _TInput, unsigned int >( input ); +#endif // cpPlugins_CONFIG_INTEGER_TYPES_int +#ifdef cpPlugins_CONFIG_INTEGER_TYPES_long + if( out_res == "long" ) this->_GD1< _TInput, long >( input ); + if( out_res == "ulong" ) this->_GD1< _TInput, unsigned long >( input ); +#endif // cpPlugins_CONFIG_INTEGER_TYPES_long +#ifdef cpPlugins_CONFIG_REAL_TYPES_float + if( out_res == "float" ) this->_GD1< _TInput, float >( input ); +#endif // cpPlugins_CONFIG_REAL_TYPES_float +#ifdef cpPlugins_CONFIG_REAL_TYPES_double + if( out_res == "double" ) this->_GD1< _TInput, double >( input ); +#endif // cpPlugins_CONFIG_REAL_TYPES_double +} + +// ------------------------------------------------------------------------- +template< class _TInput, class _TOutputPixel > +void cpPluginsImageGenericFilters::CastImageFilter:: +_GD1( _TInput* input ) +{ + typedef itk::Image< _TOutputPixel, _TInput::ImageDimension > _TOutput; + typedef itk::CastImageFilter< _TInput, _TOutput > _TFilter; + + auto filter = this->_CreateITK< _TFilter >( ); + filter->SetInput( input ); + filter->Update( ); + this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) ); +} + +// eof - $RCSfile$ diff --git a/plugins/ImageGenericFilters/CastImageFilter.h b/plugins/ImageGenericFilters/CastImageFilter.h new file mode 100644 index 0000000..3ce8f80 --- /dev/null +++ b/plugins/ImageGenericFilters/CastImageFilter.h @@ -0,0 +1,32 @@ +#ifndef __cpPluginsImageGenericFilters__CastImageFilter__h__ +#define __cpPluginsImageGenericFilters__CastImageFilter__h__ + +#include +#include + +namespace cpPluginsImageGenericFilters +{ + /** + */ + class cpPluginsImageGenericFilters_EXPORT CastImageFilter + : public cpPlugins::BaseObjects::ProcessObject + { + cpPluginsObject( + CastImageFilter, + cpPlugins::BaseObjects::ProcessObject, + ImageFilters + ); + + protected: + template< class _TInput > + inline void _GD0( _TInput* input ); + + template< class _TInput, class _TOutputPixel > + inline void _GD1( _TInput* input ); + }; + +} // ecapseman + +#endif // __cpPluginsImageGenericFilters__CastImageFilter__h__ + +// eof - $RCSfile$