]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/CPRFilter.cxx
MAC compilation issues solved... Now some tests please
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / CPRFilter.cxx
1 #include "CPRFilter.h"
2 #include <cpPlugins/Interface/Image.h>
3 #include <cpPlugins/Interface/PolyLineParametricPath.h>
4 #include <cpExtensions/Algorithms/CPRFilter.h>
5 #include <itkInterpolateImageFunction.h>
6
7 // -------------------------------------------------------------------------
8 cpPlugins::BasicFilters::CPRFilter::
9 CPRFilter( )
10   : Superclass( )
11 {
12   this->_AddInput( "InputImage" );
13   this->_AddInput( "InputAxis" );
14   this->_AddInput( "Interpolator", false );
15   this->_AddOutput< cpPlugins::Interface::Image >( "Output" );
16
17   this->m_Parameters->ConfigureAsUint( "NumberOfSlices" );
18   this->m_Parameters->ConfigureAsReal( "SliceRadius" );
19   std::vector< std::string > choices;
20   choices.push_back( "float" );
21   choices.push_back( "double" );
22   this->m_Parameters->ConfigureAsChoices( "ScalarType", choices );
23
24   this->m_Parameters->SetUint( "NumberOfSlices", 0 );
25   this->m_Parameters->SetReal( "SliceRadius", 10 );
26   this->m_Parameters->SetSelectedChoice( "ScalarType", "float" );
27 }
28
29 // -------------------------------------------------------------------------
30 cpPlugins::BasicFilters::CPRFilter::
31 ~CPRFilter( )
32 {
33 }
34
35 // -------------------------------------------------------------------------
36 std::string cpPlugins::BasicFilters::CPRFilter::
37 _GenerateData( )
38 {
39   auto image =
40     this->GetInputData< cpPlugins::Interface::Image >( "InputImage" );
41   itk::DataObject* itk_image = NULL;
42   std::string r = "";
43   cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
44   else r = "CPRFilter: Input image type not supported.";
45   return( r );
46 }
47
48 // -------------------------------------------------------------------------
49 template< class I >
50 std::string cpPlugins::BasicFilters::CPRFilter::
51 _GD0( itk::DataObject* dobj )
52 {
53   I* image = dynamic_cast< I* >( dobj );
54
55   auto choice = this->m_Parameters->GetSelectedChoice( "ScalarType" );
56   if( choice == "float" )
57     return( this->_GD1< I, float >( image ) );
58   else if( choice == "double" )
59     return( this->_GD1< I, double >( image ) );
60   else
61     return( "CPRFilter: Scalar type not supported." );
62 }
63
64 // -------------------------------------------------------------------------
65 template< class I, class S >
66 std::string cpPlugins::BasicFilters::CPRFilter::
67 _GD1( I* image )
68 {
69   typedef cpExtensions::Algorithms::CPRFilter< I, S > _Filter;
70   typedef itk::PolyLineParametricPath< I::ImageDimension > _Path;
71   typedef itk::InterpolateImageFunction< I, S > _Interpolator;
72
73   auto axis =
74     this->GetInputData< cpPlugins::Interface::PolyLineParametricPath >(
75       "InputAxis"
76       )->GetITK< _Path >( );
77   if( axis == NULL )
78     return( "CPRFilter: Invalid input axis." );
79   auto w_int =
80     this->GetInputData< cpPlugins::Interface::DataObject >( "Interpolator" );
81   _Interpolator* interpolator = NULL;
82   if( w_int != NULL )
83     interpolator = w_int->GetITK< _Interpolator >( );
84
85   // Configure filter
86   _Filter* filter = this->_CreateITK< _Filter >( );
87   filter->SetInput( image );
88   filter->SetAxis( axis );
89   if( interpolator != NULL )
90     filter->SetInterpolator( interpolator );
91   filter->SetNumberOfSlices( this->m_Parameters->GetUint( "NumberOfSlices" ) );
92   filter->SetSliceRadius( this->m_Parameters->GetReal( "SliceRadius" ) );
93   filter->Update( );
94
95   // Assign output
96   auto out =
97     this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
98   out->SetITK( filter->GetOutput( ) );
99   return( "" );
100 }
101
102 // eof - $RCSfile$