]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Image/MinimumSpanningTree.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / MinimumSpanningTree.hxx
index 616365ef18689afb8065b958130fd9f9da0cc943..b99953b28ed029636ab4c3fddca40bf6429038f1 100644 (file)
-#ifndef __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
-#define __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
-
-#include <limits>
+#ifndef __fpa__Image__MinimumSpanningTree__hxx__
+#define __fpa__Image__MinimumSpanningTree__hxx__
 
 // -------------------------------------------------------------------------
-template< unsigned int _NDim >
-void fpa::Image::MinimumSpanningTree< _NDim >::
-CopyMetaData( itk::ImageBase< _NDim >* infoImage )
+template< unsigned int _VDim >
+typename fpa::Image::MinimumSpanningTree< _VDim >::
+TVertex fpa::Image::MinimumSpanningTree< _VDim >::
+GetParent( const TVertex& v ) const
 {
-  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( );
+  TVertex p = v + this->GetPixel( v );
+  return( p );
 }
 
 // -------------------------------------------------------------------------
-template< unsigned int _NDim >
-void fpa::Image::MinimumSpanningTree< _NDim >::
-SetNode(
-  const TVertex& v, const TVertex& p,
-  const short& fid, const double& cost
-  )
+template< unsigned int _VDim >
+void fpa::Image::MinimumSpanningTree< _VDim >::
+SetParent( const TVertex& v, const TVertex& p )
 {
-  this->Superclass::SetNode( v, p, fid, cost );
-  TInfo info;
-  info.Parent = p - v;
-  info.FrontId = fid;
-  info.GlobalCost = cost;
-  this->SetPixel( v, info );
+  this->SetPixel( v, p - v );
 }
 
 // -------------------------------------------------------------------------
-template< unsigned int _NDim >
-void fpa::Image::MinimumSpanningTree< _NDim >::
-Clear( )
+template< unsigned int _VDim >
+void fpa::Image::MinimumSpanningTree< _VDim >::
+GetPath( typename TPath::Pointer& path, const TVertex& a ) const
 {
-  this->Superclass::Clear( );
-  TInfo info;
-  info.Parent.Fill( 0 );
-  info.FrontId = std::numeric_limits< short >::max( );
-  info.GlobalCost = double( 0 );
-  this->FillBuffer( info );
+  if( path.GetPointer( ) == NULL )
+    path = TPath::New( );
+  path->SetReferenceImage( this );
+  this->Superclass::GetPath( path, a );
 }
 
 // -------------------------------------------------------------------------
-template< unsigned int _NDim >
-typename fpa::Image::MinimumSpanningTree< _NDim >::
-TPoints fpa::Image::MinimumSpanningTree< _NDim >::
-GetEuclideanPath( const TVertex& a ) const
+template< unsigned int _VDim >
+void fpa::Image::MinimumSpanningTree< _VDim >::
+GetPath(
+  typename TPath::Pointer& path, const TVertex& a, const TVertex& b
+  ) 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 );
+  if( path.GetPointer( ) == NULL )
+    path = TPath::New( );
+  path->SetReferenceImage( this );
+  this->Superclass::GetPath( path, a, b );
 }
 
 // -------------------------------------------------------------------------
-template< unsigned int _NDim >
-bool fpa::Image::MinimumSpanningTree< _NDim >::
-IsDefinedInEuclideanSpace( ) const
-{
-  return( true );
-}
-
-// -------------------------------------------------------------------------
-template< unsigned int _NDim >
-fpa::Image::MinimumSpanningTree< _NDim >::
+template< unsigned int _VDim >
+fpa::Image::MinimumSpanningTree< _VDim >::
 MinimumSpanningTree( )
   : Superclass( )
 {
 }
 
 // -------------------------------------------------------------------------
-template< unsigned int _NDim >
-fpa::Image::MinimumSpanningTree< _NDim >::
+template< unsigned int _VDim >
+fpa::Image::MinimumSpanningTree< _VDim >::
 ~MinimumSpanningTree( )
 {
 }
 
-// -------------------------------------------------------------------------
-template< unsigned int _NDim >
-bool fpa::Image::MinimumSpanningTree< _NDim >::
-_HasVertex( const TVertex& a ) const
-{
-  return( this->_FrontId( a ) < std::numeric_limits< short >::max( ) );
-}
-
-// -------------------------------------------------------------------------
-template< unsigned int _NDim >
-short fpa::Image::MinimumSpanningTree< _NDim >::
-_FrontId( const TVertex& a ) const
-{
-  static const short MAX_ID = std::numeric_limits< short >::max( );
-  if( this->GetRequestedRegion( ).IsInside( a ) )
-    return( this->GetPixel( a ).FrontId );
-  else
-    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 );
-    path.push_back( it );
-
-  } // fi
-}
-
-#endif // __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
+#endif // __fpa__Image__MinimumSpanningTree__hxx__
 
 // eof - $RCSfile$