ITK
4.2.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Core
Common
include
itkTreeIteratorBase.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 __itkTreeIteratorBase_h
19
#define __itkTreeIteratorBase_h
20
21
#include "
itkTreeNode.h
"
22
23
namespace
itk
24
{
41
template
<
class
TTreeType >
42
class
TreeIteratorBase
43
{
44
public
:
45
47
typedef
TreeIteratorBase
Self
;
48
typedef
typename
TTreeType::ValueType
ValueType
;
49
typedef
typename
TTreeType::TreeNodeType
TreeNodeType
;
50
typedef
typename
TreeNodeType::ChildIdentifier
ChildIdentifier
;
51
53
typedef
enum
54
{
55
UNDEFIND
= 0,
56
PREORDER
= 1,
57
INORDER
= 2,
58
POSTORDER
= 3,
59
LEVELORDER
= 4,
60
CHILD
= 5,
61
ROOT
= 6,
62
LEAF
= 7
63
}
64
NodeType
;
65
67
virtual
bool
Add
(
ValueType
element);
68
70
virtual
bool
Add
(
int
position,
ValueType
element);
71
73
virtual
bool
Add
(TTreeType & subTree);
74
76
virtual
const
ValueType
&
Get
()
const
;
77
79
virtual
TTreeType *
GetSubTree
()
const
;
80
82
virtual
bool
IsLeaf
()
const
;
83
85
virtual
bool
IsRoot
()
const
;
86
88
virtual
NodeType
GetType
()
const
= 0;
89
91
virtual
bool
GoToChild
(
ChildIdentifier
number = 0);
92
94
virtual
bool
GoToParent
();
95
97
void
Set
(
ValueType
element);
98
100
virtual
bool
HasChild
(
int
number = 0)
const
;
101
103
virtual
int
ChildPosition
(
ValueType
element)
const
;
104
106
virtual
bool
RemoveChild
(
int
number);
107
109
virtual
int
CountChildren
()
const
;
110
112
virtual
bool
HasParent
()
const
;
113
115
virtual
bool
Disconnect
();
116
118
virtual
TreeIteratorBase< TTreeType >
*
Children
();
119
121
virtual
TreeIteratorBase< TTreeType >
*
Parents
();
122
124
virtual
TreeIteratorBase< TTreeType >
*
GetChild
(
int
number)
const
;
125
127
virtual
int
Count
();
128
130
bool
Remove
();
131
133
virtual
TreeNodeType
*
GetNode
();
134
135
virtual
const
TreeNodeType
*
GetNode
()
const
;
136
138
TreeNodeType
*
GetRoot
();
139
140
const
TreeNodeType
*
GetRoot
()
const
;
141
143
TTreeType *
GetTree
()
const
;
144
146
const
TreeNodeType
*
GetParent
()
const
;
147
149
void
GoToBegin
() {
m_Position
=
m_Begin
; }
150
152
void
GoToEnd
() {
m_Position
=
m_End
; }
153
155
bool
IsAtBegin
(
void
)
const
{
return
(
m_Position
==
m_Begin
); }
156
159
bool
IsAtEnd
(
void
)
const
{
return
(
m_Position
==
m_End
); }
160
162
virtual
TreeIteratorBase< TTreeType >
*
Clone
() = 0;
163
165
Self
&
166
operator++
()
167
{
168
this->
Next
();
169
return
*
this
;
170
}
172
174
void
175
operator++
(
int
)
176
{
177
// itkAssertInDebugAndIgnoreInReleaseMacro( !IsAtEnd() );
178
this->
Next
();
179
}
181
183
const
Self
&
operator=
(
const
Self
& iterator)
184
{
185
m_Position
= iterator.
m_Position
;
186
m_Begin
= iterator.
m_Begin
;
187
m_End
= iterator.
m_End
;
188
m_Root
= iterator.
m_Root
;
189
m_Tree
= iterator.
m_Tree
;
190
return
*
this
;
191
}
192
193
virtual
~TreeIteratorBase
() {}
194
protected
:
195
197
TreeIteratorBase
(TTreeType *tree,
const
TreeNodeType
*start);
198
TreeIteratorBase
(
const
TTreeType *tree,
const
TreeNodeType
*start);
200
201
mutable
TreeNodeType
*
m_Position
;
// Current position of the iterator
202
mutable
TreeNodeType
*
m_Begin
;
203
mutable
TreeNodeType
*
m_End
;
204
const
TreeNodeType
*
m_Root
;
205
TTreeType *
m_Tree
;
206
207
virtual
bool
HasNext
()
const
= 0;
208
209
virtual
const
ValueType
&
Next
() = 0;
210
};
211
}
//end namespace itk
212
213
// Define instantiation macro for this template.
214
#define ITK_TEMPLATE_TreeIteratorBase(_, EXPORT, TypeX, TypeY) \
215
namespace itk \
216
{ \
217
_( 1 ( class EXPORT TreeIteratorBase< ITK_TEMPLATE_1 TypeX > ) ) \
218
namespace Templates \
219
{ \
220
typedef TreeIteratorBase< ITK_TEMPLATE_1 TypeX > \
221
TreeIteratorBase##TypeY; \
222
} \
223
}
224
225
#if ITK_TEMPLATE_EXPLICIT
226
#include "Templates/itkTreeIteratorBase+-.h"
227
#endif
228
229
#if ITK_TEMPLATE_TXX
230
#include "itkTreeIteratorBase.hxx"
231
#endif
232
233
#endif
234
Generated on Tue Jul 10 2012 23:46:24 for ITK by
1.8.1