1 #include <plugins/Plugins/ImageDijkstra.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <vtkPolyData.h>
5 #include <fpa/Image/Dijkstra.h>
6 #include <fpa/Base/Dijkstra.hxx>
7 #include <fpa/Image/Dijkstra.hxx>
9 // -------------------------------------------------------------------------
10 fpaPlugins::ImageDijkstra::
14 typedef cpPlugins::BaseObjects::DataObject _TData;
15 typedef cpPlugins::DataObjects::Image _TMST;
17 this->_ConfigureInput< _TData >( "Cost", false, false );
18 this->_ConfigureInput< _TData >( "CostConversion", false, false );
19 this->_ConfigureOutput< _TMST >( "MST" );
21 std::vector< std::string > choices;
22 choices.push_back( "float" );
23 choices.push_back( "double" );
24 this->m_Parameters.ConfigureAsChoices( "ResultType", choices );
25 this->m_Parameters.SetSelectedChoice( "ResultType", "float" );
28 // -------------------------------------------------------------------------
29 fpaPlugins::ImageDijkstra::
34 // -------------------------------------------------------------------------
35 void fpaPlugins::ImageDijkstra::
38 auto o = this->GetInputData( "Input" );
39 cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
40 else this->_Error( "Invalid input image." );
43 // -------------------------------------------------------------------------
44 template< class _TImage >
45 void fpaPlugins::ImageDijkstra::
46 _GD0( _TImage* image )
48 typedef itk::Image< float, _TImage::ImageDimension > _TFloat;
49 typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
51 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
52 if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image );
53 else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image );
56 // -------------------------------------------------------------------------
57 template< class _TInputImage, class _TOutputImage >
58 void fpaPlugins::ImageDijkstra::
59 _GD1( _TInputImage* image )
61 typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage > _TFilter;
62 typedef typename _TFilter::TCostConversionFunction _TCostConversion;
63 typedef typename _TFilter::TCostFunction _TCost;
64 typedef typename _TFilter::TNeighborhoodFunction _TNeighborhood;
67 auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" );
68 auto cost = this->GetInputData< _TCost >( "Cost" );
69 auto conv = this->GetInputData< _TCostConversion >( "CostConversion" );
72 auto filter = this->_CreateITK< _TFilter >( );
73 filter->SetInput( image );
75 filter->SetNeighborhoodFunction( neig );
77 filter->SetCostFunction( cost );
79 filter->SetCostConversionFunction( conv );
80 filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) );
83 auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
86 typename _TInputImage::PointType pnt;
87 typename _TInputImage::IndexType idx;
89 ( _TInputImage::ImageDimension < 3 )? _TInputImage::ImageDimension: 3;
90 for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i )
93 seeds->GetPoint( i, buf );
95 for( unsigned int d = 0; d < dim; ++d )
98 if( image->TransformPhysicalPointToIndex( pnt, idx ) )
99 filter->AddSeed( idx, 0 );
107 this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
108 this->GetOutput( "MST" )->SetITK( filter->GetMinimumSpanningTree( ) );