ITK  4.3.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< class TTreeType >
26 class 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< class TTreeType >
70  TreeIteratorBase< TTreeType >(tree, NULL)
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< class TTreeType >
88  TreeIteratorBase< TTreeType >(tree, NULL)
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< class TTreeType >
106 {}
107 
109 template< class TTreeType >
112 {
114 }
115 
117 template< class TTreeType >
119 {
120  if ( this->m_Position == NULL )
121  {
122  return false;
123  }
124  if ( const_cast< TreeNodeType * >( FindNextNode() ) != NULL )
125  {
126  return true;
127  }
128  return false;
129 }
131 
133 template< class TTreeType >
136 {
137  this->m_Position = const_cast< TreeNodeType * >( FindNextNode() );
138  return this->m_Position->Get();
139 }
141 
143 template< class TTreeType >
146 {
147  PreOrderTreeIterator< TTreeType > it(this->m_Tree, this->m_Position);
148  ++it; // go next
149  if ( it.IsAtEnd() )
150  {
151  return NULL;
152  }
154 
155  if ( !it.HasChild() )
156  {
157  return it.GetNode();
158  }
159 
160  while ( !it.IsAtEnd() )
161  {
162  if ( !it.HasChild() )
163  {
164  return it.GetNode();
165  }
166  ++it;
167  }
168 
169  return NULL;
170 }
171 
173 template< class TTreeType >
175 {
177  *clone = *this;
178  return clone;
179 }
180 } // end namespace itk
182 
183 #endif
184