]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.hxx
f8793c9c5936f3a2c0259b7b9585a71ab6537e8e
[FrontAlgorithms.git] / lib / fpa / Base / ExtractBranchesFromMinimumSpanningTree.hxx
1 #ifndef __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__HXX__
2 #define __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__HXX__
3
4 // -------------------------------------------------------------------------
5 template< class T >
6 const T* fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
7 GetInput( ) const
8 {
9   return(
10     dynamic_cast< const T* >( this->itk::ProcessObject::GetInput( 0 ) )
11     );
12 }
13
14 // -------------------------------------------------------------------------
15 template< class T >
16 void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
17 SetInput( const T* tree )
18 {
19   this->itk::ProcessObject::SetNthInput( 0, const_cast< T* >( tree ) );
20 }
21
22 // -------------------------------------------------------------------------
23 template< class T >
24 typename fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
25 TBranches* fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
26 GetOutput( )
27 {
28   return(
29     itkDynamicCastInDebugMode< TBranches* >( this->GetPrimaryOutput( ) )
30     );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class T >
35 void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
36 ClearEndPoints( )
37 {
38   this->m_EndPoints.clear( );
39   this->Modified( );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class T >
44 void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
45 AddEndPoint( const TVertex& v )
46 {
47   if( this->m_EndPoints.find( v ) == this->m_EndPoints.end( ) )
48   {
49     this->m_EndPoints.insert( v );
50     this->Modified( );
51
52   } // fi
53 }
54
55 // -------------------------------------------------------------------------
56 template< class T >
57 bool fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
58 HasEndPoint( const TVertex& v ) const
59 {
60   return( this->m_EndPoints.find( v ) != this->m_EndPoints.end( ) );
61 }
62
63 // -------------------------------------------------------------------------
64 template< class T >
65 unsigned long fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
66 GetNumberOfEndPoints( ) const
67 {
68   return( this->m_EndPoints.size( ) );
69 }
70
71 // -------------------------------------------------------------------------
72 template< class T >
73 fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
74 ExtractBranchesFromMinimumSpanningTree( )
75   : Superclass( )
76 {
77   this->itk::ProcessObject::SetNumberOfRequiredInputs( 1 );
78
79   typename TBranches::Pointer out = TBranches::New( );
80   this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
81   this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) );
82 }
83
84 // -------------------------------------------------------------------------
85 template< class T >
86 fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
87 ~ExtractBranchesFromMinimumSpanningTree( )
88 {
89 }
90
91 // -------------------------------------------------------------------------
92 template< class T >
93 void fpa::Base::ExtractBranchesFromMinimumSpanningTree< T >::
94 GenerateData( )
95 {
96   const T* tree = this->GetInput( );
97   TBranches* branches = this->GetOutput( );
98
99   // Find bifurcations
100   TEndPoints all_points, marks;
101   auto e0It = this->m_EndPoints.begin( );
102   for( ; e0It != this->m_EndPoints.end( ); ++e0It )
103   {
104     all_points.insert( *e0It );
105     auto e1It = e0It;
106     e1It++;
107     for( ; e1It != this->m_EndPoints.end( ); ++e1It )
108     {
109       all_points.insert( *e0It );
110       auto path = tree->GetPath( *e0It, *e1It );
111       auto pIt = path.begin( );
112       for( ; pIt != path.end( ); ++pIt )
113       {
114         if( *pIt == *e0It || *pIt == *e1It )
115           continue;
116
117         if( marks.find( *pIt ) == marks.end( ) )
118           marks.insert( *pIt );
119         else
120           all_points.insert( *pIt );
121         
122       } // rof
123
124     } // rof
125
126   } // rof
127
128   // Construct branches
129   std::cout << all_points.size( ) << std::endl;
130 }
131
132 #endif // __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__HXX__
133
134 // eof - $RCSfile$