1 #include "ImageInterpolatorSource.h"
3 #include <cpPlugins/Interface/Image.h>
4 #include <itkLinearInterpolateImageFunction.h>
5 #include <itkNearestNeighborInterpolateImageFunction.h>
7 // -------------------------------------------------------------------------
8 cpPlugins::BasicFilters::ImageInterpolatorSource::
9 ImageInterpolatorSource( )
12 this->_AddInput( "ReferenceImage" );
13 this->_AddOutput< cpPlugins::Interface::DataObject >( "Output" );
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" );
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" );
28 // -------------------------------------------------------------------------
29 cpPlugins::BasicFilters::ImageInterpolatorSource::
30 ~ImageInterpolatorSource( )
34 // -------------------------------------------------------------------------
35 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
39 this->GetInputData< cpPlugins::Interface::Image >( "ReferenceImage" );
40 itk::DataObject* itk_image = NULL;
42 cpPlugins_Image_Demangle_AllScalarTypes( 2, image, itk_image, r, _GD0 );
43 else cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
44 else cpPlugins_Image_Demangle_AllScalarTypes( 4, image, itk_image, r, _GD0 );
45 else r = "ImageInterpolatorSource: Input image type not supported.";
49 // -------------------------------------------------------------------------
51 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
52 _GD0( itk::DataObject* dobj )
54 std::string int_choice =
55 this->m_Parameters->GetSelectedChoice( "InterpolationType" );
56 std::string scalar_choice =
57 this->m_Parameters->GetSelectedChoice( "ScalarType" );
59 if( int_choice == "Linear" )
61 if( scalar_choice == "float" )
63 this->_GD1< itk::LinearInterpolateImageFunction< I, float > >( )
65 else if( scalar_choice == "double" )
67 this->_GD1< itk::LinearInterpolateImageFunction< I, double > >( )
70 return( "ImageInterpolatorSource: Invalid scalar type" );
72 else if( int_choice == "NearestNeighbor" )
74 if( scalar_choice == "float" )
76 this->_GD1< itk::NearestNeighborInterpolateImageFunction< I, float > >( )
78 else if( scalar_choice == "double" )
80 this->_GD1< itk::NearestNeighborInterpolateImageFunction< I, double > >( )
83 return( "ImageInterpolatorSource: Invalid scalar type" );
86 return( "ImageInterpolatorSource: Invalid interpolator" );
89 // -------------------------------------------------------------------------
91 std::string cpPlugins::BasicFilters::ImageInterpolatorSource::
95 this->GetOutputData< cpPlugins::Interface::DataObject >( "Output" );
96 if( out->GetITK< T >( ) == NULL )
98 typename T::Pointer res = T::New( );
99 out->SetITK( res.GetPointer( ) );