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