]> Creatis software - cpPlugins.git/blob - plugins/ImageGenericFilters/CastImageFilter.cxx
CastImageFilter added.
[cpPlugins.git] / plugins / ImageGenericFilters / CastImageFilter.cxx
1 #include <ImageGenericFilters/CastImageFilter.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Image_Demanglers.h>
4
5 #include <itkCastImageFilter.h>
6
7 // -------------------------------------------------------------------------
8 cpPluginsImageGenericFilters::CastImageFilter::
9 CastImageFilter( )
10   : Superclass( )
11 {
12   typedef cpPlugins::DataObjects::Image _TImage;
13   this->_ConfigureInput< _TImage >( "Input", true, false );
14   this->_ConfigureOutput< _TImage >( "Output" );
15   this->m_Parameters.ConfigureAsScalarTypesChoices( "CastType" );
16 }
17
18 // -------------------------------------------------------------------------
19 cpPluginsImageGenericFilters::CastImageFilter::
20 ~CastImageFilter( )
21 {
22 }
23
24 // -------------------------------------------------------------------------
25 void cpPluginsImageGenericFilters::CastImageFilter::
26 _GenerateData( )
27 {
28   auto o = this->GetInputData( "Input" );
29   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
30     this->_Error( "Invalid input image." );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class _TInput >
35 void cpPluginsImageGenericFilters::CastImageFilter::
36 _GD0( _TInput* input )
37 {
38   std::string out_res =
39     this->m_Parameters.GetSelectedChoice( "CastType" );
40 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
41   if( out_res == "char" ) this->_GD1< _TInput, char >( input );
42   if( out_res == "uchar" ) this->_GD1< _TInput, unsigned char >( input );
43 #endif // cpPlugins_CONFIG_INTEGER_TYPES_char
44 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
45   if( out_res == "short" ) this->_GD1< _TInput, short >( input );
46   if( out_res == "ushort" ) this->_GD1< _TInput, unsigned short >( input );
47 #endif // cpPlugins_CONFIG_INTEGER_TYPES_short
48 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
49   if( out_res == "int" ) this->_GD1< _TInput, int >( input );
50   if( out_res == "uint" ) this->_GD1< _TInput, unsigned int >( input );
51 #endif // cpPlugins_CONFIG_INTEGER_TYPES_int
52 #ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
53   if( out_res == "long" ) this->_GD1< _TInput, long >( input );
54   if( out_res == "ulong" ) this->_GD1< _TInput, unsigned long >( input );
55 #endif // cpPlugins_CONFIG_INTEGER_TYPES_long
56 #ifdef cpPlugins_CONFIG_REAL_TYPES_float
57   if( out_res == "float" ) this->_GD1< _TInput, float >( input );
58 #endif // cpPlugins_CONFIG_REAL_TYPES_float
59 #ifdef cpPlugins_CONFIG_REAL_TYPES_double
60   if( out_res == "double" ) this->_GD1< _TInput, double >( input );
61 #endif // cpPlugins_CONFIG_REAL_TYPES_double
62 }
63
64 // -------------------------------------------------------------------------
65 template< class _TInput, class _TOutputPixel >
66 void cpPluginsImageGenericFilters::CastImageFilter::
67 _GD1( _TInput* input )
68 {
69   typedef itk::Image< _TOutputPixel, _TInput::ImageDimension > _TOutput;
70   typedef itk::CastImageFilter< _TInput, _TOutput > _TFilter;
71
72   auto filter = this->_CreateITK< _TFilter >( );
73   filter->SetInput( input );
74   filter->Update( );
75   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
76 }
77
78 // eof - $RCSfile$