netgen/libsrc/stlgeom/stlgeommesh.cpp

1618 lines
40 KiB
C++
Raw Permalink Normal View History

2009-01-13 04:40:13 +05:00
//20.11.1999 second part of stlgeom.cc, mainly mesh functions
#include <mystdlib.h>
#include <myadt.hpp>
#include <linalg.hpp>
#include <gprim.hpp>
#include <meshing.hpp>
#include "stlgeom.hpp"
namespace netgen
{
2019-07-09 13:39:16 +05:00
int EdgeUsed(int p1, int p2, NgArray<INDEX_2>& edges, INDEX_2_HASHTABLE<int>& hashtab)
2009-01-13 04:40:13 +05:00
{
if (p1 > p2) {swap (p1,p2);}
if (hashtab.Used(INDEX_2(p1,p2)))
{return hashtab.Get(INDEX_2(p1,p2));}
return 0;
}
Point<3> STLGeometry :: PointBetween(const Point<3> & ap1, int t1,
const Point<3> & ap2, int t2)
{
2009-01-25 04:28:47 +05:00
//funktioniert nicht in allen Fällen!
2009-01-13 04:40:13 +05:00
PrintWarning("Point between");
ClearMarkedSegs();
InitMarkedTrigs();
SetMarkedTrig(t1,1);
SetMarkedTrig(t2,1);
TABLE<Point3d> edgepoints;
TABLE<double> edgepointdists;
TABLE<int> edgepointorigines;
TABLE<int> edgepointoriginps;
2019-07-09 13:39:16 +05:00
NgArray<int> edgetrigs;
NgArray<INDEX_2> edgepointnums;
NgArray<int> edgetriglocinds;
2009-01-13 04:40:13 +05:00
int size = 3*GetNT();
INDEX_2_HASHTABLE<int> hashtab(size);
int divisions = 10;
edgepoints.SetSize(size);
edgepointdists.SetSize(size);
edgepointorigines.SetSize(size);
edgepointoriginps.SetSize(size);
edgetrigs.SetSize(size);
edgepointnums.SetSize(size);
edgetriglocinds.SetSize(size);
2019-07-09 13:39:16 +05:00
NgArray<int> edgelist1;
NgArray<int> edgelist2;
2009-01-13 04:40:13 +05:00
edgelist1.SetSize(0);
edgelist2.SetSize(0);
int i, j, k, l, m;
int edgecnt = 0;
//first triangle:
for (i = 1; i <= 3; i++)
{
int ptn1 = GetTriangle(t1).PNum(i);
int ptn2 = GetTriangle(t1).PNumMod(i+1);
if (ptn1 > ptn2) {swap(ptn1,ptn2);}
Point3d pt1 = GetPoint(ptn1);
Point3d pt2 = GetPoint(ptn2);
edgecnt++;
edgetrigs.Elem(edgecnt) = t1;
edgepointnums.Elem(edgecnt) = INDEX_2(ptn1,ptn2);
hashtab.Set(edgepointnums.Get(edgecnt),edgecnt);
edgetriglocinds.Elem(edgecnt) = i;
edgelist1.Append(edgecnt);
for (j = 1; j <= divisions; j++)
{
double lfact = (double)j/(double)divisions;
Point3d pbtw(lfact*pt1.X()+(1.-lfact)*pt2.X(),
lfact*pt1.Y()+(1.-lfact)*pt2.Y(),
lfact*pt1.Z()+(1.-lfact)*pt2.Z());
//AddMarkedSeg(ap1,pbtw);
edgepoints.Add1(edgecnt,pbtw);
edgepointdists.Add1(edgecnt,Dist(pbtw,ap1));
edgepointorigines.Add1(edgecnt,0);
edgepointoriginps.Add1(edgecnt,0);
}
}
int finished = 0;
int endpointorigine = 0;
int endpointoriginp = 0;
double endpointmindist = 1E50;
int maxsize = 0;
while (!finished)
{
finished = 1;
if (edgelist1.Size() > maxsize) {maxsize = edgelist1.Size();}
for (i = 1; i <= edgelist1.Size(); i++)
{
int en = edgelist1.Get(i);
int trig = edgetrigs.Get(en);
int edgenum = edgetriglocinds.Get(en);
int tn = NeighbourTrigSorted(trig,edgenum);
if (tn != t2)
{
for (k = 1; k <= 3; k++)
{
int pnt1 = GetTriangle(tn).PNum(k);
int pnt2 = GetTriangle(tn).PNumMod(k+1);
if (pnt1 > pnt2) {swap(pnt1,pnt2);}
Point3d pt1 = GetPoint(pnt1);
Point3d pt2 = GetPoint(pnt2);
//AddMarkedSeg(pt1,pt2);
//if (!(pnt1 == ep1 && pnt2 == ep2))
// {
int edgeused = 0;
edgenum = EdgeUsed(pnt1, pnt2, edgepointnums, hashtab);
if (edgenum != en)
{
if (edgenum != 0)
{edgeused = 1;}
else
{
edgecnt++;
edgenum = edgecnt;
edgetrigs.Elem(edgenum) = tn;
edgepointnums.Elem(edgenum) = INDEX_2(pnt1,pnt2);
hashtab.Set(edgepointnums.Get(edgenum),edgenum);
edgetriglocinds.Elem(edgenum) = k;
}
if (edgenum > size || edgenum == 0) {PrintSysError("edgenum = ", edgenum);}
double minofmindist = 1E50;
int changed = 0;
for (l = 1; l <= divisions; l++)
{
double lfact = (double)l/(double)divisions;
Point3d pbtw(lfact*pt1.X()+(1.-lfact)*pt2.X(),
lfact*pt1.Y()+(1.-lfact)*pt2.Y(),
lfact*pt1.Z()+(1.-lfact)*pt2.Z());
double mindist = 1E50;
int index=0;
for (m = 1; m <= divisions; m++)
{
const Point3d& p = edgepoints.Get(en,m);
if (Dist(pbtw,p) + edgepointdists.Get(en,m) < mindist)
{mindist = Dist(pbtw,p) + edgepointdists.Get(en,m); index = m;}
}
//if (mindist < endpointmindist) {finished = 0;}
if (mindist < minofmindist) {minofmindist = mindist;}
if (!edgeused)
{
//AddMarkedSeg(pbtw,edgepoints.Get(en,index));
edgepoints.Add1(edgenum,pbtw);
edgepointdists.Add1(edgenum,mindist);
edgepointorigines.Add1(edgenum,en);
edgepointoriginps.Add1(edgenum,index);
changed = 1;
}
else
{
if (mindist < edgepointdists.Get(edgenum,l))
{
edgepointdists.Set(edgenum,l,mindist);
edgepointorigines.Set(edgenum,l,en);
edgepointoriginps.Set(edgenum,l,index);
changed = 1;
}
}
}
if (minofmindist < endpointmindist-1E-10 && changed)
{
finished = 0;
edgelist2.Append(edgenum);
}
}
}
}
else
{
double mindist = 1E50;
int index(0);
for (m = 1; m <= divisions; m++)
{
const Point3d& p = edgepoints.Get(en,m);
if (Dist(ap2,p) + edgepointdists.Get(en,m) < mindist)
{mindist = Dist(ap2,p) + edgepointdists.Get(en,m); index = m;}
}
if (mindist < endpointmindist)
{
endpointorigine = en;
endpointoriginp = index;
endpointmindist = mindist;
}
}
}
edgelist1.SetSize(0);
for (i = 1; i <= edgelist2.Size(); i++)
{
edgelist1.Append(edgelist2.Get(i));
}
}
if (!endpointorigine) {PrintSysError("No connection found!");}
2019-07-09 13:39:16 +05:00
NgArray<Point3d> plist;
2009-01-13 04:40:13 +05:00
plist.Append(ap2);
int laste = endpointorigine;
int lastp = endpointoriginp;
int lle, llp;
while (laste)
{
plist.Append(edgepoints.Get(laste,lastp));
lle = laste;
llp = lastp;
laste = edgepointorigines.Get(lle,llp);
lastp = edgepointoriginps.Get(lle,llp);
}
plist.Append(ap1);
for (i = 1; i <= plist.Size()-1; i++)
{
AddMarkedSeg(plist.Get(i),plist.Get(i+1));
}
PrintMessage(5,"PointBetween: complexity=", maxsize);
Point3d pm;
double dist = 0;
int found = 0;
for (i = 1; i <= plist.Size()-1; i++)
{
dist += Dist(plist.Get(i),plist.Get(i+1));
if (dist > endpointmindist*0.5)
{
double segl = Dist(plist.Get(i), plist.Get(i+1));
double d = dist - endpointmindist * 0.5;
pm = Point3d(d/segl*plist.Get(i).X() + (1.-d/segl)*plist.Get(i+1).X(),
d/segl*plist.Get(i).Y() + (1.-d/segl)*plist.Get(i+1).Y(),
d/segl*plist.Get(i).Z() + (1.-d/segl)*plist.Get(i+1).Z());
found = 1;
break;
}
}
if (!found) {PrintWarning("Problem in PointBetween"); pm = Center(ap1,ap2);}
AddMarkedSeg(pm, Point3d(0.,0.,0.));
return pm;
}
void STLGeometry :: PrepareSurfaceMeshing()
{
meshchart = -1; //clear no old chart
meshcharttrigs.SetSize(GetNT());
2012-10-22 19:13:57 +06:00
meshcharttrigs = 0;
2009-01-13 04:40:13 +05:00
}
2019-09-30 13:19:35 +05:00
void STLGeometry::GetMeshChartBoundary (NgArray<Point<2>> & apoints,
NgArray<Point<3>> & points3d,
2019-07-09 13:39:16 +05:00
NgArray<INDEX_2> & alines, double h)
2009-01-13 04:40:13 +05:00
{
twoint seg, newseg;
int zone;
Point<2> p2;
const STLChart& chart = GetChart(meshchart);
2012-10-22 19:13:57 +06:00
for (int i = 1; i <= chart.GetNOLimit(); i++)
2009-01-13 04:40:13 +05:00
{
seg = chart.GetOLimit(i);
INDEX_2 i2;
2012-10-22 19:13:57 +06:00
for (int j = 1; j <= 2; j++)
2009-01-13 04:40:13 +05:00
{
int pi = (j == 1) ? seg.i1 : seg.i2;
int lpi;
if (ha_points.Get(pi) == 0)
{
const Point<3> & p3d = GetPoint (pi);
Point<2> p2d;
points3d.Append (p3d);
ToPlane(p3d, 0, p2d, h, zone, 0);
apoints.Append (p2d);
lpi = apoints.Size();
ha_points.Elem(pi) = lpi;
}
else
lpi = ha_points.Get(pi);
i2.I(j) = lpi;
}
alines.Append (i2);
/*
seg = chart.GetOLimit(i);
psize = points.Size();
newseg.i1 = psize+1;
newseg.i2 = psize+2;
ToPlane(GetPoint(seg.i1), 0, p2, h, zone, 0);
points.Append(p2);
points3d.Append (GetPoint(seg.i1));
ToPlane(GetPoint(seg.i2), 0, p2, h, zone, 0);
points.Append(p2);
points3d.Append (GetPoint(seg.i2));
lines.Append (INDEX_2 (points.Size()-1, points.Size()));
*/
}
2012-10-22 19:13:57 +06:00
for (int i = 1; i <= chart.GetNOLimit(); i++)
2009-01-13 04:40:13 +05:00
{
seg = chart.GetOLimit(i);
ha_points.Elem(seg.i1) = 0;
ha_points.Elem(seg.i2) = 0;
}
}
void STLGeometry :: DefineTangentialPlane (const Point<3> & ap1, const Point<3> & ap2, int trig)
{
p1 = ap1; //save for ToPlane, in data of STLGeometry class
Point<3> p2 = ap2; //only locally used
meshchart = GetChartNr(trig);
if (usechartnormal)
meshtrignv = GetChart(meshchart).GetNormal();
else
meshtrignv = GetTriangle(trig).Normal();
//meshtrignv = GetTriangle(trig).Normal(points);
meshtrignv /= meshtrignv.Length();
GetTriangle(trig).ProjectInPlain(points, meshtrignv, p2);
ez = meshtrignv;
ez /= ez.Length();
ex = p2 - p1;
ex -= (ex * ez) * ez;
ex /= ex.Length();
ey = Cross (ez, ex);
}
2019-10-03 13:45:09 +05:00
void STLGeometry :: SelectChartOfTriangle (int trignum) const
2009-01-13 04:40:13 +05:00
{
meshchart = GetChartNr(trignum);
meshtrignv = GetTriangle(trignum).Normal();
}
void STLGeometry :: SelectChartOfPoint (const Point<3> & p)
{
int i, ii;
2019-07-09 13:39:16 +05:00
NgArray<int> trigsinbox;
2009-01-13 04:40:13 +05:00
Box<3> box(p,p);
box.Increase (1e-6);
GetTrianglesInBox (box, trigsinbox);
// for (i = 1; i <= GetNT(); i++)
for (ii = 1; ii <= trigsinbox.Size(); ii++)
{
i = trigsinbox.Get(ii);
Point<3> hp = p;
if (GetTriangle(i).GetNearestPoint(points, hp) <= 1E-8)
{
SelectChartOfTriangle (i);
break;
}
}
return;
}
void STLGeometry :: ToPlane (const Point<3> & locpoint, int * trigs,
Point<2> & plainpoint, double h, int& zone,
int checkchart)
{
if (checkchart)
{
//check if locpoint lies on actual chart:
zone = 0;
// Point3d p;
int i = 1;
const STLChart& chart = GetChart(meshchart);
int foundinchart = 0;
const double range = 1e-6; //1e-4 old
if (trigs)
{
int * htrigs = trigs;
while (*htrigs)
{
if (TrigIsInOC (*htrigs, meshchart))
{
foundinchart = 1;
break;
}
htrigs++;
}
}
else
{
2019-09-21 04:06:49 +05:00
NgArray<STLTrigId> trigsinbox;
2009-01-13 04:40:13 +05:00
if (!geomsearchtreeon)
{
//alter chart-tree
Box<3> box(locpoint, locpoint);
box.Increase (range);
chart.GetTrianglesInBox (box.PMin(), box.PMax(), trigsinbox);
}
else
{
2019-07-09 13:39:16 +05:00
NgArray<int> trigsinbox2;
2009-01-13 04:40:13 +05:00
Box<3> box(locpoint, locpoint);
box.Increase (range);
GetTrianglesInBox (box, trigsinbox2);
for (i = 1; i <= trigsinbox2.Size(); i++)
{
if (TrigIsInOC(trigsinbox2.Get(i),meshchart)) {trigsinbox.Append(trigsinbox2.Get(i));}
}
}
for (i = 1; i <= trigsinbox.Size(); i++)
{
Point<3> p = locpoint;
if (GetTriangle(trigsinbox.Get(i)).GetNearestPoint(points, p)
<= 1E-8)
{
foundinchart = 1;
break;
}
}
}
//do not use this point (but do correct projection (joachim)
if (!foundinchart)
{
zone = -1; // plainpoint.X() = 11111; plainpoint.Y() = 11111; return;
}
}
else
{
zone = 0;
}
//transform in plane
Vec<3> p1p = locpoint - p1;
plainpoint(0) = (p1p * ex) / h;
plainpoint(1) = (p1p * ey) / h;
}
int STLGeometry :: FromPlane (const Point<2> & plainpoint,
Point<3> & locpoint, double h)
{
2019-09-30 13:19:35 +05:00
Vec<3> p1p = h * plainpoint[0] * ex + h * plainpoint[1] * ey;
2009-01-13 04:40:13 +05:00
locpoint = p1 + p1p;
int rv = Project(locpoint);
if (!rv) {return 1;} //project nicht gegangen
return 0;
}
int lasttrig;
int STLGeometry :: LastTrig() const {return lasttrig;};
//project normal to tangential plane
int STLGeometry :: Project(Point<3> & p3d) const
{
Point<3> p, pf;
2019-09-22 16:15:53 +05:00
int j;
2009-01-13 04:40:13 +05:00
int fi = 0;
int cnt = 0;
int different = 0;
const double lamtol = 1e-6;
const STLChart& chart = GetChart(meshchart);
2019-09-30 21:14:46 +05:00
STLTrigId trig = chart.ProjectNormal(p3d);
return trig;
// cout << "new, trig = " << trig << endl;
// #define MOVEDTOCHART
#ifdef MOVEDTOCHART
2009-01-13 04:40:13 +05:00
int nt = chart.GetNT();
QuadraticFunction3d quadfun(p3d, meshtrignv);
/*
Vec3d hv = meshtrignv;
hv /= hv.Length();
Vec3d t1, t2;
hv.GetNormal (t1);
Cross (hv, t1, t2);
*/
for (j = 1; j <= nt; j++)
{
2019-09-22 16:15:53 +05:00
STLTrigId i = chart.GetTrig1(j);
2009-01-13 04:40:13 +05:00
const Point<3> & c = GetTriangle(i).center;
/*
double d1 = t1 * (c-p3d);
double d2 = t2 * (c-p3d);
*/
/*
if (d1 * d1 + d2 * d2 > sqr (GetTriangle(i).rad))
continue;
*/
if (quadfun.Eval(c) > sqr (GetTriangle(i).rad))
continue;
p = p3d;
Vec<3> lam;
int err = GetTriangle(i).ProjectInPlain(points, meshtrignv, p, lam);
int inside = (err == 0 && lam(0) > -lamtol &&
lam(1) > -lamtol && (1-lam(0)-lam(1)) > -lamtol);
/*
p = p3d;
GetTriangle(i).ProjectInPlain(points, meshtrignv, p);
if (GetTriangle(i).PointInside(points, p))
*/
if (inside)
{
if (cnt != 0)
{
if (Dist2(p,pf)>=1E-16)
{
// (*testout) << "ERROR: found two points to project which are different" << endl;
//(*testout) << "p=" << p << ", pf=" << pf << endl;
different = 1;
}
}
pf = p; fi = i; cnt++;
}
if (inside)
2019-09-30 21:14:46 +05:00
break;
2009-01-13 04:40:13 +05:00
}
2019-09-30 21:14:46 +05:00
#endif
2009-01-13 04:40:13 +05:00
2019-09-30 21:14:46 +05:00
// cout << "oldtrig = " << fi << endl;
2009-01-13 04:40:13 +05:00
// if (cnt == 2) {(*testout) << "WARNING: found 2 triangles to project" << endl;}
//if (cnt == 3) {(*testout) << "WARNING: found 3 triangles to project" << endl;}
//if (cnt > 3) {(*testout) << "WARNING: found more than 3 triangles to project" << endl;}
if (fi != 0) {lasttrig = fi;}
if (fi != 0 && !different) {p3d = pf; return fi;}
// (*testout) << "WARNING: Project failed" << endl;
return 0;
}
//project normal to tangential plane
int STLGeometry :: ProjectOnWholeSurface(Point<3> & p3d) const
{
Point<3> p, pf;
int i;
int fi = 0;
int cnt = 0;
int different = 0;
const double lamtol = 1e-6;
for (i = 1; i <= GetNT(); i++)
{
p = p3d;
Vec<3> lam;
int err =
GetTriangle(i).ProjectInPlain(points, meshtrignv, p, lam);
int inside = (err == 0 && lam(0) > -lamtol &&
lam(1) > -lamtol && (1-lam(0)-lam(1)) > -lamtol);
/*
p = p3d;
GetTriangle(i).ProjectInPlain(points, meshtrignv, p);
if (GetTriangle(i).PointInside(points, p))
*/
if (inside)
{
if (cnt != 0)
{
if (Dist2(p,pf)>=1E-16)
{
// (*testout) << "ERROR: found two points to project which are different" << endl;
// (*testout) << "p=" << p << ", pf=" << pf << endl;
different = 1;
}
}
pf = p; fi = i; cnt++;
}
}
/*
if (cnt == 2) {(*testout) << "WARNING: found 2 triangles to project" << endl;}
if (cnt == 3) {(*testout) << "WARNING: found 3 triangles to project" << endl;}
if (cnt > 3) {(*testout) << "WARNING: found more than 3 triangles to project" << endl;}
*/
if (fi != 0) {lasttrig = fi;}
if (fi != 0 && !different) {p3d = pf; return fi;}
// (*testout) << "WARNING: Project failed" << endl;
return 0;
}
int STLGeometry :: ProjectNearest(Point<3> & p3d) const
{
2009-04-20 03:15:26 +06:00
Point<3> p, pf = 0.0;
2009-01-13 04:40:13 +05:00
//set new chart
const STLChart& chart = GetChart(meshchart);
int i;
double nearest = 1E50;
double dist;
int ft = 0;
for (i = 1; i <= chart.GetNT(); i++)
{
p = p3d;
2019-09-21 04:06:49 +05:00
dist = GetTriangle(chart.GetTrig1(i)).GetNearestPoint(points, p);
2009-01-13 04:40:13 +05:00
if (dist < nearest)
{
pf = p;
nearest = dist;
2019-09-21 04:06:49 +05:00
ft = chart.GetTrig1(i);
2009-01-13 04:40:13 +05:00
}
}
p3d = pf;
//if (!ft) {(*testout) << "ERROR: ProjectNearest failed" << endl;}
return ft;
}
//Restrict local h due to curvature for make atlas
void STLGeometry :: RestrictLocalHCurv(class Mesh & mesh, double gh, const STLParameters& stlparam)
2009-01-13 04:40:13 +05:00
{
PushStatusF("Restrict H due to surface curvature");
//bei jedem Dreieck alle Nachbardreiecke vergleichen, und, fallskein Kante dazwischen,
//die Meshsize auf ein bestimmtes Mass limitieren
int i,j;
2019-09-21 05:04:35 +05:00
STLPointId ap1,ap2,p3,p4;
2009-01-13 04:40:13 +05:00
Point<3> p1p, p2p, p3p, p4p;
Vec<3> n, ntn;
double rzyl, localh;
// double localhfact = 0.5;
// double geometryignorelength = 1E-4;
double minlocalh = stlparam.atlasminh;
Box<3> bb = GetBoundingBox();
// mesh.SetLocalH(bb.PMin() - Vec3d(10, 10, 10),bb.PMax() + Vec3d(10, 10, 10),
// mparam.grading);
// mesh.SetGlobalH(gh);
double mincalch = 1E10;
2009-01-25 04:28:47 +05:00
double maxcalch = -1E10
;
2009-01-13 04:40:13 +05:00
double objectsize = bb.Diam();
double geometryignoreedgelength = objectsize * 1e-5;
if (stlparam.resthatlasenable)
{
2019-07-09 13:39:16 +05:00
NgArray<double> minh; //minimales h pro punkt
2009-01-13 04:40:13 +05:00
minh.SetSize(GetNP());
for (i = 1; i <= GetNP(); i++)
{
minh.Elem(i) = gh;
}
for (i = 1; i <= GetNT(); i++)
{
SetThreadPercent((double)i/(double)GetNT()*100.);
if (multithread.terminate)
{PopStatus(); return;}
const STLTriangle& trig = GetTriangle(i);
n = GetTriangle(i).Normal();
for (j = 1; j <= 3; j++)
{
const STLTriangle& nt = GetTriangle(NeighbourTrig(i,j));
trig.GetNeighbourPointsAndOpposite(nt,ap1,ap2,p3);
//checken, ob ap1-ap2 eine Kante sind
if (IsEdge(ap1,ap2)) continue;
p4 = trig.PNum(1) + trig.PNum(2) + trig.PNum(3) - ap1 - ap2;
p1p = GetPoint(ap1); p2p = GetPoint(ap2);
p3p = GetPoint(p3); p4p = GetPoint(p4);
double h1 = GetDistFromInfiniteLine(p1p,p2p, p4p);
double h2 = GetDistFromInfiniteLine(p1p,p2p, p3p);
double diaglen = Dist (p1p, p2p);
if (diaglen < geometryignoreedgelength)
continue;
rzyl = ComputeCylinderRadius
(n, GetTriangle(NeighbourTrig(i,j)).Normal(),
h1, h2);
if (h1 < 1e-3 * diaglen && h2 < 1e-3 * diaglen)
continue;
if (h1 < 1e-5 * objectsize && h2 < 1e-5 * objectsize)
continue;
// rzyl = mindist/(2*sinang);
localh = 10.*rzyl / stlparam.resthatlasfac;
if (localh < mincalch) {mincalch = localh;}
if (localh > maxcalch) {maxcalch = localh;}
if (localh < minlocalh) {localh = minlocalh;}
if (localh < gh)
{
minh.Elem(ap1) = min2(minh.Elem(ap1),localh);
minh.Elem(ap2) = min2(minh.Elem(ap2),localh);
}
mesh.RestrictLocalHLine(p1p, p2p, localh);
}
}
}
PrintMessage(5, "done\nATLAS H: nmin local h=", mincalch);
PrintMessage(5, "ATLAS H: max local h=", maxcalch);
PrintMessage(5, "Local h tree has ", mesh.LocalHFunction().GetNBoxes(), " boxes of size ",
(int)sizeof(GradingBox));
PopStatus();
}
//restrict local h due to near edges and due to outer chart distance
void STLGeometry :: RestrictLocalH(class Mesh & mesh, double gh, const STLParameters& stlparam, const MeshingParameters& mparam)
2009-01-13 04:40:13 +05:00
{
//bei jedem Dreieck alle Nachbardreiecke vergleichen, und, fallskein Kante dazwischen,
//die Meshsize auf ein bestimmtes Mass limitieren
int i,j;
2019-09-21 05:04:35 +05:00
STLPointId ap1,ap2,p3,p4;
2009-01-13 04:40:13 +05:00
Point3d p1p, p2p, p3p, p4p;
Vec3d n, ntn;
double rzyl, localh;
// double localhfact = 0.5;
// double geometryignorelength = 1E-4;
Box<3> bb = GetBoundingBox();
//mesh.SetLocalH(bb.PMin() - Vec3d(10, 10, 10),bb.PMax() + Vec3d(10, 10, 10),
// mparam.grading);
//mesh.SetGlobalH(gh);
double mincalch = 1E10;
double maxcalch = -1E10;
double objectsize = bb.Diam();
double geometryignoreedgelength = objectsize * 1e-5;
if (stlparam.resthsurfcurvenable)
{
PushStatusF("Restrict H due to surface curvature");
2019-07-09 13:39:16 +05:00
NgArray<double> minh; //minimales h pro punkt
2009-01-13 04:40:13 +05:00
minh.SetSize(GetNP());
for (i = 1; i <= GetNP(); i++)
{
minh.Elem(i) = gh;
}
for (i = 1; i <= GetNT(); i++)
{
SetThreadPercent((double)i/(double)GetNT()*100.);
if (i%20000==19999) {PrintMessage(7, (double)i/(double)GetNT()*100. , "%");}
if (multithread.terminate)
{PopStatus(); return;}
const STLTriangle& trig = GetTriangle(i);
n = GetTriangle(i).Normal();
for (j = 1; j <= 3; j++)
{
const STLTriangle& nt = GetTriangle(NeighbourTrig(i,j));
trig.GetNeighbourPointsAndOpposite(nt,ap1,ap2,p3);
//checken, ob ap1-ap2 eine Kante sind
if (IsEdge(ap1,ap2)) continue;
p4 = trig.PNum(1) + trig.PNum(2) + trig.PNum(3) - ap1 - ap2;
p1p = GetPoint(ap1); p2p = GetPoint(ap2);
p3p = GetPoint(p3); p4p = GetPoint(p4);
double h1 = GetDistFromInfiniteLine(p1p,p2p, p4p);
double h2 = GetDistFromInfiniteLine(p1p,p2p, p3p);
double diaglen = Dist (p1p, p2p);
if (diaglen < geometryignoreedgelength)
continue;
rzyl = ComputeCylinderRadius
(n, GetTriangle (NeighbourTrig(i,j)).Normal(),
h1, h2);
if (h1 < 1e-3 * diaglen && h2 < 1e-3 * diaglen)
continue;
if (h1 < 1e-5 * objectsize && h2 < 1e-5 * objectsize)
continue;
// rzyl = mindist/(2*sinang);
localh = rzyl / stlparam.resthsurfcurvfac;
if (localh < mincalch) {mincalch = localh;}
if (localh > maxcalch) {maxcalch = localh;}
if (localh < gh)
{
minh.Elem(ap1) = min2(minh.Elem(ap1),localh);
minh.Elem(ap2) = min2(minh.Elem(ap2),localh);
}
//if (localh < 0.2) {localh = 0.2;}
if(localh < objectsize)
mesh.RestrictLocalHLine(p1p, p2p, localh);
(*testout) << "restrict h along " << p1p << " - " << p2p << " to " << localh << endl;
if (localh < 0.1)
{
localh = 0.1;
}
}
}
PrintMessage(7, "done\nmin local h=", mincalch, "\nmax local h=", maxcalch);
PopStatus();
}
if (mparam.closeedgefac.has_value())
2009-01-13 04:40:13 +05:00
{
PushStatusF("Restrict H due to close edges");
2009-01-25 04:28:47 +05:00
//geht nicht für spiralen!!!!!!!!!!!!!!!!!!
2009-01-13 04:40:13 +05:00
2019-11-05 19:19:54 +05:00
double disttohfact = sqr(10.0 / *mparam.closeedgefac);
2009-01-13 04:40:13 +05:00
int k,l;
double h1, h2, dist;
int rc = 0;
Point3d p3p1;
double mindist = 1E50;
PrintMessage(7,"build search tree...");
BoxTree<3> * lsearchtree = new BoxTree<3> (GetBoundingBox().PMin() - Vec3d(1,1,1),
GetBoundingBox().PMax() + Vec3d(1,1,1));
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<Point3d> pmins(GetNLines());
NgArray<Point3d> pmaxs(GetNLines());
2009-01-13 04:40:13 +05:00
double maxhline;
for (i = 1; i <= GetNLines(); i++)
{
maxhline = 0;
STLLine* l1 = GetLine(i);
Point3d pmin(GetPoint(l1->StartP())), pmax(GetPoint(l1->StartP())), px;
for (j = 2; j <= l1->NP(); j++)
{
px = GetPoint(l1->PNum(j));
maxhline = max2(maxhline,mesh.GetH(px));
pmin.SetToMin (px);
pmax.SetToMax (px);
}
Box3d box(pmin,pmax);
box.Increase(maxhline);
lsearchtree->Insert (box.PMin(), box.PMax(), i);
pmins.Elem(i) = box.PMin();
pmaxs.Elem(i) = box.PMax();
}
2019-07-09 13:39:16 +05:00
NgArray<int> linenums;
2009-01-13 04:40:13 +05:00
int k2;
for (i = 1; i <= GetNLines(); i++)
{
SetThreadPercent((double)i/(double)GetNLines()*100.);
if (multithread.terminate)
{PopStatus(); return;}
linenums.SetSize(0);
lsearchtree->GetIntersecting(pmins.Get(i),pmaxs.Get(i),linenums);
STLLine* l1 = GetLine(i);
for (j = 1; j <= l1->NP(); j++)
{
p3p1 = GetPoint(l1->PNum(j));
h1 = sqr(mesh.GetH(p3p1));
for (k2 = 1; k2 <= linenums.Size(); k2++)
{
k = linenums.Get(k2);
if (k <= i) {continue;}
/*
//old, without searchtrees
for (k = i+1; k <= GetNLines(); k++)
{
*/
STLLine* l2 = GetLine(k);
for (l = 1; l <= l2->NP(); l++)
{
const Point3d& p3p2 = GetPoint(l2->PNum(l));
h2 = sqr(mesh.GetH(p3p2));
dist = Dist2(p3p1,p3p2)*disttohfact;
if (dist > 1E-12)
{
if (dist < h1)
{
mesh.RestrictLocalH(p3p1,sqrt(dist));
rc++;
mindist = min2(mindist,sqrt(dist));
}
if (dist < h2)
{
mesh.RestrictLocalH(p3p2,sqrt(dist));
rc++;
mindist = min2(mindist,sqrt(dist));
}
}
}
}
}
}
PrintMessage(5, "done\n Restricted h in ", rc, " points due to near edges!");
PopStatus();
}
if (stlparam.resthedgeangleenable)
{
PushStatusF("Restrict h due to close edges");
int lp1, lp2;
Vec3d v1,v2;
mincalch = 1E50;
maxcalch = -1E50;
for (i = 1; i <= GetNP(); i++)
{
SetThreadPercent((double)i/(double)GetNP()*100.);
if (multithread.terminate)
{PopStatus(); return;}
if (GetNEPP(i) == 2 && !IsLineEndPoint(i))
{
if (GetEdge(GetEdgePP(i,1)).PNum(2) == GetEdge(GetEdgePP(i,2)).PNum(1) ||
GetEdge(GetEdgePP(i,1)).PNum(1) == GetEdge(GetEdgePP(i,2)).PNum(2))
{
lp1 = 1; lp2 = 2;
}
else
{
lp1 = 2; lp2 = 1;
}
v1 = Vec3d(GetPoint(GetEdge(GetEdgePP(i,1)).PNum(1)),
GetPoint(GetEdge(GetEdgePP(i,1)).PNum(2)));
v2 = Vec3d(GetPoint(GetEdge(GetEdgePP(i,2)).PNum(lp1)),
GetPoint(GetEdge(GetEdgePP(i,2)).PNum(lp2)));
rzyl = ComputeCylinderRadius(v1, v2, v1.Length(), v2.Length());
localh = rzyl / stlparam.resthedgeanglefac;
if (localh < mincalch) {mincalch = localh;}
if (localh > maxcalch) {maxcalch = localh;}
if (localh != 0)
mesh.RestrictLocalH(GetPoint(i), localh);
}
}
PrintMessage(7,"edge-angle min local h=", mincalch, "\nedge-angle max local h=", maxcalch);
PopStatus();
}
if (stlparam.resthchartdistenable)
{
PushStatusF("Restrict H due to outer chart distance");
// mesh.LocalHFunction().Delete();
//berechne minimale distanz von chart zu einem nicht-outerchart-punkt in jedem randpunkt einer chart
2019-07-09 13:39:16 +05:00
NgArray<int> acttrigs(GetNT()); //outercharttrigs
2012-10-22 19:13:57 +06:00
acttrigs = 0;
2009-01-13 04:40:13 +05:00
for (i = 1; i <= GetNOCharts(); i++)
{
SetThreadPercent((double)i/(double)GetNOCharts()*100.);
if (multithread.terminate)
{PopStatus(); return;}
RestrictHChartDistOneChart(i, acttrigs, mesh, gh, 1., 0., stlparam);
2009-01-13 04:40:13 +05:00
}
PopStatus();
2013-04-03 02:31:20 +06:00
// NgProfiler::Print(stdout);
2009-01-13 04:40:13 +05:00
}
if (stlparam.resthlinelengthenable)
{
//restrict h due to short lines
PushStatusF("Restrict H due to line-length");
double minhl = 1E50;
double linefact = 1./stlparam.resthlinelengthfac;
double l;
for (i = 1; i <= GetNLines(); i++)
{
SetThreadPercent((double)i/(double)GetNLines()*100.);
if (multithread.terminate)
{PopStatus(); return;}
l = GetLine(i)->GetLength(points);
const Point3d& pp1 = GetPoint(GetLine(i)->StartP());
const Point3d& pp2 = GetPoint(GetLine(i)->EndP());
if (l != 0)
{
minhl = min2(minhl,l*linefact);
mesh.RestrictLocalH(pp1, l*linefact);
mesh.RestrictLocalH(pp2, l*linefact);
}
}
PopStatus();
PrintMessage(5, "minh due to line length=", minhl);
}
}
void STLGeometry :: RestrictHChartDistOneChart(ChartId chartnum, NgArray<int>& acttrigs,
class Mesh & mesh, double gh, double fact, double minh,
const STLParameters& stlparam)
2009-01-13 04:40:13 +05:00
{
2012-10-22 19:13:57 +06:00
static int timer1 = NgProfiler::CreateTimer ("restrictH OneChart 1");
static int timer2 = NgProfiler::CreateTimer ("restrictH OneChart 2");
static int timer3 = NgProfiler::CreateTimer ("restrictH OneChart 3");
2012-10-27 17:43:14 +06:00
static int timer3a = NgProfiler::CreateTimer ("restrictH OneChart 3a");
static int timer3b = NgProfiler::CreateTimer ("restrictH OneChart 3b");
2009-01-13 04:40:13 +05:00
2012-10-22 19:13:57 +06:00
NgProfiler::StartTimer (timer1);
2009-01-13 04:40:13 +05:00
double limessafety = stlparam.resthchartdistfac*fact; // original: 2
double localh;
// mincalch = 1E10;
//maxcalch = -1E10;
2019-07-09 13:39:16 +05:00
NgArray<int> limes1;
NgArray<int> limes2;
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<Point3d> plimes1;
NgArray<Point3d> plimes2;
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<int> plimes1trigs; //check from which trig the points come
NgArray<int> plimes2trigs;
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<int> plimes1origin; //either the original pointnumber or zero, if new point
2009-01-13 04:40:13 +05:00
int divisions = 10;
2019-09-21 05:04:35 +05:00
STLPointId np1, np2;
2012-10-22 19:13:57 +06:00
// Point3d p3p1, p3p2;
2009-01-13 04:40:13 +05:00
STLTriangle tt;
limes1.SetSize(0);
limes2.SetSize(0);
plimes1.SetSize(0);
plimes2.SetSize(0);
plimes1trigs.SetSize(0);
plimes2trigs.SetSize(0);
plimes1origin.SetSize(0);
2012-10-22 19:13:57 +06:00
STLChart& chart = GetChart(chartnum);
2009-01-13 04:40:13 +05:00
chart.ClearOLimit();
chart.ClearILimit();
2012-10-22 19:13:57 +06:00
for (int j = 1; j <= chart.GetNChartT(); j++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
int t = chart.GetChartTrig1(j);
2009-01-13 04:40:13 +05:00
tt = GetTriangle(t);
2012-10-22 19:13:57 +06:00
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
2012-10-22 19:13:57 +06:00
int nt = NeighbourTrig(t,k);
if (GetChartNr(nt) != chartnum)
2009-01-13 04:40:13 +05:00
{
tt.GetNeighbourPoints(GetTriangle(nt),np1,np2);
if (!IsEdge(np1,np2) && !GetSpiralPoint(np1) && !GetSpiralPoint(np2))
{
2012-10-22 19:13:57 +06:00
Point3d p3p1 = GetPoint(np1);
Point3d p3p2 = GetPoint(np2);
2018-07-29 15:03:56 +05:00
// if (AddIfNotExists(limes1,np1))
if (!limes1.Contains(np1))
2009-01-13 04:40:13 +05:00
{
2018-07-29 15:03:56 +05:00
limes1.Append(np1);
2009-01-13 04:40:13 +05:00
plimes1.Append(p3p1);
plimes1trigs.Append(t);
plimes1origin.Append(np1);
}
2018-07-29 15:03:56 +05:00
// if (AddIfNotExists(limes1,np2))
if (!limes1.Contains(np2))
2009-01-13 04:40:13 +05:00
{
2018-07-29 15:03:56 +05:00
limes1.Append(np2);
2009-01-13 04:40:13 +05:00
plimes1.Append(p3p2);
plimes1trigs.Append(t);
plimes1origin.Append(np2);
}
chart.AddILimit(twoint(np1,np2));
for (int di = 1; di <= divisions; di++)
{
2012-10-22 19:13:57 +06:00
double f1 = (double)di/(double)(divisions+1.);
double f2 = (divisions+1.-(double)di)/(double)(divisions+1.);
2009-01-13 04:40:13 +05:00
plimes1.Append(Point3d(p3p1.X()*f1+p3p2.X()*f2,
p3p1.Y()*f1+p3p2.Y()*f2,
p3p1.Z()*f1+p3p2.Z()*f2));
plimes1trigs.Append(t);
plimes1origin.Append(0);
}
}
}
}
}
2012-10-22 19:13:57 +06:00
NgProfiler::StopTimer (timer1);
NgProfiler::StartTimer (timer2);
for (int j = 1; j <= chart.GetNT(); j++)
2019-09-21 04:06:49 +05:00
acttrigs.Elem(chart.GetTrig1(j)) = chartnum;
2012-10-22 19:13:57 +06:00
for (int j = 1; j <= chart.GetNOuterT(); j++)
2009-01-13 04:40:13 +05:00
{
2019-09-21 04:06:49 +05:00
int t = chart.GetOuterTrig1(j);
2009-01-13 04:40:13 +05:00
tt = GetTriangle(t);
2012-10-22 19:13:57 +06:00
for (int k = 1; k <= 3; k++)
2009-01-13 04:40:13 +05:00
{
2012-10-22 19:13:57 +06:00
int nt = NeighbourTrig(t,k);
if (acttrigs.Get(nt) != chartnum)
2009-01-13 04:40:13 +05:00
{
tt.GetNeighbourPoints(GetTriangle(nt),np1,np2);
if (!IsEdge(np1,np2))
{
2012-10-22 19:13:57 +06:00
Point3d p3p1 = GetPoint(np1);
Point3d p3p2 = GetPoint(np2);
2009-01-13 04:40:13 +05:00
2018-07-29 15:03:56 +05:00
// if (AddIfNotExists(limes2,np1)) {plimes2.Append(p3p1); plimes2trigs.Append(t);}
// if (AddIfNotExists(limes2,np2)) {plimes2.Append(p3p2); plimes2trigs.Append(t);}
if (!limes2.Contains(np1))
{
limes2.Append(np1);
plimes2.Append(p3p1);
plimes2trigs.Append(t);
}
if (!limes2.Contains(np2))
{
limes2.Append(np2);
plimes2.Append(p3p2);
plimes2trigs.Append(t);
}
2009-01-13 04:40:13 +05:00
chart.AddOLimit(twoint(np1,np2));
for (int di = 1; di <= divisions; di++)
{
2012-10-22 19:13:57 +06:00
double f1 = (double)di/(double)(divisions+1.);
double f2 = (divisions+1.-(double)di)/(double)(divisions+1.);
2009-01-13 04:40:13 +05:00
plimes2.Append(Point3d(p3p1.X()*f1+p3p2.X()*f2,
p3p1.Y()*f1+p3p2.Y()*f2,
p3p1.Z()*f1+p3p2.Z()*f2));
plimes2trigs.Append(t);
}
}
}
}
}
2012-10-22 19:13:57 +06:00
NgProfiler::StopTimer (timer2);
NgProfiler::StartTimer (timer3);
2009-01-13 04:40:13 +05:00
double chartmindist = 1E50;
if (plimes2.Size())
{
2012-10-27 17:43:14 +06:00
NgProfiler::StartTimer (timer3a);
2009-01-13 04:40:13 +05:00
Box3d bbox;
bbox.SetPoint (plimes2.Get(1));
2012-10-22 19:13:57 +06:00
for (int j = 2; j <= plimes2.Size(); j++)
2009-01-13 04:40:13 +05:00
bbox.AddPoint (plimes2.Get(j));
Point3dTree stree(bbox.PMin(), bbox.PMax());
2012-10-22 19:13:57 +06:00
for (int j = 1; j <= plimes2.Size(); j++)
2009-01-13 04:40:13 +05:00
stree.Insert (plimes2.Get(j), j);
2019-07-09 13:39:16 +05:00
NgArray<int> foundpts;
2009-01-13 04:40:13 +05:00
2012-10-27 17:43:14 +06:00
NgProfiler::StopTimer (timer3a);
NgProfiler::StartTimer (timer3b);
for (int j = 1; j <= plimes1.Size(); j++)
2009-01-13 04:40:13 +05:00
{
double mindist = 1E50;
const Point3d & ap1 = plimes1.Get(j);
double boxs = mesh.GetH (plimes1.Get(j)) * limessafety;
Point3d pmin = ap1 - Vec3d (boxs, boxs, boxs);
Point3d pmax = ap1 + Vec3d (boxs, boxs, boxs);
stree.GetIntersecting (pmin, pmax, foundpts);
for (int kk = 1; kk <= foundpts.Size(); kk++)
{
2012-10-22 19:13:57 +06:00
int k = foundpts.Get(kk);
double dist = Dist2(plimes1.Get(j),plimes2.Get(k));
if (dist < mindist) mindist = dist;
2009-01-13 04:40:13 +05:00
}
/*
const Point3d & ap1 = plimes1.Get(j);
double his = mesh.GetH (plimes1.Get(j));
double xmin = ap1.X() - his * limessafety;
double xmax = ap1.X() + his * limessafety;
double ymin = ap1.Y() - his * limessafety;
double ymax = ap1.Y() + his * limessafety;
double zmin = ap1.Z() - his * limessafety;
double zmax = ap1.Z() + his * limessafety;
for (k = 1; k <= plimes2.Size(); k++)
{
const Point3d & ap2 = plimes2.Get(k);
if (ap2.X() >= xmin && ap2.X() <= xmax &&
ap2.Y() >= ymin && ap2.Y() <= ymax &&
ap2.Z() >= zmin && ap2.Z() <= zmax)
{
dist = Dist2(plimes1.Get(j),plimes2.Get(k));
if (dist < mindist)
{
mindist = dist;
}
}
}
*/
mindist = sqrt(mindist);
localh = mindist/limessafety;
if (localh < minh && localh != 0) {localh = minh;} //minh is generally 0! (except make atlas)
if (localh < gh && localh > 0)
{
mesh.RestrictLocalH(plimes1.Get(j), localh);
// if (mindist < mincalch) {mincalch = mindist;}
// if (mindist > maxcalch) {maxcalch = mindist;}
if (mindist < chartmindist) {chartmindist = mindist;}
}
}
2012-10-27 17:43:14 +06:00
NgProfiler::StopTimer (timer3b);
2009-01-13 04:40:13 +05:00
}
2012-10-22 19:13:57 +06:00
NgProfiler::StopTimer (timer3);
2009-01-13 04:40:13 +05:00
}
int STLMeshingDummy (STLGeometry* stlgeometry, shared_ptr<Mesh> & mesh, const MeshingParameters & mparam,
const STLParameters& stlparam)
2009-01-13 04:40:13 +05:00
{
if (mparam.perfstepsstart > mparam.perfstepsend) return 0;
2009-01-13 04:40:13 +05:00
multithread.terminate = 0;
int success = 1;
//int trialcntouter = 0;
if (mparam.perfstepsstart <= MESHCONST_MESHEDGES)
2009-01-13 04:40:13 +05:00
{
2014-12-11 20:27:45 +05:00
if (mesh)
mesh -> DeleteMesh();
else
mesh = make_shared<Mesh>();
2009-01-13 04:40:13 +05:00
2009-03-25 13:51:23 +05:00
mesh->geomtype = Mesh::GEOM_STL;
2009-01-13 04:40:13 +05:00
mesh -> SetGlobalH (mparam.maxh);
mesh -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10),
mparam.grading);
mesh -> LoadLocalMeshSize (mparam.meshsizefilename);
2019-08-28 12:52:51 +05:00
if (mparam.uselocalh)
for (auto mspnt : mparam.meshsize_points)
mesh->RestrictLocalH(mspnt.pnt, mspnt.h);
2009-01-13 04:40:13 +05:00
success = 0;
//mesh->DeleteMesh();
STLMeshing (*stlgeometry, *mesh, mparam, stlparam);
2009-01-13 04:40:13 +05:00
stlgeometry->edgesfound = 1;
stlgeometry->surfacemeshed = 0;
stlgeometry->surfaceoptimized = 0;
stlgeometry->volumemeshed = 0;
}
if (multithread.terminate)
return 0;
if (mparam.perfstepsstart <= MESHCONST_MESHSURFACE &&
mparam.perfstepsend >= MESHCONST_MESHSURFACE)
2009-01-13 04:40:13 +05:00
{
if (!stlgeometry->edgesfound)
{
PrintUserError("You have to do 'analyse geometry' first!!!");
return 0;
}
if (stlgeometry->surfacemeshed || stlgeometry->surfacemeshed)
{
PrintUserError("Already meshed. Please start again with 'Analyse Geometry'!!!");
return 0;
}
success = 0;
int retval = STLSurfaceMeshing (*stlgeometry, *mesh, mparam, stlparam);
2009-01-13 04:40:13 +05:00
if (retval == MESHING3_OK)
{
PrintMessage(3,"Success !!!!");
stlgeometry->surfacemeshed = 1;
stlgeometry->surfaceoptimized = 0;
stlgeometry->volumemeshed = 0;
success = 1;
}
else if (retval == MESHING3_OUTERSTEPSEXCEEDED)
{
PrintError("Give up because of too many trials. Meshing aborted!");
}
else if (retval == MESHING3_TERMINATE)
{
PrintWarning("Meshing Stopped by user!");
}
else
{
PrintError("Surface meshing not successful. Meshing aborted!");
}
#ifdef STAT_STREAM
(*statout) << mesh->GetNSeg() << " & " << endl
<< mesh->GetNSE() << " & " << endl
<< GetTime() << " & ";
#endif
}
if (multithread.terminate)
return 0;
if (success)
{
if (mparam.perfstepsstart <= MESHCONST_OPTSURFACE &&
mparam.perfstepsend >= MESHCONST_OPTSURFACE)
2009-01-13 04:40:13 +05:00
{
if (!stlgeometry->edgesfound)
{
PrintUserError("You have to do 'meshing->analyse geometry' first!!!");
return 0;
}
if (!stlgeometry->surfacemeshed)
{
PrintUserError("You have to do 'meshing->mesh surface' first!!!");
return 0;
}
if (stlgeometry->volumemeshed)
{
PrintWarning("Surface optimization with meshed volume is dangerous!!!");
}
2011-01-11 01:18:01 +05:00
/*
2009-01-13 04:40:13 +05:00
if (!optstring || strlen(optstring) == 0)
{
mparam.optimize2d = "smcm";
}
else
{
mparam.optimize2d = optstring;
}
2011-01-11 01:18:01 +05:00
*/
2009-01-13 04:40:13 +05:00
STLSurfaceOptimization (*stlgeometry, *mesh, mparam);
if (stlparam.recalc_h_opt)
{
mesh -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10),
mparam.grading);
mesh -> LoadLocalMeshSize (mparam.meshsizefilename);
2011-07-25 14:40:23 +06:00
mesh -> CalcLocalHFromSurfaceCurvature (mparam.grading,
stlparam.resthsurfmeshcurvfac);
MeshingParameters mpar = mparam;
mpar.optimize2d = "cmsmSm";
STLSurfaceOptimization (*stlgeometry, *mesh, mpar);
2009-01-13 04:40:13 +05:00
#ifdef STAT_STREAM
(*statout) << GetTime() << " & ";
#endif
mpar.Render();
2009-01-13 04:40:13 +05:00
}
stlgeometry->surfaceoptimized = 1;
}
if (multithread.terminate)
return 0;
if (mparam.perfstepsstart <= MESHCONST_MESHVOLUME &&
mparam.perfstepsend >= MESHCONST_MESHVOLUME)
2009-01-13 04:40:13 +05:00
{
if (stlgeometry->volumemeshed)
{
PrintUserError("Volume already meshed!"); return 0;
}
if (!stlgeometry->edgesfound)
{
PrintUserError("You have to do 'meshing->analyse geometry' first!!!");
return 0;
}
if (!stlgeometry->surfacemeshed)
{
PrintUserError("You have to do 'meshing->mesh surface' first!!!");
return 0;
}
if (!stlgeometry->surfaceoptimized)
{
PrintWarning("You should do 'meshing->optimize surface' first!!!");
}
PrintMessage(5,"Check Overlapping boundary: ");
mesh->FindOpenElements();
mesh->CheckOverlappingBoundary();
PrintMessage(5,"");
if (stlparam.recalc_h_opt)
{
mesh -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10),
mparam.grading);
mesh -> LoadLocalMeshSize (mparam.meshsizefilename);
2011-07-25 14:40:23 +06:00
mesh -> CalcLocalH (mparam.grading);
2009-01-13 04:40:13 +05:00
}
PrintMessage(5,"Volume meshing");
int retval = MeshVolume (mparam, *mesh);
if (retval == MESHING3_OK)
{
RemoveIllegalElements(*mesh);
stlgeometry->volumemeshed = 1;
}
else if (retval == MESHING3_OUTERSTEPSEXCEEDED)
{
PrintError("Give up because of too many trials. Meshing aborted!");
return 0;
}
else if (retval == MESHING3_TERMINATE)
{
PrintWarning("Meshing Stopped by user!");
}
else
{
PrintError("Volume meshing not successful. Meshing aborted!");
return 0;
}
#ifdef STAT_STREAM
(*statout) << GetTime() << " & " << endl;
#endif
MeshQuality3d (*mesh);
}
if (multithread.terminate)
return 0;
if (mparam.perfstepsstart <= MESHCONST_OPTVOLUME &&
mparam.perfstepsend >= MESHCONST_OPTVOLUME)
2009-01-13 04:40:13 +05:00
{
if (!stlgeometry->edgesfound)
{
PrintUserError("You have to do 'meshing->analyse geometry' first!!!");
return 0;
}
if (!stlgeometry->surfacemeshed)
{
PrintUserError("You have to do 'meshing->mesh surface' first!!!");
return 0;
}
if (!stlgeometry->volumemeshed)
{
PrintUserError("You have to do 'meshing->mesh volume' first!!!");
return 0;
}
2011-01-11 01:18:01 +05:00
/*
2009-01-13 04:40:13 +05:00
if (!optstring || strlen(optstring) == 0)
{
mparam.optimize3d = "cmdmstm";
}
else
{
mparam.optimize3d = optstring;
}
2011-01-11 01:18:01 +05:00
*/
2009-01-13 04:40:13 +05:00
OptimizeVolume (mparam, *mesh);
#ifdef STAT_STREAM
(*statout) << GetTime() << " & " << endl;
(*statout) << mesh->GetNE() << " & " << endl
<< mesh->GetNP() << " " << '\\' << '\\' << " \\" << "hline" << endl;
#endif
2014-11-17 22:23:05 +05:00
mparam.Render();
2009-01-13 04:40:13 +05:00
}
}
return 0;
}
}