Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/gprim/adtree.hpp
3206 views
1
#ifndef FILE_ADTREE
2
#define FILE_ADTREE
3
4
/* *************************************************************************/
5
/* File: adtree.hh */
6
/* Author: Joachim Schoeberl */
7
/* Date: 16. Feb. 98 */
8
/* Redesigned by Wolfram Muehlhuber, May 1998 */
9
/* *************************************************************************/
10
11
12
13
/**
14
Alternating Digital Tree
15
*/
16
17
#include "../include/mystdlib.h"
18
#include "../include/myadt.hpp"
19
20
class ADTreeNode
21
{
22
public:
23
ADTreeNode *left, *right, *father;
24
int dim;
25
float sep;
26
float *data;
27
float *boxmin;
28
float *boxmax;
29
int pi;
30
int nchilds;
31
32
ADTreeNode (int adim);
33
~ADTreeNode ();
34
35
friend class ADTree;
36
};
37
38
39
class ADTreeCriterion
40
{
41
public:
42
ADTreeCriterion() { }
43
virtual int Eval (const ADTreeNode * node) const = 0;
44
};
45
46
47
class ADTree
48
{
49
int dim;
50
ADTreeNode * root;
51
float *cmin, *cmax;
52
ARRAY<ADTreeNode*> ela;
53
const ADTreeCriterion * criterion;
54
55
ARRAY<ADTreeNode*> stack;
56
ARRAY<int> stackdir;
57
int stackindex;
58
59
public:
60
ADTree (int adim, const float * acmin,
61
const float * acmax);
62
~ADTree ();
63
64
void Insert (const float * p, int pi);
65
// void GetIntersecting (const float * bmin, const float * bmax,
66
// ARRAY<int> & pis) const;
67
void SetCriterion (ADTreeCriterion & acriterion);
68
void Reset ();
69
int Next ();
70
void GetMatch (ARRAY<int> & matches);
71
72
void DeleteElement (int pi);
73
74
75
void Print (ostream & ost) const
76
{ PrintRec (ost, root); }
77
78
void PrintRec (ostream & ost, const ADTreeNode * node) const;
79
};
80
81
82
83
class ADTreeNode3
84
{
85
public:
86
ADTreeNode3 *left, *right, *father;
87
float sep;
88
float data[3];
89
int pi;
90
int nchilds;
91
92
ADTreeNode3 ();
93
void DeleteChilds ();
94
friend class ADTree3;
95
96
static BlockAllocator ball;
97
void * operator new(size_t);
98
void operator delete (void *);
99
};
100
101
102
class ADTree3
103
{
104
ADTreeNode3 * root;
105
float cmin[3], cmax[3];
106
ARRAY<ADTreeNode3*> ela;
107
108
public:
109
ADTree3 (const float * acmin,
110
const float * acmax);
111
~ADTree3 ();
112
113
void Insert (const float * p, int pi);
114
void GetIntersecting (const float * bmin, const float * bmax,
115
ARRAY<int> & pis) const;
116
117
void DeleteElement (int pi);
118
119
120
void Print (ostream & ost) const
121
{ PrintRec (ost, root); }
122
123
void PrintRec (ostream & ost, const ADTreeNode3 * node) const;
124
};
125
126
127
/*
128
129
// divide each direction
130
#define ADTN_DIV 10
131
class ADTreeNode3Div
132
{
133
public:
134
ADTreeNode3Div *father;
135
ADTreeNode3Div *childs[ADTN_DIV];
136
137
float minx, dist;
138
float data[3];
139
int pi;
140
int nchilds;
141
142
ADTreeNode3Div ();
143
void DeleteChilds ();
144
friend class ADTree3Div;
145
146
static BlockAllocator ball;
147
void * operator new(size_t);
148
void operator delete (void *);
149
};
150
151
152
class ADTree3Div
153
{
154
ADTreeNode3Div * root;
155
float cmin[3], cmax[3];
156
ARRAY<ADTreeNode3Div*> ela;
157
158
public:
159
ADTree3Div (const float * acmin,
160
const float * acmax);
161
~ADTree3Div ();
162
163
void Insert (const float * p, int pi);
164
void GetIntersecting (const float * bmin, const float * bmax,
165
ARRAY<int> & pis) const;
166
167
void DeleteElement (int pi);
168
169
170
void Print (ostream & ost) const
171
{ PrintRec (ost, root); }
172
173
void PrintRec (ostream & ost, const ADTreeNode3Div * node) const;
174
};
175
176
177
178
179
#define ADTN_SIZE 10
180
181
// multiple entries
182
class ADTreeNode3M
183
{
184
public:
185
ADTreeNode3M *left, *right, *father;
186
float sep;
187
float data[ADTN_SIZE][3];
188
int pi[ADTN_SIZE];
189
int nchilds;
190
191
ADTreeNode3M ();
192
void DeleteChilds ();
193
friend class ADTree3M;
194
195
static BlockAllocator ball;
196
void * operator new(size_t);
197
void operator delete (void *);
198
};
199
200
201
class ADTree3M
202
{
203
ADTreeNode3M * root;
204
float cmin[3], cmax[3];
205
ARRAY<ADTreeNode3M*> ela;
206
207
public:
208
ADTree3M (const float * acmin,
209
const float * acmax);
210
~ADTree3M ();
211
212
void Insert (const float * p, int pi);
213
void GetIntersecting (const float * bmin, const float * bmax,
214
ARRAY<int> & pis) const;
215
216
void DeleteElement (int pi);
217
218
219
void Print (ostream & ost) const
220
{ PrintRec (ost, root); }
221
222
void PrintRec (ostream & ost, const ADTreeNode3M * node) const;
223
};
224
225
226
227
228
229
230
class ADTreeNode3F
231
{
232
public:
233
ADTreeNode3F *father;
234
ADTreeNode3F *childs[8];
235
float sep[3];
236
float data[3];
237
int pi;
238
int nchilds;
239
240
ADTreeNode3F ();
241
void DeleteChilds ();
242
friend class ADTree3F;
243
244
static BlockAllocator ball;
245
void * operator new(size_t);
246
void operator delete (void *);
247
};
248
249
// fat tree
250
class ADTree3F
251
{
252
ADTreeNode3F * root;
253
float cmin[3], cmax[3];
254
ARRAY<ADTreeNode3F*> ela;
255
256
public:
257
ADTree3F (const float * acmin,
258
const float * acmax);
259
~ADTree3F ();
260
261
void Insert (const float * p, int pi);
262
void GetIntersecting (const float * bmin, const float * bmax,
263
ARRAY<int> & pis) const;
264
265
void DeleteElement (int pi);
266
267
268
void Print (ostream & ost) const
269
{ PrintRec (ost, root); }
270
271
void PrintRec (ostream & ost, const ADTreeNode3F * node) const;
272
};
273
274
275
276
277
class ADTreeNode3FM
278
{
279
public:
280
ADTreeNode3FM *father;
281
ADTreeNode3FM *childs[8];
282
float sep[3];
283
float data[ADTN_SIZE][3];
284
int pi[ADTN_SIZE];
285
int nchilds;
286
287
ADTreeNode3FM ();
288
void DeleteChilds ();
289
friend class ADTree3FM;
290
291
static BlockAllocator ball;
292
void * operator new(size_t);
293
void operator delete (void *);
294
};
295
296
// fat tree
297
class ADTree3FM
298
{
299
ADTreeNode3FM * root;
300
float cmin[3], cmax[3];
301
ARRAY<ADTreeNode3FM*> ela;
302
303
public:
304
ADTree3FM (const float * acmin,
305
const float * acmax);
306
~ADTree3FM ();
307
308
void Insert (const float * p, int pi);
309
void GetIntersecting (const float * bmin, const float * bmax,
310
ARRAY<int> & pis) const;
311
312
void DeleteElement (int pi);
313
314
315
void Print (ostream & ost) const
316
{ PrintRec (ost, root); }
317
318
void PrintRec (ostream & ost, const ADTreeNode3FM * node) const;
319
};
320
321
322
323
*/
324
325
326
327
328
329
class ADTreeNode6
330
{
331
public:
332
ADTreeNode6 *left, *right, *father;
333
float sep;
334
float data[6];
335
int pi;
336
int nchilds;
337
338
ADTreeNode6 ();
339
void DeleteChilds ();
340
friend class ADTree6;
341
342
static BlockAllocator ball;
343
void * operator new(size_t);
344
void operator delete (void *);
345
};
346
347
348
class ADTree6
349
{
350
ADTreeNode6 * root;
351
float cmin[6], cmax[6];
352
ARRAY<ADTreeNode6*> ela;
353
354
public:
355
ADTree6 (const float * acmin,
356
const float * acmax);
357
~ADTree6 ();
358
359
void Insert (const float * p, int pi);
360
void GetIntersecting (const float * bmin, const float * bmax,
361
ARRAY<int> & pis) const;
362
363
void DeleteElement (int pi);
364
365
366
void Print (ostream & ost) const
367
{ PrintRec (ost, root); }
368
int Depth () const
369
{ return DepthRec (root); }
370
int Elements () const
371
{ return ElementsRec (root); }
372
373
void PrintRec (ostream & ost, const ADTreeNode6 * node) const;
374
int DepthRec (const ADTreeNode6 * node) const;
375
int ElementsRec (const ADTreeNode6 * node) const;
376
377
void PrintMemInfo (ostream & ost) const;
378
};
379
380
381
382
383
/*
384
385
class ADTreeNode6F
386
{
387
public:
388
ADTreeNode6F * father;
389
ADTreeNode6F * childs[64];
390
391
float sep[6];
392
float data[6];
393
int pi;
394
int nchilds;
395
396
ADTreeNode6F ();
397
void DeleteChilds ();
398
friend class ADTree6F;
399
400
static BlockAllocator ball;
401
void * operator new(size_t);
402
void operator delete (void *);
403
};
404
405
406
class ADTree6F
407
{
408
ADTreeNode6F * root;
409
float cmin[6], cmax[6];
410
ARRAY<ADTreeNode6F*> ela;
411
412
public:
413
ADTree6F (const float * acmin,
414
const float * acmax);
415
~ADTree6F ();
416
417
void Insert (const float * p, int pi);
418
void GetIntersecting (const float * bmin, const float * bmax,
419
ARRAY<int> & pis) const;
420
421
void DeleteElement (int pi);
422
423
424
void Print (ostream & ost) const
425
{ PrintRec (ost, root); }
426
int Depth () const
427
{ return DepthRec (root); }
428
429
void PrintRec (ostream & ost, const ADTreeNode6F * node) const;
430
int DepthRec (const ADTreeNode6F * node) const;
431
};
432
433
434
435
436
437
438
439
*/
440
441
442
443
444
445
class Point3dTree
446
{
447
ADTree3 * tree;
448
449
public:
450
Point3dTree (const Point3d & pmin, const Point3d & pmax);
451
~Point3dTree ();
452
void Insert (const Point3d & p, int pi);
453
void DeleteElement (int pi)
454
{ tree->DeleteElement(pi); }
455
void GetIntersecting (const Point3d & pmin, const Point3d & pmax,
456
ARRAY<int> & pis) const;
457
const ADTree3 & Tree() const { return *tree; };
458
};
459
460
461
462
class Box3dTree
463
{
464
ADTree6 * tree;
465
Point3d boxpmin, boxpmax;
466
public:
467
Box3dTree (const Point3d & apmin, const Point3d & apmax);
468
~Box3dTree ();
469
void Insert (const Point3d & bmin, const Point3d & bmax, int pi);
470
void Insert (const Box<3> & box, int pi)
471
{
472
Insert (box.PMin(), box.PMax(), pi);
473
}
474
void DeleteElement (int pi)
475
{ tree->DeleteElement(pi); }
476
void GetIntersecting (const Point3d & pmin, const Point3d & pmax,
477
ARRAY<int> & pis) const;
478
479
const ADTree6 & Tree() const { return *tree; };
480
};
481
#endif
482
483