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