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