]> Creatis software - FrontAlgorithms.git/blob - plugins/fpa/GradientBaseImageFunctionSource.cxx
...
[FrontAlgorithms.git] / plugins / fpa / GradientBaseImageFunctionSource.cxx
1 #include "GradientBaseImageFunctionSource.h"
2
3 #include <cpPlugins/Image.h>
4 #include <fpa_Instances/Functors.h>
5
6 // -------------------------------------------------------------------------
7 fpaPlugins::GradientBaseImageFunctionSource::
8 GradientBaseImageFunctionSource( )
9   : Superclass( )
10 {
11   this->_AddInput( "Input" );
12   this->_AddOutput< cpPlugins::Image >( "Output" );
13
14   std::vector< std::string > choices;
15   choices.push_back( "Gulsun&Tek" );
16   choices.push_back( "Flux" );
17   choices.push_back( "MFlux" );
18   this->m_Parameters.ConfigureAsChoices( "FunctionType", choices );
19   this->m_Parameters.SetSelectedChoice( "FunctionType", "Gulsun&Tek" );
20
21   this->m_Parameters.ConfigureAsReal( "MinRadius" );
22   this->m_Parameters.ConfigureAsReal( "MaxRadius" );
23   this->m_Parameters.ConfigureAsUint( "ProfileSampling" );
24   this->m_Parameters.ConfigureAsUint( "RadialSampling" );
25   this->m_Parameters.SetReal( "MinRadius", 0 );
26   this->m_Parameters.SetReal( "MaxRadius", 1 );
27   this->m_Parameters.SetUint( "ProfileSampling", 4 );
28   this->m_Parameters.SetUint( "RadialSampling", 10 );
29 }
30
31 // -------------------------------------------------------------------------
32 fpaPlugins::GradientBaseImageFunctionSource::
33 ~GradientBaseImageFunctionSource( )
34 {
35 }
36
37 // -------------------------------------------------------------------------
38 void fpaPlugins::GradientBaseImageFunctionSource::
39 _GenerateData( )
40 {
41   auto image = this->GetInputData< itk::DataObject >( "Input" );
42   cpPlugins_Image_Demangle_VectorPixel_AllFloats     ( _GD0, image, CovariantVector, 2 );
43   else cpPlugins_Image_Demangle_VectorPixel_AllFloats( _GD0, image, CovariantVector, 3 );
44   else this->_Error( "Invalid input image." );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class _TImage >
49 void fpaPlugins::GradientBaseImageFunctionSource::
50 _GD0( _TImage* image )
51 {
52   typedef fpa::Image::Functors::GulsunTekMedialness< _TImage > _TGT;
53   typedef fpa::Image::Functors::FluxMedialness< _TImage > _TFl;
54   typedef fpa::Image::Functors::MFluxMedialness< _TImage > _TMFl;
55
56   auto ft = this->m_Parameters.GetSelectedChoice( "FunctionType" );
57   if     ( ft == "Gulsun&Tek" ) this->_GD1< _TImage, _TGT >( image );
58   else if( ft == "Flux" )       this->_GD1< _TImage, _TFl >( image );
59   else if( ft == "MFlux" )      this->_GD1< _TImage, _TMFl >( image );
60   else this->_Error( "Invalid function type." );
61 }
62
63 // -------------------------------------------------------------------------
64 template< class _TImage, class _TFunction >
65 void fpaPlugins::GradientBaseImageFunctionSource::
66 _GD1( _TImage* image )
67 {
68   typedef itk::Image< typename _TFunction::TOutput, _TImage::ImageDimension > _TOutImage;
69   typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutImage, _TFunction > _TFilter;
70
71   _TFilter* filter = this->_CreateITK< _TFilter >( );
72   filter->SetInput( image );
73   _TFunction* function = filter->GetFunction( );
74   if( function == NULL )
75   {
76     filter->SetFunction( _TFunction::New( ) );
77     function = filter->GetFunction( );
78
79   } // fi
80   function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
81   function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
82   /*
83     function->SetProfileSampling( this->m_Parameters.GetUint( "ProfileSampling" ) );
84     function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
85   */
86
87   filter->Update( );
88
89   // Connect output and finish
90   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
91 }
92
93 // eof - $RCSfile$