#ifndef __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__ #define __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__ #include // ------------------------------------------------------------------------- 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< 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< unsigned int _NDim > fpa::Image::MinimumSpanningTree< _NDim >:: ~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__ // eof - $RCSfile$