]> Creatis software - FrontAlgorithms.git/blob - plugins/fpa/ImageDijkstra.cxx
cd34a9c7c30687f1e1b778cafaeee7c658213e80
[FrontAlgorithms.git] / plugins / fpa / ImageDijkstra.cxx
1 #include "ImageDijkstra.h"
2 #include "MinimumSpanningTree.h"
3
4 #include <cpPlugins/Image.h>
5 #include <fpa/Image/Dijkstra.h>
6 #include <fpa/Base/Dijkstra.hxx>
7 #include <fpa/Image/Dijkstra.hxx>
8 #include <fpa/Base/Algorithm.hxx>
9 #include <fpa/Image/Algorithm.hxx>
10 #include <fpa/Base/Functors/InvertCostFunction.h>
11 #include <itkSimpleDataObjectDecorator.hxx>
12
13 // -------------------------------------------------------------------------
14 fpaPlugins::ImageDijkstra::
15 ImageDijkstra( )
16   : Superclass( )
17 {
18   this->_AddInput( "CostFunctor", false );
19   this->_AddOutput< fpaPlugins::MinimumSpanningTree >( "MST" );
20   this->m_Parameters.ConfigureAsBool( "FillNodeQueue" );
21   this->m_Parameters.SetBool( "FillNodeQueue", false );
22 }
23
24 // -------------------------------------------------------------------------
25 fpaPlugins::ImageDijkstra::
26 ~ImageDijkstra( )
27 {
28 }
29
30 // -------------------------------------------------------------------------
31 std::string fpaPlugins::ImageDijkstra::
32 _GenerateData( )
33 {
34   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
35   std::string   cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 2 );
36   if( r != "" ) cpPlugin_Image_Demangle_Pixel_AllScalars( r, _GD0, image, 3 );
37   return( r );
38 }
39
40 // -------------------------------------------------------------------------
41 template< class _TImage >
42 std::string fpaPlugins::ImageDijkstra::
43 _GD0( _TImage* image )
44 {
45   typedef fpa::Image::Dijkstra< _TImage, _TImage > _TFilter;
46   typedef typename _TFilter::TResult               _TCost;
47   typedef itk::FunctionBase< _TCost, _TCost >      _TCostFunctor;
48   typedef typename _TFilter::TMinimumSpanningTree  _TMST;
49
50   if( image == NULL )
51     return( "fpaPlugins::ImageDijkstra: Invalid image type." );
52
53   auto base_functor =
54     this->GetInputData( "CostFunctor" )->GetITK< itk::LightObject >( );
55   _TCostFunctor* functor = NULL;
56   if( base_functor != NULL )
57   {
58     functor = dynamic_cast< _TCostFunctor* >( base_functor );
59     if( functor == NULL )
60       return( "fpaPlugins::ImageDijkstra: Given cost functor is invalid." );
61
62   } // fi
63   
64   // Create filter
65   _TFilter* filter = this->_ConfigureFilter< _TFilter >( );
66   filter->SetFillNodeQueue( this->m_Parameters.GetBool( "FillNodeQueue" ) );
67   filter->SetConversionFunction( functor );
68
69   // Go!!!
70   this->_ExecuteFilter( filter );
71
72   // Connect remaining output
73   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
74   this->GetOutputData( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) );
75   return( "" );
76 }
77
78 // eof - $RCSfile$