X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=plugins%2FPlugins%2FExtractPathFromMinimumSpanningTree.cxx;fp=plugins%2FPlugins%2FExtractPathFromMinimumSpanningTree.cxx;h=c80ffde353e426ab9eb89ae8727015093347bba6;hb=203ea510f7cc3990e606dd93a97dd0b5075d35c4;hp=f6b69d19fd80610a462d6ab5beaec7d7574bbded;hpb=3f4722ccf68d830e26dac9b945925efa68e39e4c;p=FrontAlgorithms.git diff --git a/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx b/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx index f6b69d1..c80ffde 100644 --- a/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx +++ b/plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx @@ -1,27 +1,21 @@ #include #include -#include +#include #include - -/* TODO - #include - #include -*/ +#include // ------------------------------------------------------------------------- fpaPlugins::ExtractPathFromMinimumSpanningTree:: ExtractPathFromMinimumSpanningTree( ) : Superclass( ) { - typedef cpPlugins::BaseObjects::DataObject _TData; - typedef cpPlugins::DataObjects::Image _TMST; - typedef cpPlugins::DataObjects::Mesh _TMesh; + typedef cpPlugins::BaseObjects::DataObject _TData; + typedef cpPlugins::DataObjects::Image _TMST; + typedef cpPlugins::DataObjects::PolyLineParametricPath _TPath; this->_ConfigureInput< _TMST >( "MST", true, false ); this->_ConfigureInput< _TData >( "Seeds", true, false ); - this->_ConfigureOutput< _TMesh >( "Paths" ); - - this->m_Parameters.ConfigureAsUintList( "Indices" ); + this->_ConfigureOutput< _TPath >( "Paths" ); } // ------------------------------------------------------------------------- @@ -50,17 +44,21 @@ void fpaPlugins::ExtractPathFromMinimumSpanningTree:: _GD0( _TMST* mst ) { typedef typename _TMST::IndexType _TIndex; + typedef typename _TMST::TPath _TPath; // Get seeds std::vector< _TIndex > seeds; auto points = this->GetInputData< vtkPolyData >( "Seeds" ); if( points != NULL ) { + if( points->GetNumberOfPoints( ) < 2 ) + this->_Error( "Not enough seeds (<2)." ); + typename _TMST::PointType pnt; typename _TMST::IndexType idx; unsigned int dim = ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3; - for( unsigned int i = 0; i < points->GetNumberOfPoints( ); ++i ) + for( unsigned int i = 0; i < 2; ++i ) { double buf[ 3 ]; points->GetPoint( i, buf ); @@ -74,51 +72,9 @@ _GD0( _TMST* mst ) } // fi - // Prepare result - auto mesh = this->_CreateVTK< vtkPolyData >( ); - mesh->SetPoints( vtkSmartPointer< vtkPoints >::New( ) ); - mesh->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) ); - mesh->SetLines( vtkSmartPointer< vtkCellArray >::New( ) ); - mesh->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) ); - mesh->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) ); - /* TODO - vtkSmartPointer< vtkFloatArray > data = - vtkSmartPointer< vtkFloatArray >::New( ); - data->SetNumberOfComponents( 1 ); - mesh->GetPointData( )->SetScalars( data ); - */ - - // Compute - auto indices = this->m_Parameters.GetUintList( "Indices" ); - for( unsigned int i = 0; i < indices.size( ); i += 2 ) - { - if( i < indices.size( ) - 1 ) - { - _TIndex a = seeds[ indices[ i ] ]; - _TIndex b = seeds[ indices[ i + 1 ] ]; - - auto path = mst->GetEuclideanPath( a, b ); - for( unsigned long j = 0; j < path.size( ); ++j ) - { - auto p = path[ j ]; - if( _TMST::ImageDimension == 2 ) - mesh->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 ); - else if( _TMST::ImageDimension == 3 ) - mesh->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], p[ 2 ] ); - if( j > 0 ) - { - mesh->GetLines( )->InsertNextCell( 2 ); - mesh->GetLines( )->InsertCellPoint( j - 1 ); - mesh->GetLines( )->InsertCellPoint( j ); - - } // fi - - } // rof - - } // fi - - } // rof - this->GetOutput( "Paths" )->SetVTK( mesh ); + typename _TPath::Pointer path; + mst->GetPath( path, seeds[ 0 ], seeds[ 1 ] ); + this->GetOutput( "Paths" )->SetITK( path ); } // eof - $RCSfile$