]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/DataStructures/Image/Skeleton.hxx
c3316da357501a55042f9f922557b39f177aaeea
[FrontAlgorithms.git] / lib / fpa / DataStructures / Image / Skeleton.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __fpa__DataStructures__Image__Skeleton__hxx__
6 #define __fpa__DataStructures__Image__Skeleton__hxx__
7
8 // -------------------------------------------------------------------------
9 template< unsigned int _VDim >
10 void fpa::DataStructures::Image::Skeleton< _VDim >::
11 AddBranch( TPath* path )
12 {
13   // Check inputs
14   if( path == NULL )
15     return;
16   unsigned long size = path->GetSize( );
17   if( size == 0 )
18     return;
19   TIndex a = path->GetVertex( 0 );
20   TIndex b = path->GetVertex( size - 1 );
21   if( this->HasEdge( a, b ) )
22     return;
23
24   // Add path
25   this->SetVertex( a, a );
26   this->SetVertex( b, b );
27   this->AddEdge( a, b, path );
28   this->AddEdge( b, a, path );
29   this->Modified( );
30 }
31
32 // -------------------------------------------------------------------------
33 template< unsigned int _VDim >
34 const typename fpa::DataStructures::Image::Skeleton< _VDim >::
35 TPath* fpa::DataStructures::Image::Skeleton< _VDim >::
36 GetBranch( const TIndex& a, const TIndex& b ) const
37 {
38   static const TPath* null_path = NULL;
39   if( this->HasEdge( a, b ) )
40     return( this->GetEdges( a, b ).front( ) );
41   else
42     return( null_path );
43 }
44
45 // -------------------------------------------------------------------------
46 template< unsigned int _VDim >
47 std::vector< typename fpa::DataStructures::Image::Skeleton< _VDim >::TIndex >
48 fpa::DataStructures::Image::Skeleton< _VDim >::
49 GetEndPoints( ) const
50 {
51   std::vector< TIndex > res;
52   typename Superclass::TMatrix::const_iterator mIt = this->BeginEdgesRows( );
53   for( ; mIt != this->EndEdgesRows( ); ++mIt )
54   {
55     unsigned long count = mIt->second.size( );
56     if( count == 1 )
57       res.push_back( mIt->first );
58
59   } // rof
60   return( res );
61 }
62
63 // -------------------------------------------------------------------------
64 template< unsigned int _VDim >
65 std::vector< typename fpa::DataStructures::Image::Skeleton< _VDim >::TIndex >
66 fpa::DataStructures::Image::Skeleton< _VDim >::
67 GetBifurcations( ) const
68 {
69   std::vector< TIndex > res;
70   typename Superclass::TMatrix::const_iterator mIt = this->BeginEdgesRows( );
71   for( ; mIt != this->EndEdgesRows( ); ++mIt )
72   {
73     unsigned long count = mIt->second.size( );
74     if( count > 1 )
75       res.push_back( mIt->first );
76
77   } // rof
78   return( res );
79 }
80
81 // -------------------------------------------------------------------------
82 template< unsigned int _VDim >
83 fpa::DataStructures::Image::Skeleton< _VDim >::
84 Skeleton( )
85   : Superclass( )
86 {
87 }
88
89 // -------------------------------------------------------------------------
90 template< unsigned int _VDim >
91 fpa::DataStructures::Image::Skeleton< _VDim >::
92 ~Skeleton( )
93 {
94 }
95
96 #endif // __fpa__DataStructures__Image__Skeleton__hxx__
97
98 // eof - $RCSfile$