]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/ImageSkeleton.hxx
...
[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 aIt = this->Get( ).find( a );
15   if( aIt != this->Get( ).end( ) )
16     found = ( aIt->second.find( b ) != aIt->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
29   typedef typename TSkeleton::value_type _T1;
30   typedef typename TSkeletonRow::value_type _T2;
31
32   TSkeleton& sk = this->Get( );
33   auto sIt = sk.find( a );
34   if( sIt == sk.end( ) )
35   {
36     sIt = sk.insert( _T1( a, TSkeletonRow( ) ) ).first;
37     this->Modified( );
38
39   } // fi
40   if( sIt->second.find( b ) == sIt->second.end( ) )
41   {
42     sIt->second.insert( _T2( b, path ) );
43     this->Modified( );
44
45   } // fi
46 }
47
48 // -------------------------------------------------------------------------
49 template< class _TMST >
50 const typename fpa::Base::ImageSkeleton< _TMST >::
51 TPath* fpa::Base::ImageSkeleton< _TMST >::
52 GetBranch( const TVertex& a, const TVertex& b ) const
53 {
54   auto aIt = this->Get( ).find( a );
55   if( aIt != this->Get( ).end( ) )
56   {
57     auto bIt = aIt->second.find( b );
58     if( bIt != aIt->second.end( ) )
59       return( bIt->second.GetPointer( ) );
60     else
61       return( NULL );
62   }
63   else
64     return( NULL );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TMST >
69 fpa::Base::ImageSkeleton< _TMST >::
70 ImageSkeleton( )
71   : Superclass( )
72 {
73 }
74
75 // -------------------------------------------------------------------------
76 template< class _TMST >
77 fpa::Base::ImageSkeleton< _TMST >::
78 ~ImageSkeleton( )
79 {
80 }
81
82 #endif // __FPA__BASE__IMAGESKELETON__HXX__
83
84 // eof - $RCSfile$