]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsImageFilters/ResampleImageFilter.cxx
8c9a8dd2eb070a0c518d917f154a92e24bf3c0a4
[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, 2 );
31   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
32   /* TODO
33      if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 1 );
34      if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 4 );
35   */
36   return( r );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class _TImage >
41 std::string cpPluginsImageFilters::ResampleImageFilter::
42 _GD0( _TImage* image )
43 {
44   if( image != NULL )
45   {
46     auto choice = this->m_Parameters.GetSelectedChoice( "OutputResolution" );
47     if( choice == "float" )
48       return( this->_GD1< _TImage, float >( image ) );
49     else if( choice == "double" )
50       return( this->_GD1< _TImage, double >( image ) );
51     else return( "ResampleImageFilter: no valid scalar type." );
52   }
53   else
54     return(
55       "ResampleImageFilter: No valid input image."
56       );
57 }
58
59 // -------------------------------------------------------------------------
60 template< class _TImage, class _TScalar >
61 std::string cpPluginsImageFilters::ResampleImageFilter::
62 _GD1( _TImage* image )
63 {
64   typedef
65     itk::ResampleImageFilter< _TImage, _TImage, _TScalar, _TScalar >
66     _TFilter;
67
68   if( image == NULL )
69     return(
70       "ImageFilters::ResampleImageFilter: No valid input image."
71       );
72
73   // Configure filter
74   _TFilter* filter = this->_CreateITK< _TFilter >( );
75   filter->SetInput( image );
76
77   // Connect output
78   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
79   return( "" );
80 }
81
82 // eof - $RCSfile$