]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/ImageSkeleton.hxx
cd2daec2c66a0aab5f2ac974797dd9d353dc42d9
[FrontAlgorithms.git] / lib / fpa / Base / ImageSkeleton.hxx
1 #ifndef __FPA__BASE__IMAGESKELETON__HXX__
2 #define __FPA__BASE__IMAGESKELETON__HXX__
3
4 // -------------------------------------------------------------------------
5 template< class _TMST >
6 void fpa::Base::ImageSkeleton< _TMST >::
7 AddBranch( const TVertex& a, const TVertex& b )
8 {
9   if( this->m_MinimumSpanningTree.IsNull( ) )
10     return;
11
12   // Check if the branch already exists
13   bool found = false;
14   auto arIt = this->Get( ).find( a );
15   if( arIt != this->Get( ).end( ) )
16     found = ( arIt->second.find( b ) != arIt->second.end( ) );
17   if( found )
18     return;
19
20   // Create path
21   auto vertices = this->m_MinimumSpanningTree->GetPath( a, b );
22   typename TPath::Pointer path = TPath::New( );
23   for( auto vIt = vertices.begin( ); vIt != vertices.end( ); ++vIt )
24     path->AddVertex( *vIt );
25   
26   // Assign path vertices
27   path->SetReferenceImage( this->m_MinimumSpanningTree );
28   this->Get( )[ a ][ b ] = path;
29
30   // Create symmetric path
31   this->AddBranch( b, a );
32 }
33
34 // -------------------------------------------------------------------------
35 template< class _TMST >
36 const typename fpa::Base::ImageSkeleton< _TMST >::
37 TPath* fpa::Base::ImageSkeleton< _TMST >::
38 GetBranch( const TVertex& a, const TVertex& b ) const
39 {
40   if( this->m_MinimumSpanningTree.IsNull( ) )
41     return( NULL );
42
43   auto aIt = this->Get( ).find( a );
44   if( aIt != this->Get( ).end( ) )
45   {
46     auto bIt = aIt->second.find( b );
47     if( bIt != aIt->second.end( ) )
48       return( bIt->second.GetPointer( ) );
49     else
50       return( NULL );
51   }
52   else
53     return( NULL );
54 }
55
56 // -------------------------------------------------------------------------
57 template< class _TMST >
58 fpa::Base::ImageSkeleton< _TMST >::
59 ImageSkeleton( )
60   : Superclass( )
61 {
62 }
63
64 // -------------------------------------------------------------------------
65 template< class _TMST >
66 fpa::Base::ImageSkeleton< _TMST >::
67 ~ImageSkeleton( )
68 {
69 }
70
71 #endif // __FPA__BASE__IMAGESKELETON__HXX__
72
73 // eof - $RCSfile$