ITK  4.2.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< class TTreeType >
34 class 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 = NULL);
48 
50  LevelOrderTreeIterator(TreeType *tree, int startLevel, int endLevel, const TreeNodeType *start = NULL);
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  this->Superclass::operator=(iterator);
73  m_StartLevel = iterator.m_StartLevel;
74  m_EndLevel = iterator.m_EndLevel;
75  m_Queue = iterator.m_Queue;
76  return *this;
77  }
79 
80 protected:
81 
83  const ValueType & Next();
84 
86  bool HasNext() const;
87 
88 private:
89 
90  const TreeNodeType * FindNextNode() const;
91 
92  const TreeNodeType * FindNextNodeHelp() const;
93 
94  int GetLevel(const TreeNodeType *node) const;
95 
98  mutable std::queue< const TreeNodeType * > m_Queue;
99 };
100 
101 } // end namespace itk
102 
103 #ifndef ITK_MANUAL_INSTANTIATION
104 #include "itkLevelOrderTreeIterator.hxx"
105 #endif
106 
107 #endif
108