]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/ImageInterpolatorSource.cxx
bffab1674d0cb975f86d4f76272f1c0e49c8f16a
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / ImageInterpolatorSource.cxx
1 #include "ImageInterpolatorSource.h"
2
3 #include <cpPlugins/Interface/Image.h>
4 #include <itkLinearInterpolateImageFunction.h>
5 #include <itkNearestNeighborInterpolateImageFunction.h>
6
7 // -------------------------------------------------------------------------
8 cpPlugins::BasicFilters::ImageInterpolatorSource::
9 ImageInterpolatorSource( )
10   : Superclass( )
11 {
12   this->_AddInput( "ReferenceImage" );
13   this->_AddOutput< cpPlugins::Interface::DataObject >( "Output" );
14
15   std::vector< std::string > type_choices;
16   type_choices.push_back( "Linear" );
17   type_choices.push_back( "NearestNeighbor" );
18   this->m_Parameters->ConfigureAsChoices( "InterpolationType", type_choices );
19   this->m_Parameters->SetSelectedChoice( "InterpolationType", "Linear" );
20
21   std::vector< std::string > scalar_choices;
22   scalar_choices.push_back( "float" );
23   scalar_choices.push_back( "double" );
24   this->m_Parameters->ConfigureAsChoices( "ScalarType", scalar_choices );
25   this->m_Parameters->SetSelectedChoice( "ScalarType", "float" );
26 }
27
28 // -------------------------------------------------------------------------
29 cpPlugins::BasicFilters::ImageInterpolatorSource::
30 ~ImageInterpolatorSource( )
31 {
32 }
33
34 // -------------------------------------------------------------------------
35 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
36 _GenerateData( )
37 {
38   auto image = this->GetInputData( "ReferenceImage" );
39   itk::DataObject* itk_image = NULL;
40   std::string r = "";
41   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
42   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
43   else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
44   else r = "ImageInterpolatorSource: Input image type not supported.";
45   return( r );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class I >
50 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
51 _GD0( itk::DataObject* dobj )
52 {
53   std::string int_choice =
54     this->m_Parameters->GetSelectedChoice( "InterpolationType" );
55   std::string scalar_choice =
56     this->m_Parameters->GetSelectedChoice( "ScalarType" );
57
58   if( int_choice == "Linear" )
59   {
60     if( scalar_choice == "float" )
61       return(
62         this->_GD1< itk::LinearInterpolateImageFunction< I, float > >( )
63         );
64     else if( scalar_choice == "double" )
65       return(
66         this->_GD1< itk::LinearInterpolateImageFunction< I, double > >( )
67         );
68     else
69       return( "ImageInterpolatorSource: Invalid scalar type" );
70   }
71   else if( int_choice == "NearestNeighbor" )
72   {
73     if( scalar_choice == "float" )
74       return(
75         this->_GD1< itk::NearestNeighborInterpolateImageFunction< I, float > >( )
76         );
77     else if( scalar_choice == "double" )
78       return(
79         this->_GD1< itk::NearestNeighborInterpolateImageFunction< I, double > >( )
80         );
81     else
82       return( "ImageInterpolatorSource: Invalid scalar type" );
83   }
84   else
85     return( "ImageInterpolatorSource: Invalid interpolator" );
86 }
87
88 // -------------------------------------------------------------------------
89 template< class T >
90 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
91 _GD1( )
92 {
93   auto out = this->GetOutputData( "Output" );
94   if( out->GetITK< T >( ) == NULL )
95   {
96     typename T::Pointer res = T::New( );
97     out->SetITK( res.GetPointer( ) );
98
99   } // fi
100   return( "" );
101 }
102
103 // eof - $RCSfile$