]> Creatis software - FrontAlgorithms.git/blobdiff - plugins/fpa/ExtractPathFromMinimumSpanningTree.cxx
...
[FrontAlgorithms.git] / plugins / fpa / ExtractPathFromMinimumSpanningTree.cxx
index c263b9c0c09ab8830a78c513fa61f6c7e6a2a75d..0f717abc9e932917458844d187c55b43ffd80226 100644 (file)
@@ -25,44 +25,47 @@ fpaPlugins::ExtractPathFromMinimumSpanningTree::
 }
 
 // -------------------------------------------------------------------------
-std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
+void fpaPlugins::ExtractPathFromMinimumSpanningTree::
 _GenerateData( )
 {
   typedef fpa::Image::MinimumSpanningTree< 2 > _2DMST;
   typedef fpa::Image::MinimumSpanningTree< 3 > _3DMST;
 
-  auto mst = this->GetInputData( "MST" )->GetITK< itk::DataObject >( );
+  auto mst = this->GetInputData< itk::DataObject >( "MST" );
   auto mst2 = dynamic_cast< _2DMST* >( mst );
   auto mst3 = dynamic_cast< _3DMST* >( mst );
-  std::string   r = this->_GD0( mst2 );
-  if( r != "" ) r = this->_GD0( mst3 );
-  return( r );
+  if     ( mst2 != NULL ) this->_GD0( mst2 );
+  else if( mst3 != NULL ) this->_GD0( mst3 );
+  else this->_Error( "Invalid input MST." );
 }
 
 // -------------------------------------------------------------------------
 template< class _TMST >
-std::string fpaPlugins::ExtractPathFromMinimumSpanningTree::
+void fpaPlugins::ExtractPathFromMinimumSpanningTree::
 _GD0( _TMST* mst )
 {
   typedef fpa::Base::ExtractPathFromMinimumSpanningTree< _TMST > _TFilter;
-  typedef
-    cpExtensions::DataStructures::ImageIndexesContainer< _TMST::Dimension >
-    _TVertices;
-  if( mst == NULL )
-    return(
-      "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid input tree."
-      );
-  auto vertices = this->GetInputData( "Seeds" )->GetITK< _TVertices >( );
+  auto vertices = this->GetInputData< vtkPoints >( "Seeds" );
   if( vertices == NULL )
-    return(
-      "fpaPlugins::ExtractPathFromMinimumSpanningTree: No valid vertices."
-      );
-  if( vertices->Get( ).size( ) < 2 )
-    return(
-      "fpaPlugins::ExtractPathFromMinimumSpanningTree: Not enough vertices."
-      );
-  auto v0 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex0" ) ];
-  auto v1 = vertices->Get( )[ this->m_Parameters.GetUint( "Vertex1" ) ];
+    this->_Error( "No valid vertices." );
+  if( vertices->GetNumberOfPoints( ) < 2 )
+    this->_Error( "Not enough vertices." );
+
+  double b0[ 3 ], b1[ 3 ];
+  vertices->GetPoint( this->m_Parameters.GetUint( "Vertex0" ), b0 );
+  vertices->GetPoint( this->m_Parameters.GetUint( "Vertex1" ), b1 );
+
+  typename _TMST::PointType p0, p1;
+  unsigned int dim = ( _TMST::ImageDimension < 3 )? _TMST::ImageDimension: 3;
+  for( unsigned int d = 0; d < dim; ++d )
+  {
+    p0[ d ] = b0[ d ];
+    p1[ d ] = b1[ d ];
+
+  } // rof
+  typename _TMST::TVertex v0, v1;
+  mst->TransformPhysicalPointToIndex( p0, v0 );
+  mst->TransformPhysicalPointToIndex( p1, v1 );
 
   // Create filter and connect input
   _TFilter* filter = this->_CreateITK< _TFilter >( );
@@ -72,8 +75,7 @@ _GD0( _TMST* mst )
   filter->Update( );
 
   // Connect output and finish
-  this->GetOutputData( "Output" )->SetITK( filter->GetOutput( ) );
-  return( "" );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
 }
 
 // eof - $RCSfile$