1 #include <plugins/Plugins/ExtractPathFromMinimumSpanningTree.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/PolyLineParametricPath.h>
4 #include <fpa_DataObjects.h>
5 #include <vtkPolyData.h>
7 // -------------------------------------------------------------------------
8 fpaPlugins::ExtractPathFromMinimumSpanningTree::
9 ExtractPathFromMinimumSpanningTree( )
12 typedef cpPlugins::BaseObjects::DataObject _TData;
13 typedef cpPlugins::DataObjects::Image _TMST;
14 typedef cpPlugins::DataObjects::PolyLineParametricPath _TPath;
16 this->_ConfigureInput< _TMST >( "MST", true, false );
17 this->_ConfigureInput< _TData >( "Seeds", true, false );
18 this->_ConfigureOutput< _TPath >( "Paths" );
21 // -------------------------------------------------------------------------
22 fpaPlugins::ExtractPathFromMinimumSpanningTree::
23 ~ExtractPathFromMinimumSpanningTree( )
27 // -------------------------------------------------------------------------
28 void fpaPlugins::ExtractPathFromMinimumSpanningTree::
31 typedef fpa::Image::MinimumSpanningTree< 2 > _TMST2;
32 typedef fpa::Image::MinimumSpanningTree< 3 > _TMST3;
34 auto mst2 = this->GetInputData< _TMST2 >( "MST" );
35 auto mst3 = this->GetInputData< _TMST3 >( "MST" );
36 if ( mst2 != NULL ) this->_GD0( mst2 );
37 else if( mst3 != NULL ) this->_GD0( mst3 );
38 else this->_Error( "Invalid input spanning tree." );
41 // -------------------------------------------------------------------------
42 template< class _TMST >
43 void fpaPlugins::ExtractPathFromMinimumSpanningTree::
46 typedef typename _TMST::IndexType _TIndex;
47 typedef typename _TMST::TPath _TPath;
50 std::vector< _TIndex > seeds;
51 auto points = this->GetInputData< vtkPolyData >( "Seeds" );
54 if( points->GetNumberOfPoints( ) < 2 )
55 this->_Error( "Not enough seeds (<2)." );
57 typename _TMST::PointType pnt;
58 typename _TMST::IndexType idx;
60 ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3;
61 for( unsigned int i = 0; i < 2; ++i )
64 points->GetPoint( i, buf );
66 for( unsigned int d = 0; d < dim; ++d )
68 if( mst->TransformPhysicalPointToIndex( pnt, idx ) )
69 seeds.push_back( idx );
75 typename _TPath::Pointer path;
76 mst->GetPath( path, seeds[ 0 ], seeds[ 1 ] );
77 this->GetOutput( "Paths" )->SetITK( path );