]> 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 void fpaPlugins::ImageDijkstra::
26 _GenerateData( )
27 {
28   auto image = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
29   cpPlugins_Image_Demangle_Pixel_AllScalars     ( _GD0, image, 2 );
30   else cpPlugins_Image_Demangle_Pixel_AllScalars( _GD0, image, 3 );
31   else this->_Error( "No valid input image." );
32 }
33
34 // -------------------------------------------------------------------------
35 template< class _TImage >
36 void 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   auto base_functor =
47     this->GetInputData( "CostFunctor" )->GetITK< itk::LightObject >( );
48   _TCostFunctor* functor = NULL;
49   if( base_functor != NULL )
50   {
51     functor = dynamic_cast< _TCostFunctor* >( base_functor );
52     if( functor == NULL )
53       this->_Error( "Given cost functor is invalid." );
54
55   } // fi
56   
57   // Create filter
58   _TFilter* filter = this->_ConfigureFilter< _TFilter >( );
59   filter->SetFillNodeQueue( this->m_Parameters.GetBool( "FillNodeQueue" ) );
60   filter->SetConversionFunction( functor );
61
62   // Go!!!
63   this->_ExecuteFilter( filter );
64
65   // Connect remaining output
66   this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
67   this->GetOutputData( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) );
68 }
69
70 // eof - $RCSfile$