ITK
4.3.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Core
Common
include
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
21
#include "
itkPreOrderTreeIterator.h
"
22
23
namespace
itk
24
{
25
template
<
class
TTreeType >
26
class
LeafTreeIterator
:
public
TreeIteratorBase
< TTreeType >
27
{
28
public
:
29
31
typedef
LeafTreeIterator
Self
;
32
typedef
TreeIteratorBase< TTreeType >
Superclass
;
33
typedef
TTreeType
TreeType
;
34
typedef
typename
TreeType::ValueType
ValueType
;
35
typedef
typename
Superclass::TreeNodeType
TreeNodeType
;
36
typedef
typename
Superclass::NodeType
NodeType
;
37
39
LeafTreeIterator
(
const
TreeType
*tree);
40
42
LeafTreeIterator
(
TreeType
*tree);
43
45
virtual
~LeafTreeIterator
();
46
48
NodeType
GetType
()
const
;
49
51
TreeIteratorBase< TTreeType >
*
Clone
();
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 >
69
LeafTreeIterator< TTreeType >::LeafTreeIterator
(
const
TTreeType *tree):
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 >
87
LeafTreeIterator< TTreeType >::LeafTreeIterator
(TTreeType *tree):
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 >
105
LeafTreeIterator< TTreeType >::~LeafTreeIterator
()
106
{}
107
109
template
<
class
TTreeType >
110
typename
LeafTreeIterator< TTreeType >::NodeType
111
LeafTreeIterator< TTreeType >::GetType
()
const
112
{
113
return
TreeIteratorBase< TTreeType >::LEAF
;
114
}
115
117
template
<
class
TTreeType >
118
bool
LeafTreeIterator< TTreeType >::HasNext
()
const
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 >
134
const
typename
LeafTreeIterator< TTreeType >::ValueType
&
135
LeafTreeIterator< TTreeType >::Next
()
136
{
137
this->m_Position =
const_cast<
TreeNodeType
*
>
( FindNextNode() );
138
return
this->m_Position->Get();
139
}
141
143
template
<
class
TTreeType >
144
const
typename
LeafTreeIterator< TTreeType >::TreeNodeType
*
145
LeafTreeIterator< TTreeType >::FindNextNode
()
const
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 >
174
TreeIteratorBase< TTreeType >
*
LeafTreeIterator< TTreeType >::Clone
()
175
{
176
LeafTreeIterator< TTreeType >
*clone =
new
LeafTreeIterator< TTreeType >
(this->m_Tree);
177
*clone = *
this
;
178
return
clone;
179
}
180
}
// end namespace itk
182
183
#endif
184
Generated on Sun Dec 9 2012 01:16:23 for ITK by
1.8.2