]> Creatis software - FrontAlgorithms.git/blob - plugins/fpa/GradientBaseImageFunctionSource.cxx
926523d9dcdbe162e439d5253f87b0392ba39fe2
[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 std::string fpaPlugins::GradientBaseImageFunctionSource::
39 _GenerateData( )
40 {
41   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
42   std::string   cpPlugin_Image_Demangle_VectorPixel_AllFloats( r, _GD0, image, itk::CovariantVector, 2 );
43   if( r != "" ) cpPlugin_Image_Demangle_VectorPixel_AllFloats( r, _GD0, image, itk::CovariantVector, 3 );
44   return( r );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class _TImage >
49 std::string 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   if( image == NULL )
57     return( "GradientBaseImageFunctionSource: Invalid input image." );
58
59   auto ft = this->m_Parameters.GetSelectedChoice( "FunctionType" );
60   if     ( ft == "Gulsun&Tek" ) return( this->_GD1< _TImage, _TGT >( image ) );
61   else if( ft == "Flux" )       return( this->_GD1< _TImage, _TFl >( image ) );
62   else if( ft == "MFlux" )      return( this->_GD1< _TImage, _TMFl >( image ) );
63   else
64     return( "GradientBaseImageFunctionSource: Invalid function type." );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TImage, class _TFunction >
69 std::string fpaPlugins::GradientBaseImageFunctionSource::
70 _GD1( _TImage* image )
71 {
72   typedef itk::Image< typename _TFunction::TOutput, _TImage::ImageDimension > _TOutImage;
73   typedef cpExtensions::Algorithms::ImageFunctionFilter< _TImage, _TOutImage, _TFunction > _TFilter;
74
75   _TFilter* filter = this->_CreateITK< _TFilter >( );
76   filter->SetInput( image );
77   _TFunction* function = filter->GetFunction( );
78   if( function == NULL )
79   {
80     filter->SetFunction( _TFunction::New( ) );
81     function = filter->GetFunction( );
82
83   } // fi
84   function->SetMinRadius( this->m_Parameters.GetReal( "MinRadius" ) );
85   function->SetMaxRadius( this->m_Parameters.GetReal( "MaxRadius" ) );
86   /*
87     function->SetProfileSampling( this->m_Parameters.GetUint( "ProfileSampling" ) );
88     function->SetRadialSampling( this->m_Parameters.GetUint( "RadialSampling" ) );
89   */
90
91   filter->Update( );
92
93   // Connect output and finish
94   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
95   return( "" );
96 }
97
98 // eof - $RCSfile$