]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/MinimumSpanningTree.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / MinimumSpanningTree.hxx
index 48a43cb8190504d74eaf015f2142dbb7bb19e84d..a4dc47ec98a0565fa7ad487ea9dbbdb6709c1961 100644 (file)
 #ifndef __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
 #define __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
 
+#include <limits>
+
+// -------------------------------------------------------------------------
+template< unsigned int _NDim >
+void fpa::Image::MinimumSpanningTree< _NDim >::
+CopyMetaData( itk::ImageBase< _NDim >* infoImage )
+{
+  this->SetLargestPossibleRegion( infoImage->GetLargestPossibleRegion( ) );
+  this->SetRequestedRegion( infoImage->GetRequestedRegion( ) );
+  this->SetBufferedRegion( infoImage->GetBufferedRegion( ) );
+  this->SetDirection( infoImage->GetDirection( ) );
+  this->SetOrigin( infoImage->GetOrigin( ) );
+  this->SetSpacing( infoImage->GetSpacing( ) );
+  this->Allocate( );
+  this->Clear( );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int _NDim >
+void fpa::Image::MinimumSpanningTree< _NDim >::
+SetNode(
+  const TVertex& v, const TVertex& p,
+  const short& fid, const double& cost
+  )
+{
+  this->Superclass::SetNode( v, p, fid, cost );
+  TInfo info;
+  info.Parent = p - v;
+  info.FrontId = fid;
+  info.GlobalCost = cost;
+  this->SetPixel( v, info );
+}
+
 // -------------------------------------------------------------------------
-template< class V, class N, class C, unsigned int D, unsigned long L >
-fpa::Image::MinimumSpanningTree< V, N, C, D, L >::
+template< unsigned int _NDim >
+void fpa::Image::MinimumSpanningTree< _NDim >::
+Clear( )
+{
+  this->Superclass::Clear( );
+  TInfo info;
+  info.Parent.Fill( 0 );
+  info.FrontId = std::numeric_limits< short >::max( );
+  info.GlobalCost = double( 0 );
+  this->FillBuffer( info );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int _NDim >
+typename fpa::Image::MinimumSpanningTree< _NDim >::
+TPoints fpa::Image::MinimumSpanningTree< _NDim >::
+GetEuclideanPath( const TVertex& a ) const
+{
+  TPoints path;
+  auto vertices = this->GetPath( a );
+  for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt )
+  {
+    TPoint pnt;
+    this->TransformIndexToPhysicalPoint( *vIt, pnt );
+    path.push_back( pnt );
+
+  } // rof
+  return( path );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int _NDim >
+typename fpa::Image::MinimumSpanningTree< _NDim >::
+TPoints fpa::Image::MinimumSpanningTree< _NDim >::
+GetEuclideanPath( const TVertex& a, const TVertex& b ) const
+{
+  TPoints path;
+  auto vertices = this->GetPath( a, b );
+  for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt )
+  {
+    TPoint pnt;
+    this->TransformIndexToPhysicalPoint( *vIt, pnt );
+    path.push_back( pnt );
+
+  } // rof
+  return( path );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int _NDim >
+bool fpa::Image::MinimumSpanningTree< _NDim >::
+IsDefinedInEuclideanSpace( ) const
+{
+  return( true );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int _NDim >
+fpa::Image::MinimumSpanningTree< _NDim >::
 MinimumSpanningTree( )
   : Superclass( )
 {
 }
 
 // -------------------------------------------------------------------------
-template< class V, class N, class C, unsigned int D, unsigned long L >
-fpa::Image::MinimumSpanningTree< V, N, C, D, L >::
+template< unsigned int _NDim >
+fpa::Image::MinimumSpanningTree< _NDim >::
 ~MinimumSpanningTree( )
 {
 }
 
 // -------------------------------------------------------------------------
-template< class V, class N, class C, unsigned int D, unsigned long L >
-long fpa::Image::MinimumSpanningTree< V, N, C, D, L >::
-_FrontId( const V& v ) const
+template< unsigned int _NDim >
+bool fpa::Image::MinimumSpanningTree< _NDim >::
+_HasVertex( const TVertex& a ) const
 {
-  return( this->GetPixel( v ).FrontId );
+  return( this->_FrontId( a ) < std::numeric_limits< short >::max( ) );
 }
 
 // -------------------------------------------------------------------------
-template< class V, class N, class C, unsigned int D, unsigned long L >
-V fpa::Image::MinimumSpanningTree< V, N, C, D, L >::
-_Parent( const V& v ) const
+template< unsigned int _NDim >
+short fpa::Image::MinimumSpanningTree< _NDim >::
+_FrontId( const TVertex& a ) const
 {
-  _TNode n = this->GetPixel( v );
-  if( n.Label == L )
-    return( n.Parent );
+  static const short MAX_ID = std::numeric_limits< short >::max( );
+  if( this->GetRequestedRegion( ).IsInside( a ) )
+    return( this->GetPixel( a ).FrontId );
   else
-    return( v );
+    return( MAX_ID );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int _NDim >
+void fpa::Image::MinimumSpanningTree< _NDim >::
+_Path( TVertices& path, const TVertex& a ) const
+{
+  if( this->_HasVertex( a ) )
+  {
+    typename TVertex::OffsetType zero;
+    zero.Fill( 0 );
+    auto it = a;
+    do
+    {
+      path.push_back( it );
+      it += this->GetPixel( it ).Parent;
+
+    } while( this->GetPixel( it ).Parent != zero );
+
+  } // fi
 }
 
 #endif // __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__