ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkLevelOrderTreeIterator.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 itkLevelOrderTreeIterator_h
19 #define itkLevelOrderTreeIterator_h
20 
21 #include <queue>
22 #include <climits>
23 #include "itkTreeIteratorBase.h"
24 
25 namespace itk
26 {
33 template< typename TTreeType >
34 class ITK_TEMPLATE_EXPORT LevelOrderTreeIterator:public TreeIteratorBase< TTreeType >
35 {
36 public:
37 
41  typedef TTreeType TreeType;
42  typedef typename TTreeType::ValueType ValueType;
44  typedef typename Superclass::NodeType NodeType;
45 
47  LevelOrderTreeIterator(TreeType *tree, int endLevel = INT_MAX, const TreeNodeType *start = ITK_NULLPTR);
48 
50  LevelOrderTreeIterator(TreeType *tree, int startLevel, int endLevel, const TreeNodeType *start = ITK_NULLPTR);
51 
53 
55  NodeType GetType() const;
56 
58  int GetStartLevel() const;
59 
61  int GetEndLevel() const;
62 
64  int GetLevel() const;
65 
68 
70  const Self & operator=(const Self & iterator)
71  {
72  if(this != &iterator)
73  {
74  this->Superclass::operator=(iterator);
75  m_StartLevel = iterator.m_StartLevel;
76  m_EndLevel = iterator.m_EndLevel;
77  m_Queue = iterator.m_Queue;
78  }
79  return *this;
80  }
82 
83 protected:
84 
86  const ValueType & Next();
87 
89  bool HasNext() const;
90 
91 private:
92 
93  const TreeNodeType * FindNextNode() const;
94 
95  const TreeNodeType * FindNextNodeHelp() const;
96 
97  int GetLevel(const TreeNodeType *node) const;
98 
101  mutable std::queue< const TreeNodeType * > m_Queue;
102 };
103 
104 } // end namespace itk
105 
106 #ifndef ITK_MANUAL_INSTANTIATION
107 #include "itkLevelOrderTreeIterator.hxx"
108 #endif
109 
110 #endif
Iterate over a tree in level order.
TTreeType::TreeNodeType TreeNodeType
std::queue< const TreeNodeType * > m_Queue
Superclass::TreeNodeType TreeNodeType
const Self & operator=(const Self &iterator)
This class provides the base implementation for tree iterators.
TreeIteratorBase< TTreeType > Superclass