]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/ImageInterpolatorSource.cxx
...
[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", true );
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 =
39     this->GetInputData< cpPlugins::Interface::Image >( "ReferenceImage" );
40   if( image == NULL )
41     return( "ImageInterpolatorSource: No input image." );
42
43   itk::DataObject* itk_image = NULL;
44   std::string r = "";
45   cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
46   else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
47   else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
48   else r = "ImageInterpolatorSource: Input image type not supported.";
49   return( r );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class I >
54 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
55 _GD0( itk::DataObject* dobj )
56 {
57   std::string int_choice =
58     this->m_Parameters->GetSelectedChoice( "InterpolationType" );
59   std::string scalar_choice =
60     this->m_Parameters->GetSelectedChoice( "ScalarType" );
61
62   if( int_choice == "Linear" )
63   {
64     if( scalar_choice == "float" )
65       return(
66         this->_GD1< itk::LinearInterpolateImageFunction< I, float > >( )
67         );
68     else if( scalar_choice == "double" )
69       return(
70         this->_GD1< itk::LinearInterpolateImageFunction< I, double > >( )
71         );
72     else
73       return( "ImageInterpolatorSource: Invalid scalar type" );
74   }
75   else if( int_choice == "NearestNeighbor" )
76   {
77     if( scalar_choice == "float" )
78       return(
79         this->_GD1< itk::NearestNeighborInterpolateImageFunction< I, float > >( )
80         );
81     else if( scalar_choice == "double" )
82       return(
83         this->_GD1< itk::NearestNeighborInterpolateImageFunction< I, double > >( )
84         );
85     else
86       return( "ImageInterpolatorSource: Invalid scalar type" );
87   }
88   else
89     return( "ImageInterpolatorSource: Invalid interpolator" );
90 }
91
92 // -------------------------------------------------------------------------
93 template< class T >
94 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
95 _GD1( )
96 {
97   auto out =
98     this->GetOutputData< cpPlugins::Interface::DataObject >( "Output" );
99   if( out->GetITK< T >( ) == NULL )
100   {
101     typename T::Pointer res = T::New( );
102     out->SetITK( res.GetPointer( ) );
103
104   } // fi
105   return( "" );
106 }
107
108 // eof - $RCSfile$