]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/CPRFilter.cxx
...
[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", true );
13   this->_AddInput( "InputAxis", true );
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   if( image == NULL )
42     return( "CPRFilter: No input image." );
43
44   itk::DataObject* itk_image = NULL;
45   std::string r = "";
46   cpPlugins_Image_Demangle_AllScalarTypes( 3, image, itk_image, r, _GD0 );
47   else r = "CPRFilter: Input image type not supported.";
48   return( r );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class I >
53 std::string cpPlugins::BasicFilters::CPRFilter::
54 _GD0( itk::DataObject* dobj )
55 {
56   I* image = dynamic_cast< I* >( dobj );
57
58   auto choice = this->m_Parameters->GetSelectedChoice( "ScalarType" );
59   if( choice == "float" )
60     return( this->_GD1< I, float >( image ) );
61   else if( choice == "double" )
62     return( this->_GD1< I, double >( image ) );
63   else
64     return( "CPRFilter: Scalar type not supported." );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class I, class S >
69 std::string cpPlugins::BasicFilters::CPRFilter::
70 _GD1( I* image )
71 {
72   typedef cpExtensions::Algorithms::CPRFilter< I, S > _Filter;
73   typedef itk::PolyLineParametricPath< I::ImageDimension > _Path;
74   typedef itk::InterpolateImageFunction< I, S > _Interpolator;
75
76   auto axis =
77     this->GetInputData< cpPlugins::Interface::PolyLineParametricPath >(
78       "InputAxis"
79       )->GetITK< _Path >( );
80   auto w_int =
81     this->GetInputData< cpPlugins::Interface::DataObject >( "Interpolator" );
82   _Interpolator* interpolator = NULL;
83   if( w_int != NULL )
84     interpolator = w_int->GetITK< _Interpolator >( );
85
86   // Configure filter
87   _Filter* filter = this->_CreateITK< _Filter >( );
88   filter->SetInput( image );
89   filter->SetAxis( axis );
90   if( interpolator != NULL )
91     filter->SetInterpolator( interpolator );
92   filter->SetNumberOfSlices( this->m_Parameters->GetUint( "NumberOfSlices" ) );
93   filter->SetSliceRadius( this->m_Parameters->GetReal( "SliceRadius" ) );
94   filter->Update( );
95
96   // Assign output
97   auto out =
98     this->GetOutputData< cpPlugins::Interface::Image >( "Output" );
99   out->SetITK< I >( filter->GetOutput( ) );
100   return( "" );
101 }
102
103 // eof - $RCSfile$