ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkLeafTreeIterator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkLeafTreeIterator_h
19 #define itkLeafTreeIterator_h
20 
22 
23 namespace itk
24 {
25 template< typename TTreeType >
26 class ITK_TEMPLATE_EXPORT LeafTreeIterator:public TreeIteratorBase< TTreeType >
27 {
28 public:
29 
33  typedef TTreeType TreeType;
34  typedef typename TreeType::ValueType ValueType;
36  typedef typename Superclass::NodeType NodeType;
37 
39  LeafTreeIterator(const TreeType *tree);
40 
43 
45  virtual ~LeafTreeIterator();
46 
48  NodeType GetType() const;
49 
52 
53 protected:
54 
56  const ValueType & Next();
57 
59  bool HasNext() const;
60 
61 private:
62 
64  const TreeNodeType * FindNextNode() const;
65 };
66 
68 template< typename TTreeType >
70  TreeIteratorBase< TTreeType >(tree, ITK_NULLPTR)
71 {
72  this->m_Begin = const_cast< TreeNodeType * >( this->FindNextNode() ); //
73  //
74  // Position
75  // the
76  //
77  // iterator
78  // to
79  // the
80  // first
81  // leaf;
82 }
84 
86 template< typename TTreeType >
88  TreeIteratorBase< TTreeType >(tree, ITK_NULLPTR)
89 {
90  this->m_Begin = const_cast< TreeNodeType * >( this->FindNextNode() ); //
91  //
92  // Position
93  // the
94  //
95  // iterator
96  // to
97  // the
98  // first
99  // leaf;
100 }
102 
104 template< typename TTreeType >
106 {}
107 
109 template< typename TTreeType >
112 {
114 }
115 
117 template< typename TTreeType >
119 {
120  if ( this->m_Position == ITK_NULLPTR )
121  {
122  return false;
123  }
124  if ( const_cast< TreeNodeType * >( FindNextNode() ) != ITK_NULLPTR )
125  {
126  return true;
127  }
128  return false;
129 }
131 
133 template< typename TTreeType >
136 {
137  this->m_Position = const_cast< TreeNodeType * >( FindNextNode() );
138  return this->m_Position->Get();
139 }
141 
143 template< typename TTreeType >
146 {
147  PreOrderTreeIterator< TTreeType > it(this->m_Tree, this->m_Position);
148  it.m_Root = this->m_Root;
149  ++it; // go next
150  if ( it.IsAtEnd() )
151  {
152  return ITK_NULLPTR;
153  }
155 
156  if ( !it.HasChild() )
157  {
158  return it.GetNode();
159  }
160 
161  while ( !it.IsAtEnd() )
162  {
163  if ( !it.HasChild() )
164  {
165  return it.GetNode();
166  }
167  ++it;
168  }
169 
170  return ITK_NULLPTR;
171 }
172 
174 template< typename TTreeType >
176 {
178  *clone = *this;
179  return clone;
180 }
181 } // end namespace itk
183 
184 #endif
LeafTreeIterator(const TreeType *tree)
TTreeType::TreeNodeType TreeNodeType
Superclass::NodeType NodeType
virtual bool HasChild(int number=0) const
const TreeNodeType * FindNextNode() const
virtual TreeNodeType * GetNode()
TreeType::ValueType ValueType
const ValueType & Next()
TreeIteratorBase< TTreeType > * Clone()
NodeType GetType() const
This class provides the base implementation for tree iterators.
bool IsAtEnd(void) const
Superclass::TreeNodeType TreeNodeType
class ITK_TEMPLATE_EXPORT LeafTreeIterator
TreeIteratorBase< TTreeType > Superclass
const TreeNodeType * m_Root