Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/meshing2.cpp
3206 views
1
#include <mystdlib.h>
2
#include "meshing.hpp"
3
4
namespace netgen
5
{
6
static void glrender (int wait);
7
8
9
// global variable for visualization
10
11
static ARRAY<Point3d> locpoints;
12
static ARRAY<int> legalpoints;
13
static ARRAY<Point2d> plainpoints;
14
static ARRAY<int> plainzones;
15
static ARRAY<INDEX_2> loclines;
16
static int geomtrig;
17
//static const char * rname;
18
static int cntelem, trials, nfaces;
19
static int oldnl;
20
static int qualclass;
21
22
23
Meshing2 :: Meshing2 (const Box<3> & aboundingbox)
24
{
25
boundingbox = aboundingbox;
26
27
LoadRules (NULL);
28
// LoadRules ("rules/quad.rls");
29
// LoadRules ("rules/triangle.rls");
30
31
adfront = new AdFront2(boundingbox);
32
starttime = GetTime();
33
34
maxarea = -1;
35
}
36
37
38
Meshing2 :: ~Meshing2 ()
39
{
40
delete adfront;
41
for (int i = 0; i < rules.Size(); i++)
42
delete rules[i];
43
}
44
45
void Meshing2 :: AddPoint (const Point3d & p, PointIndex globind,
46
MultiPointGeomInfo * mgi,
47
bool pointonsurface)
48
{
49
//(*testout) << "add point " << globind << endl;
50
adfront ->AddPoint (p, globind, mgi, pointonsurface);
51
}
52
53
void Meshing2 :: AddBoundaryElement (int i1, int i2,
54
const PointGeomInfo & gi1, const PointGeomInfo & gi2)
55
{
56
// (*testout) << "add line " << i1 << " - " << i2 << endl;
57
if (!gi1.trignum || !gi2.trignum)
58
{
59
PrintSysError ("addboundaryelement: illegal geominfo");
60
}
61
adfront -> AddLine (i1-1, i2-1, gi1, gi2);
62
}
63
64
65
66
void Meshing2 :: StartMesh ()
67
{
68
foundmap.SetSize (rules.Size());
69
canuse.SetSize (rules.Size());
70
ruleused.SetSize (rules.Size());
71
72
foundmap = 0;
73
canuse = 0;
74
ruleused = 0;
75
76
cntelem = 0;
77
trials = 0;
78
}
79
80
void Meshing2 :: EndMesh ()
81
{
82
for (int i = 0; i < ruleused.Size(); i++)
83
(*testout) << setw(4) << ruleused[i]
84
<< " times used rule " << rules[i] -> Name() << endl;
85
}
86
87
void Meshing2 :: SetStartTime (double astarttime)
88
{
89
starttime = astarttime;
90
}
91
92
93
void Meshing2 :: SetMaxArea (double amaxarea)
94
{
95
maxarea = amaxarea;
96
}
97
98
99
double Meshing2 :: CalcLocalH (const Point3d & /* p */, double gh) const
100
{
101
return gh;
102
}
103
104
// should be class variables !!(?)
105
static Vec3d ex, ey;
106
static Point3d globp1;
107
108
void Meshing2 :: DefineTransformation (const Point3d & p1, const Point3d & p2,
109
const PointGeomInfo * geominfo1,
110
const PointGeomInfo * geominfo2)
111
{
112
globp1 = p1;
113
ex = p2 - p1;
114
ex /= ex.Length();
115
ey.X() = -ex.Y();
116
ey.Y() = ex.X();
117
ey.Z() = 0;
118
}
119
120
void Meshing2 :: TransformToPlain (const Point3d & locpoint,
121
const MultiPointGeomInfo & geominf,
122
Point2d & plainpoint, double h, int & zone)
123
{
124
Vec3d p1p (globp1, locpoint);
125
126
// p1p = locpoint - globp1;
127
p1p /= h;
128
plainpoint.X() = p1p * ex;
129
plainpoint.Y() = p1p * ey;
130
zone = 0;
131
}
132
133
int Meshing2 :: TransformFromPlain (Point2d & plainpoint,
134
Point3d & locpoint,
135
PointGeomInfo & gi,
136
double h)
137
{
138
Vec3d p1p;
139
gi.trignum = 1;
140
141
p1p = plainpoint.X() * ex + plainpoint.Y() * ey;
142
p1p *= h;
143
locpoint = globp1 + p1p;
144
return 0;
145
}
146
147
148
int Meshing2 :: BelongsToActiveChart (const Point3d & p,
149
const PointGeomInfo & gi)
150
{
151
return 1;
152
}
153
154
155
int Meshing2 :: ComputePointGeomInfo (const Point3d & p, PointGeomInfo & gi)
156
{
157
gi.trignum = 1;
158
return 0;
159
}
160
161
162
int Meshing2 :: ChooseChartPointGeomInfo (const MultiPointGeomInfo & mpgi,
163
PointGeomInfo & pgi)
164
{
165
pgi = mpgi.GetPGI(1);
166
return 0;
167
}
168
169
170
171
int Meshing2 ::
172
IsLineVertexOnChart (const Point3d & p1, const Point3d & p2,
173
int endpoint, const PointGeomInfo & geominfo)
174
{
175
return 1;
176
}
177
178
void Meshing2 ::
179
GetChartBoundary (ARRAY<Point2d> & points,
180
ARRAY<Point3d> & points3d,
181
ARRAY<INDEX_2> & lines, double h) const
182
{
183
points.SetSize (0);
184
points3d.SetSize (0);
185
lines.SetSize (0);
186
}
187
188
double Meshing2 :: Area () const
189
{
190
return -1;
191
}
192
193
194
195
196
197
MESHING2_RESULT Meshing2 :: GenerateMesh (Mesh & mesh, double gh, int facenr)
198
{
199
ARRAY<int> pindex, lindex;
200
ARRAY<int> delpoints, dellines;
201
202
ARRAY<PointGeomInfo> upgeominfo; // unique info
203
ARRAY<MultiPointGeomInfo> mpgeominfo; // multiple info
204
205
ARRAY<Element2d> locelements;
206
207
int z1, z2, oldnp(-1);
208
SurfaceElementIndex sei;
209
bool found;
210
int rulenr(-1);
211
int globind;
212
Point<3> p1, p2;
213
214
const PointGeomInfo * blgeominfo1;
215
const PointGeomInfo * blgeominfo2;
216
217
bool morerisc;
218
bool debugflag;
219
220
double h, his, hshould;
221
222
223
// test for 3d overlaps
224
Box3dTree surfeltree (boundingbox.PMin(),
225
boundingbox.PMax());
226
227
ARRAY<int> intersecttrias;
228
ARRAY<Point3d> critpoints;
229
230
// test for doubled edges
231
//INDEX_2_HASHTABLE<int> doubleedge(300000);
232
233
234
testmode = 0;
235
236
StartMesh();
237
238
ARRAY<Point2d> chartboundpoints;
239
ARRAY<Point3d> chartboundpoints3d;
240
ARRAY<INDEX_2> chartboundlines;
241
242
// illegal points: points with more then 50 elements per node
243
int maxlegalpoint(-1), maxlegalline(-1);
244
ARRAY<int,PointIndex::BASE> trigsonnode;
245
ARRAY<int,PointIndex::BASE> illegalpoint;
246
247
trigsonnode.SetSize (mesh.GetNP());
248
illegalpoint.SetSize (mesh.GetNP());
249
250
trigsonnode = 0;
251
illegalpoint = 0;
252
253
254
double totalarea = Area ();
255
double meshedarea = 0;
256
257
// search tree for surface elements:
258
for (sei = 0; sei < mesh.GetNSE(); sei++)
259
{
260
const Element2d & sel = mesh[sei];
261
262
if (sel.IsDeleted()) continue;
263
264
if (sel.GetIndex() == facenr)
265
{
266
Box<3> box;
267
box.Set ( mesh[sel[0]] );
268
box.Add ( mesh[sel[1]] );
269
box.Add ( mesh[sel[2]] );
270
surfeltree.Insert (box, sei);
271
}
272
273
double trigarea = Cross ( mesh[sel[1]]-mesh[sel[0]],
274
mesh[sel[2]]-mesh[sel[0]] ).Length() / 2;
275
276
277
if (sel.GetNP() == 4)
278
trigarea += Cross (Vec3d (mesh.Point (sel.PNum(1)),
279
mesh.Point (sel.PNum(3))),
280
Vec3d (mesh.Point (sel.PNum(1)),
281
mesh.Point (sel.PNum(4)))).Length() / 2;;
282
meshedarea += trigarea;
283
}
284
285
286
const char * savetask = multithread.task;
287
multithread.task = "Surface meshing";
288
289
adfront ->SetStartFront ();
290
291
292
int plotnexttrial = 999;
293
294
double meshedarea_before = meshedarea;
295
296
while (!adfront ->Empty() && !multithread.terminate)
297
{
298
if (multithread.terminate)
299
throw NgException ("Meshing stopped");
300
301
// known for STL meshing
302
if (totalarea > 0)
303
multithread.percent = 100 * meshedarea / totalarea;
304
/*
305
else
306
multithread.percent = 0;
307
*/
308
309
locpoints.SetSize(0);
310
loclines.SetSize(0);
311
pindex.SetSize(0);
312
lindex.SetSize(0);
313
delpoints.SetSize(0);
314
dellines.SetSize(0);
315
locelements.SetSize(0);
316
317
318
319
// plot statistics
320
if (trials > plotnexttrial)
321
{
322
PrintMessage (5,
323
"faces = ", nfaces,
324
" trials = ", trials,
325
" elements = ", mesh.GetNSE(),
326
" els/sec = ",
327
(mesh.GetNSE() / (GetTime() - starttime + 0.0001)));
328
plotnexttrial += 1000;
329
}
330
331
332
// unique-pgi, multi-pgi
333
upgeominfo.SetSize(0);
334
mpgeominfo.SetSize(0);
335
336
337
nfaces = adfront->GetNFL();
338
trials ++;
339
340
341
if (trials % 1000 == 0)
342
{
343
(*testout) << "\n";
344
for (int i = 1; i <= canuse.Size(); i++)
345
{
346
(*testout) << foundmap.Get(i) << "/"
347
<< canuse.Get(i) << "/"
348
<< ruleused.Get(i) << " map/can/use rule " << rules.Get(i)->Name() << "\n";
349
}
350
(*testout) << "\n";
351
}
352
353
354
int baselineindex = adfront -> SelectBaseLine (p1, p2, blgeominfo1, blgeominfo2, qualclass);
355
356
357
found = 1;
358
359
his = Dist (p1, p2);
360
361
Point3d pmid = Center (p1, p2);
362
hshould = CalcLocalH (pmid, mesh.GetH (pmid));
363
if (gh < hshould) hshould = gh;
364
365
mesh.RestrictLocalH (pmid, hshould);
366
367
h = hshould;
368
369
double hinner = (3 + qualclass) * max2 (his, hshould);
370
371
adfront ->GetLocals (baselineindex, locpoints, mpgeominfo, loclines,
372
pindex, lindex, 2*hinner);
373
//(*testout) << "h for locals: " << 2*hinner << endl;
374
375
376
//(*testout) << "locpoints " << locpoints << endl;
377
378
if (qualclass > mparam.giveuptol2d)
379
{
380
PrintMessage (3, "give up with qualclass ", qualclass);
381
PrintMessage (3, "number of frontlines = ", adfront->GetNFL());
382
// throw NgException ("Give up 2d meshing");
383
break;
384
}
385
386
/*
387
if (found && qualclass > 60)
388
{
389
found = 0;
390
}
391
*/
392
// morerisc = ((qualclass > 20) && (qualclass % 2 == 1));
393
// morerisc = 1;
394
morerisc = 0;
395
396
397
PointIndex gpi1 = adfront -> GetGlobalIndex (pindex.Get(loclines[0].I1()));
398
PointIndex gpi2 = adfront -> GetGlobalIndex (pindex.Get(loclines[0].I2()));
399
400
401
debugflag =
402
debugparam.haltsegment &&
403
( (debugparam.haltsegmentp1 == gpi1) &&
404
(debugparam.haltsegmentp2 == gpi2) ||
405
(debugparam.haltsegmentp1 == gpi2) &&
406
(debugparam.haltsegmentp2 == gpi1)) ||
407
debugparam.haltnode &&
408
( (debugparam.haltsegmentp1 == gpi1) ||
409
(debugparam.haltsegmentp2 == gpi1));
410
411
412
if (debugparam.haltface && debugparam.haltfacenr == facenr)
413
{
414
debugflag = 1;
415
cout << "set debugflag" << endl;
416
}
417
418
if (debugparam.haltlargequalclass && qualclass > 50)
419
debugflag = 1;
420
421
422
// problem recognition !
423
if (found &&
424
(gpi1 < illegalpoint.Size()+PointIndex::BASE) &&
425
(gpi2 < illegalpoint.Size()+PointIndex::BASE) )
426
{
427
if (illegalpoint[gpi1] || illegalpoint[gpi2])
428
found = 0;
429
}
430
431
432
Point2d p12d, p22d;
433
434
if (found)
435
{
436
oldnp = locpoints.Size();
437
oldnl = loclines.Size();
438
439
if (debugflag)
440
(*testout) << "define new transformation" << endl;
441
442
DefineTransformation (p1, p2, blgeominfo1, blgeominfo2);
443
444
plainpoints.SetSize (locpoints.Size());
445
plainzones.SetSize (locpoints.Size());
446
447
// (*testout) << endl;
448
449
// (*testout) << "3d->2d transformation" << endl;
450
451
for (int i = 1; i <= locpoints.Size(); i++)
452
{
453
// (*testout) << "pindex(i) = " << pindex[i-1] << endl;
454
TransformToPlain (locpoints.Get(i),
455
mpgeominfo.Get(i),
456
plainpoints.Elem(i), h, plainzones.Elem(i));
457
// (*testout) << mpgeominfo.Get(i).GetPGI(1).u << " " << mpgeominfo.Get(i).GetPGI(1).v << " ";
458
// (*testout) << plainpoints.Get(i).X() << " " << plainpoints.Get(i).Y() << endl;
459
//(*testout) << "transform " << locpoints.Get(i) << " to " << plainpoints.Get(i).X() << " " << plainpoints.Get(i).Y() << endl;
460
}
461
// (*testout) << endl << endl << endl;
462
463
464
p12d = plainpoints.Get(1);
465
p22d = plainpoints.Get(2);
466
467
/*
468
// last idea on friday
469
plainzones.Elem(1) = 0;
470
plainzones.Elem(2) = 0;
471
*/
472
473
474
/*
475
// old netgen:
476
for (i = 2; i <= loclines.Size(); i++) // don't remove first line
477
{
478
z1 = plainzones.Get(loclines.Get(i).I1());
479
z2 = plainzones.Get(loclines.Get(i).I2());
480
481
if (z1 && z2 && (z1 != z2) || (z1 == -1) || (z2 == -1) )
482
{
483
loclines.DeleteElement(i);
484
lindex.DeleteElement(i);
485
oldnl--;
486
i--;
487
}
488
}
489
490
// for (i = 1; i <= plainpoints.Size(); i++)
491
// if (plainzones.Elem(i) == -1)
492
// plainpoints.Elem(i) = Point2d (1e4, 1e4);
493
*/
494
495
496
497
for (int i = 2; i <= loclines.Size(); i++) // don't remove first line
498
{
499
// (*testout) << "loclines(i) = " << loclines.Get(i).I1() << " - " << loclines.Get(i).I2() << endl;
500
z1 = plainzones.Get(loclines.Get(i).I1());
501
z2 = plainzones.Get(loclines.Get(i).I2());
502
503
504
// one inner point, one outer
505
if ( (z1 >= 0) != (z2 >= 0))
506
{
507
int innerp = (z1 >= 0) ? 1 : 2;
508
if (IsLineVertexOnChart (locpoints.Get(loclines.Get(i).I1()),
509
locpoints.Get(loclines.Get(i).I2()),
510
innerp,
511
adfront->GetLineGeomInfo (lindex.Get(i), innerp)))
512
// pgeominfo.Get(loclines.Get(i).I(innerp))))
513
{
514
515
if (!morerisc)
516
{
517
// use one end of line
518
int pini, pouti;
519
Vec2d v;
520
521
pini = loclines.Get(i).I(innerp);
522
pouti = loclines.Get(i).I(3-innerp);
523
524
Point2d pin (plainpoints.Get(pini));
525
Point2d pout (plainpoints.Get(pouti));
526
v = pout - pin;
527
double len = v.Length();
528
if (len <= 1e-6)
529
(*testout) << "WARNING(js): inner-outer: short vector" << endl;
530
else
531
v /= len;
532
533
/*
534
// don't elongate line towards base-line !!
535
if (Vec2d (pin, p12d) * v > 0 &&
536
Vec2d (pin, p22d) * v > 0)
537
v *= -1;
538
*/
539
540
Point2d newpout = pin + 1000 * v;
541
newpout = pout;
542
543
544
plainpoints.Append (newpout);
545
Point3d pout3d = locpoints.Get(pouti);
546
locpoints.Append (pout3d);
547
548
plainzones.Append (0);
549
pindex.Append (-1);
550
oldnp++;
551
loclines.Elem(i).I(3-innerp) = oldnp;
552
}
553
else
554
plainzones.Elem(loclines.Get(i).I(3-innerp)) = 0;
555
556
557
// (*testout) << "inner - outer correction" << endl;
558
}
559
else
560
{
561
// remove line
562
loclines.DeleteElement(i);
563
lindex.DeleteElement(i);
564
oldnl--;
565
i--;
566
}
567
}
568
569
else if (z1 > 0 && z2 > 0 && (z1 != z2) || (z1 < 0) && (z2 < 0) )
570
{
571
loclines.DeleteElement(i);
572
lindex.DeleteElement(i);
573
oldnl--;
574
i--;
575
}
576
}
577
578
579
580
581
582
legalpoints.SetSize(plainpoints.Size());
583
for (int i = 1; i <= legalpoints.Size(); i++)
584
legalpoints.Elem(i) = 1;
585
586
double avy = 0;
587
for (int i = 1; i <= plainpoints.Size(); i++)
588
avy += plainpoints.Elem(i).Y();
589
avy *= 1./plainpoints.Size();
590
591
592
for (int i = 1; i <= plainpoints.Size(); i++)
593
{
594
if (plainzones.Elem(i) < 0)
595
{
596
plainpoints.Elem(i) = Point2d (1e4, 1e4);
597
legalpoints.Elem(i) = 0;
598
}
599
if (pindex.Elem(i) == -1)
600
{
601
legalpoints.Elem(i) = 0;
602
}
603
604
605
if (plainpoints.Elem(i).Y() < -1e-10*avy) // changed
606
{
607
legalpoints.Elem(i) = 0;
608
}
609
}
610
/*
611
for (i = 3; i <= plainpoints.Size(); i++)
612
if (sqr (plainpoints.Get(i).X()) + sqr (plainpoints.Get(i).Y())
613
> sqr (2 + 0.2 * qualclass))
614
legalpoints.Elem(i) = 0;
615
*/
616
617
/*
618
int clp = 0;
619
for (i = 1; i <= plainpoints.Size(); i++)
620
if (legalpoints.Get(i))
621
clp++;
622
(*testout) << "legalpts: " << clp << "/" << plainpoints.Size() << endl;
623
624
// sort legal/illegal lines
625
int lastleg = 2;
626
int firstilleg = oldnl;
627
628
while (lastleg < firstilleg)
629
{
630
while (legalpoints.Get(loclines.Get(lastleg).I1()) &&
631
legalpoints.Get(loclines.Get(lastleg).I2()) &&
632
lastleg < firstilleg)
633
lastleg++;
634
while ( ( !legalpoints.Get(loclines.Get(firstilleg).I1()) ||
635
!legalpoints.Get(loclines.Get(firstilleg).I2())) &&
636
lastleg < firstilleg)
637
firstilleg--;
638
639
if (lastleg < firstilleg)
640
{
641
swap (loclines.Elem(lastleg), loclines.Elem(firstilleg));
642
swap (lindex.Elem(lastleg), lindex.Elem(firstilleg));
643
}
644
}
645
646
(*testout) << "leglines " << lastleg << "/" << oldnl << endl;
647
*/
648
649
650
GetChartBoundary (chartboundpoints,
651
chartboundpoints3d,
652
chartboundlines, h);
653
654
oldnp = plainpoints.Size();
655
656
maxlegalpoint = locpoints.Size();
657
maxlegalline = loclines.Size();
658
659
660
661
if (mparam.checkchartboundary)
662
{
663
for (int i = 1; i <= chartboundpoints.Size(); i++)
664
{
665
plainpoints.Append (chartboundpoints.Get(i));
666
locpoints.Append (chartboundpoints3d.Get(i));
667
legalpoints.Append (0);
668
}
669
670
671
for (int i = 1; i <= chartboundlines.Size(); i++)
672
{
673
INDEX_2 line (chartboundlines.Get(i).I1()+oldnp,
674
chartboundlines.Get(i).I2()+oldnp);
675
loclines.Append (line);
676
// (*testout) << "line: " << line.I1() << "-" << line.I2() << endl;
677
}
678
}
679
680
oldnl = loclines.Size();
681
oldnp = plainpoints.Size();
682
}
683
684
685
/*
686
if (qualclass > 100)
687
{
688
multithread.drawing = 1;
689
glrender(1);
690
cout << "qualclass 100, nfl = " << adfront->GetNFL() << endl;
691
}
692
*/
693
694
if (found)
695
{
696
rulenr = ApplyRules (plainpoints, legalpoints, maxlegalpoint,
697
loclines, maxlegalline, locelements,
698
dellines, qualclass);
699
// (*testout) << "Rule Nr = " << rulenr << endl;
700
if (!rulenr)
701
{
702
found = 0;
703
if ( debugflag || debugparam.haltnosuccess )
704
PrintWarning ("no rule found");
705
}
706
}
707
708
for (int i = 1; i <= locelements.Size() && found; i++)
709
{
710
const Element2d & el = locelements.Get(i);
711
712
for (int j = 1; j <= el.GetNP(); j++)
713
if (el.PNum(j) <= oldnp && pindex.Get(el.PNum(j)) == -1)
714
{
715
found = 0;
716
PrintSysError ("meshing2, index missing");
717
}
718
}
719
720
721
if (found)
722
{
723
locpoints.SetSize (plainpoints.Size());
724
upgeominfo.SetSize(locpoints.Size());
725
726
for (int i = oldnp+1; i <= plainpoints.Size(); i++)
727
{
728
int err =
729
TransformFromPlain (plainpoints.Elem(i), locpoints.Elem(i),
730
upgeominfo.Elem(i), h);
731
732
if (err)
733
{
734
found = 0;
735
736
if ( debugflag || debugparam.haltnosuccess )
737
PrintSysError ("meshing2, Backtransformation failed");
738
739
break;
740
}
741
}
742
}
743
744
745
// for (i = 1; i <= oldnl; i++)
746
// adfront -> ResetClass (lindex[i]);
747
748
749
/*
750
double violateminh;
751
if (qualclass <= 10)
752
violateminh = 3;
753
else
754
violateminh = 3 * qualclass;
755
756
if (uselocalh && found) // && qualclass <= 10)
757
{
758
for (i = 1; i <= locelements.Size(); i++)
759
{
760
Point3d pmin = locpoints.Get(locelements.Get(i).PNum(1));
761
Point3d pmax = pmin;
762
for (j = 2; j <= 3; j++)
763
{
764
const Point3d & hp =
765
locpoints.Get(locelements.Get(i).PNum(j));
766
pmin.SetToMin (hp);
767
pmax.SetToMax (hp);
768
}
769
double minh = mesh.GetMinH (pmin, pmax);
770
if (h > violateminh * minh)
771
{
772
found = 0;
773
loclines.SetSize (oldnl);
774
locpoints.SetSize (oldnp);
775
}
776
}
777
}
778
*/
779
780
781
if (found)
782
{
783
double violateminh = 3 + 0.1 * sqr (qualclass);
784
double minh = 1e8;
785
double newedgemaxh = 0;
786
for (int i = oldnl+1; i <= loclines.Size(); i++)
787
{
788
double eh = Dist (locpoints.Get(loclines.Get(i).I1()),
789
locpoints.Get(loclines.Get(i).I2()));
790
791
// Markus (brute force method to avoid bad elements on geometries like \_/ )
792
//if(eh > 4.*mesh.GetH(locpoints.Get(loclines.Get(i).I1()))) found = 0;
793
//if(eh > 4.*mesh.GetH(locpoints.Get(loclines.Get(i).I2()))) found = 0;
794
// Markus end
795
796
if (eh > newedgemaxh)
797
newedgemaxh = eh;
798
}
799
800
for (int i = 1; i <= locelements.Size(); i++)
801
{
802
Point3d pmin = locpoints.Get(locelements.Get(i).PNum(1));
803
Point3d pmax = pmin;
804
for (int j = 2; j <= locelements.Get(i).GetNP(); j++)
805
{
806
const Point3d & hp =
807
locpoints.Get(locelements.Get(i).PNum(j));
808
pmin.SetToMin (hp);
809
pmax.SetToMax (hp);
810
}
811
double eh = mesh.GetMinH (pmin, pmax);
812
if (eh < minh)
813
minh = eh;
814
}
815
816
for (int i = 1; i <= locelements.Size(); i++)
817
for (int j = 1; j <= locelements.Get(i).GetNP(); j++)
818
if (Dist2 (locpoints.Get(locelements.Get(i).PNum(j)), pmid) > hinner*hinner)
819
found = 0;
820
821
// cout << "violate = " << newedgemaxh / minh << endl;
822
static double maxviolate = 0;
823
if (newedgemaxh / minh > maxviolate)
824
{
825
maxviolate = newedgemaxh / minh;
826
// cout << "max minhviolate = " << maxviolate << endl;
827
}
828
829
830
if (newedgemaxh > violateminh * minh)
831
{
832
found = 0;
833
loclines.SetSize (oldnl);
834
locpoints.SetSize (oldnp);
835
836
if ( debugflag || debugparam.haltnosuccess )
837
PrintSysError ("meshing2, maxh too large");
838
839
840
}
841
}
842
843
844
845
/*
846
// test good ComputeLineGeoInfo
847
if (found)
848
{
849
// is line on chart ?
850
for (i = oldnl+1; i <= loclines.Size(); i++)
851
{
852
int gisize;
853
void *geominfo;
854
855
if (ComputeLineGeoInfo (locpoints.Get(loclines.Get(i).I1()),
856
locpoints.Get(loclines.Get(i).I2()),
857
gisize, geominfo))
858
found = 0;
859
}
860
}
861
*/
862
863
864
// changed for OCC meshing
865
if (found)
866
{
867
// take geominfo from dellines
868
// upgeominfo.SetSize(locpoints.Size());
869
870
/*
871
for (i = 1; i <= dellines.Size(); i++)
872
for (j = 1; j <= 2; j++)
873
{
874
upgeominfo.Elem(loclines.Get(dellines.Get(i)).I(j)) =
875
adfront -> GetLineGeomInfo (lindex.Get(dellines.Get(i)), j);
876
}
877
*/
878
879
880
for (int i = 1; i <= locelements.Size(); i++)
881
for (int j = 1; j <= locelements.Get(i).GetNP(); j++)
882
{
883
int pi = locelements.Get(i).PNum(j);
884
if (pi <= oldnp)
885
{
886
887
if (ChooseChartPointGeomInfo (mpgeominfo.Get(pi), upgeominfo.Elem(pi)))
888
{
889
// cannot select, compute new one
890
PrintWarning ("calc point geominfo instead of using");
891
if (ComputePointGeomInfo (locpoints.Get(pi), upgeominfo.Elem(pi)))
892
{
893
found = 0;
894
PrintSysError ("meshing2d, geominfo failed");
895
}
896
}
897
}
898
}
899
900
/*
901
// use upgeominfo from ProjectFromPlane
902
for (i = oldnp+1; i <= locpoints.Size(); i++)
903
{
904
if (ComputePointGeomInfo (locpoints.Get(i), upgeominfo.Elem(i)))
905
{
906
found = 0;
907
if ( debugflag || debugparam.haltnosuccess )
908
PrintSysError ("meshing2d, compute geominfo failed");
909
}
910
}
911
*/
912
}
913
914
915
if (found && mparam.checkoverlap)
916
{
917
// cout << "checkoverlap" << endl;
918
// test for overlaps
919
920
Point3d hullmin(1e10, 1e10, 1e10);
921
Point3d hullmax(-1e10, -1e10, -1e10);
922
923
for (int i = 1; i <= locelements.Size(); i++)
924
for (int j = 1; j <= locelements.Get(i).GetNP(); j++)
925
{
926
const Point3d & p = locpoints.Get(locelements.Get(i).PNum(j));
927
hullmin.SetToMin (p);
928
hullmax.SetToMax (p);
929
}
930
hullmin += Vec3d (-his, -his, -his);
931
hullmax += Vec3d ( his, his, his);
932
933
surfeltree.GetIntersecting (hullmin, hullmax, intersecttrias);
934
935
critpoints.SetSize (0);
936
for (int i = oldnp+1; i <= locpoints.Size(); i++)
937
critpoints.Append (locpoints.Get(i));
938
939
for (int i = 1; i <= locelements.Size(); i++)
940
{
941
const Element2d & tri = locelements.Get(i);
942
if (tri.GetNP() == 3)
943
{
944
const Point3d & tp1 = locpoints.Get(tri.PNum(1));
945
const Point3d & tp2 = locpoints.Get(tri.PNum(2));
946
const Point3d & tp3 = locpoints.Get(tri.PNum(3));
947
948
Vec3d tv1 (tp1, tp2);
949
Vec3d tv2 (tp1, tp3);
950
951
double lam1, lam2;
952
for (lam1 = 0.2; lam1 <= 0.8; lam1 += 0.2)
953
for (lam2 = 0.2; lam2 + lam1 <= 0.8; lam2 += 0.2)
954
{
955
Point3d hp = tp1 + lam1 * tv1 + lam2 * tv2;
956
critpoints.Append (hp);
957
}
958
}
959
else if (tri.GetNP() == 4)
960
{
961
const Point3d & tp1 = locpoints.Get(tri.PNum(1));
962
const Point3d & tp2 = locpoints.Get(tri.PNum(2));
963
const Point3d & tp3 = locpoints.Get(tri.PNum(3));
964
const Point3d & tp4 = locpoints.Get(tri.PNum(4));
965
966
double l1, l2;
967
for (l1 = 0.1; l1 <= 0.9; l1 += 0.1)
968
for (l2 = 0.1; l2 <= 0.9; l2 += 0.1)
969
{
970
Point3d hp;
971
hp.X() =
972
(1-l1)*(1-l2) * tp1.X() +
973
l1*(1-l2) * tp2.X() +
974
l1*l2 * tp3.X() +
975
(1-l1)*l2 * tp4.X();
976
hp.Y() =
977
(1-l1)*(1-l2) * tp1.Y() +
978
l1*(1-l2) * tp2.Y() +
979
l1*l2 * tp3.Y() +
980
(1-l1)*l2 * tp4.Y();
981
hp.Z() =
982
(1-l1)*(1-l2) * tp1.Z() +
983
l1*(1-l2) * tp2.Z() +
984
l1*l2 * tp3.Z() +
985
(1-l1)*l2 * tp4.Z();
986
987
988
critpoints.Append (hp);
989
}
990
}
991
}
992
/*
993
for (i = oldnl+1; i <= loclines.Size(); i++)
994
{
995
Point3d hp = locpoints.Get(loclines.Get(i).I1());
996
Vec3d hv(hp, locpoints.Get(loclines.Get(i).I2()));
997
int ncp = 2;
998
for (j = 1; j <= ncp; j++)
999
critpoints.Append ( hp + (double(j)/(ncp+1)) * hv);
1000
}
1001
*/
1002
1003
1004
/*
1005
for (i = oldnp+1; i <= locpoints.Size(); i++)
1006
{
1007
const Point3d & p = locpoints.Get(i);
1008
*/
1009
1010
1011
for (int i = 1; i <= critpoints.Size(); i++)
1012
{
1013
const Point3d & p = critpoints.Get(i);
1014
1015
1016
/*
1017
for (j = 1; j <= mesh.GetNSE(); j++)
1018
{
1019
*/
1020
int jj;
1021
for (jj = 1; jj <= intersecttrias.Size(); jj++)
1022
{
1023
int j = intersecttrias.Get(jj);
1024
const Element2d & el = mesh.SurfaceElement(j);
1025
1026
int ntrig = (el.GetNP() == 3) ? 1 : 2;
1027
1028
int jl;
1029
for (jl = 1; jl <= ntrig; jl++)
1030
{
1031
Point3d tp1, tp2, tp3;
1032
1033
if (jl == 1)
1034
{
1035
tp1 = mesh.Point(el.PNum(1));
1036
tp2 = mesh.Point(el.PNum(2));
1037
tp3 = mesh.Point(el.PNum(3));
1038
}
1039
else
1040
{
1041
tp1 = mesh.Point(el.PNum(1));
1042
tp2 = mesh.Point(el.PNum(3));
1043
tp3 = mesh.Point(el.PNum(4));
1044
}
1045
1046
int onchart = 0;
1047
for (int k = 1; k <= el.GetNP(); k++)
1048
if (BelongsToActiveChart (mesh.Point(el.PNum(k)),
1049
el.GeomInfoPi(k)))
1050
onchart = 1;
1051
if (!onchart)
1052
continue;
1053
1054
Vec3d e1(tp1, tp2);
1055
Vec3d e2(tp1, tp3);
1056
Vec3d n = Cross (e1, e2);
1057
n /= n.Length();
1058
double lam1, lam2, lam3;
1059
lam3 = n * Vec3d (tp1, p);
1060
LocalCoordinates (e1, e2, Vec3d (tp1, p), lam1, lam2);
1061
1062
if (fabs (lam3) < 0.1 * hshould &&
1063
lam1 > 0 && lam2 > 0 && (lam1 + lam2) < 1)
1064
{
1065
#ifdef DEVELOP
1066
cout << "overlap" << endl;
1067
(*testout) << "overlap:" << endl
1068
<< "tri = " << tp1 << "-" << tp2 << "-" << tp3 << endl
1069
<< "point = " << p << endl
1070
<< "lam1, 2 = " << lam1 << ", " << lam2 << endl
1071
<< "lam3 = " << lam3 << endl;
1072
1073
// cout << "overlap !!!" << endl;
1074
#endif
1075
for (int k = 1; k <= 5; k++)
1076
adfront -> IncrementClass (lindex.Get(1));
1077
1078
found = 0;
1079
1080
if ( debugflag || debugparam.haltnosuccess )
1081
PrintWarning ("overlapping");
1082
1083
1084
if (debugparam.haltoverlap)
1085
{
1086
debugflag = 1;
1087
}
1088
1089
/*
1090
multithread.drawing = 1;
1091
glrender(1);
1092
*/
1093
}
1094
}
1095
}
1096
}
1097
}
1098
1099
1100
if (found)
1101
{
1102
// check, whether new front line already exists
1103
1104
for (int i = oldnl+1; i <= loclines.Size(); i++)
1105
{
1106
int nlgpi1 = loclines.Get(i).I1();
1107
int nlgpi2 = loclines.Get(i).I2();
1108
if (nlgpi1 <= pindex.Size() && nlgpi2 <= pindex.Size())
1109
{
1110
nlgpi1 = adfront->GetGlobalIndex (pindex.Get(nlgpi1));
1111
nlgpi2 = adfront->GetGlobalIndex (pindex.Get(nlgpi2));
1112
1113
int exval = adfront->ExistsLine (nlgpi1, nlgpi2);
1114
if (exval)
1115
{
1116
cout << "ERROR: new line exits, val = " << exval << endl;
1117
(*testout) << "ERROR: new line exits, val = " << exval << endl;
1118
found = 0;
1119
1120
1121
if (debugparam.haltexistingline)
1122
debugflag = 1;
1123
1124
}
1125
}
1126
}
1127
1128
}
1129
1130
1131
/*
1132
if (found)
1133
{
1134
// check, whether new triangles insert edges twice
1135
for (i = 1; i <= locelements.Size(); i++)
1136
for (j = 1; j <= 3; j++)
1137
{
1138
int tpi1 = locelements.Get(i).PNumMod (j);
1139
int tpi2 = locelements.Get(i).PNumMod (j+1);
1140
if (tpi1 <= pindex.Size() && tpi2 <= pindex.Size())
1141
{
1142
tpi1 = adfront->GetGlobalIndex (pindex.Get(tpi1));
1143
tpi2 = adfront->GetGlobalIndex (pindex.Get(tpi2));
1144
1145
if (doubleedge.Used (INDEX_2(tpi1, tpi2)))
1146
{
1147
if (debugparam.haltexistingline)
1148
debugflag = 1;
1149
cerr << "ERROR Insert edge "
1150
<< tpi1 << " - " << tpi2 << " twice !!!" << endl;
1151
found = 0;
1152
}
1153
doubleedge.Set (INDEX_2(tpi1, tpi2), 1);
1154
}
1155
}
1156
}
1157
*/
1158
1159
1160
if (found)
1161
{
1162
// everything is ok, perform mesh update
1163
1164
ruleused.Elem(rulenr)++;
1165
1166
1167
pindex.SetSize(locpoints.Size());
1168
1169
for (int i = oldnp+1; i <= locpoints.Size(); i++)
1170
{
1171
globind = mesh.AddPoint (locpoints.Get(i));
1172
pindex.Elem(i) = adfront -> AddPoint (locpoints.Get(i), globind);
1173
}
1174
1175
for (int i = oldnl+1; i <= loclines.Size(); i++)
1176
{
1177
/*
1178
for (j = 1; j <= locpoints.Size(); j++)
1179
{
1180
(*testout) << j << ": " << locpoints.Get(j) << endl;
1181
}
1182
*/
1183
1184
/*
1185
ComputeLineGeoInfo (locpoints.Get(loclines.Get(i).I1()),
1186
locpoints.Get(loclines.Get(i).I2()),
1187
gisize, geominfo);
1188
*/
1189
1190
if (pindex.Get(loclines.Get(i).I1()) == -1 ||
1191
pindex.Get(loclines.Get(i).I2()) == -1)
1192
{
1193
(*testout) << "pindex is 0" << endl;
1194
}
1195
1196
if (!upgeominfo.Get(loclines.Get(i).I1()).trignum ||
1197
!upgeominfo.Get(loclines.Get(i).I2()).trignum)
1198
{
1199
cout << "new el: illegal geominfo" << endl;
1200
}
1201
1202
adfront -> AddLine (pindex.Get(loclines.Get(i).I1()),
1203
pindex.Get(loclines.Get(i).I2()),
1204
upgeominfo.Get(loclines.Get(i).I1()),
1205
upgeominfo.Get(loclines.Get(i).I2()));
1206
}
1207
for (int i = 1; i <= locelements.Size(); i++)
1208
{
1209
Element2d mtri(locelements.Get(i).GetNP());
1210
mtri = locelements.Get(i);
1211
mtri.SetIndex (facenr);
1212
1213
1214
// compute triangle geominfo:
1215
// (*testout) << "triggeominfo: ";
1216
for (int j = 1; j <= locelements.Get(i).GetNP(); j++)
1217
{
1218
mtri.GeomInfoPi(j) = upgeominfo.Get(locelements.Get(i).PNum(j));
1219
// (*testout) << mtri.GeomInfoPi(j).trignum << " ";
1220
}
1221
// (*testout) << endl;
1222
1223
for (int j = 1; j <= locelements.Get(i).GetNP(); j++)
1224
{
1225
mtri.PNum(j) =
1226
locelements.Elem(i).PNum(j) =
1227
adfront -> GetGlobalIndex (pindex.Get(locelements.Get(i).PNum(j)));
1228
}
1229
1230
1231
1232
1233
mesh.AddSurfaceElement (mtri);
1234
cntelem++;
1235
// cout << "elements: " << cntelem << endl;
1236
1237
1238
1239
Box<3> box;
1240
box.Set (mesh[mtri[0]]);
1241
box.Add (mesh[mtri[1]]);
1242
box.Add (mesh[mtri[2]]);
1243
surfeltree.Insert (box, mesh.GetNSE());
1244
1245
const Point3d & sep1 = mesh.Point (mtri.PNum(1));
1246
const Point3d & sep2 = mesh.Point (mtri.PNum(2));
1247
const Point3d & sep3 = mesh.Point (mtri.PNum(3));
1248
1249
double trigarea = Cross (Vec3d (sep1, sep2),
1250
Vec3d (sep1, sep3)).Length() / 2;
1251
1252
if (mtri.GetNP() == 4)
1253
{
1254
const Point3d & sep4 = mesh.Point (mtri.PNum(4));
1255
trigarea += Cross (Vec3d (sep1, sep3),
1256
Vec3d (sep1, sep4)).Length() / 2;
1257
}
1258
1259
meshedarea += trigarea;
1260
1261
if(maxarea > 0 && meshedarea-meshedarea_before > maxarea)
1262
{
1263
cerr << "meshed area = " << meshedarea-meshedarea_before << endl
1264
<< "maximal area = " << maxarea << endl
1265
<< "GIVING UP" << endl;
1266
return MESHING2_GIVEUP;
1267
}
1268
1269
1270
1271
for (int j = 1; j <= locelements.Get(i).GetNP(); j++)
1272
{
1273
int gpi = locelements.Get(i).PNum(j);
1274
1275
int oldts = trigsonnode.Size();
1276
if (gpi >= oldts+PointIndex::BASE)
1277
{
1278
trigsonnode.SetSize (gpi+1-PointIndex::BASE);
1279
illegalpoint.SetSize (gpi+1-PointIndex::BASE);
1280
for (int k = oldts+PointIndex::BASE;
1281
k <= gpi; k++)
1282
{
1283
trigsonnode[k] = 0;
1284
illegalpoint[k] = 0;
1285
}
1286
}
1287
1288
trigsonnode[gpi]++;
1289
1290
if (trigsonnode[gpi] > 20)
1291
{
1292
illegalpoint[gpi] = 1;
1293
// cout << "illegal point: " << gpi << endl;
1294
(*testout) << "illegal point: " << gpi << endl;
1295
}
1296
1297
static int mtonnode = 0;
1298
if (trigsonnode[gpi] > mtonnode)
1299
mtonnode = trigsonnode[gpi];
1300
}
1301
// cout << "els = " << cntelem << " trials = " << trials << endl;
1302
// if (trials > 100) return;
1303
}
1304
1305
for (int i = 1; i <= dellines.Size(); i++)
1306
adfront -> DeleteLine (lindex.Get(dellines.Get(i)));
1307
1308
// rname = rules.Get(rulenr)->Name();
1309
#ifdef MYGRAPH
1310
if (silentflag<3)
1311
{
1312
plotsurf.DrawPnL(locpoints, loclines);
1313
plotsurf.Plot(testmode, testmode);
1314
}
1315
#endif
1316
1317
if (morerisc)
1318
{
1319
cout << "generated due to morerisc" << endl;
1320
// multithread.drawing = 1;
1321
// glrender(1);
1322
}
1323
1324
1325
1326
1327
if ( debugparam.haltsuccess || debugflag )
1328
{
1329
// adfront -> PrintOpenSegments (*testout);
1330
cout << "success of rule" << rules.Get(rulenr)->Name() << endl;
1331
multithread.drawing = 1;
1332
multithread.testmode = 1;
1333
multithread.pause = 1;
1334
1335
1336
/*
1337
extern STLGeometry * stlgeometry;
1338
stlgeometry->ClearMarkedSegs();
1339
for (i = 1; i <= loclines.Size(); i++)
1340
{
1341
stlgeometry->AddMarkedSeg(locpoints.Get(loclines.Get(i).I1()),
1342
locpoints.Get(loclines.Get(i).I2()));
1343
}
1344
*/
1345
1346
(*testout) << "success of rule" << rules.Get(rulenr)->Name() << endl;
1347
(*testout) << "trials = " << trials << endl;
1348
1349
(*testout) << "locpoints " << endl;
1350
for (int i = 1; i <= pindex.Size(); i++)
1351
(*testout) << adfront->GetGlobalIndex (pindex.Get(i)) << endl;
1352
1353
(*testout) << "old number of lines = " << oldnl << endl;
1354
for (int i = 1; i <= loclines.Size(); i++)
1355
{
1356
(*testout) << "line ";
1357
for (int j = 1; j <= 2; j++)
1358
{
1359
int hi = 0;
1360
if (loclines.Get(i).I(j) >= 1 &&
1361
loclines.Get(i).I(j) <= pindex.Size())
1362
hi = adfront->GetGlobalIndex (pindex.Get(loclines.Get(i).I(j)));
1363
1364
(*testout) << hi << " ";
1365
}
1366
(*testout) << " : "
1367
<< plainpoints.Get(loclines.Get(i).I1()) << " - "
1368
<< plainpoints.Get(loclines.Get(i).I2()) << " 3d: "
1369
<< locpoints.Get(loclines.Get(i).I1()) << " - "
1370
<< locpoints.Get(loclines.Get(i).I2())
1371
<< endl;
1372
}
1373
1374
1375
1376
glrender(1);
1377
}
1378
}
1379
else
1380
{
1381
adfront -> IncrementClass (lindex.Get(1));
1382
1383
if ( debugparam.haltnosuccess || debugflag )
1384
{
1385
cout << "Problem with seg " << gpi1 << " - " << gpi2
1386
<< ", class = " << qualclass << endl;
1387
1388
(*testout) << "Problem with seg " << gpi1 << " - " << gpi2
1389
<< ", class = " << qualclass << endl;
1390
1391
multithread.drawing = 1;
1392
multithread.testmode = 1;
1393
multithread.pause = 1;
1394
1395
1396
/*
1397
extern STLGeometry * stlgeometry;
1398
stlgeometry->ClearMarkedSegs();
1399
for (i = 1; i <= loclines.Size(); i++)
1400
{
1401
stlgeometry->AddMarkedSeg(locpoints.Get(loclines.Get(i).I1()),
1402
locpoints.Get(loclines.Get(i).I2()));
1403
}
1404
*/
1405
1406
for (int i = 1; i <= loclines.Size(); i++)
1407
{
1408
(*testout) << "line ";
1409
for (int j = 1; j <= 2; j++)
1410
{
1411
int hi = 0;
1412
if (loclines.Get(i).I(j) >= 1 &&
1413
loclines.Get(i).I(j) <= pindex.Size())
1414
hi = adfront->GetGlobalIndex (pindex.Get(loclines.Get(i).I(j)));
1415
1416
(*testout) << hi << " ";
1417
}
1418
(*testout) << " : "
1419
<< plainpoints.Get(loclines.Get(i).I1()) << " - "
1420
<< plainpoints.Get(loclines.Get(i).I2()) << " 3d: "
1421
<< locpoints.Get(loclines.Get(i).I1()) << " - "
1422
<< locpoints.Get(loclines.Get(i).I2())
1423
<< endl;
1424
}
1425
1426
1427
/*
1428
cout << "p1gi = " << blgeominfo[0].trignum
1429
<< ", p2gi = " << blgeominfo[1].trignum << endl;
1430
*/
1431
1432
glrender(1);
1433
}
1434
1435
1436
#ifdef MYGRAPH
1437
if (silentflag<3)
1438
{
1439
if (testmode || trials%2 == 0)
1440
{
1441
plotsurf.DrawPnL(locpoints, loclines);
1442
plotsurf.Plot(testmode, testmode);
1443
}
1444
}
1445
#endif
1446
}
1447
1448
}
1449
1450
PrintMessage (3, "Surface meshing done");
1451
1452
adfront->PrintOpenSegments (*testout);
1453
1454
multithread.task = savetask;
1455
1456
1457
// cout << "surfeltree.depth = " << surfeltree.Tree().Depth() << endl;
1458
EndMesh ();
1459
1460
if (!adfront->Empty())
1461
return MESHING2_GIVEUP;
1462
1463
return MESHING2_OK;
1464
}
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
}
1475
1476
1477
1478
1479
1480
1481
1482
#ifdef OPENGL
1483
1484
/* *********************** Draw Surface Meshing **************** */
1485
1486
1487
#include <visual.hpp>
1488
#include <stlgeom.hpp>
1489
1490
namespace netgen
1491
{
1492
1493
extern STLGeometry * stlgeometry;
1494
extern Mesh * mesh;
1495
VisualSceneSurfaceMeshing vssurfacemeshing;
1496
1497
1498
1499
void glrender (int wait)
1500
{
1501
// cout << "plot adfront" << endl;
1502
1503
if (multithread.drawing)
1504
{
1505
// vssurfacemeshing.Render();
1506
Render ();
1507
1508
if (wait || multithread.testmode)
1509
{
1510
multithread.pause = 1;
1511
}
1512
while (multithread.pause);
1513
}
1514
}
1515
1516
1517
1518
VisualSceneSurfaceMeshing :: VisualSceneSurfaceMeshing ()
1519
: VisualScene()
1520
{
1521
;
1522
}
1523
1524
VisualSceneSurfaceMeshing :: ~VisualSceneSurfaceMeshing ()
1525
{
1526
;
1527
}
1528
1529
void VisualSceneSurfaceMeshing :: DrawScene ()
1530
{
1531
int i, j, k;
1532
1533
if (loclines.Size() != changeval)
1534
{
1535
center = Point<3>(0,0,-5);
1536
rad = 0.1;
1537
1538
CalcTransformationMatrices();
1539
changeval = loclines.Size();
1540
}
1541
1542
glClearColor(backcolor, backcolor, backcolor, 1.0);
1543
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1544
SetLight();
1545
1546
// glEnable (GL_COLOR_MATERIAL);
1547
1548
// glDisable (GL_SHADING);
1549
// glColor3f (0.0f, 1.0f, 1.0f);
1550
// glLineWidth (1.0f);
1551
// glShadeModel (GL_SMOOTH);
1552
1553
// glCallList (linelists.Get(1));
1554
1555
// SetLight();
1556
1557
glPushMatrix();
1558
glMultMatrixf (transformationmat);
1559
1560
glShadeModel (GL_SMOOTH);
1561
// glDisable (GL_COLOR_MATERIAL);
1562
glEnable (GL_COLOR_MATERIAL);
1563
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1564
1565
glEnable (GL_BLEND);
1566
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1567
1568
// glEnable (GL_LIGHTING);
1569
1570
double shine = vispar.shininess;
1571
double transp = vispar.transp;
1572
1573
glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shine);
1574
glLogicOp (GL_COPY);
1575
1576
1577
1578
/*
1579
1580
float mat_col[] = { 0.2, 0.2, 0.8, 1 };
1581
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);
1582
1583
glPolygonOffset (1, 1);
1584
glEnable (GL_POLYGON_OFFSET_FILL);
1585
1586
float mat_colbl[] = { 0.8, 0.2, 0.2, 1 };
1587
float mat_cololdl[] = { 0.2, 0.8, 0.2, 1 };
1588
float mat_colnewl[] = { 0.8, 0.8, 0.2, 1 };
1589
1590
1591
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1592
glPolygonOffset (1, -1);
1593
glLineWidth (3);
1594
1595
for (i = 1; i <= loclines.Size(); i++)
1596
{
1597
if (i == 1)
1598
{
1599
glEnable (GL_POLYGON_OFFSET_FILL);
1600
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colbl);
1601
}
1602
else if (i <= oldnl)
1603
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_cololdl);
1604
else
1605
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colnewl);
1606
1607
int pi1 = loclines.Get(i).I1();
1608
int pi2 = loclines.Get(i).I2();
1609
1610
if (pi1 >= 1 && pi2 >= 1)
1611
{
1612
Point3d p1 = locpoints.Get(pi1);
1613
Point3d p2 = locpoints.Get(pi2);
1614
1615
glBegin (GL_LINES);
1616
glVertex3f (p1.X(), p1.Y(), p1.Z());
1617
glVertex3f (p2.X(), p2.Y(), p2.Z());
1618
glEnd();
1619
}
1620
1621
glDisable (GL_POLYGON_OFFSET_FILL);
1622
}
1623
1624
1625
glLineWidth (1);
1626
1627
1628
glPointSize (5);
1629
float mat_colp[] = { 1, 0, 0, 1 };
1630
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);
1631
glBegin (GL_POINTS);
1632
for (i = 1; i <= locpoints.Size(); i++)
1633
{
1634
Point3d p = locpoints.Get(i);
1635
glVertex3f (p.X(), p.Y(), p.Z());
1636
}
1637
glEnd();
1638
1639
1640
glPopMatrix();
1641
*/
1642
1643
float mat_colp[] = { 1, 0, 0, 1 };
1644
1645
float mat_col2d1[] = { 1, 0.5, 0.5, 1 };
1646
float mat_col2d[] = { 1, 1, 1, 1 };
1647
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);
1648
1649
double scalex = 0.1, scaley = 0.1;
1650
1651
glBegin (GL_LINES);
1652
for (i = 1; i <= loclines.Size(); i++)
1653
{
1654
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);
1655
if (i == 1)
1656
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d1);
1657
1658
int pi1 = loclines.Get(i).I1();
1659
int pi2 = loclines.Get(i).I2();
1660
1661
if (pi1 >= 1 && pi2 >= 1)
1662
{
1663
Point2d p1 = plainpoints.Get(pi1);
1664
Point2d p2 = plainpoints.Get(pi2);
1665
1666
glBegin (GL_LINES);
1667
glVertex3f (scalex * p1.X(), scaley * p1.Y(), -5);
1668
glVertex3f (scalex * p2.X(), scaley * p2.Y(), -5);
1669
glEnd();
1670
}
1671
}
1672
glEnd ();
1673
1674
1675
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);
1676
glBegin (GL_POINTS);
1677
for (i = 1; i <= plainpoints.Size(); i++)
1678
{
1679
Point2d p = plainpoints.Get(i);
1680
glVertex3f (scalex * p.X(), scaley * p.Y(), -5);
1681
}
1682
glEnd();
1683
1684
1685
1686
1687
1688
1689
glDisable (GL_POLYGON_OFFSET_FILL);
1690
1691
glPopMatrix();
1692
DrawCoordinateCross ();
1693
DrawNetgenLogo ();
1694
glFinish();
1695
1696
/*
1697
glDisable (GL_POLYGON_OFFSET_FILL);
1698
1699
// cout << "draw surfacemeshing" << endl;
1700
//
1701
// if (changeval != stlgeometry->GetNT())
1702
// BuildScene();
1703
// changeval = stlgeometry->GetNT();
1704
1705
1706
glClearColor(backcolor, backcolor, backcolor, 1.0);
1707
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1708
1709
SetLight();
1710
1711
glPushMatrix();
1712
glLoadMatrixf (transmat);
1713
glMultMatrixf (rotmat);
1714
1715
glShadeModel (GL_SMOOTH);
1716
glDisable (GL_COLOR_MATERIAL);
1717
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1718
1719
glEnable (GL_BLEND);
1720
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1721
1722
float mat_spec_col[] = { 1, 1, 1, 1 };
1723
glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_spec_col);
1724
1725
double shine = vispar.shininess;
1726
double transp = vispar.transp;
1727
1728
glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shine);
1729
glLogicOp (GL_COPY);
1730
1731
1732
float mat_col[] = { 0.2, 0.2, 0.8, transp };
1733
float mat_colrt[] = { 0.2, 0.8, 0.8, transp };
1734
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);
1735
1736
glPolygonOffset (1, 1);
1737
glEnable (GL_POLYGON_OFFSET_FILL);
1738
1739
glColor3f (1.0f, 1.0f, 1.0f);
1740
1741
glEnable (GL_NORMALIZE);
1742
1743
// glBegin (GL_TRIANGLES);
1744
// for (j = 1; j <= stlgeometry -> GetNT(); j++)
1745
// {
1746
// glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);
1747
// if (j == geomtrig)
1748
// glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colrt);
1749
1750
1751
// const STLReadTriangle & tria = stlgeometry -> GetReadTriangle(j);
1752
// glNormal3f (tria.normal.X(),
1753
// tria.normal.Y(),
1754
// tria.normal.Z());
1755
1756
// for (k = 0; k < 3; k++)
1757
// {
1758
// glVertex3f (tria.pts[k].X(),
1759
// tria.pts[k].Y(),
1760
// tria.pts[k].Z());
1761
// }
1762
// }
1763
// glEnd ();
1764
1765
1766
1767
glDisable (GL_POLYGON_OFFSET_FILL);
1768
1769
float mat_colbl[] = { 0.8, 0.2, 0.2, 1 };
1770
float mat_cololdl[] = { 0.2, 0.8, 0.2, 1 };
1771
float mat_colnewl[] = { 0.8, 0.8, 0.2, 1 };
1772
1773
1774
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
1775
glPolygonOffset (1, -1);
1776
glLineWidth (3);
1777
1778
for (i = 1; i <= loclines.Size(); i++)
1779
{
1780
if (i == 1)
1781
{
1782
glEnable (GL_POLYGON_OFFSET_FILL);
1783
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colbl);
1784
}
1785
else if (i <= oldnl)
1786
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_cololdl);
1787
else
1788
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colnewl);
1789
1790
int pi1 = loclines.Get(i).I1();
1791
int pi2 = loclines.Get(i).I2();
1792
1793
if (pi1 >= 1 && pi2 >= 1)
1794
{
1795
Point3d p1 = locpoints.Get(pi1);
1796
Point3d p2 = locpoints.Get(pi2);
1797
1798
glBegin (GL_LINES);
1799
glVertex3f (p1.X(), p1.Y(), p1.Z());
1800
glVertex3f (p2.X(), p2.Y(), p2.Z());
1801
glEnd();
1802
}
1803
1804
glDisable (GL_POLYGON_OFFSET_FILL);
1805
}
1806
1807
1808
glLineWidth (1);
1809
1810
1811
glPointSize (5);
1812
float mat_colp[] = { 1, 0, 0, 1 };
1813
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);
1814
glBegin (GL_POINTS);
1815
for (i = 1; i <= locpoints.Size(); i++)
1816
{
1817
Point3d p = locpoints.Get(i);
1818
glVertex3f (p.X(), p.Y(), p.Z());
1819
}
1820
glEnd();
1821
1822
1823
glPopMatrix();
1824
1825
1826
float mat_col2d1[] = { 1, 0.5, 0.5, 1 };
1827
float mat_col2d[] = { 1, 1, 1, 1 };
1828
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);
1829
1830
double scalex = 0.1, scaley = 0.1;
1831
1832
glBegin (GL_LINES);
1833
for (i = 1; i <= loclines.Size(); i++)
1834
{
1835
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);
1836
if (i == 1)
1837
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d1);
1838
1839
int pi1 = loclines.Get(i).I1();
1840
int pi2 = loclines.Get(i).I2();
1841
1842
if (pi1 >= 1 && pi2 >= 1)
1843
{
1844
Point2d p1 = plainpoints.Get(pi1);
1845
Point2d p2 = plainpoints.Get(pi2);
1846
1847
glBegin (GL_LINES);
1848
glVertex3f (scalex * p1.X(), scaley * p1.Y(), -5);
1849
glVertex3f (scalex * p2.X(), scaley * p2.Y(), -5);
1850
glEnd();
1851
}
1852
}
1853
glEnd ();
1854
1855
1856
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);
1857
glBegin (GL_POINTS);
1858
for (i = 1; i <= plainpoints.Size(); i++)
1859
{
1860
Point2d p = plainpoints.Get(i);
1861
glVertex3f (scalex * p.X(), scaley * p.Y(), -5);
1862
}
1863
glEnd();
1864
1865
glFinish();
1866
*/
1867
}
1868
1869
1870
void VisualSceneSurfaceMeshing :: BuildScene (int zoomall)
1871
{
1872
int i, j, k;
1873
/*
1874
center = stlgeometry -> GetBoundingBox().Center();
1875
rad = stlgeometry -> GetBoundingBox().Diam() / 2;
1876
1877
CalcTransformationMatrices();
1878
*/
1879
}
1880
1881
}
1882
1883
1884
#else
1885
namespace netgen
1886
{
1887
void glrender (int wait)
1888
{ ; }
1889
}
1890
#endif
1891
1892