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