]> Creatis software - cpPlugins.git/blob - plugins/ImageFilters/CastImageFilter.cxx
Code cleaning
[cpPlugins.git] / plugins / ImageFilters / CastImageFilter.cxx
1 #include <plugins/ImageFilters/CastImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances_CastImageFilters.h>
4
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::CastImageFilter::
7 CastImageFilter( )
8   : Superclass( )
9 {
10   this->_AddInput( "Input" );
11   this->_AddOutput< cpPlugins::Image >( "Output" );
12
13   std::vector< std::string > choices;
14   choices.push_back( "char" );
15   choices.push_back( "short" );
16   choices.push_back( "int" );
17   choices.push_back( "long" );
18   choices.push_back( "uchar" );
19   choices.push_back( "ushort" );
20   choices.push_back( "uint" );
21   choices.push_back( "ulong" );
22   choices.push_back( "float" );
23   choices.push_back( "double" );
24   this->m_Parameters.ConfigureAsChoices( "CastType", choices );
25   this->m_Parameters.SetSelectedChoice( "CastType", "uchar" );
26 }
27
28 // -------------------------------------------------------------------------
29 cpPluginsImageFilters::CastImageFilter::
30 ~CastImageFilter( )
31 {
32 }
33
34 // -------------------------------------------------------------------------
35 void cpPluginsImageFilters::CastImageFilter::
36 _GenerateData( )
37 {
38   auto image = this->GetInputData< itk::DataObject >( "Input" );
39   cpPlugins_Image_Demangle_Pixel_AllScalars     ( _GD0, image, 1 );
40   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 2 );
41   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
42   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 4 );
43   else this->_Error( "No valid input image." );
44 }
45
46 // -------------------------------------------------------------------------
47 template< class _TInputImage >
48 void cpPluginsImageFilters::CastImageFilter::
49 _GD0( _TInputImage* image )
50 {
51   auto out = this->m_Parameters.GetSelectedChoice( "CastType" );
52   if( out == "char" )
53     this->_GD1< _TInputImage, char >( image );
54   else if( out == "short" )
55     this->_GD1< _TInputImage, short >( image );
56   else if( out == "int" )
57     this->_GD1< _TInputImage, int >( image );
58   else if( out == "long" )
59     this->_GD1< _TInputImage, long >( image );
60   else if( out == "float" )
61     this->_GD1< _TInputImage, float >( image );
62   else if( out == "double" )
63     this->_GD1< _TInputImage, double >( image );
64   else if( out == "uchar" )
65     this->_GD1< _TInputImage, unsigned char >( image );
66   else if( out == "ushort" )
67     this->_GD1< _TInputImage, unsigned short >( image );
68   else if( out == "uint" )
69     this->_GD1< _TInputImage, unsigned int >( image );
70   else if( out == "ulong" )
71     this->_GD1< _TInputImage, unsigned long >( image );
72   else
73     this->_Error( "Invalid output casting type." );
74 }
75
76 // -------------------------------------------------------------------------
77 template< class _TInputImage, class _TOutputPixel >
78 void cpPluginsImageFilters::CastImageFilter::
79 _GD1( _TInputImage* image )
80 {
81   typedef itk::Image< _TOutputPixel, _TInputImage::ImageDimension > _TOutputImage;
82   typedef itk::CastImageFilter< _TInputImage, _TOutputImage > _TFilter;
83
84   // Configure filter
85   auto filter = this->_CreateITK< _TFilter >( );
86   filter->SetInput( image );
87   filter->Update( );
88
89   // Connect output
90   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
91 }
92
93 // eof - $RCSfile$