]> Creatis software - FrontAlgorithms.git/blob - plugins/Plugins/ImageDijkstra.cxx
be69f49e8f91f4dfe303e82d78f0111da9614d02
[FrontAlgorithms.git] / plugins / Plugins / ImageDijkstra.cxx
1 #include "ImageDijkstra.h"
2 // TODO: #include "MinimumSpanningTree.h"
3
4 #include <cpPlugins/DataObjects/Image.h>
5 #include <fpa/Image/Dijkstra.h>
6
7 #include <fpa/Base/Algorithm.hxx>
8 #include <fpa/Base/Dijkstra.hxx>
9 #include <fpa/Image/Algorithm.hxx>
10 #include <fpa/Image/Dijkstra.hxx>
11
12 // -------------------------------------------------------------------------
13 fpaPlugins::ImageDijkstra::
14 ImageDijkstra( )
15   : Superclass( )
16 {
17   this->_ConfigureInput< cpPlugins::BaseObjects::DataObject >( "CostFunctor", false, false );
18   this->_ConfigureOutput< cpPlugins::BaseObjects::DataObject >( "MST" );
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   this->m_Parameters.ConfigureAsBool( "FillNodeQueue" );
25   this->m_Parameters.SetBool( "FillNodeQueue", false );
26 }
27
28 // -------------------------------------------------------------------------
29 fpaPlugins::ImageDijkstra::
30 ~ImageDijkstra( )
31 {
32 }
33
34 // -------------------------------------------------------------------------
35 void fpaPlugins::ImageDijkstra::
36 _GenerateData( )
37 {
38   auto o = this->GetInputData( "Input" );
39   cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
40   else this->_Error( "Invalid input image." );
41 }
42
43 // -------------------------------------------------------------------------
44 template< class _TImage >
45 void fpaPlugins::ImageDijkstra::
46 _GD0( _TImage* image )
47 {
48   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
49   if( rtype == "float" )       this->_GD1< _TImage, float >( image );
50   else if( rtype == "double" ) this->_GD1< _TImage, double >( image );
51 }
52
53 // -------------------------------------------------------------------------
54 template< class _TInputImage, class _TOutput >
55 void fpaPlugins::ImageDijkstra::
56 _GD1( _TInputImage* input )
57 {
58   typedef itk::Image< _TOutput, _TInputImage::ImageDimension > _TOutputImage;
59   typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage >  _TFilter;
60   typedef typename _TFilter::TCostConversionFunction           _TCostFunctor;
61
62   // Get functor
63   auto base_functor =
64     this->GetInputData< itk::LightObject >( "CostFunctor" );
65   _TCostFunctor* functor = NULL;
66   if( base_functor != NULL )
67   {
68     functor = dynamic_cast< _TCostFunctor* >( base_functor );
69     if( functor == NULL )
70       this->_Error( "Given cost functor is invalid." );
71
72   } // fi
73
74   // Create filter
75   _TFilter* filter = this->_ConfigureFilter< _TFilter >( );
76   // TODO: filter->SetFillNodeQueue( this->m_Parameters.GetBool( "FillNodeQueue" ) );
77   filter->SetCostConversionFunction( functor );
78
79   // Go!!!
80   this->_ExecuteFilter( filter );
81
82   // Connect remaining output
83   this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) );
84 }
85
86 // eof - $RCSfile$