]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/ExtractBranchesFromMinimumSpanningTree.hxx
...
[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   auto tree = this->GetInput( );
97   auto branches = this->GetOutput( );
98
99   // Find bifurcations
100   TEndPoints bifurcations, marks;
101   auto e0It = this->m_EndPoints.begin( );
102   for( ; e0It != this->m_EndPoints.end( ); ++e0It )
103   {
104     auto e1It = e0It;
105     e1It++;
106     for( ; e1It != this->m_EndPoints.end( ); ++e1It )
107     {
108       auto path = tree->GetPath( *e0It, *e1It );
109       std::cout << "path" << std::endl;
110       auto pIt = path.begin( );
111       for( ; pIt != path.end( ); ++pIt )
112       {
113         if( marks.find( *pIt ) == marks.end( ) )
114           marks.insert( *pIt );
115         else
116           bifurcations.insert( *pIt );
117
118       } // rof
119
120     } // rof
121
122   } // rof
123
124   // Construct branches
125   std::cout << bifurcations.size( ) << std::endl;
126 }
127
128 #endif // __FPA__BASE__EXTRACTBRANCHESFROMMINIMUMSPANNINGTREE__HXX__
129
130 // eof - $RCSfile$