]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/FastMarching.cxx
...
[FrontAlgorithms.git] / plugins / ImageAlgorithms / FastMarching.cxx
1 #include "FastMarching.h"
2 #include <cpPlugins/Pipeline/Functor.h>
3 #include <cpInstances/DataObjects/Image.h>
4
5 #include <fpa/Image/FastMarching.h>
6
7 // -------------------------------------------------------------------------
8 fpaPlugins_ImageAlgorithms::FastMarching::
9 FastMarching( )
10   : Superclass( )
11 {
12   typedef cpPlugins::Pipeline::DataObject _TFunctor;
13
14   this->_ConfigureInput< _TFunctor >( "VertexFunction", false, false );
15   this->_ConfigureInput< _TFunctor >( "ConversionFunction", false, false );
16
17   std::vector< std::string > choices;
18   choices.push_back( "float" );
19   choices.push_back( "double" );
20   this->m_Parameters.ConfigureAsChoices( "ResultType", choices );
21   this->m_Parameters.SetSelectedChoice( "ResultType", "float" );
22 }
23
24 // -------------------------------------------------------------------------
25 fpaPlugins_ImageAlgorithms::FastMarching::
26 ~FastMarching( )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 void fpaPlugins_ImageAlgorithms::FastMarching::
32 _GenerateData( )
33 {
34   auto o = this->GetInputData( "Input" );
35   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
36     this->_Error( "Invalid input image." );
37 }
38
39 // -------------------------------------------------------------------------
40 template< class _TImage >
41 void fpaPlugins_ImageAlgorithms::FastMarching::
42 _GD0( _TImage* image )
43 {
44   typedef itk::Image< float, _TImage::ImageDimension >  _TFloat;
45   typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
46
47   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
48   if     ( rtype == "float"  ) this->_GD1< _TImage, _TFloat >( image );
49   else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TInputImage, class _TOutputImage >
54 void fpaPlugins_ImageAlgorithms::FastMarching::
55 _GD1( _TInputImage* image )
56 {
57   typedef cpPlugins::Pipeline::Functor _TFunctor;
58   typedef fpa::Image::FastMarching< _TInputImage, _TOutputImage > _TFilter;
59   typedef typename _TFilter::TConversionFunction      _TConversionFunction;
60   typedef typename _TFilter::TVertexFunction              _TVertexFunction;
61
62   // Create filter
63   auto filter = this->_CreateITK< _TFilter >( );
64   std::vector< typename _TInputImage::IndexType > seeds;
65   this->_ConfigureFilter( filter, image, seeds );
66
67   // Instantiate functors
68   auto cost_conversion = this->GetInputData< _TFunctor >( "ConversionFunction" );
69   if( cost_conversion != NULL )
70   {
71     cost_conversion->Instantiate( filter );
72     auto cost_conversion_functor = cost_conversion->GetFunctor< _TConversionFunction >( );
73     if( cost_conversion_functor != NULL )
74       filter->SetConversionFunction( cost_conversion_functor );
75
76   } // fi
77
78   auto vertex = this->GetInputData< _TFunctor >( "VertexFunction" );
79   if( vertex != NULL )
80   {
81     vertex->Instantiate( filter );
82     auto vertex_functor = vertex->GetFunctor< _TVertexFunction >( );
83     if( vertex_functor != NULL )
84       filter->SetVertexFunction( vertex_functor );
85
86   } // fi
87
88   // Finish filter's configuration
89   filter->ClearSeeds( );
90   for( auto seed : seeds )
91     filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) );
92   filter->Update( );
93   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
94 }
95
96 // eof - $RCSfile$