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