]> Creatis software - FrontAlgorithms.git/blob - plugins/DijkstraFunctors/SimpleImageDijkstraCost.cxx
update
[FrontAlgorithms.git] / plugins / DijkstraFunctors / SimpleImageDijkstraCost.cxx
1 #include <DijkstraFunctors/SimpleImageDijkstraCost.h>
2 #include <cpInstances/DataObjects/Image.h>
3
4 #include <itkImage.h>
5 #include <fpa/Image/Functors/SimpleDijkstraCost.h>
6
7 // -------------------------------------------------------------------------
8 fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost::
9 SimpleImageDijkstraCost( )
10   : Superclass( )
11 {
12   typedef cpPlugins::Pipeline::DataObject _TData;
13   typedef cpInstances::DataObjects::Image _TImage;
14
15   this->_ConfigureInput< _TImage >( "Input", true, false );
16   this->_ConfigureOutput< _TData >( "Output" );
17
18   std::vector< std::string > choices;
19   choices.push_back( "float" );
20   choices.push_back( "double" );
21   this->m_Parameters.ConfigureAsChoices( "ResultType", choices );
22   this->m_Parameters.SetSelectedChoice( "ResultType", "float" );
23   this->m_Parameters.ConfigureAsBool( "UseImageSpacing", false );
24 }
25
26 // -------------------------------------------------------------------------
27 fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost::
28 ~SimpleImageDijkstraCost( )
29 {
30 }
31
32 // -------------------------------------------------------------------------
33 void fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost::
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 fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost::
44 _GD0( _TImage* image )
45 {
46   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
47   if     ( rtype == "float"  ) this->_GD1< _TImage, float >( image );
48   else if( rtype == "double" ) this->_GD1< _TImage, double >( image );
49 }
50
51 // -------------------------------------------------------------------------
52 template< class _TImage, class _TOutput >
53 void fpaPluginsDijkstraFunctors::SimpleImageDijkstraCost::
54 _GD1( _TImage* image )
55 {
56   typedef
57     fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput >
58     _TFunctor;
59   auto out = this->GetOutput( "Output" );
60   auto f = out->GetITK< _TFunctor >( );
61   if( f == NULL )
62   {
63     typename _TFunctor::Pointer ptr_f = _TFunctor::New( );
64     f = ptr_f.GetPointer( );
65     out->SetITK( f );
66
67   } // fi
68   f->SetUseImageSpacing( this->m_Parameters.GetBool( "UseImageSpacing" ) );
69 }
70
71 // eof - $RCSfile$