]> Creatis software - FrontAlgorithms.git/blob - plugins/Plugins/SimpleImageDijkstraCost.cxx
...
[FrontAlgorithms.git] / plugins / Plugins / SimpleImageDijkstraCost.cxx
1 #include <Plugins/SimpleImageDijkstraCost.h>
2 #include <cpInstances/Image.h>
3 #include <cpInstances/Image_Demanglers.h>
4
5 #include <itkImage.h>
6 #include <fpa/Image/Functors/SimpleDijkstraCost.h>
7
8 // -------------------------------------------------------------------------
9 fpaPlugins::SimpleImageDijkstraCost::
10 SimpleImageDijkstraCost( )
11   : Superclass( )
12 {
13   typedef cpPlugins::BaseObjects::DataObject _TData;
14   typedef cpInstances::Image _TImage;
15
16   this->_ConfigureInput< _TImage >( "Input", true, false );
17   this->_ConfigureOutput< _TData >( "Output" );
18
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( "UseImageSpacing", false );
25 }
26
27 // -------------------------------------------------------------------------
28 fpaPlugins::SimpleImageDijkstraCost::
29 ~SimpleImageDijkstraCost( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 void fpaPlugins::SimpleImageDijkstraCost::
35 _GenerateData( )
36 {
37   auto o = this->GetInputData( "Input" );
38   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
39     this->_Error( "Invalid input image." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TImage >
44 void fpaPlugins::SimpleImageDijkstraCost::
45 _GD0( _TImage* image )
46 {
47   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
48   if     ( rtype == "float"  ) this->_GD1< _TImage, float >( image );
49   else if( rtype == "double" ) this->_GD1< _TImage, double >( image );
50 }
51
52 // -------------------------------------------------------------------------
53 template< class _TImage, class _TOutput >
54 void fpaPlugins::SimpleImageDijkstraCost::
55 _GD1( _TImage* image )
56 {
57   typedef
58     fpa::Image::Functors::SimpleDijkstraCost< _TImage, _TOutput >
59     _TFunctor;
60   auto out = this->GetOutput( "Output" );
61   auto f = out->GetITK< _TFunctor >( );
62   if( f == NULL )
63   {
64     typename _TFunctor::Pointer ptr_f = _TFunctor::New( );
65     f = ptr_f.GetPointer( );
66     out->SetITK( f );
67
68   } // fi
69   f->SetUseImageSpacing( this->m_Parameters.GetBool( "UseImageSpacing" ) );
70 }
71
72 // eof - $RCSfile$