]> Creatis software - FrontAlgorithms.git/blob - plugins/ImageAlgorithms/FastMarching.cxx
5805e307adc2a629b68b61e3051b7d046f07a38a
[FrontAlgorithms.git] / plugins / ImageAlgorithms / FastMarching.cxx
1 #include <ImageAlgorithms/FastMarching.h>
2 #include <cpInstances/DataObjects/Image.h>
3
4 #include <fpa/Image/FastMarching.h>
5
6 // -------------------------------------------------------------------------
7 fpaPluginsImageAlgorithms::FastMarching::
8 FastMarching( )
9   : Superclass( )
10 {
11   typedef cpPlugins::Pipeline::DataObject _TData;
12   typedef cpInstances::DataObjects::Image _TMST;
13
14   this->_ConfigureInput< _TData >( "VertexFunction", false, false );
15   this->_ConfigureInput< _TData >( "ConversionFunction", false, false );
16   this->_ConfigureOutput< _TMST >( "MST" );
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 }
24
25 // -------------------------------------------------------------------------
26 fpaPluginsImageAlgorithms::FastMarching::
27 ~FastMarching( )
28 {
29 }
30
31 // -------------------------------------------------------------------------
32 void fpaPluginsImageAlgorithms::FastMarching::
33 _GenerateData( )
34 {
35   auto o = this->GetInputData( "Input" );
36   cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
37     this->_Error( "Invalid input image." );
38 }
39
40 // -------------------------------------------------------------------------
41 template< class _TImage >
42 void fpaPluginsImageAlgorithms::FastMarching::
43 _GD0( _TImage* image )
44 {
45   typedef itk::Image< float, _TImage::ImageDimension >  _TFloat;
46   typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
47
48   auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
49   if     ( rtype == "float"  ) this->_GD1< _TImage, _TFloat >( image );
50   else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image );
51 }
52
53 // -------------------------------------------------------------------------
54 template< class _TInputImage, class _TOutputImage >
55 void fpaPluginsImageAlgorithms::FastMarching::
56 _GD1( _TInputImage* image )
57 {
58   typedef fpa::Image::FastMarching< _TInputImage, _TOutputImage > _TFilter;
59   typedef typename _TFilter::TConversionFunction      _TConversionFunction;
60   typedef typename _TFilter::TVertexFunction              _TVertexFunction;
61
62   auto filter = this->_CreateITK< _TFilter >( );
63   std::vector< typename _TInputImage::IndexType > seeds;
64   this->_ConfigureFilter( filter, image, seeds );
65   filter->ClearSeeds( );
66   for( auto seed : seeds )
67     filter->AddSeed( seed, ( typename _TOutputImage::PixelType )( 0 ) );
68   filter->Update( );
69   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
70
71   /* TODO
72      auto filter = this->_CreateITK< _TFilter >( );
73      this->_ConfigureFilter( filter, image );
74      auto cost = this->GetInputData< _TCost >( "Cost" );
75      auto conv = this->GetInputData< _TCostConversion >( "CostConversion" );
76      if( cost != NULL )
77      filter->SetCostFunction( cost );
78      if( conv != NULL )
79      filter->SetCostConversionFunction( conv );
80      filter->Update( );
81      this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
82      this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) );
83   */
84 }
85
86 // eof - $RCSfile$