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