]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/ResampleImageFilter.cxx
...
[cpPlugins.git] / plugins / cpPluginsImageFilters / ResampleImageFilter.cxx
1 #include <cpPluginsImageFilters/ResampleImageFilter.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins_Instances/ResamplingFilters.h>
4
5 // -------------------------------------------------------------------------
6 cpPluginsImageFilters::ResampleImageFilter::
7 ResampleImageFilter( )
8   : Superclass( )
9 {
10   this->_AddInput( "Input" );
11   this->_AddOutput< cpPlugins::Image >( "Output" );
12   std::vector< std::string > choices;
13   choices.push_back( "float" );
14   choices.push_back( "double" );
15   this->m_Parameters.ConfigureAsChoices( "ScalarType", choices );
16   this->m_Parameters.SetSelectedChoice( "ScalarType", "float" );
17 }
18
19 // -------------------------------------------------------------------------
20 cpPluginsImageFilters::ResampleImageFilter::
21 ~ResampleImageFilter( )
22 {
23 }
24
25 // -------------------------------------------------------------------------
26 std::string cpPluginsImageFilters::ResampleImageFilter::
27 _GenerateData( )
28 {
29   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
30   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
31   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
32   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
33   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
34   return( r );
35 }
36
37 // -------------------------------------------------------------------------
38 template< class _TImage >
39 std::string cpPluginsImageFilters::ResampleImageFilter::
40 _GD0( _TImage* image )
41 {
42   if( image != NULL )
43   {
44     auto choice = this->m_Parameters.GetSelectedChoice( "OutputResolution" );
45     if( choice == "float" )
46       return( this->_GD1< _TImage, float >( image ) );
47     else if( choice == "double" )
48       return( this->_GD1< _TImage, double >( image ) );
49     else return( "ResampleImageFilter: no valid scalar type." );
50   }
51   else
52     return(
53       "ResampleImageFilter: No valid input image."
54       );
55 }
56
57 // -------------------------------------------------------------------------
58 template< class _TImage, class _TScalar >
59 std::string cpPluginsImageFilters::ResampleImageFilter::
60 _GD1( _TImage* image )
61 {
62   typedef
63     itk::ResampleImageFilter< _TImage, _TImage, _TScalar, _TScalar >
64     _TFilter;
65
66   if( image == NULL )
67     return(
68       "ImageFilters::ResampleImageFilter: No valid input image."
69       );
70
71   // Configure filter
72   _TFilter* filter = this->_CreateITK< _TFilter >( );
73   filter->SetInput( image );
74
75   // Connect output
76   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
77   return( "" );
78 }
79
80 // eof - $RCSfile$