]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Image/MinimumSpanningTree.hxx
...
[FrontAlgorithms.git] / lib / fpa / Image / MinimumSpanningTree.hxx
1 #ifndef __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
2 #define __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
3
4 #include <limits>
5
6 // -------------------------------------------------------------------------
7 template< unsigned int _NDim >
8 void fpa::Image::MinimumSpanningTree< _NDim >::
9 CopyMetaData( itk::ImageBase< _NDim >* infoImage )
10 {
11   this->SetLargestPossibleRegion( infoImage->GetLargestPossibleRegion( ) );
12   this->SetRequestedRegion( infoImage->GetRequestedRegion( ) );
13   this->SetBufferedRegion( infoImage->GetBufferedRegion( ) );
14   this->SetDirection( infoImage->GetDirection( ) );
15   this->SetOrigin( infoImage->GetOrigin( ) );
16   this->SetSpacing( infoImage->GetSpacing( ) );
17   this->Allocate( );
18   this->Clear( );
19 }
20
21 // -------------------------------------------------------------------------
22 template< unsigned int _NDim >
23 void fpa::Image::MinimumSpanningTree< _NDim >::
24 SetNode(
25   const TVertex& v, const TVertex& p,
26   const short& fid, const double& cost
27   )
28 {
29   this->Superclass::SetNode( v, p, fid, cost );
30   TInfo info;
31   info.Parent = p - v;
32   info.FrontId = fid;
33   info.GlobalCost = cost;
34   this->SetPixel( v, info );
35 }
36
37 // -------------------------------------------------------------------------
38 template< unsigned int _NDim >
39 void fpa::Image::MinimumSpanningTree< _NDim >::
40 Clear( )
41 {
42   this->Superclass::Clear( );
43   TInfo info;
44   info.Parent.Fill( 0 );
45   info.FrontId = std::numeric_limits< short >::max( );
46   info.GlobalCost = double( 0 );
47   this->FillBuffer( info );
48 }
49
50 // -------------------------------------------------------------------------
51 template< unsigned int _NDim >
52 typename fpa::Image::MinimumSpanningTree< _NDim >::
53 TPoints fpa::Image::MinimumSpanningTree< _NDim >::
54 GetEuclideanPath( const TVertex& a ) const
55 {
56   TPoints path;
57   auto vertices = this->GetPath( a );
58   for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt )
59   {
60     TPoint pnt;
61     this->TransformIndexToPhysicalPoint( *vIt, pnt );
62     path.push_back( pnt );
63
64   } // rof
65   return( path );
66 }
67
68 // -------------------------------------------------------------------------
69 template< unsigned int _NDim >
70 typename fpa::Image::MinimumSpanningTree< _NDim >::
71 TPoints fpa::Image::MinimumSpanningTree< _NDim >::
72 GetEuclideanPath( const TVertex& a, const TVertex& b ) const
73 {
74   TPoints path;
75   auto vertices = this->GetPath( a, b );
76   for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt )
77   {
78     TPoint pnt;
79     this->TransformIndexToPhysicalPoint( *vIt, pnt );
80     path.push_back( pnt );
81
82   } // rof
83   return( path );
84 }
85
86 // -------------------------------------------------------------------------
87 template< unsigned int _NDim >
88 bool fpa::Image::MinimumSpanningTree< _NDim >::
89 IsDefinedInEuclideanSpace( ) const
90 {
91   return( true );
92 }
93
94 // -------------------------------------------------------------------------
95 template< unsigned int _NDim >
96 fpa::Image::MinimumSpanningTree< _NDim >::
97 MinimumSpanningTree( )
98   : Superclass( )
99 {
100 }
101
102 // -------------------------------------------------------------------------
103 template< unsigned int _NDim >
104 fpa::Image::MinimumSpanningTree< _NDim >::
105 ~MinimumSpanningTree( )
106 {
107 }
108
109 // -------------------------------------------------------------------------
110 template< unsigned int _NDim >
111 bool fpa::Image::MinimumSpanningTree< _NDim >::
112 _HasVertex( const TVertex& a ) const
113 {
114   return( this->_FrontId( a ) < std::numeric_limits< short >::max( ) );
115 }
116
117 // -------------------------------------------------------------------------
118 template< unsigned int _NDim >
119 short fpa::Image::MinimumSpanningTree< _NDim >::
120 _FrontId( const TVertex& a ) const
121 {
122   static const short MAX_ID = std::numeric_limits< short >::max( );
123   if( this->GetRequestedRegion( ).IsInside( a ) )
124     return( this->GetPixel( a ).FrontId );
125   else
126     return( MAX_ID );
127 }
128
129 // -------------------------------------------------------------------------
130 template< unsigned int _NDim >
131 void fpa::Image::MinimumSpanningTree< _NDim >::
132 _Path( TVertices& path, const TVertex& a ) const
133 {
134   if( this->_HasVertex( a ) )
135   {
136     typename TVertex::OffsetType zero;
137     zero.Fill( 0 );
138     auto it = a;
139     do
140     {
141       path.push_back( it );
142       it += this->GetPixel( it ).Parent;
143
144     } while( this->GetPixel( it ).Parent != zero );
145     path.push_back( it );
146
147   } // fi
148 }
149
150 #endif // __FPA__IMAGE__MINIMUMSPANNINGTREE__HXX__
151
152 // eof - $RCSfile$