Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/adfront2.cpp
3206 views
1
/*
2
Advancing front class for surfaces
3
*/
4
5
#include <mystdlib.h>
6
#include "meshing.hpp"
7
8
9
namespace netgen
10
{
11
AdFront2::FrontPoint2 :: FrontPoint2 (const Point<3> & ap, PointIndex agi,
12
MultiPointGeomInfo * amgi, bool aonsurface)
13
{
14
p = ap;
15
globalindex = agi;
16
nlinetopoint = 0;
17
frontnr = INT_MAX-10;
18
onsurface = aonsurface;
19
20
if (amgi)
21
{
22
mgi = new MultiPointGeomInfo (*amgi);
23
for (int i = 1; i <= mgi->GetNPGI(); i++)
24
if (mgi->GetPGI(i).trignum <= 0)
25
cout << "Add FrontPoint2, illegal geominfo = " << mgi->GetPGI(i).trignum << endl;
26
}
27
else
28
mgi = NULL;
29
}
30
31
32
AdFront2 :: AdFront2 (const Box3d & aboundingbox)
33
: boundingbox(aboundingbox),
34
linesearchtree(boundingbox.PMin(), boundingbox.PMax()),
35
pointsearchtree(boundingbox.PMin(), boundingbox.PMax()),
36
cpointsearchtree(boundingbox.PMin(), boundingbox.PMax())
37
{
38
nfl = 0;
39
allflines = 0;
40
41
minval = 0;
42
starti = lines.Begin();
43
}
44
45
AdFront2 :: ~AdFront2 ()
46
{
47
delete allflines;
48
}
49
50
51
void AdFront2 :: PrintOpenSegments (ostream & ost) const
52
{
53
if (nfl > 0)
54
{
55
ost << nfl << " open front segments left:" << endl;
56
for (int i = lines.Begin(); i < lines.End(); i++)
57
if (lines[i].Valid())
58
ost << i << ": "
59
<< GetGlobalIndex (lines[i].L().I1()) << "-"
60
<< GetGlobalIndex (lines[i].L().I2()) << endl;
61
}
62
}
63
64
/*
65
void AdFront2 :: GetPoints (ARRAY<Point<3> > & apoints) const
66
{
67
apoints.Append (points);
68
// for (int i = 0; i < points.Size(); i++)
69
// apoints.Append (points[i].P());
70
}
71
*/
72
73
74
75
int AdFront2 :: AddPoint (const Point<3> & p, PointIndex globind,
76
MultiPointGeomInfo * mgi,
77
bool pointonsurface)
78
{
79
// inserts at empty position or resizes array
80
int pi;
81
82
if (delpointl.Size() != 0)
83
{
84
pi = delpointl.Last();
85
delpointl.DeleteLast ();
86
87
points[pi] = FrontPoint2 (p, globind, mgi, pointonsurface);
88
}
89
else
90
{
91
pi = points.Append (FrontPoint2 (p, globind, mgi, pointonsurface)) - 1;
92
}
93
94
if (mgi)
95
cpointsearchtree.Insert (p, pi);
96
97
pointsearchtree.Insert (p, pi);
98
99
return pi;
100
}
101
102
103
int AdFront2 :: AddLine (int pi1, int pi2,
104
const PointGeomInfo & gi1, const PointGeomInfo & gi2)
105
{
106
int minfn;
107
int li;
108
109
FrontPoint2 & p1 = points[pi1];
110
FrontPoint2 & p2 = points[pi2];
111
112
113
nfl++;
114
115
p1.AddLine();
116
p2.AddLine();
117
118
minfn = min2 (p1.FrontNr(), p2.FrontNr());
119
p1.DecFrontNr (minfn+1);
120
p2.DecFrontNr (minfn+1);
121
122
if (dellinel.Size() != 0)
123
{
124
li = dellinel.Last();
125
dellinel.DeleteLast ();
126
lines[li] = FrontLine (INDEX_2(pi1, pi2));
127
}
128
else
129
{
130
li = lines.Append(FrontLine (INDEX_2(pi1, pi2))) - 1;
131
}
132
133
134
if (!gi1.trignum || !gi2.trignum)
135
{
136
cout << "ERROR: in AdFront::AddLine, illegal geominfo" << endl;
137
}
138
139
lines[li].SetGeomInfo (gi1, gi2);
140
141
Box3d lbox;
142
lbox.SetPoint(p1.P());
143
lbox.AddPoint(p2.P());
144
145
linesearchtree.Insert (lbox.PMin(), lbox.PMax(), li);
146
147
if (allflines)
148
{
149
if (allflines->Used (INDEX_2 (GetGlobalIndex (pi1),
150
GetGlobalIndex (pi2))))
151
{
152
cerr << "ERROR Adfront2::AddLine: line exists" << endl;
153
(*testout) << "ERROR Adfront2::AddLine: line exists" << endl;
154
}
155
156
allflines->Set (INDEX_2 (GetGlobalIndex (pi1),
157
GetGlobalIndex (pi2)), 1);
158
}
159
160
return li;
161
}
162
163
164
void AdFront2 :: DeleteLine (int li)
165
{
166
int pi;
167
168
nfl--;
169
170
for (int i = 1; i <= 2; i++)
171
{
172
pi = lines[li].L().I(i);
173
points[pi].RemoveLine();
174
175
if (!points[pi].Valid())
176
{
177
delpointl.Append (pi);
178
if (points[pi].mgi)
179
{
180
cpointsearchtree.DeleteElement (pi);
181
delete points[pi].mgi;
182
points[pi].mgi = NULL;
183
}
184
185
pointsearchtree.DeleteElement (pi);
186
}
187
}
188
189
if (allflines)
190
{
191
allflines->Set (INDEX_2 (GetGlobalIndex (lines[li].L().I1()),
192
GetGlobalIndex (lines[li].L().I2())), 2);
193
}
194
195
lines[li].Invalidate();
196
linesearchtree.DeleteElement (li);
197
198
dellinel.Append (li);
199
}
200
201
202
int AdFront2 :: ExistsLine (int pi1, int pi2)
203
{
204
if (!allflines)
205
return 0;
206
if (allflines->Used (INDEX_2(pi1, pi2)))
207
return allflines->Get (INDEX_2 (pi1, pi2));
208
else
209
return 0;
210
}
211
212
213
/*
214
void AdFront2 :: IncrementClass (int li)
215
{
216
lines[li].IncrementClass();
217
}
218
219
220
void AdFront2 :: ResetClass (int li)
221
{
222
lines[li].ResetClass();
223
}
224
*/
225
226
int AdFront2 :: SelectBaseLine (Point<3> & p1, Point<3> & p2,
227
const PointGeomInfo *& geominfo1,
228
const PointGeomInfo *& geominfo2,
229
int & qualclass)
230
{
231
int baselineindex = -1;
232
233
for (int i = starti; i < lines.End(); i++)
234
{
235
if (lines[i].Valid())
236
{
237
int hi = lines[i].LineClass() +
238
points[lines[i].L().I1()].FrontNr() +
239
points[lines[i].L().I2()].FrontNr();
240
241
if (hi <= minval)
242
{
243
minval = hi;
244
baselineindex = i;
245
break;
246
}
247
}
248
}
249
250
if (baselineindex == -1)
251
{
252
minval = INT_MAX;
253
for (int i = lines.Begin(); i < lines.End(); i++)
254
if (lines[i].Valid())
255
{
256
int hi = lines[i].LineClass() +
257
points[lines[i].L().I1()].FrontNr() +
258
points[lines[i].L().I2()].FrontNr();
259
260
if (hi < minval)
261
{
262
minval = hi;
263
baselineindex = i;
264
}
265
}
266
}
267
starti = baselineindex+1;
268
269
p1 = points[lines[baselineindex].L().I1()].P();
270
p2 = points[lines[baselineindex].L().I2()].P();
271
geominfo1 = &lines[baselineindex].GetGeomInfo(1);
272
geominfo2 = &lines[baselineindex].GetGeomInfo(2);
273
274
qualclass = lines[baselineindex].LineClass();
275
276
return baselineindex;
277
}
278
279
280
281
282
int AdFront2 :: GetLocals (int baselineindex,
283
ARRAY<Point3d> & locpoints,
284
ARRAY<MultiPointGeomInfo> & pgeominfo,
285
ARRAY<INDEX_2> & loclines, // local index
286
ARRAY<INDEX> & pindex,
287
ARRAY<INDEX> & lindex,
288
double xh)
289
{
290
// baselineindex += 1-lines.Begin();
291
292
int pstind;
293
Point<3> midp, p0;
294
295
pstind = lines[baselineindex].L().I1();
296
p0 = points[pstind].P();
297
298
loclines.Append(lines[baselineindex].L());
299
lindex.Append(baselineindex); // +1-lines.Begin());
300
301
static ARRAY<int> nearlines;
302
nearlines.SetSize(0);
303
static ARRAY<int> nearpoints;
304
nearpoints.SetSize(0);
305
306
linesearchtree.GetIntersecting (p0 - Vec3d(xh, xh, xh),
307
p0 + Vec3d(xh, xh, xh),
308
nearlines);
309
310
pointsearchtree.GetIntersecting (p0 - Vec3d(xh, xh, xh),
311
p0 + Vec3d(xh, xh, xh),
312
nearpoints);
313
314
315
for (int ii = 1; ii <= nearlines.Size(); ii++)
316
{
317
int i = nearlines.Get(ii);
318
if (lines[i].Valid() && i != baselineindex) // + 1-lines.Begin())
319
{
320
loclines.Append(lines[i].L());
321
lindex.Append(i);
322
}
323
}
324
325
static ARRAY<int> invpindex;
326
invpindex.SetSize (points.Size());
327
// invpindex = -1;
328
for (int i = 0; i < nearpoints.Size(); i++)
329
invpindex[nearpoints[i]] = -1;
330
331
for (int i = 0; i < loclines.Size(); i++)
332
{
333
invpindex[loclines[i].I1()] = 0;
334
invpindex[loclines[i].I2()] = 0;
335
}
336
337
338
for (int i = 0; i < loclines.Size(); i++)
339
{
340
for (int j = 0; j < 2; j++)
341
{
342
int pi = loclines[i][j];
343
if (invpindex[pi] == 0)
344
{
345
pindex.Append (pi);
346
invpindex[pi] = pindex.Size();
347
loclines[i][j] = locpoints.Append (points[pi].P());
348
}
349
else
350
loclines[i][j] = invpindex[pi];
351
}
352
}
353
354
355
// double xh2 = xh*xh;
356
for (int ii = 0; ii < nearpoints.Size(); ii++)
357
{
358
int i = nearpoints[ii];
359
if (points[i].Valid() &&
360
points[i].OnSurface() &&
361
// Dist2 (points.Get(i).P(), p0) <= xh2 &&
362
invpindex[i] <= 0)
363
{
364
invpindex[i] = locpoints.Append (points[i].P());
365
pindex.Append(i);
366
}
367
}
368
/*
369
double xh2 = xh*xh;
370
for (i = 1; i <= points.Size(); i++)
371
{
372
if (points.Get(i).Valid() &&
373
points.Get(i).OnSurface() &&
374
Dist2 (points.Get(i).P(), p0) <= xh2 &&
375
invpindex.Get(i) <= 0)
376
{
377
invpindex.Elem(i) =
378
locpoints.Append (points.Get(i).P());
379
pindex.Append(i);
380
}
381
}
382
*/
383
384
pgeominfo.SetSize (locpoints.Size());
385
for (int i = 0; i < pgeominfo.Size(); i++)
386
pgeominfo[i].Init();
387
388
389
for (int i = 0; i < loclines.Size(); i++)
390
for (int j = 0; j < 2; j++)
391
{
392
int lpi = loclines[i][j];
393
394
const PointGeomInfo & gi =
395
lines[lindex[i]].GetGeomInfo (j+1);
396
pgeominfo.Elem(lpi).AddPointGeomInfo (gi);
397
398
/*
399
if (pgeominfo.Elem(lpi).cnt == MULTIPOINTGEOMINFO_MAX)
400
break;
401
402
const PointGeomInfo & gi =
403
lines.Get(lindex.Get(i)).GetGeomInfo (j);
404
405
PointGeomInfo * pgi = pgeominfo.Elem(lpi).mgi;
406
407
int found = 0;
408
for (k = 0; k < pgeominfo.Elem(lpi).cnt; k++)
409
if (pgi[k].trignum == gi.trignum)
410
found = 1;
411
412
if (!found)
413
{
414
pgi[pgeominfo.Elem(lpi).cnt] = gi;
415
pgeominfo.Elem(lpi).cnt++;
416
}
417
*/
418
}
419
420
for (int i = 0; i < locpoints.Size(); i++)
421
{
422
int pi = pindex[i];
423
424
if (points[pi].mgi)
425
for (int j = 1; j <= points[pi].mgi->GetNPGI(); j++)
426
pgeominfo[i].AddPointGeomInfo (points[pi].mgi->GetPGI(j));
427
}
428
429
if (loclines.Size() == 1)
430
{
431
cout << "loclines.Size = 1" << endl;
432
(*testout) << "loclines.size = 1" << endl
433
<< " h = " << xh << endl
434
<< " nearline.size = " << nearlines.Size() << endl
435
<< " p0 = " << p0 << endl;
436
}
437
438
return lines[baselineindex].LineClass();
439
}
440
441
442
443
void AdFront2 :: SetStartFront ()
444
{
445
for (int i = lines.Begin(); i < lines.End(); i++)
446
if (lines[i].Valid())
447
for (int j = 1; j <= 2; j++)
448
points[lines[i].L().I(j)].DecFrontNr(0);
449
}
450
451
452
void AdFront2 :: Print (ostream & ost) const
453
{
454
ost << points.Size() << " Points: " << endl;
455
for (int i = points.Begin(); i < points.End(); i++)
456
if (points[i].Valid())
457
ost << i << " " << points[i].P() << endl;
458
459
ost << nfl << " Lines: " << endl;
460
for (int i = lines.Begin(); i < lines.End(); i++)
461
if (lines[i].Valid())
462
ost << lines[i].L().I1() << " - " << lines[i].L().I2() << endl;
463
464
ost << flush;
465
}
466
}
467
468