Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/meshing2.cpp
3206 views
#include <mystdlib.h>1#include "meshing.hpp"23namespace netgen4{5static void glrender (int wait);678// global variable for visualization910static ARRAY<Point3d> locpoints;11static ARRAY<int> legalpoints;12static ARRAY<Point2d> plainpoints;13static ARRAY<int> plainzones;14static ARRAY<INDEX_2> loclines;15static int geomtrig;16//static const char * rname;17static int cntelem, trials, nfaces;18static int oldnl;19static int qualclass;202122Meshing2 :: Meshing2 (const Box<3> & aboundingbox)23{24boundingbox = aboundingbox;2526LoadRules (NULL);27// LoadRules ("rules/quad.rls");28// LoadRules ("rules/triangle.rls");2930adfront = new AdFront2(boundingbox);31starttime = GetTime();3233maxarea = -1;34}353637Meshing2 :: ~Meshing2 ()38{39delete adfront;40for (int i = 0; i < rules.Size(); i++)41delete rules[i];42}4344void Meshing2 :: AddPoint (const Point3d & p, PointIndex globind,45MultiPointGeomInfo * mgi,46bool pointonsurface)47{48//(*testout) << "add point " << globind << endl;49adfront ->AddPoint (p, globind, mgi, pointonsurface);50}5152void Meshing2 :: AddBoundaryElement (int i1, int i2,53const PointGeomInfo & gi1, const PointGeomInfo & gi2)54{55// (*testout) << "add line " << i1 << " - " << i2 << endl;56if (!gi1.trignum || !gi2.trignum)57{58PrintSysError ("addboundaryelement: illegal geominfo");59}60adfront -> AddLine (i1-1, i2-1, gi1, gi2);61}62636465void Meshing2 :: StartMesh ()66{67foundmap.SetSize (rules.Size());68canuse.SetSize (rules.Size());69ruleused.SetSize (rules.Size());7071foundmap = 0;72canuse = 0;73ruleused = 0;7475cntelem = 0;76trials = 0;77}7879void Meshing2 :: EndMesh ()80{81for (int i = 0; i < ruleused.Size(); i++)82(*testout) << setw(4) << ruleused[i]83<< " times used rule " << rules[i] -> Name() << endl;84}8586void Meshing2 :: SetStartTime (double astarttime)87{88starttime = astarttime;89}909192void Meshing2 :: SetMaxArea (double amaxarea)93{94maxarea = amaxarea;95}969798double Meshing2 :: CalcLocalH (const Point3d & /* p */, double gh) const99{100return gh;101}102103// should be class variables !!(?)104static Vec3d ex, ey;105static Point3d globp1;106107void Meshing2 :: DefineTransformation (const Point3d & p1, const Point3d & p2,108const PointGeomInfo * geominfo1,109const PointGeomInfo * geominfo2)110{111globp1 = p1;112ex = p2 - p1;113ex /= ex.Length();114ey.X() = -ex.Y();115ey.Y() = ex.X();116ey.Z() = 0;117}118119void Meshing2 :: TransformToPlain (const Point3d & locpoint,120const MultiPointGeomInfo & geominf,121Point2d & plainpoint, double h, int & zone)122{123Vec3d p1p (globp1, locpoint);124125// p1p = locpoint - globp1;126p1p /= h;127plainpoint.X() = p1p * ex;128plainpoint.Y() = p1p * ey;129zone = 0;130}131132int Meshing2 :: TransformFromPlain (Point2d & plainpoint,133Point3d & locpoint,134PointGeomInfo & gi,135double h)136{137Vec3d p1p;138gi.trignum = 1;139140p1p = plainpoint.X() * ex + plainpoint.Y() * ey;141p1p *= h;142locpoint = globp1 + p1p;143return 0;144}145146147int Meshing2 :: BelongsToActiveChart (const Point3d & p,148const PointGeomInfo & gi)149{150return 1;151}152153154int Meshing2 :: ComputePointGeomInfo (const Point3d & p, PointGeomInfo & gi)155{156gi.trignum = 1;157return 0;158}159160161int Meshing2 :: ChooseChartPointGeomInfo (const MultiPointGeomInfo & mpgi,162PointGeomInfo & pgi)163{164pgi = mpgi.GetPGI(1);165return 0;166}167168169170int Meshing2 ::171IsLineVertexOnChart (const Point3d & p1, const Point3d & p2,172int endpoint, const PointGeomInfo & geominfo)173{174return 1;175}176177void Meshing2 ::178GetChartBoundary (ARRAY<Point2d> & points,179ARRAY<Point3d> & points3d,180ARRAY<INDEX_2> & lines, double h) const181{182points.SetSize (0);183points3d.SetSize (0);184lines.SetSize (0);185}186187double Meshing2 :: Area () const188{189return -1;190}191192193194195196MESHING2_RESULT Meshing2 :: GenerateMesh (Mesh & mesh, double gh, int facenr)197{198ARRAY<int> pindex, lindex;199ARRAY<int> delpoints, dellines;200201ARRAY<PointGeomInfo> upgeominfo; // unique info202ARRAY<MultiPointGeomInfo> mpgeominfo; // multiple info203204ARRAY<Element2d> locelements;205206int z1, z2, oldnp(-1);207SurfaceElementIndex sei;208bool found;209int rulenr(-1);210int globind;211Point<3> p1, p2;212213const PointGeomInfo * blgeominfo1;214const PointGeomInfo * blgeominfo2;215216bool morerisc;217bool debugflag;218219double h, his, hshould;220221222// test for 3d overlaps223Box3dTree surfeltree (boundingbox.PMin(),224boundingbox.PMax());225226ARRAY<int> intersecttrias;227ARRAY<Point3d> critpoints;228229// test for doubled edges230//INDEX_2_HASHTABLE<int> doubleedge(300000);231232233testmode = 0;234235StartMesh();236237ARRAY<Point2d> chartboundpoints;238ARRAY<Point3d> chartboundpoints3d;239ARRAY<INDEX_2> chartboundlines;240241// illegal points: points with more then 50 elements per node242int maxlegalpoint(-1), maxlegalline(-1);243ARRAY<int,PointIndex::BASE> trigsonnode;244ARRAY<int,PointIndex::BASE> illegalpoint;245246trigsonnode.SetSize (mesh.GetNP());247illegalpoint.SetSize (mesh.GetNP());248249trigsonnode = 0;250illegalpoint = 0;251252253double totalarea = Area ();254double meshedarea = 0;255256// search tree for surface elements:257for (sei = 0; sei < mesh.GetNSE(); sei++)258{259const Element2d & sel = mesh[sei];260261if (sel.IsDeleted()) continue;262263if (sel.GetIndex() == facenr)264{265Box<3> box;266box.Set ( mesh[sel[0]] );267box.Add ( mesh[sel[1]] );268box.Add ( mesh[sel[2]] );269surfeltree.Insert (box, sei);270}271272double trigarea = Cross ( mesh[sel[1]]-mesh[sel[0]],273mesh[sel[2]]-mesh[sel[0]] ).Length() / 2;274275276if (sel.GetNP() == 4)277trigarea += Cross (Vec3d (mesh.Point (sel.PNum(1)),278mesh.Point (sel.PNum(3))),279Vec3d (mesh.Point (sel.PNum(1)),280mesh.Point (sel.PNum(4)))).Length() / 2;;281meshedarea += trigarea;282}283284285const char * savetask = multithread.task;286multithread.task = "Surface meshing";287288adfront ->SetStartFront ();289290291int plotnexttrial = 999;292293double meshedarea_before = meshedarea;294295while (!adfront ->Empty() && !multithread.terminate)296{297if (multithread.terminate)298throw NgException ("Meshing stopped");299300// known for STL meshing301if (totalarea > 0)302multithread.percent = 100 * meshedarea / totalarea;303/*304else305multithread.percent = 0;306*/307308locpoints.SetSize(0);309loclines.SetSize(0);310pindex.SetSize(0);311lindex.SetSize(0);312delpoints.SetSize(0);313dellines.SetSize(0);314locelements.SetSize(0);315316317318// plot statistics319if (trials > plotnexttrial)320{321PrintMessage (5,322"faces = ", nfaces,323" trials = ", trials,324" elements = ", mesh.GetNSE(),325" els/sec = ",326(mesh.GetNSE() / (GetTime() - starttime + 0.0001)));327plotnexttrial += 1000;328}329330331// unique-pgi, multi-pgi332upgeominfo.SetSize(0);333mpgeominfo.SetSize(0);334335336nfaces = adfront->GetNFL();337trials ++;338339340if (trials % 1000 == 0)341{342(*testout) << "\n";343for (int i = 1; i <= canuse.Size(); i++)344{345(*testout) << foundmap.Get(i) << "/"346<< canuse.Get(i) << "/"347<< ruleused.Get(i) << " map/can/use rule " << rules.Get(i)->Name() << "\n";348}349(*testout) << "\n";350}351352353int baselineindex = adfront -> SelectBaseLine (p1, p2, blgeominfo1, blgeominfo2, qualclass);354355356found = 1;357358his = Dist (p1, p2);359360Point3d pmid = Center (p1, p2);361hshould = CalcLocalH (pmid, mesh.GetH (pmid));362if (gh < hshould) hshould = gh;363364mesh.RestrictLocalH (pmid, hshould);365366h = hshould;367368double hinner = (3 + qualclass) * max2 (his, hshould);369370adfront ->GetLocals (baselineindex, locpoints, mpgeominfo, loclines,371pindex, lindex, 2*hinner);372//(*testout) << "h for locals: " << 2*hinner << endl;373374375//(*testout) << "locpoints " << locpoints << endl;376377if (qualclass > mparam.giveuptol2d)378{379PrintMessage (3, "give up with qualclass ", qualclass);380PrintMessage (3, "number of frontlines = ", adfront->GetNFL());381// throw NgException ("Give up 2d meshing");382break;383}384385/*386if (found && qualclass > 60)387{388found = 0;389}390*/391// morerisc = ((qualclass > 20) && (qualclass % 2 == 1));392// morerisc = 1;393morerisc = 0;394395396PointIndex gpi1 = adfront -> GetGlobalIndex (pindex.Get(loclines[0].I1()));397PointIndex gpi2 = adfront -> GetGlobalIndex (pindex.Get(loclines[0].I2()));398399400debugflag =401debugparam.haltsegment &&402( (debugparam.haltsegmentp1 == gpi1) &&403(debugparam.haltsegmentp2 == gpi2) ||404(debugparam.haltsegmentp1 == gpi2) &&405(debugparam.haltsegmentp2 == gpi1)) ||406debugparam.haltnode &&407( (debugparam.haltsegmentp1 == gpi1) ||408(debugparam.haltsegmentp2 == gpi1));409410411if (debugparam.haltface && debugparam.haltfacenr == facenr)412{413debugflag = 1;414cout << "set debugflag" << endl;415}416417if (debugparam.haltlargequalclass && qualclass > 50)418debugflag = 1;419420421// problem recognition !422if (found &&423(gpi1 < illegalpoint.Size()+PointIndex::BASE) &&424(gpi2 < illegalpoint.Size()+PointIndex::BASE) )425{426if (illegalpoint[gpi1] || illegalpoint[gpi2])427found = 0;428}429430431Point2d p12d, p22d;432433if (found)434{435oldnp = locpoints.Size();436oldnl = loclines.Size();437438if (debugflag)439(*testout) << "define new transformation" << endl;440441DefineTransformation (p1, p2, blgeominfo1, blgeominfo2);442443plainpoints.SetSize (locpoints.Size());444plainzones.SetSize (locpoints.Size());445446// (*testout) << endl;447448// (*testout) << "3d->2d transformation" << endl;449450for (int i = 1; i <= locpoints.Size(); i++)451{452// (*testout) << "pindex(i) = " << pindex[i-1] << endl;453TransformToPlain (locpoints.Get(i),454mpgeominfo.Get(i),455plainpoints.Elem(i), h, plainzones.Elem(i));456// (*testout) << mpgeominfo.Get(i).GetPGI(1).u << " " << mpgeominfo.Get(i).GetPGI(1).v << " ";457// (*testout) << plainpoints.Get(i).X() << " " << plainpoints.Get(i).Y() << endl;458//(*testout) << "transform " << locpoints.Get(i) << " to " << plainpoints.Get(i).X() << " " << plainpoints.Get(i).Y() << endl;459}460// (*testout) << endl << endl << endl;461462463p12d = plainpoints.Get(1);464p22d = plainpoints.Get(2);465466/*467// last idea on friday468plainzones.Elem(1) = 0;469plainzones.Elem(2) = 0;470*/471472473/*474// old netgen:475for (i = 2; i <= loclines.Size(); i++) // don't remove first line476{477z1 = plainzones.Get(loclines.Get(i).I1());478z2 = plainzones.Get(loclines.Get(i).I2());479480if (z1 && z2 && (z1 != z2) || (z1 == -1) || (z2 == -1) )481{482loclines.DeleteElement(i);483lindex.DeleteElement(i);484oldnl--;485i--;486}487}488489// for (i = 1; i <= plainpoints.Size(); i++)490// if (plainzones.Elem(i) == -1)491// plainpoints.Elem(i) = Point2d (1e4, 1e4);492*/493494495496for (int i = 2; i <= loclines.Size(); i++) // don't remove first line497{498// (*testout) << "loclines(i) = " << loclines.Get(i).I1() << " - " << loclines.Get(i).I2() << endl;499z1 = plainzones.Get(loclines.Get(i).I1());500z2 = plainzones.Get(loclines.Get(i).I2());501502503// one inner point, one outer504if ( (z1 >= 0) != (z2 >= 0))505{506int innerp = (z1 >= 0) ? 1 : 2;507if (IsLineVertexOnChart (locpoints.Get(loclines.Get(i).I1()),508locpoints.Get(loclines.Get(i).I2()),509innerp,510adfront->GetLineGeomInfo (lindex.Get(i), innerp)))511// pgeominfo.Get(loclines.Get(i).I(innerp))))512{513514if (!morerisc)515{516// use one end of line517int pini, pouti;518Vec2d v;519520pini = loclines.Get(i).I(innerp);521pouti = loclines.Get(i).I(3-innerp);522523Point2d pin (plainpoints.Get(pini));524Point2d pout (plainpoints.Get(pouti));525v = pout - pin;526double len = v.Length();527if (len <= 1e-6)528(*testout) << "WARNING(js): inner-outer: short vector" << endl;529else530v /= len;531532/*533// don't elongate line towards base-line !!534if (Vec2d (pin, p12d) * v > 0 &&535Vec2d (pin, p22d) * v > 0)536v *= -1;537*/538539Point2d newpout = pin + 1000 * v;540newpout = pout;541542543plainpoints.Append (newpout);544Point3d pout3d = locpoints.Get(pouti);545locpoints.Append (pout3d);546547plainzones.Append (0);548pindex.Append (-1);549oldnp++;550loclines.Elem(i).I(3-innerp) = oldnp;551}552else553plainzones.Elem(loclines.Get(i).I(3-innerp)) = 0;554555556// (*testout) << "inner - outer correction" << endl;557}558else559{560// remove line561loclines.DeleteElement(i);562lindex.DeleteElement(i);563oldnl--;564i--;565}566}567568else if (z1 > 0 && z2 > 0 && (z1 != z2) || (z1 < 0) && (z2 < 0) )569{570loclines.DeleteElement(i);571lindex.DeleteElement(i);572oldnl--;573i--;574}575}576577578579580581legalpoints.SetSize(plainpoints.Size());582for (int i = 1; i <= legalpoints.Size(); i++)583legalpoints.Elem(i) = 1;584585double avy = 0;586for (int i = 1; i <= plainpoints.Size(); i++)587avy += plainpoints.Elem(i).Y();588avy *= 1./plainpoints.Size();589590591for (int i = 1; i <= plainpoints.Size(); i++)592{593if (plainzones.Elem(i) < 0)594{595plainpoints.Elem(i) = Point2d (1e4, 1e4);596legalpoints.Elem(i) = 0;597}598if (pindex.Elem(i) == -1)599{600legalpoints.Elem(i) = 0;601}602603604if (plainpoints.Elem(i).Y() < -1e-10*avy) // changed605{606legalpoints.Elem(i) = 0;607}608}609/*610for (i = 3; i <= plainpoints.Size(); i++)611if (sqr (plainpoints.Get(i).X()) + sqr (plainpoints.Get(i).Y())612> sqr (2 + 0.2 * qualclass))613legalpoints.Elem(i) = 0;614*/615616/*617int clp = 0;618for (i = 1; i <= plainpoints.Size(); i++)619if (legalpoints.Get(i))620clp++;621(*testout) << "legalpts: " << clp << "/" << plainpoints.Size() << endl;622623// sort legal/illegal lines624int lastleg = 2;625int firstilleg = oldnl;626627while (lastleg < firstilleg)628{629while (legalpoints.Get(loclines.Get(lastleg).I1()) &&630legalpoints.Get(loclines.Get(lastleg).I2()) &&631lastleg < firstilleg)632lastleg++;633while ( ( !legalpoints.Get(loclines.Get(firstilleg).I1()) ||634!legalpoints.Get(loclines.Get(firstilleg).I2())) &&635lastleg < firstilleg)636firstilleg--;637638if (lastleg < firstilleg)639{640swap (loclines.Elem(lastleg), loclines.Elem(firstilleg));641swap (lindex.Elem(lastleg), lindex.Elem(firstilleg));642}643}644645(*testout) << "leglines " << lastleg << "/" << oldnl << endl;646*/647648649GetChartBoundary (chartboundpoints,650chartboundpoints3d,651chartboundlines, h);652653oldnp = plainpoints.Size();654655maxlegalpoint = locpoints.Size();656maxlegalline = loclines.Size();657658659660if (mparam.checkchartboundary)661{662for (int i = 1; i <= chartboundpoints.Size(); i++)663{664plainpoints.Append (chartboundpoints.Get(i));665locpoints.Append (chartboundpoints3d.Get(i));666legalpoints.Append (0);667}668669670for (int i = 1; i <= chartboundlines.Size(); i++)671{672INDEX_2 line (chartboundlines.Get(i).I1()+oldnp,673chartboundlines.Get(i).I2()+oldnp);674loclines.Append (line);675// (*testout) << "line: " << line.I1() << "-" << line.I2() << endl;676}677}678679oldnl = loclines.Size();680oldnp = plainpoints.Size();681}682683684/*685if (qualclass > 100)686{687multithread.drawing = 1;688glrender(1);689cout << "qualclass 100, nfl = " << adfront->GetNFL() << endl;690}691*/692693if (found)694{695rulenr = ApplyRules (plainpoints, legalpoints, maxlegalpoint,696loclines, maxlegalline, locelements,697dellines, qualclass);698// (*testout) << "Rule Nr = " << rulenr << endl;699if (!rulenr)700{701found = 0;702if ( debugflag || debugparam.haltnosuccess )703PrintWarning ("no rule found");704}705}706707for (int i = 1; i <= locelements.Size() && found; i++)708{709const Element2d & el = locelements.Get(i);710711for (int j = 1; j <= el.GetNP(); j++)712if (el.PNum(j) <= oldnp && pindex.Get(el.PNum(j)) == -1)713{714found = 0;715PrintSysError ("meshing2, index missing");716}717}718719720if (found)721{722locpoints.SetSize (plainpoints.Size());723upgeominfo.SetSize(locpoints.Size());724725for (int i = oldnp+1; i <= plainpoints.Size(); i++)726{727int err =728TransformFromPlain (plainpoints.Elem(i), locpoints.Elem(i),729upgeominfo.Elem(i), h);730731if (err)732{733found = 0;734735if ( debugflag || debugparam.haltnosuccess )736PrintSysError ("meshing2, Backtransformation failed");737738break;739}740}741}742743744// for (i = 1; i <= oldnl; i++)745// adfront -> ResetClass (lindex[i]);746747748/*749double violateminh;750if (qualclass <= 10)751violateminh = 3;752else753violateminh = 3 * qualclass;754755if (uselocalh && found) // && qualclass <= 10)756{757for (i = 1; i <= locelements.Size(); i++)758{759Point3d pmin = locpoints.Get(locelements.Get(i).PNum(1));760Point3d pmax = pmin;761for (j = 2; j <= 3; j++)762{763const Point3d & hp =764locpoints.Get(locelements.Get(i).PNum(j));765pmin.SetToMin (hp);766pmax.SetToMax (hp);767}768double minh = mesh.GetMinH (pmin, pmax);769if (h > violateminh * minh)770{771found = 0;772loclines.SetSize (oldnl);773locpoints.SetSize (oldnp);774}775}776}777*/778779780if (found)781{782double violateminh = 3 + 0.1 * sqr (qualclass);783double minh = 1e8;784double newedgemaxh = 0;785for (int i = oldnl+1; i <= loclines.Size(); i++)786{787double eh = Dist (locpoints.Get(loclines.Get(i).I1()),788locpoints.Get(loclines.Get(i).I2()));789790// Markus (brute force method to avoid bad elements on geometries like \_/ )791//if(eh > 4.*mesh.GetH(locpoints.Get(loclines.Get(i).I1()))) found = 0;792//if(eh > 4.*mesh.GetH(locpoints.Get(loclines.Get(i).I2()))) found = 0;793// Markus end794795if (eh > newedgemaxh)796newedgemaxh = eh;797}798799for (int i = 1; i <= locelements.Size(); i++)800{801Point3d pmin = locpoints.Get(locelements.Get(i).PNum(1));802Point3d pmax = pmin;803for (int j = 2; j <= locelements.Get(i).GetNP(); j++)804{805const Point3d & hp =806locpoints.Get(locelements.Get(i).PNum(j));807pmin.SetToMin (hp);808pmax.SetToMax (hp);809}810double eh = mesh.GetMinH (pmin, pmax);811if (eh < minh)812minh = eh;813}814815for (int i = 1; i <= locelements.Size(); i++)816for (int j = 1; j <= locelements.Get(i).GetNP(); j++)817if (Dist2 (locpoints.Get(locelements.Get(i).PNum(j)), pmid) > hinner*hinner)818found = 0;819820// cout << "violate = " << newedgemaxh / minh << endl;821static double maxviolate = 0;822if (newedgemaxh / minh > maxviolate)823{824maxviolate = newedgemaxh / minh;825// cout << "max minhviolate = " << maxviolate << endl;826}827828829if (newedgemaxh > violateminh * minh)830{831found = 0;832loclines.SetSize (oldnl);833locpoints.SetSize (oldnp);834835if ( debugflag || debugparam.haltnosuccess )836PrintSysError ("meshing2, maxh too large");837838839}840}841842843844/*845// test good ComputeLineGeoInfo846if (found)847{848// is line on chart ?849for (i = oldnl+1; i <= loclines.Size(); i++)850{851int gisize;852void *geominfo;853854if (ComputeLineGeoInfo (locpoints.Get(loclines.Get(i).I1()),855locpoints.Get(loclines.Get(i).I2()),856gisize, geominfo))857found = 0;858}859}860*/861862863// changed for OCC meshing864if (found)865{866// take geominfo from dellines867// upgeominfo.SetSize(locpoints.Size());868869/*870for (i = 1; i <= dellines.Size(); i++)871for (j = 1; j <= 2; j++)872{873upgeominfo.Elem(loclines.Get(dellines.Get(i)).I(j)) =874adfront -> GetLineGeomInfo (lindex.Get(dellines.Get(i)), j);875}876*/877878879for (int i = 1; i <= locelements.Size(); i++)880for (int j = 1; j <= locelements.Get(i).GetNP(); j++)881{882int pi = locelements.Get(i).PNum(j);883if (pi <= oldnp)884{885886if (ChooseChartPointGeomInfo (mpgeominfo.Get(pi), upgeominfo.Elem(pi)))887{888// cannot select, compute new one889PrintWarning ("calc point geominfo instead of using");890if (ComputePointGeomInfo (locpoints.Get(pi), upgeominfo.Elem(pi)))891{892found = 0;893PrintSysError ("meshing2d, geominfo failed");894}895}896}897}898899/*900// use upgeominfo from ProjectFromPlane901for (i = oldnp+1; i <= locpoints.Size(); i++)902{903if (ComputePointGeomInfo (locpoints.Get(i), upgeominfo.Elem(i)))904{905found = 0;906if ( debugflag || debugparam.haltnosuccess )907PrintSysError ("meshing2d, compute geominfo failed");908}909}910*/911}912913914if (found && mparam.checkoverlap)915{916// cout << "checkoverlap" << endl;917// test for overlaps918919Point3d hullmin(1e10, 1e10, 1e10);920Point3d hullmax(-1e10, -1e10, -1e10);921922for (int i = 1; i <= locelements.Size(); i++)923for (int j = 1; j <= locelements.Get(i).GetNP(); j++)924{925const Point3d & p = locpoints.Get(locelements.Get(i).PNum(j));926hullmin.SetToMin (p);927hullmax.SetToMax (p);928}929hullmin += Vec3d (-his, -his, -his);930hullmax += Vec3d ( his, his, his);931932surfeltree.GetIntersecting (hullmin, hullmax, intersecttrias);933934critpoints.SetSize (0);935for (int i = oldnp+1; i <= locpoints.Size(); i++)936critpoints.Append (locpoints.Get(i));937938for (int i = 1; i <= locelements.Size(); i++)939{940const Element2d & tri = locelements.Get(i);941if (tri.GetNP() == 3)942{943const Point3d & tp1 = locpoints.Get(tri.PNum(1));944const Point3d & tp2 = locpoints.Get(tri.PNum(2));945const Point3d & tp3 = locpoints.Get(tri.PNum(3));946947Vec3d tv1 (tp1, tp2);948Vec3d tv2 (tp1, tp3);949950double lam1, lam2;951for (lam1 = 0.2; lam1 <= 0.8; lam1 += 0.2)952for (lam2 = 0.2; lam2 + lam1 <= 0.8; lam2 += 0.2)953{954Point3d hp = tp1 + lam1 * tv1 + lam2 * tv2;955critpoints.Append (hp);956}957}958else if (tri.GetNP() == 4)959{960const Point3d & tp1 = locpoints.Get(tri.PNum(1));961const Point3d & tp2 = locpoints.Get(tri.PNum(2));962const Point3d & tp3 = locpoints.Get(tri.PNum(3));963const Point3d & tp4 = locpoints.Get(tri.PNum(4));964965double l1, l2;966for (l1 = 0.1; l1 <= 0.9; l1 += 0.1)967for (l2 = 0.1; l2 <= 0.9; l2 += 0.1)968{969Point3d hp;970hp.X() =971(1-l1)*(1-l2) * tp1.X() +972l1*(1-l2) * tp2.X() +973l1*l2 * tp3.X() +974(1-l1)*l2 * tp4.X();975hp.Y() =976(1-l1)*(1-l2) * tp1.Y() +977l1*(1-l2) * tp2.Y() +978l1*l2 * tp3.Y() +979(1-l1)*l2 * tp4.Y();980hp.Z() =981(1-l1)*(1-l2) * tp1.Z() +982l1*(1-l2) * tp2.Z() +983l1*l2 * tp3.Z() +984(1-l1)*l2 * tp4.Z();985986987critpoints.Append (hp);988}989}990}991/*992for (i = oldnl+1; i <= loclines.Size(); i++)993{994Point3d hp = locpoints.Get(loclines.Get(i).I1());995Vec3d hv(hp, locpoints.Get(loclines.Get(i).I2()));996int ncp = 2;997for (j = 1; j <= ncp; j++)998critpoints.Append ( hp + (double(j)/(ncp+1)) * hv);999}1000*/100110021003/*1004for (i = oldnp+1; i <= locpoints.Size(); i++)1005{1006const Point3d & p = locpoints.Get(i);1007*/100810091010for (int i = 1; i <= critpoints.Size(); i++)1011{1012const Point3d & p = critpoints.Get(i);101310141015/*1016for (j = 1; j <= mesh.GetNSE(); j++)1017{1018*/1019int jj;1020for (jj = 1; jj <= intersecttrias.Size(); jj++)1021{1022int j = intersecttrias.Get(jj);1023const Element2d & el = mesh.SurfaceElement(j);10241025int ntrig = (el.GetNP() == 3) ? 1 : 2;10261027int jl;1028for (jl = 1; jl <= ntrig; jl++)1029{1030Point3d tp1, tp2, tp3;10311032if (jl == 1)1033{1034tp1 = mesh.Point(el.PNum(1));1035tp2 = mesh.Point(el.PNum(2));1036tp3 = mesh.Point(el.PNum(3));1037}1038else1039{1040tp1 = mesh.Point(el.PNum(1));1041tp2 = mesh.Point(el.PNum(3));1042tp3 = mesh.Point(el.PNum(4));1043}10441045int onchart = 0;1046for (int k = 1; k <= el.GetNP(); k++)1047if (BelongsToActiveChart (mesh.Point(el.PNum(k)),1048el.GeomInfoPi(k)))1049onchart = 1;1050if (!onchart)1051continue;10521053Vec3d e1(tp1, tp2);1054Vec3d e2(tp1, tp3);1055Vec3d n = Cross (e1, e2);1056n /= n.Length();1057double lam1, lam2, lam3;1058lam3 = n * Vec3d (tp1, p);1059LocalCoordinates (e1, e2, Vec3d (tp1, p), lam1, lam2);10601061if (fabs (lam3) < 0.1 * hshould &&1062lam1 > 0 && lam2 > 0 && (lam1 + lam2) < 1)1063{1064#ifdef DEVELOP1065cout << "overlap" << endl;1066(*testout) << "overlap:" << endl1067<< "tri = " << tp1 << "-" << tp2 << "-" << tp3 << endl1068<< "point = " << p << endl1069<< "lam1, 2 = " << lam1 << ", " << lam2 << endl1070<< "lam3 = " << lam3 << endl;10711072// cout << "overlap !!!" << endl;1073#endif1074for (int k = 1; k <= 5; k++)1075adfront -> IncrementClass (lindex.Get(1));10761077found = 0;10781079if ( debugflag || debugparam.haltnosuccess )1080PrintWarning ("overlapping");108110821083if (debugparam.haltoverlap)1084{1085debugflag = 1;1086}10871088/*1089multithread.drawing = 1;1090glrender(1);1091*/1092}1093}1094}1095}1096}109710981099if (found)1100{1101// check, whether new front line already exists11021103for (int i = oldnl+1; i <= loclines.Size(); i++)1104{1105int nlgpi1 = loclines.Get(i).I1();1106int nlgpi2 = loclines.Get(i).I2();1107if (nlgpi1 <= pindex.Size() && nlgpi2 <= pindex.Size())1108{1109nlgpi1 = adfront->GetGlobalIndex (pindex.Get(nlgpi1));1110nlgpi2 = adfront->GetGlobalIndex (pindex.Get(nlgpi2));11111112int exval = adfront->ExistsLine (nlgpi1, nlgpi2);1113if (exval)1114{1115cout << "ERROR: new line exits, val = " << exval << endl;1116(*testout) << "ERROR: new line exits, val = " << exval << endl;1117found = 0;111811191120if (debugparam.haltexistingline)1121debugflag = 1;11221123}1124}1125}11261127}112811291130/*1131if (found)1132{1133// check, whether new triangles insert edges twice1134for (i = 1; i <= locelements.Size(); i++)1135for (j = 1; j <= 3; j++)1136{1137int tpi1 = locelements.Get(i).PNumMod (j);1138int tpi2 = locelements.Get(i).PNumMod (j+1);1139if (tpi1 <= pindex.Size() && tpi2 <= pindex.Size())1140{1141tpi1 = adfront->GetGlobalIndex (pindex.Get(tpi1));1142tpi2 = adfront->GetGlobalIndex (pindex.Get(tpi2));11431144if (doubleedge.Used (INDEX_2(tpi1, tpi2)))1145{1146if (debugparam.haltexistingline)1147debugflag = 1;1148cerr << "ERROR Insert edge "1149<< tpi1 << " - " << tpi2 << " twice !!!" << endl;1150found = 0;1151}1152doubleedge.Set (INDEX_2(tpi1, tpi2), 1);1153}1154}1155}1156*/115711581159if (found)1160{1161// everything is ok, perform mesh update11621163ruleused.Elem(rulenr)++;116411651166pindex.SetSize(locpoints.Size());11671168for (int i = oldnp+1; i <= locpoints.Size(); i++)1169{1170globind = mesh.AddPoint (locpoints.Get(i));1171pindex.Elem(i) = adfront -> AddPoint (locpoints.Get(i), globind);1172}11731174for (int i = oldnl+1; i <= loclines.Size(); i++)1175{1176/*1177for (j = 1; j <= locpoints.Size(); j++)1178{1179(*testout) << j << ": " << locpoints.Get(j) << endl;1180}1181*/11821183/*1184ComputeLineGeoInfo (locpoints.Get(loclines.Get(i).I1()),1185locpoints.Get(loclines.Get(i).I2()),1186gisize, geominfo);1187*/11881189if (pindex.Get(loclines.Get(i).I1()) == -1 ||1190pindex.Get(loclines.Get(i).I2()) == -1)1191{1192(*testout) << "pindex is 0" << endl;1193}11941195if (!upgeominfo.Get(loclines.Get(i).I1()).trignum ||1196!upgeominfo.Get(loclines.Get(i).I2()).trignum)1197{1198cout << "new el: illegal geominfo" << endl;1199}12001201adfront -> AddLine (pindex.Get(loclines.Get(i).I1()),1202pindex.Get(loclines.Get(i).I2()),1203upgeominfo.Get(loclines.Get(i).I1()),1204upgeominfo.Get(loclines.Get(i).I2()));1205}1206for (int i = 1; i <= locelements.Size(); i++)1207{1208Element2d mtri(locelements.Get(i).GetNP());1209mtri = locelements.Get(i);1210mtri.SetIndex (facenr);121112121213// compute triangle geominfo:1214// (*testout) << "triggeominfo: ";1215for (int j = 1; j <= locelements.Get(i).GetNP(); j++)1216{1217mtri.GeomInfoPi(j) = upgeominfo.Get(locelements.Get(i).PNum(j));1218// (*testout) << mtri.GeomInfoPi(j).trignum << " ";1219}1220// (*testout) << endl;12211222for (int j = 1; j <= locelements.Get(i).GetNP(); j++)1223{1224mtri.PNum(j) =1225locelements.Elem(i).PNum(j) =1226adfront -> GetGlobalIndex (pindex.Get(locelements.Get(i).PNum(j)));1227}12281229123012311232mesh.AddSurfaceElement (mtri);1233cntelem++;1234// cout << "elements: " << cntelem << endl;1235123612371238Box<3> box;1239box.Set (mesh[mtri[0]]);1240box.Add (mesh[mtri[1]]);1241box.Add (mesh[mtri[2]]);1242surfeltree.Insert (box, mesh.GetNSE());12431244const Point3d & sep1 = mesh.Point (mtri.PNum(1));1245const Point3d & sep2 = mesh.Point (mtri.PNum(2));1246const Point3d & sep3 = mesh.Point (mtri.PNum(3));12471248double trigarea = Cross (Vec3d (sep1, sep2),1249Vec3d (sep1, sep3)).Length() / 2;12501251if (mtri.GetNP() == 4)1252{1253const Point3d & sep4 = mesh.Point (mtri.PNum(4));1254trigarea += Cross (Vec3d (sep1, sep3),1255Vec3d (sep1, sep4)).Length() / 2;1256}12571258meshedarea += trigarea;12591260if(maxarea > 0 && meshedarea-meshedarea_before > maxarea)1261{1262cerr << "meshed area = " << meshedarea-meshedarea_before << endl1263<< "maximal area = " << maxarea << endl1264<< "GIVING UP" << endl;1265return MESHING2_GIVEUP;1266}1267126812691270for (int j = 1; j <= locelements.Get(i).GetNP(); j++)1271{1272int gpi = locelements.Get(i).PNum(j);12731274int oldts = trigsonnode.Size();1275if (gpi >= oldts+PointIndex::BASE)1276{1277trigsonnode.SetSize (gpi+1-PointIndex::BASE);1278illegalpoint.SetSize (gpi+1-PointIndex::BASE);1279for (int k = oldts+PointIndex::BASE;1280k <= gpi; k++)1281{1282trigsonnode[k] = 0;1283illegalpoint[k] = 0;1284}1285}12861287trigsonnode[gpi]++;12881289if (trigsonnode[gpi] > 20)1290{1291illegalpoint[gpi] = 1;1292// cout << "illegal point: " << gpi << endl;1293(*testout) << "illegal point: " << gpi << endl;1294}12951296static int mtonnode = 0;1297if (trigsonnode[gpi] > mtonnode)1298mtonnode = trigsonnode[gpi];1299}1300// cout << "els = " << cntelem << " trials = " << trials << endl;1301// if (trials > 100) return;1302}13031304for (int i = 1; i <= dellines.Size(); i++)1305adfront -> DeleteLine (lindex.Get(dellines.Get(i)));13061307// rname = rules.Get(rulenr)->Name();1308#ifdef MYGRAPH1309if (silentflag<3)1310{1311plotsurf.DrawPnL(locpoints, loclines);1312plotsurf.Plot(testmode, testmode);1313}1314#endif13151316if (morerisc)1317{1318cout << "generated due to morerisc" << endl;1319// multithread.drawing = 1;1320// glrender(1);1321}13221323132413251326if ( debugparam.haltsuccess || debugflag )1327{1328// adfront -> PrintOpenSegments (*testout);1329cout << "success of rule" << rules.Get(rulenr)->Name() << endl;1330multithread.drawing = 1;1331multithread.testmode = 1;1332multithread.pause = 1;133313341335/*1336extern STLGeometry * stlgeometry;1337stlgeometry->ClearMarkedSegs();1338for (i = 1; i <= loclines.Size(); i++)1339{1340stlgeometry->AddMarkedSeg(locpoints.Get(loclines.Get(i).I1()),1341locpoints.Get(loclines.Get(i).I2()));1342}1343*/13441345(*testout) << "success of rule" << rules.Get(rulenr)->Name() << endl;1346(*testout) << "trials = " << trials << endl;13471348(*testout) << "locpoints " << endl;1349for (int i = 1; i <= pindex.Size(); i++)1350(*testout) << adfront->GetGlobalIndex (pindex.Get(i)) << endl;13511352(*testout) << "old number of lines = " << oldnl << endl;1353for (int i = 1; i <= loclines.Size(); i++)1354{1355(*testout) << "line ";1356for (int j = 1; j <= 2; j++)1357{1358int hi = 0;1359if (loclines.Get(i).I(j) >= 1 &&1360loclines.Get(i).I(j) <= pindex.Size())1361hi = adfront->GetGlobalIndex (pindex.Get(loclines.Get(i).I(j)));13621363(*testout) << hi << " ";1364}1365(*testout) << " : "1366<< plainpoints.Get(loclines.Get(i).I1()) << " - "1367<< plainpoints.Get(loclines.Get(i).I2()) << " 3d: "1368<< locpoints.Get(loclines.Get(i).I1()) << " - "1369<< locpoints.Get(loclines.Get(i).I2())1370<< endl;1371}1372137313741375glrender(1);1376}1377}1378else1379{1380adfront -> IncrementClass (lindex.Get(1));13811382if ( debugparam.haltnosuccess || debugflag )1383{1384cout << "Problem with seg " << gpi1 << " - " << gpi21385<< ", class = " << qualclass << endl;13861387(*testout) << "Problem with seg " << gpi1 << " - " << gpi21388<< ", class = " << qualclass << endl;13891390multithread.drawing = 1;1391multithread.testmode = 1;1392multithread.pause = 1;139313941395/*1396extern STLGeometry * stlgeometry;1397stlgeometry->ClearMarkedSegs();1398for (i = 1; i <= loclines.Size(); i++)1399{1400stlgeometry->AddMarkedSeg(locpoints.Get(loclines.Get(i).I1()),1401locpoints.Get(loclines.Get(i).I2()));1402}1403*/14041405for (int i = 1; i <= loclines.Size(); i++)1406{1407(*testout) << "line ";1408for (int j = 1; j <= 2; j++)1409{1410int hi = 0;1411if (loclines.Get(i).I(j) >= 1 &&1412loclines.Get(i).I(j) <= pindex.Size())1413hi = adfront->GetGlobalIndex (pindex.Get(loclines.Get(i).I(j)));14141415(*testout) << hi << " ";1416}1417(*testout) << " : "1418<< plainpoints.Get(loclines.Get(i).I1()) << " - "1419<< plainpoints.Get(loclines.Get(i).I2()) << " 3d: "1420<< locpoints.Get(loclines.Get(i).I1()) << " - "1421<< locpoints.Get(loclines.Get(i).I2())1422<< endl;1423}142414251426/*1427cout << "p1gi = " << blgeominfo[0].trignum1428<< ", p2gi = " << blgeominfo[1].trignum << endl;1429*/14301431glrender(1);1432}143314341435#ifdef MYGRAPH1436if (silentflag<3)1437{1438if (testmode || trials%2 == 0)1439{1440plotsurf.DrawPnL(locpoints, loclines);1441plotsurf.Plot(testmode, testmode);1442}1443}1444#endif1445}14461447}14481449PrintMessage (3, "Surface meshing done");14501451adfront->PrintOpenSegments (*testout);14521453multithread.task = savetask;145414551456// cout << "surfeltree.depth = " << surfeltree.Tree().Depth() << endl;1457EndMesh ();14581459if (!adfront->Empty())1460return MESHING2_GIVEUP;14611462return MESHING2_OK;1463}1464146514661467146814691470147114721473}14741475147614771478147914801481#ifdef OPENGL14821483/* *********************** Draw Surface Meshing **************** */148414851486#include <visual.hpp>1487#include <stlgeom.hpp>14881489namespace netgen1490{14911492extern STLGeometry * stlgeometry;1493extern Mesh * mesh;1494VisualSceneSurfaceMeshing vssurfacemeshing;1495149614971498void glrender (int wait)1499{1500// cout << "plot adfront" << endl;15011502if (multithread.drawing)1503{1504// vssurfacemeshing.Render();1505Render ();15061507if (wait || multithread.testmode)1508{1509multithread.pause = 1;1510}1511while (multithread.pause);1512}1513}1514151515161517VisualSceneSurfaceMeshing :: VisualSceneSurfaceMeshing ()1518: VisualScene()1519{1520;1521}15221523VisualSceneSurfaceMeshing :: ~VisualSceneSurfaceMeshing ()1524{1525;1526}15271528void VisualSceneSurfaceMeshing :: DrawScene ()1529{1530int i, j, k;15311532if (loclines.Size() != changeval)1533{1534center = Point<3>(0,0,-5);1535rad = 0.1;15361537CalcTransformationMatrices();1538changeval = loclines.Size();1539}15401541glClearColor(backcolor, backcolor, backcolor, 1.0);1542glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);1543SetLight();15441545// glEnable (GL_COLOR_MATERIAL);15461547// glDisable (GL_SHADING);1548// glColor3f (0.0f, 1.0f, 1.0f);1549// glLineWidth (1.0f);1550// glShadeModel (GL_SMOOTH);15511552// glCallList (linelists.Get(1));15531554// SetLight();15551556glPushMatrix();1557glMultMatrixf (transformationmat);15581559glShadeModel (GL_SMOOTH);1560// glDisable (GL_COLOR_MATERIAL);1561glEnable (GL_COLOR_MATERIAL);1562glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);15631564glEnable (GL_BLEND);1565glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);15661567// glEnable (GL_LIGHTING);15681569double shine = vispar.shininess;1570double transp = vispar.transp;15711572glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shine);1573glLogicOp (GL_COPY);1574157515761577/*15781579float mat_col[] = { 0.2, 0.2, 0.8, 1 };1580glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);15811582glPolygonOffset (1, 1);1583glEnable (GL_POLYGON_OFFSET_FILL);15841585float mat_colbl[] = { 0.8, 0.2, 0.2, 1 };1586float mat_cololdl[] = { 0.2, 0.8, 0.2, 1 };1587float mat_colnewl[] = { 0.8, 0.8, 0.2, 1 };158815891590glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);1591glPolygonOffset (1, -1);1592glLineWidth (3);15931594for (i = 1; i <= loclines.Size(); i++)1595{1596if (i == 1)1597{1598glEnable (GL_POLYGON_OFFSET_FILL);1599glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colbl);1600}1601else if (i <= oldnl)1602glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_cololdl);1603else1604glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colnewl);16051606int pi1 = loclines.Get(i).I1();1607int pi2 = loclines.Get(i).I2();16081609if (pi1 >= 1 && pi2 >= 1)1610{1611Point3d p1 = locpoints.Get(pi1);1612Point3d p2 = locpoints.Get(pi2);16131614glBegin (GL_LINES);1615glVertex3f (p1.X(), p1.Y(), p1.Z());1616glVertex3f (p2.X(), p2.Y(), p2.Z());1617glEnd();1618}16191620glDisable (GL_POLYGON_OFFSET_FILL);1621}162216231624glLineWidth (1);162516261627glPointSize (5);1628float mat_colp[] = { 1, 0, 0, 1 };1629glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);1630glBegin (GL_POINTS);1631for (i = 1; i <= locpoints.Size(); i++)1632{1633Point3d p = locpoints.Get(i);1634glVertex3f (p.X(), p.Y(), p.Z());1635}1636glEnd();163716381639glPopMatrix();1640*/16411642float mat_colp[] = { 1, 0, 0, 1 };16431644float mat_col2d1[] = { 1, 0.5, 0.5, 1 };1645float mat_col2d[] = { 1, 1, 1, 1 };1646glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);16471648double scalex = 0.1, scaley = 0.1;16491650glBegin (GL_LINES);1651for (i = 1; i <= loclines.Size(); i++)1652{1653glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);1654if (i == 1)1655glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d1);16561657int pi1 = loclines.Get(i).I1();1658int pi2 = loclines.Get(i).I2();16591660if (pi1 >= 1 && pi2 >= 1)1661{1662Point2d p1 = plainpoints.Get(pi1);1663Point2d p2 = plainpoints.Get(pi2);16641665glBegin (GL_LINES);1666glVertex3f (scalex * p1.X(), scaley * p1.Y(), -5);1667glVertex3f (scalex * p2.X(), scaley * p2.Y(), -5);1668glEnd();1669}1670}1671glEnd ();167216731674glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);1675glBegin (GL_POINTS);1676for (i = 1; i <= plainpoints.Size(); i++)1677{1678Point2d p = plainpoints.Get(i);1679glVertex3f (scalex * p.X(), scaley * p.Y(), -5);1680}1681glEnd();1682168316841685168616871688glDisable (GL_POLYGON_OFFSET_FILL);16891690glPopMatrix();1691DrawCoordinateCross ();1692DrawNetgenLogo ();1693glFinish();16941695/*1696glDisable (GL_POLYGON_OFFSET_FILL);16971698// cout << "draw surfacemeshing" << endl;1699//1700// if (changeval != stlgeometry->GetNT())1701// BuildScene();1702// changeval = stlgeometry->GetNT();170317041705glClearColor(backcolor, backcolor, backcolor, 1.0);1706glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);17071708SetLight();17091710glPushMatrix();1711glLoadMatrixf (transmat);1712glMultMatrixf (rotmat);17131714glShadeModel (GL_SMOOTH);1715glDisable (GL_COLOR_MATERIAL);1716glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);17171718glEnable (GL_BLEND);1719glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);17201721float mat_spec_col[] = { 1, 1, 1, 1 };1722glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_spec_col);17231724double shine = vispar.shininess;1725double transp = vispar.transp;17261727glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shine);1728glLogicOp (GL_COPY);172917301731float mat_col[] = { 0.2, 0.2, 0.8, transp };1732float mat_colrt[] = { 0.2, 0.8, 0.8, transp };1733glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);17341735glPolygonOffset (1, 1);1736glEnable (GL_POLYGON_OFFSET_FILL);17371738glColor3f (1.0f, 1.0f, 1.0f);17391740glEnable (GL_NORMALIZE);17411742// glBegin (GL_TRIANGLES);1743// for (j = 1; j <= stlgeometry -> GetNT(); j++)1744// {1745// glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col);1746// if (j == geomtrig)1747// glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colrt);174817491750// const STLReadTriangle & tria = stlgeometry -> GetReadTriangle(j);1751// glNormal3f (tria.normal.X(),1752// tria.normal.Y(),1753// tria.normal.Z());17541755// for (k = 0; k < 3; k++)1756// {1757// glVertex3f (tria.pts[k].X(),1758// tria.pts[k].Y(),1759// tria.pts[k].Z());1760// }1761// }1762// glEnd ();1763176417651766glDisable (GL_POLYGON_OFFSET_FILL);17671768float mat_colbl[] = { 0.8, 0.2, 0.2, 1 };1769float mat_cololdl[] = { 0.2, 0.8, 0.2, 1 };1770float mat_colnewl[] = { 0.8, 0.8, 0.2, 1 };177117721773glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);1774glPolygonOffset (1, -1);1775glLineWidth (3);17761777for (i = 1; i <= loclines.Size(); i++)1778{1779if (i == 1)1780{1781glEnable (GL_POLYGON_OFFSET_FILL);1782glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colbl);1783}1784else if (i <= oldnl)1785glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_cololdl);1786else1787glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colnewl);17881789int pi1 = loclines.Get(i).I1();1790int pi2 = loclines.Get(i).I2();17911792if (pi1 >= 1 && pi2 >= 1)1793{1794Point3d p1 = locpoints.Get(pi1);1795Point3d p2 = locpoints.Get(pi2);17961797glBegin (GL_LINES);1798glVertex3f (p1.X(), p1.Y(), p1.Z());1799glVertex3f (p2.X(), p2.Y(), p2.Z());1800glEnd();1801}18021803glDisable (GL_POLYGON_OFFSET_FILL);1804}180518061807glLineWidth (1);180818091810glPointSize (5);1811float mat_colp[] = { 1, 0, 0, 1 };1812glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);1813glBegin (GL_POINTS);1814for (i = 1; i <= locpoints.Size(); i++)1815{1816Point3d p = locpoints.Get(i);1817glVertex3f (p.X(), p.Y(), p.Z());1818}1819glEnd();182018211822glPopMatrix();182318241825float mat_col2d1[] = { 1, 0.5, 0.5, 1 };1826float mat_col2d[] = { 1, 1, 1, 1 };1827glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);18281829double scalex = 0.1, scaley = 0.1;18301831glBegin (GL_LINES);1832for (i = 1; i <= loclines.Size(); i++)1833{1834glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d);1835if (i == 1)1836glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_col2d1);18371838int pi1 = loclines.Get(i).I1();1839int pi2 = loclines.Get(i).I2();18401841if (pi1 >= 1 && pi2 >= 1)1842{1843Point2d p1 = plainpoints.Get(pi1);1844Point2d p2 = plainpoints.Get(pi2);18451846glBegin (GL_LINES);1847glVertex3f (scalex * p1.X(), scaley * p1.Y(), -5);1848glVertex3f (scalex * p2.X(), scaley * p2.Y(), -5);1849glEnd();1850}1851}1852glEnd ();185318541855glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_colp);1856glBegin (GL_POINTS);1857for (i = 1; i <= plainpoints.Size(); i++)1858{1859Point2d p = plainpoints.Get(i);1860glVertex3f (scalex * p.X(), scaley * p.Y(), -5);1861}1862glEnd();18631864glFinish();1865*/1866}186718681869void VisualSceneSurfaceMeshing :: BuildScene (int zoomall)1870{1871int i, j, k;1872/*1873center = stlgeometry -> GetBoundingBox().Center();1874rad = stlgeometry -> GetBoundingBox().Diam() / 2;18751876CalcTransformationMatrices();1877*/1878}18791880}188118821883#else1884namespace netgen1885{1886void glrender (int wait)1887{ ; }1888}1889#endif189018911892