From d74a07c7e0854fcfe2b0189805b992785f3631e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20Fl=C3=B3rez-Valencia?= Date: Thu, 10 Nov 2016 12:14:04 -0500 Subject: [PATCH] CastImageFilter added. --- .../ImageGenericFilters/CastImageFilter.cxx | 78 +++++++++++++++++++ plugins/ImageGenericFilters/CastImageFilter.h | 32 ++++++++ 2 files changed, 110 insertions(+) create mode 100644 plugins/ImageGenericFilters/CastImageFilter.cxx create mode 100644 plugins/ImageGenericFilters/CastImageFilter.h 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$ -- 2.47.1