]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Base/MinimumSpanningTree.hxx
...
[FrontAlgorithms.git] / lib / fpa / Base / MinimumSpanningTree.hxx
index ad0d06bc00a315e654c77692f9fcef4e5ed4588d..9d0939ddf74b2e469c4416c103f1f6445ee96214 100644 (file)
@@ -4,13 +4,13 @@
 #include <limits>
 
 // -------------------------------------------------------------------------
-template< class V, class C, class B >
-const unsigned long fpa::Base::MinimumSpanningTree< V, C, B >::INF_VALUE =
+template< class V, class B >
+const unsigned long fpa::Base::MinimumSpanningTree< V, B >::INF_VALUE =
   std::numeric_limits< unsigned long >::max( ) >> 1;
 
 // -------------------------------------------------------------------------
-template< class V, class C, class B >
-void fpa::Base::MinimumSpanningTree< V, C, B >::
+template< class V, class B >
+void fpa::Base::MinimumSpanningTree< V, B >::
 SetCollisions( const TCollisions& collisions )
 {
   this->m_Collisions = collisions;
@@ -60,15 +60,16 @@ SetCollisions( const TCollisions& collisions )
 }
 
 // -------------------------------------------------------------------------
-template< class V, class C, class B >
-void fpa::Base::MinimumSpanningTree< V, C, B >::
-GetPath( std::vector< V >& path, const V& a, const V& b ) const
+template< class V, class B >
+std::vector< V > fpa::Base::MinimumSpanningTree< V, B >::
+GetPath( const V& a, const V& b ) const
 {
+  std::vector< V > path;
   typename TDecorated::const_iterator aIt = this->Get( ).find( a );
   typename TDecorated::const_iterator bIt = this->Get( ).find( b );
 
   if( aIt == this->Get( ).end( ) || bIt == this->Get( ).end( ) )
-    return;
+    return( path );
   
   short fa = aIt->second.second;
   short fb = bIt->second.second;
@@ -121,49 +122,53 @@ GetPath( std::vector< V >& path, const V& a, const V& b ) const
       if( 0 < N )
       {
         // First path: from start vertex to first collision
-        this->GetPath(
-          path, a, this->m_Collisions[ fpath[ 0 ] ][ fpath[ 1 ] ].first
+        path = this->GetPath(
+          a, this->m_Collisions[ fpath[ 0 ] ][ fpath[ 1 ] ].first
           );
 
         // Intermediary paths
         for( unsigned int i = 1; i < N - 1; ++i )
         {
-          this->GetPath(
-            path,
-            this->m_Collisions[ fpath[ i ] ][ fpath[ i - 1 ] ].first,
-            this->m_Collisions[ fpath[ i ] ][ fpath[ i + 1 ] ].first
-            );
+          std::vector< V > ipath =
+            this->GetPath(
+              this->m_Collisions[ fpath[ i ] ][ fpath[ i - 1 ] ].first,
+              this->m_Collisions[ fpath[ i ] ][ fpath[ i + 1 ] ].first
+              );
+          path.insert( path.end( ), ipath.begin( ), ipath.end( ) );
 
         } // rof
 
         // Final path: from last collision to end point
-        this->GetPath(
-          path,
-          this->m_Collisions[ fpath[ N - 1 ] ][ fpath[ N - 2 ] ].first, b
-          );
+        std::vector< V > lpath =
+          this->GetPath(
+            this->m_Collisions[ fpath[ N - 1 ] ][ fpath[ N - 2 ] ].first, b
+            );
+        path.insert( path.end( ), lpath.begin( ), lpath.end( ) );
 
       } // fi
 
     } // fi
 
   } // fi
+  return( path );
 }
 
 // -------------------------------------------------------------------------
-template< class V, class C, class B >
-template< class I, class P >
-void fpa::Base::MinimumSpanningTree< V, C, B >::
+template< class V, class B >
+template< class I >
+std::vector< typename I::PointType > fpa::Base::MinimumSpanningTree< V, B >::
 GetPathFromImage(
-  std::vector< P >& path, const V& a, const V& b,
+  const V& a, const V& b,
   const I* image, unsigned int kernel
   ) const
 {
-  std::vector< V > vertices;
-  this->GetPath( vertices, a, b );
-  path.clear( );
+  typedef typename I::PointType _P;
+
+  std::vector< _P > path;
+  std::vector< V > vertices = this->GetPath( a, b );
   for( unsigned int i = 0; i < vertices.size( ); ++i )
   {
-    P p;
+    _P p;
     image->TransformIndexToPhysicalPoint( vertices[ i ], p );
     path.push_back( p );
 
@@ -173,11 +178,11 @@ GetPathFromImage(
   if( kernel > 0 )
   {
     int k = int( kernel ) >> 1;
-    std::vector< P > lowpass_path;
+    std::vector< _P > lowpass_path;
     for( unsigned int i = 0; i < path.size( ); ++i )
     {
-      P p;
-      p.Fill( ( typename P::ValueType )( 0 ) );
+      _P p;
+      p.Fill( ( typename _P::ValueType )( 0 ) );
       unsigned int c = 0;
       for( int j = -k; j <= k; ++j )
       {
@@ -191,8 +196,8 @@ GetPathFromImage(
 
       } // rof
       if( c > 0 )
-        for( unsigned int d = 0; d < P::PointDimension; ++d )
-          p[ d ] /= ( typename P::ValueType )( c );
+        for( unsigned int d = 0; d < _P::PointDimension; ++d )
+          p[ d ] /= ( typename _P::ValueType )( c );
       lowpass_path.push_back( p );
 
     } // rof
@@ -200,26 +205,27 @@ GetPathFromImage(
     path = lowpass_path;
 
   } // fi
+  return( path );
 }
 
 // -------------------------------------------------------------------------
-template< class V, class C, class B >
-fpa::Base::MinimumSpanningTree< V, C, B >::
+template< class V, class B >
+fpa::Base::MinimumSpanningTree< V, B >::
 MinimumSpanningTree( )
   : Superclass( )
 {
 }
 
 // -------------------------------------------------------------------------
-template< class V, class C, class B >
-fpa::Base::MinimumSpanningTree< V, C, B >::
+template< class V, class B >
+fpa::Base::MinimumSpanningTree< V, B >::
 ~MinimumSpanningTree( )
 {
 }
 
 // -------------------------------------------------------------------------
-template< class V, class C, class B >
-void fpa::Base::MinimumSpanningTree< V, C, B >::
+template< class V, class B >
+void fpa::Base::MinimumSpanningTree< V, B >::
 _Path( std::vector< V >& path, const V& a ) const
 {
   typename TDecorated::const_iterator dIt = this->Get( ).find( a );