1 #include <Plugins/ImageDijkstra.h>
2 #include <cpInstances/Image.h>
3 #include <cpInstances/Image_Demanglers.h>
5 #include <fpa/Image/Dijkstra.h>
6 #include <vtkPolyData.h>
8 // -------------------------------------------------------------------------
9 fpaPlugins::ImageDijkstra::
13 typedef cpPlugins::BaseObjects::DataObject _TData;
14 typedef cpInstances::Image _TMST;
16 this->_ConfigureInput< _TData >( "Cost", false, false );
17 this->_ConfigureInput< _TData >( "CostConversion", false, false );
18 this->_ConfigureOutput< _TMST >( "MST" );
20 std::vector< std::string > choices;
21 choices.push_back( "float" );
22 choices.push_back( "double" );
23 this->m_Parameters.ConfigureAsChoices( "ResultType", choices );
24 this->m_Parameters.SetSelectedChoice( "ResultType", "float" );
27 // -------------------------------------------------------------------------
28 fpaPlugins::ImageDijkstra::
33 // -------------------------------------------------------------------------
34 void fpaPlugins::ImageDijkstra::
37 auto o = this->GetInputData( "Input" );
38 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
39 this->_Error( "Invalid input image." );
42 // -------------------------------------------------------------------------
43 template< class _TImage >
44 void fpaPlugins::ImageDijkstra::
45 _GD0( _TImage* image )
47 typedef itk::Image< float, _TImage::ImageDimension > _TFloat;
48 typedef itk::Image< double, _TImage::ImageDimension > _TDouble;
50 auto rtype = this->m_Parameters.GetSelectedChoice( "ResultType" );
51 if ( rtype == "float" ) this->_GD1< _TImage, _TFloat >( image );
52 else if( rtype == "double" ) this->_GD1< _TImage, _TDouble >( image );
55 // -------------------------------------------------------------------------
56 template< class _TInputImage, class _TOutputImage >
57 void fpaPlugins::ImageDijkstra::
58 _GD1( _TInputImage* image )
60 typedef fpa::Image::Dijkstra< _TInputImage, _TOutputImage > _TFilter;
61 typedef typename _TFilter::TCostConversionFunction _TCostConversion;
62 typedef typename _TFilter::TCostFunction _TCost;
63 typedef typename _TFilter::TNeighborhoodFunction _TNeighborhood;
66 auto neig = this->GetInputData< _TNeighborhood >( "Neighborhood" );
67 auto cost = this->GetInputData< _TCost >( "Cost" );
68 auto conv = this->GetInputData< _TCostConversion >( "CostConversion" );
71 auto filter = this->_CreateITK< _TFilter >( );
72 filter->SetInput( image );
74 filter->SetNeighborhoodFunction( neig );
76 filter->SetCostFunction( cost );
78 filter->SetCostConversionFunction( conv );
79 filter->SetStopAtOneFront( this->m_Parameters.GetBool( "StopAtOneFront" ) );
82 auto seeds = this->GetInputData< vtkPolyData >( "Seeds" );
85 typename _TInputImage::PointType pnt;
86 typename _TInputImage::IndexType idx;
88 ( _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( ) );