Overture
Version 25
Main Page
Namespaces
Classes
Files
File List
File Members
Overture.v25.d
include
GeometricADT.h
Go to the documentation of this file.
1
#ifndef __KKC_GEOMETRIC_SEARCH__
2
#define __KKC_GEOMETRIC_SEARCH__
3
4
//kkc 040415 #include <iostream.h>
5
#include "
OvertureDefine.h
"
6
#include OV_STD_INCLUDE(iostream)
7
8
#include "
Overture.h
"
9
#include "
NTreeNode.h
"
10
#include "
GeometricADTExceptions.h
"
11
#include "
AssertException.h
"
12
13
#include "
ArraySimple.h
"
14
15
#ifndef OV_USE_OLD_STL_HEADERS
16
#include <list>
17
OV_USINGNAMESPACE
(std);
18
#else
19
#include <list.h>
20
#endif
21
22
template
<
class
dataT>
23
class
GeomADTTuple
// helper class to be used in the GeometricADT
24
{
25
public
:
26
GeomADTTuple
() { ; }
27
GeomADTTuple
(
GeomADTTuple
&x)
28
{
29
boundingBox
= x.
boundingBox
;
30
data
= x.
data
;
31
}
32
// GeomADTTuple(realArray & boundingBox_, realArray &coords_, dataT i)
33
GeomADTTuple
(
ArraySimple<real>
& boundingBox_,
ArraySimple<real>
&coords_, dataT i)
34
{
35
this->
boundingBox
= boundingBox_;
36
//this->boundingBox = evaluate(boundingBox_);
37
data
= i;
38
//this->coords = evaluate(coords_);
39
this->
coords
= coords_;
40
}
41
GeomADTTuple
&
operator=
(
GeomADTTuple
&x)
42
{
43
44
//boundingBox = evaluate(x.boundingBox);
45
boundingBox
= x.
boundingBox
;
46
data
= x.
data
;
47
//coords = evaluate(x.coords);
48
coords
= x.
coords
;
49
return
*
this
;
50
}
51
~GeomADTTuple
() { ; }
52
53
54
// realArray boundingBox;
55
//realArray coords;
56
ArraySimple<real>
boundingBox
;
57
ArraySimple<real>
coords
;
58
dataT
data
;
59
};
60
61
//typedef NTreeNode<2,GeomADTTuple> GeometricADT<dataT>::ADTType;
62
//typedef NTreeNode<2,GeomADTTuple<dataT> > __ADTType;
63
#define __ADTType NTreeNode<2,GeomADTTuple<dataT> >
64
65
const
int
ADT_LEFT
= 0;
66
const
int
ADT_RIGHT
= 1;
67
68
69
// forward declare this guy
70
template
<
class
dataT>
class
GeometricADT
;
71
72
// GeometricADT iterator class
73
template
<
class
dataT>
74
class
__GeometricADTiterator
75
{
76
public
:
77
// __GeometricADTiterator(const GeometricADT<dataT> &gADT, realArray & target_);
78
__GeometricADTiterator
(
const
GeometricADT<dataT>
&gADT,
ArraySimple<real>
& target_);
79
__GeometricADTiterator
(
__GeometricADTiterator
&
x
);
80
~__GeometricADTiterator
();
81
82
__GeometricADTiterator
&
operator=
(
__GeometricADTiterator<dataT>
& i);
83
__GeometricADTiterator
&
operator=
(
NTreeNode
<2,
GeomADTTuple<dataT>
> & i);
84
__GeometricADTiterator
&
operator++
();
// decend to the next node in the tree
85
__GeometricADTiterator
operator++
(
int
);
// decend to the next node in the tree
86
87
GeomADTTuple<dataT>
&
operator*
();
// dereference the iterator
88
89
bool
isTerminal
();
// is this iterator at an end of the tree ?
90
int
getDepth
();
91
92
friend
class
GeometricADT
<dataT>;
93
94
protected
:
95
// these constructors make no sense
96
__GeometricADTiterator
();
// { } // what does this do ?
97
__GeometricADTiterator
(
GeometricADT<dataT>
&x);
// { } // should probably be a standard tree iteration (eg preorder or postorder...)
98
99
private
:
100
GeometricADT<dataT>
*thisADT;
101
__ADTType
*current;
102
103
// realArray target;
104
ArraySimple<real>
target;
105
int
depth
;
106
};
107
108
109
// GeometricADT traversor class
110
template
<
class
dataT>
111
class
__GeometricADTtraversor
// this class should probably have a superclass in NTreeNode
112
{
113
public
:
114
// __GeometricADTtraversor(const GeometricADT<dataT> &gADT, realArray & target_);
115
__GeometricADTtraversor
(
const
GeometricADT<dataT>
&gADT,
ArraySimple<real>
& target_);
116
__GeometricADTtraversor
(
GeometricADT<dataT>
&x) :
117
thisADT((
GeometricADT
<dataT> *)&x), target(x.ADTDimension), a(x.ADTDimension), b(x.ADTDimension) { };
118
__GeometricADTtraversor
(
__GeometricADTtraversor
&x);
119
~__GeometricADTtraversor
();
120
121
__GeometricADTtraversor
&
operator=
(
__GeometricADTtraversor<dataT>
& i);
122
__GeometricADTtraversor
&
operator=
(
NTreeNode
<2,
GeomADTTuple<dataT>
> & i);
123
__GeometricADTtraversor
&
operator++
();
// decend to the next node in the tree
124
__GeometricADTtraversor
operator++
(
int
);
// decend to the next node in the tree
125
126
void
setTarget
(
const
ArraySimple<real>
&target_);
127
128
GeomADTTuple<dataT>
&
operator*
();
// dereference the traversor
129
130
bool
isFinished
()
const
;
// is this traversor finished traversing the tree ?
131
132
int
getDepth
();
133
134
friend
class
GeometricADT
<dataT>;
135
136
protected
:
137
// these constructors make no sense
138
__GeometricADTtraversor
() { }
// what does this do ?
139
140
// bool isOverlapping(int depth, const realArray &bBox);
141
//bool isCandidate(const realArray &candidate);
142
143
bool
isOverlapping
(
int
depth
,
const
ArraySimple<real>
&bBox);
144
bool
isCandidate
(
const
ArraySimple<real>
&candidate);
145
146
private
:
147
int
depth
;
148
bool
traversalFinished;
149
150
list<bool> leftSubTreeFinished;
// keeps a stack of the traversal
151
GeometricADT<dataT>
*thisADT;
152
__ADTType
*current;
153
// realArray target;
154
//realArray a;
155
//realArray b;
156
ArraySimple<real>
target;
157
ArraySimple<real>
a;
158
ArraySimple<real>
b;
159
};
160
161
// Actual GeometricADT class
162
template
<
class
dataT>
163
class
GeometricADT
164
{
165
public
:
166
167
GeometricADT
(
int
rangeDimension_=2);
168
// GeometricADT(const realArray & boundingBox_);
169
GeometricADT
(
int
rangeDimension_,
const
ArraySimple<real>
& boundingBox_);
170
171
typedef
__ADTType
ADTType
;
172
173
~GeometricADT
();
174
175
typedef
__GeometricADTiterator<dataT>
iterator
;
176
typedef
__GeometricADTtraversor<dataT>
traversor
;
177
178
void
initTree
();
179
180
// void initTree(const realArray & boundingBox_);
181
void
initTree
(
int
rangeDimension_,
const
ArraySimple<real>
& boundingBox_);
182
183
// int addElement(realArray & bBox, dataT &data);
184
int
addElement
(
ArraySimple<real>
& bBox, dataT &data);
185
186
int
delElement
(
typename
GeometricADT<dataT>::iterator
& delItem);
187
int
delElement
(
typename
GeometricADT<dataT>::traversor
& delItem);
188
void
verifyTree
();
189
190
//const realArray &getBoundingBox() const { return boundingBox; } // probably should just return a copy of
191
// the boundingBox ?
192
const
ArraySimple<real>
&
getBoundingBox
()
const
{
return
boundingBox; }
// probably should just return a copy of
193
// the boundingBox ?
194
friend
class
__GeometricADTiterator
<dataT>;
195
friend
class
__GeometricADTtraversor
<dataT>;
196
197
protected
:
198
inline
int
getSplitAxis
(
int
depth
)
const
;
199
200
//inline Real getSplitLocation(int axis, const realArray & box) const;
201
inline
Real
getSplitLocation
(
int
axis,
const
ArraySimple<real>
& box)
const
;
202
203
void
shiftTreeUp
(
typename
GeometricADT<dataT>::ADTType
*node,
int
depth
);
// used to rebuild the search tree
204
void
verifyNode
(
typename
GeometricADT<dataT>::ADTType
&node,
int
depth
);
205
int
insert
(
typename
GeometricADT<dataT>::iterator
&insParent,
int
leaf,
GeomADTTuple<dataT>
&data);
206
207
private
:
208
209
int
rangeDimension;
210
int
ADTDimension;
211
int
ADTdepth;
212
int
numberOfItems;
213
214
//realArray boundingBox;
215
ArraySimple<real>
boundingBox;
216
217
typename
GeometricADT<dataT>::ADTType
*adtRoot;
218
219
};
220
221
222
//
223
// implementation of inlined GeometricADT methods
224
//
225
226
227
template
<
class
dataT>
228
inline
229
int
230
GeometricADT<dataT>::
231
getSplitAxis
(
int
depth
)
const
232
{
233
//AssertException<GeometricADT::InvalidDepth> (depth<=ADTdepth);
234
//assert(depth<=ADTdepth);
235
return
depth%ADTDimension;
236
}
237
238
template
<
class
dataT>
239
inline
240
real
241
GeometricADT<dataT>
::
242
//getSplitLocation(int axis, const realArray & box) const
243
getSplitLocation(
int
axis,
const
ArraySimple<real>
& box)
const
244
{
245
//AssertException<InvalidADTDimension> (axis<ADTDimension && box.getLength(0)==2*ADTDimension);
246
//assert(axis<ADTDimension && box.getLength(0)==2*ADTDimension);
247
// return (box(2*axis+1) + box(2*axis))/2.0;
248
return
(box[2*axis+1] + box[2*axis])/2.0;
249
}
250
251
#include "
GeometricADT.C
"
252
#include "
GeometricADTIterator.C
"
253
#include "
GeometricADTTraversor.C
"
254
255
256
#endif
Generated on Fri Jan 4 2013 10:17:52 for Overture by
1.8.3