]> Creatis software - FrontAlgorithms.git/blobdiff - plugins/Plugins/ExtractPathFromMinimumSpanningTree.cxx
...
[FrontAlgorithms.git] / plugins / Plugins / ExtractPathFromMinimumSpanningTree.cxx
index f6b69d19fd80610a462d6ab5beaec7d7574bbded..c80ffde353e426ab9eb89ae8727015093347bba6 100644 (file)
@@ -1,27 +1,21 @@
 #include <plugins/Plugins/ExtractPathFromMinimumSpanningTree.h>
 #include <cpPlugins/DataObjects/Image.h>
-#include <cpPlugins/DataObjects/Mesh.h>
+#include <cpPlugins/DataObjects/PolyLineParametricPath.h>
 #include <fpa_DataObjects.h>
-
-/* TODO
-   #include <vtkFloatArray.h>
-   #include <vtkPointData.h>
-*/
+#include <vtkPolyData.h>
 
 // -------------------------------------------------------------------------
 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$