Orfeo Toolbox  3.16
itkPostOrderTreeIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkPostOrderTreeIterator.h,v $
5  Language: C++
6  Date: $Date: 2009-03-03 15:07:57 $
7  Version: $Revision: 1.5 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkPostOrderTreeIterator_h
18 #define __itkPostOrderTreeIterator_h
19 
20 #include <itkTreeIteratorBase.h>
21 
22 namespace itk {
23 
24 template <class TTreeType>
25 class PostOrderTreeIterator : public TreeIteratorBase<TTreeType>
26 {
27 public:
28 
32  typedef TTreeType TreeType;
33  typedef typename TTreeType::ValueType ValueType;
35 
38 
40  int GetType() const;
43 
44 protected:
46  const ValueType& Next();
48  bool HasNext() const;
49 
50 protected:
51 
52  const TreeNodeType* FindNextNode() const;
53  const TreeNodeType* FindMostRightLeaf(TreeNodeType* node) const;
54  const TreeNodeType* FindSister(TreeNodeType* node) const;
55 
56 };
57 
59 template <class TTreeType>
61  :TreeIteratorBase<TTreeType>(tree,NULL)
62 {
63  this->m_Position = const_cast<TreeNode<ValueType>*>(tree->GetRoot());
64 
65  if ( this->m_Position == NULL )
66  {
67  this->m_Begin = NULL;
68  }
69  else
70  {
71  this->m_Position =const_cast<TreeNodeType* >(FindMostRightLeaf(this->m_Position));
72  this->m_Begin = this->m_Position;
73  }
74 }
75 
77 template <class TTreeType>
78 int
80 {
82 }
83 
84 
86 template <class TTreeType>
87 bool
89 {
90  if(const_cast<TreeNodeType* >(FindNextNode()) != NULL)
91  {
92  return true;
93  }
94  return false;
95 }
96 
98 template <class TTreeType>
101 {
102  this->m_Position = const_cast<TreeNodeType*>(FindNextNode());
103  return this->m_Position->Get();
104 }
105 
107 template <class TTreeType>
110 {
111  if ( this->m_Position == NULL || this->m_Position == this->m_Root )
112  {
113  return NULL;
114  }
115  TreeNodeType* sister = const_cast<TreeNodeType*>(FindSister( this->m_Position ));
116 
117  if ( sister != NULL )
118  {
119  return FindMostRightLeaf( sister );
120  }
121 
122  return this->m_Position->GetParent();
123 }
124 
125 
127 template <class TTreeType>
130 {
131  if ( !node->HasParent() )
132  {
133  return NULL;
134  }
135 
136  TreeNodeType* parent = node->GetParent();
137  int childPosition = parent->ChildPosition( node );
138  int lastChildPosition = parent->CountChildren() - 1;
139 
140  while ( childPosition < lastChildPosition )
141  {
142  TreeNodeType* sister = parent->GetChild( childPosition + 1);
143 
144  if ( sister != NULL )
145  {
146  return sister;
147  }
148  childPosition++;
149  }
150  return NULL;
151 }
152 
154 template <class TTreeType>
157 {
158  while ( node->HasChildren() )
159  {
160  TreeNodeType* helpNode;
161  int childCount = node->CountChildren();
162  int i = 0;
163 
164  do
165  {
166  helpNode = node->GetChild( i );
167  i++;
168  }
169  while ( helpNode == NULL && i < childCount );
170 
171  if ( helpNode == NULL )
172  {
173  return node;
174  }
175  node = helpNode;
176  }
177  return node;
178 }
179 
181 template <class TTreeType>
183 {
184  PostOrderTreeIterator<TTreeType>* clone = new PostOrderTreeIterator<TTreeType>( const_cast<TTreeType*>(this->m_Tree) );
185  *clone = *this;
186  return clone;
187 }
188 
189 } // end namespace itk
190 
191 #endif

Generated at Sun Feb 3 2013 00:00:02 for Orfeo Toolbox with doxygen 1.8.1.1