2014-01-26 03:17:16 +06:00
|
|
|
#ifdef OCCGEOMETRY
|
|
|
|
|
|
|
|
#include <mystdlib.h>
|
|
|
|
#include <occgeom.hpp>
|
|
|
|
#include <meshing.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace netgen
|
|
|
|
{
|
|
|
|
|
|
|
|
#include "occmeshsurf.hpp"
|
|
|
|
|
|
|
|
#define TCL_OK 0
|
|
|
|
#define TCL_ERROR 1
|
|
|
|
|
2021-08-15 16:29:28 +05:00
|
|
|
#define DIVIDEEDGESECTIONS 10000 // better solution to come soon
|
2014-01-26 03:17:16 +06:00
|
|
|
#define IGNORECURVELENGTH 1e-4
|
|
|
|
#define VSMALL 1e-10
|
|
|
|
|
|
|
|
|
2021-07-30 11:42:35 +05:00
|
|
|
DLL_HEADER bool merge_solids = false;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
// can you please explain what you intend to compute here (JS) !!!
|
2019-07-28 23:22:48 +05:00
|
|
|
double Line :: Dist (Line l)
|
|
|
|
{
|
|
|
|
Vec<3> n = p1-p0;
|
|
|
|
Vec<3> q = l.p1-l.p0;
|
|
|
|
double nq = n*q;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
Point<3> p = p0 + 0.5*n;
|
|
|
|
double lambda = (p-l.p0)*n / (nq + VSMALL);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (lambda >= 0 && lambda <= 1)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
double d = (p-l.p0-lambda*q).Length();
|
|
|
|
// if (d < 1e-3) d = 1e99;
|
|
|
|
return d;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
else
|
|
|
|
return 1e99;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
2019-07-27 22:05:43 +05:00
|
|
|
double ComputeH (double kappa, const MeshingParameters & mparam)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2019-10-02 14:16:44 +05:00
|
|
|
kappa *= mparam.curvaturesafety;
|
2019-07-28 23:22:48 +05:00
|
|
|
/*
|
|
|
|
double hret;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (mparam.maxh * kappa < 1)
|
|
|
|
hret = mparam.maxh;
|
|
|
|
else
|
|
|
|
hret = 1 / (kappa + VSMALL);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (mparam.maxh < hret)
|
|
|
|
hret = mparam.maxh;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
return hret;
|
|
|
|
*/
|
|
|
|
// return min(mparam.maxh, 1/kappa);
|
|
|
|
return (mparam.maxh*kappa < 1) ? mparam.maxh : 1/kappa;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
void RestrictHTriangle (gp_Pnt2d & par0, gp_Pnt2d & par1, gp_Pnt2d & par2,
|
2019-10-04 17:55:36 +05:00
|
|
|
BRepLProp_SLProps * prop, BRepLProp_SLProps * prop2, Mesh & mesh, int depth, double h,
|
2019-07-28 23:22:48 +05:00
|
|
|
const MeshingParameters & mparam)
|
|
|
|
{
|
|
|
|
int ls = -1;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
gp_Pnt pnt0,pnt1,pnt2;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
prop->SetParameters (par0.X(), par0.Y());
|
|
|
|
pnt0 = prop->Value();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
prop->SetParameters (par1.X(), par1.Y());
|
|
|
|
pnt1 = prop->Value();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
prop->SetParameters (par2.X(), par2.Y());
|
|
|
|
pnt2 = prop->Value();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
double aux;
|
|
|
|
double maxside = pnt0.Distance(pnt1);
|
|
|
|
ls = 2;
|
|
|
|
aux = pnt1.Distance(pnt2);
|
|
|
|
if(aux > maxside)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
maxside = aux;
|
|
|
|
ls = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
aux = pnt2.Distance(pnt0);
|
|
|
|
if(aux > maxside)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
maxside = aux;
|
|
|
|
ls = 1;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
gp_Pnt2d parmid;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
parmid.SetX( (par0.X()+par1.X()+par2.X()) / 3 );
|
|
|
|
parmid.SetY( (par0.Y()+par1.Y()+par2.Y()) / 3 );
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (depth%3 == 0)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
double curvature = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
prop2->SetParameters (parmid.X(), parmid.Y());
|
|
|
|
if (!prop2->IsCurvatureDefined())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
(*testout) << "curvature not defined!" << endl;
|
|
|
|
return;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2019-10-04 17:55:36 +05:00
|
|
|
curvature = max(fabs(prop2->MinCurvature()),
|
|
|
|
fabs(prop2->MaxCurvature()));
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
prop2->SetParameters (par0.X(), par0.Y());
|
|
|
|
if (!prop2->IsCurvatureDefined())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
(*testout) << "curvature not defined!" << endl;
|
|
|
|
return;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2019-10-04 17:55:36 +05:00
|
|
|
curvature = max(curvature,max(fabs(prop2->MinCurvature()),
|
|
|
|
fabs(prop2->MaxCurvature())));
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
prop2->SetParameters (par1.X(), par1.Y());
|
|
|
|
if (!prop2->IsCurvatureDefined())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
(*testout) << "curvature not defined!" << endl;
|
|
|
|
return;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2019-10-04 17:55:36 +05:00
|
|
|
curvature = max(curvature,max(fabs(prop2->MinCurvature()),
|
|
|
|
fabs(prop2->MaxCurvature())));
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
prop2->SetParameters (par2.X(), par2.Y());
|
|
|
|
if (!prop2->IsCurvatureDefined())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
(*testout) << "curvature not defined!" << endl;
|
|
|
|
return;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2019-10-04 17:55:36 +05:00
|
|
|
curvature = max(curvature,max(fabs(prop2->MinCurvature()),
|
|
|
|
fabs(prop2->MaxCurvature())));
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
//(*testout) << "curvature " << curvature << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (curvature < 1e-3)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
//(*testout) << "curvature too small (" << curvature << ")!" << endl;
|
|
|
|
return;
|
|
|
|
// return war bis 10.2.05 auskommentiert
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
h = ComputeH (curvature+1e-10, mparam);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if(h < 1e-4*maxside)
|
|
|
|
return;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
// if (h > 30) return;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (h < maxside && depth < 10)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
//cout << "\r h " << h << flush;
|
|
|
|
gp_Pnt2d pm;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
//cout << "h " << h << " maxside " << maxside << " depth " << depth << endl;
|
|
|
|
//cout << "par0 " << par0.X() << " " << par0.Y()
|
|
|
|
//<< " par1 " << par1.X() << " " << par1.Y()
|
|
|
|
// << " par2 " << par2.X() << " " << par2.Y()<< endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if(ls == 0)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
pm.SetX(0.5*(par1.X()+par2.X())); pm.SetY(0.5*(par1.Y()+par2.Y()));
|
2019-10-04 17:55:36 +05:00
|
|
|
RestrictHTriangle(pm, par2, par0, prop, prop2, mesh, depth+1, h, mparam);
|
|
|
|
RestrictHTriangle(pm, par0, par1, prop, prop2, mesh, depth+1, h, mparam);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
else if(ls == 1)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
pm.SetX(0.5*(par0.X()+par2.X())); pm.SetY(0.5*(par0.Y()+par2.Y()));
|
2019-10-04 17:55:36 +05:00
|
|
|
RestrictHTriangle(pm, par1, par2, prop, prop2, mesh, depth+1, h, mparam);
|
|
|
|
RestrictHTriangle(pm, par0, par1, prop, prop2, mesh, depth+1, h, mparam);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
else if(ls == 2)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
pm.SetX(0.5*(par0.X()+par1.X())); pm.SetY(0.5*(par0.Y()+par1.Y()));
|
2019-10-04 17:55:36 +05:00
|
|
|
RestrictHTriangle(pm, par1, par2, prop, prop2, mesh, depth+1, h, mparam);
|
|
|
|
RestrictHTriangle(pm, par2, par0, prop, prop2, mesh, depth+1, h, mparam);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
else
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
gp_Pnt pnt;
|
|
|
|
Point3d p3d;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
prop->SetParameters (parmid.X(), parmid.Y());
|
|
|
|
pnt = prop->Value();
|
|
|
|
p3d = Point3d(pnt.X(), pnt.Y(), pnt.Z());
|
|
|
|
mesh.RestrictLocalH (p3d, h);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
p3d = Point3d(pnt0.X(), pnt0.Y(), pnt0.Z());
|
|
|
|
mesh.RestrictLocalH (p3d, h);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
p3d = Point3d(pnt1.X(), pnt1.Y(), pnt1.Z());
|
|
|
|
mesh.RestrictLocalH (p3d, h);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
p3d = Point3d(pnt2.X(), pnt2.Y(), pnt2.Z());
|
|
|
|
mesh.RestrictLocalH (p3d, h);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
//(*testout) << "p = " << p3d << ", h = " << h << ", maxside = " << maxside << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
void DivideEdge (TopoDS_Edge & edge, NgArray<MeshPoint> & ps,
|
2021-09-03 00:48:05 +05:00
|
|
|
Array<double> & params, Mesh & mesh,
|
2019-07-28 23:22:48 +05:00
|
|
|
const MeshingParameters & mparam)
|
|
|
|
{
|
|
|
|
double s0, s1;
|
|
|
|
int nsubedges = 1;
|
|
|
|
gp_Pnt pnt, oldpnt;
|
|
|
|
double svalue[DIVIDEEDGESECTIONS];
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
GProp_GProps system;
|
|
|
|
BRepGProp::LinearProperties(edge, system);
|
|
|
|
double L = system.Mass();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
double hvalue[DIVIDEEDGESECTIONS+1];
|
|
|
|
hvalue[0] = 0;
|
|
|
|
pnt = c->Value(s0);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int tmpVal = (int)(DIVIDEEDGESECTIONS);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 1; i <= tmpVal; i++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
oldpnt = pnt;
|
|
|
|
pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0));
|
|
|
|
hvalue[i] = hvalue[i-1] +
|
|
|
|
1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
|
|
|
|
pnt.Distance(oldpnt);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
//(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))
|
|
|
|
// << " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS]));
|
|
|
|
nsubedges = max (1, int(floor(hvalue[DIVIDEEDGESECTIONS]+0.5)));
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
ps.SetSize(nsubedges-1);
|
|
|
|
params.SetSize(nsubedges+1);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int i = 1;
|
|
|
|
int i1 = 0;
|
|
|
|
do
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
|
|
|
|
pnt = c->Value(params[i]);
|
|
|
|
ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z()));
|
|
|
|
i++;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
i1++;
|
|
|
|
if (i1 > DIVIDEEDGESECTIONS)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
nsubedges = i;
|
|
|
|
ps.SetSize(nsubedges-1);
|
|
|
|
params.SetSize(nsubedges+1);
|
|
|
|
cout << "divide edge: local h too small" << endl;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
} while (i < nsubedges);
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
params[0] = s0;
|
|
|
|
params[nsubedges] = s1;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (params[nsubedges] <= params[nsubedges-1])
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
cout << "CORRECTED" << endl;
|
|
|
|
ps.SetSize (nsubedges-2);
|
|
|
|
params.SetSize (nsubedges);
|
|
|
|
params[nsubedges] = s1;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-28 18:41:31 +05:00
|
|
|
void OCCFindEdges (const OCCGeometry & geom, Mesh & mesh, const MeshingParameters & mparam)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
static Timer t("OCCFindEdges"); RegionTimer r(t);
|
|
|
|
static Timer tsearch("OCCFindEdges - search point");
|
|
|
|
const char * savetask = multithread.task;
|
|
|
|
multithread.task = "Edge meshing";
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
(*testout) << "edge meshing" << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int nvertices = geom.vmap.Extent();
|
|
|
|
int nedges = geom.emap.Extent();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-09-03 00:48:05 +05:00
|
|
|
Array<Array<PointIndex>> alledgepnums(nedges);
|
|
|
|
Array<Array<double>> alledgeparams(nedges);
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
(*testout) << "nvertices = " << nvertices << endl;
|
|
|
|
(*testout) << "nedges = " << nedges << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
double eps = 1e-6 * geom.GetBoundingBox().Diam();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
tsearch.Start();
|
|
|
|
for (int i = 1; i <= nvertices; i++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
gp_Pnt pnt = BRep_Tool::Pnt (TopoDS::Vertex(geom.vmap(i)));
|
2021-10-28 16:26:55 +05:00
|
|
|
double hpref = OCCGeometry::global_shape_properties[TopoDS::Vertex(geom.vmap(i)).TShape()].hpref;
|
2021-07-30 11:42:35 +05:00
|
|
|
MeshPoint mp(occ2ng(pnt));
|
2021-10-28 16:26:55 +05:00
|
|
|
// mp.Singularity(hpref);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-07-30 11:42:35 +05:00
|
|
|
bool exists = false;
|
2019-07-28 23:22:48 +05:00
|
|
|
if (merge_solids)
|
2019-08-08 03:17:53 +05:00
|
|
|
for (PointIndex pi : mesh.Points().Range())
|
|
|
|
if (Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2019-08-08 03:17:53 +05:00
|
|
|
exists = true;
|
2019-07-28 23:22:48 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!exists)
|
2021-10-28 16:26:55 +05:00
|
|
|
{
|
|
|
|
mesh.AddPoint (mp);
|
|
|
|
mesh.Points().Last().Singularity(hpref);
|
|
|
|
}
|
2021-09-24 21:47:47 +05:00
|
|
|
|
|
|
|
double maxh = OCCGeometry::global_shape_properties[TopoDS::Vertex(geom.vmap(i)).TShape()].maxh;
|
|
|
|
mesh.RestrictLocalH (occ2ng(pnt), maxh);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
tsearch.Stop();
|
|
|
|
(*testout) << "different vertices = " << mesh.GetNP() << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-08-08 02:32:14 +05:00
|
|
|
// int first_ep = mesh.GetNP()+1;
|
2019-08-09 18:30:58 +05:00
|
|
|
// PointIndex first_ep = mesh.Points().End();
|
|
|
|
PointIndex first_ep = *mesh.Points().Range().end();
|
2019-08-08 02:32:14 +05:00
|
|
|
auto vertexrange = mesh.Points().Range();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
NgArray<int> face2solid[2];
|
2019-08-08 03:17:53 +05:00
|
|
|
for (int i = 0; i < 2; i++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
face2solid[i].SetSize (geom.fmap.Extent());
|
|
|
|
face2solid[i] = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int solidnr = 0;
|
|
|
|
for (TopExp_Explorer exp0(geom.shape, TopAbs_SOLID); exp0.More(); exp0.Next())
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
solidnr++;
|
|
|
|
for (TopExp_Explorer exp1(exp0.Current(), TopAbs_FACE); exp1.More(); exp1.Next())
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
TopoDS_Face face = TopoDS::Face(exp1.Current());
|
|
|
|
int facenr = geom.fmap.FindIndex(face);
|
2020-05-26 14:23:33 +05:00
|
|
|
if(facenr < 1) continue;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
if (face2solid[0][facenr-1] == 0)
|
2019-07-28 23:22:48 +05:00
|
|
|
face2solid[0][facenr-1] = solidnr;
|
2014-01-26 03:17:16 +06:00
|
|
|
else
|
2019-07-28 23:22:48 +05:00
|
|
|
face2solid[1][facenr-1] = solidnr;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int total = 0;
|
|
|
|
for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++)
|
|
|
|
for (TopExp_Explorer exp2(geom.fmap(i3), TopAbs_WIRE); exp2.More(); exp2.Next())
|
|
|
|
for (TopExp_Explorer exp3(exp2.Current(), TopAbs_EDGE); exp3.More(); exp3.Next())
|
|
|
|
total++;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int facenr = 0;
|
2021-07-28 23:16:32 +05:00
|
|
|
// int edgenr = mesh.GetNSeg();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
(*testout) << "faces = " << geom.fmap.Extent() << endl;
|
|
|
|
int curr = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
TopoDS_Face face = TopoDS::Face(geom.fmap(i3));
|
|
|
|
facenr = geom.fmap.FindIndex (face); // sollte doch immer == i3 sein ??? JS
|
|
|
|
|
|
|
|
int solidnr0 = face2solid[0][i3-1];
|
|
|
|
int solidnr1 = face2solid[1][i3-1];
|
|
|
|
|
|
|
|
/* auskommentiert am 3.3.05 von robert
|
|
|
|
for (exp2.Init (geom.somap(solidnr0), TopAbs_FACE); exp2.More(); exp2.Next())
|
|
|
|
{
|
|
|
|
TopoDS_Face face2 = TopoDS::Face(exp2.Current());
|
|
|
|
if (geom.fmap.FindIndex(face2) == facenr)
|
|
|
|
{
|
|
|
|
// if (face.Orientation() != face2.Orientation()) swap (solidnr0, solidnr1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
mesh.AddFaceDescriptor (FaceDescriptor(facenr, solidnr0, solidnr1, 0));
|
|
|
|
|
2021-11-03 21:20:26 +05:00
|
|
|
Vec<4> col = OCCGeometry::global_shape_properties[face.TShape()].col.value_or(Vec<4>(0,1,0,1));
|
|
|
|
mesh.GetFaceDescriptor(facenr).SetSurfColour(col);
|
2019-07-28 23:22:48 +05:00
|
|
|
|
2021-11-05 20:58:22 +05:00
|
|
|
if(auto & opt_name = geom.fprops[facenr-1]->name)
|
2021-11-03 21:20:26 +05:00
|
|
|
mesh.GetFaceDescriptor(facenr).SetBCName(&*opt_name);
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.GetFaceDescriptor(facenr).SetBCProperty(facenr);
|
|
|
|
// ACHTUNG! STIMMT NICHT ALLGEMEIN (RG)
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
Handle(Geom_Surface) occface = BRep_Tool::Surface(face);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (TopExp_Explorer exp2 (face, TopAbs_WIRE); exp2.More(); exp2.Next())
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
TopoDS_Shape wire = exp2.Current();
|
|
|
|
|
|
|
|
for (TopExp_Explorer exp3 (wire, TopAbs_EDGE); exp3.More(); exp3.Next())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
curr++;
|
|
|
|
(*testout) << "edge nr " << curr << endl;
|
|
|
|
multithread.percent = 100 * curr / double (total);
|
|
|
|
if (multithread.terminate) return;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
TopoDS_Edge edge = TopoDS::Edge (exp3.Current());
|
|
|
|
if (BRep_Tool::Degenerated(edge))
|
|
|
|
{
|
|
|
|
//(*testout) << "ignoring degenerated edge" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2020-05-26 14:23:33 +05:00
|
|
|
if(geom.emap.FindIndex(edge) < 1) continue;
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) ==
|
|
|
|
geom.vmap.FindIndex(TopExp::LastVertex (edge)))
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
GProp_GProps system;
|
|
|
|
BRepGProp::LinearProperties(edge, system);
|
|
|
|
|
|
|
|
if (system.Mass() < eps)
|
|
|
|
{
|
|
|
|
cout << "ignoring edge " << geom.emap.FindIndex (edge)
|
|
|
|
<< ". closed edge with length < " << eps << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
Handle(Geom2d_Curve) cof;
|
|
|
|
double s0, s1;
|
|
|
|
cof = BRep_Tool::CurveOnSurface (edge, face, s0, s1);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int geomedgenr = geom.emap.FindIndex(edge);
|
2021-09-03 00:48:05 +05:00
|
|
|
Array<PointIndex> pnums;
|
|
|
|
Array<double> params;
|
2021-08-15 16:29:28 +05:00
|
|
|
|
|
|
|
|
|
|
|
// check for identifications
|
|
|
|
bool copy_identified = false;
|
|
|
|
if (auto it = geom.identifications.find(edge.TShape()); it != geom.identifications.end())
|
|
|
|
for (auto & ids : it->second)
|
|
|
|
{
|
|
|
|
cout << "edge has identification with trafo " << ids.name << ", inv = " << ids.inverse << endl;
|
|
|
|
int otherind = geom.emap.FindIndex(ids.other);
|
|
|
|
Array<Segment> othersegs;
|
|
|
|
for (auto & seg : mesh.LineSegments())
|
|
|
|
if (seg.edgenr == otherind)
|
|
|
|
othersegs.Append (seg);
|
|
|
|
|
|
|
|
if (othersegs.Size())
|
|
|
|
{
|
|
|
|
cout << "other has already segs" << endl;
|
|
|
|
copy_identified = true;
|
|
|
|
|
|
|
|
Array<PointIndex> pnums_other;
|
|
|
|
pnums_other.Append (othersegs[0][0]);
|
|
|
|
for (auto & seg : othersegs)
|
|
|
|
pnums_other.Append (seg[1]);
|
|
|
|
|
|
|
|
auto inv = ids.trafo.CalcInverse();
|
|
|
|
// for (auto & pi : pnums)
|
|
|
|
for (auto oi : Range(pnums_other))
|
|
|
|
{
|
|
|
|
PointIndex piother = pnums_other[pnums_other.Size()-oi-1];
|
|
|
|
Point<3> pother = mesh[piother];
|
|
|
|
Point<3> p = inv(pother);
|
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
PointIndex pi;
|
|
|
|
for (PointIndex piv : vertexrange)
|
|
|
|
if (Dist2 (mesh[piv], p) < eps*eps)
|
|
|
|
{
|
|
|
|
pi = piv;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found)
|
|
|
|
pi = mesh.AddPoint (p);
|
|
|
|
|
|
|
|
// params.Add ( find parameter p );
|
|
|
|
double s0, s1;
|
|
|
|
Handle(Geom_Curve) curve = BRep_Tool::Curve(edge, s0, s1);
|
|
|
|
|
|
|
|
GeomAPI_ProjectPointOnCurve proj(ng2occ(p), curve);
|
|
|
|
params.Append (proj.LowerDistanceParameter());
|
|
|
|
pnums.Append (pi);
|
|
|
|
mesh.GetIdentifications().Add (pi, piother, geomedgenr);
|
|
|
|
|
|
|
|
}
|
|
|
|
mesh.GetIdentifications().SetType(geomedgenr,Identifications::PERIODIC);
|
|
|
|
|
|
|
|
copy_identified = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-08-15 16:29:28 +05:00
|
|
|
|
|
|
|
if (!copy_identified)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2021-09-03 00:48:05 +05:00
|
|
|
|
2021-08-15 16:29:28 +05:00
|
|
|
|
2021-09-03 00:48:05 +05:00
|
|
|
if (alledgepnums[geomedgenr-1].Size())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2021-09-03 00:48:05 +05:00
|
|
|
pnums = alledgepnums[geomedgenr-1];
|
|
|
|
params = alledgeparams[geomedgenr-1];
|
2021-08-15 16:29:28 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-09-03 00:48:05 +05:00
|
|
|
NgArray <MeshPoint> mp;
|
|
|
|
DivideEdge (edge, mp, params, mesh, mparam);
|
2021-08-15 16:29:28 +05:00
|
|
|
|
2021-09-03 00:48:05 +05:00
|
|
|
pnums.SetSize(mp.Size()+2);
|
|
|
|
if (!merge_solids)
|
2021-08-15 16:29:28 +05:00
|
|
|
{
|
2021-09-03 00:48:05 +05:00
|
|
|
pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge)) + PointIndex::BASE-1;
|
|
|
|
pnums.Last() = geom.vmap.FindIndex (TopExp::LastVertex (edge)) + PointIndex::BASE-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Point<3> fp = occ2ng (BRep_Tool::Pnt (TopExp::FirstVertex (edge)));
|
|
|
|
Point<3> lp = occ2ng (BRep_Tool::Pnt (TopExp::LastVertex (edge)));
|
|
|
|
|
|
|
|
pnums[0] = PointIndex::INVALID;
|
|
|
|
pnums.Last() = PointIndex::INVALID;
|
|
|
|
for (PointIndex pi : vertexrange)
|
|
|
|
{
|
|
|
|
if (Dist2 (mesh[pi], fp) < eps*eps) pnums[0] = pi;
|
|
|
|
if (Dist2 (mesh[pi], lp) < eps*eps) pnums.Last() = pi;
|
|
|
|
}
|
2021-08-15 16:29:28 +05:00
|
|
|
}
|
|
|
|
|
2021-09-03 00:48:05 +05:00
|
|
|
for (size_t i = 1; i <= mp.Size(); i++)
|
|
|
|
{
|
|
|
|
bool exists = false;
|
|
|
|
tsearch.Start();
|
|
|
|
|
|
|
|
/*
|
|
|
|
// for (PointIndex j = first_ep; j < mesh.Points().End(); j++)
|
|
|
|
for (PointIndex j = first_ep; j < *mesh.Points().Range().end(); j++)
|
|
|
|
if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps)
|
|
|
|
{
|
|
|
|
exists = true;
|
|
|
|
pnums[i] = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
tsearch.Stop();
|
|
|
|
|
|
|
|
if (!exists)
|
|
|
|
pnums[i] = mesh.AddPoint (mp[i-1]);
|
|
|
|
}
|
2021-08-15 16:29:28 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-03 00:48:05 +05:00
|
|
|
alledgepnums[geomedgenr-1] = pnums;
|
|
|
|
alledgeparams[geomedgenr-1] = params;
|
|
|
|
}
|
|
|
|
|
2021-11-03 21:20:26 +05:00
|
|
|
auto name = geom.eprops[geom.emap.FindIndex(edge)-1]->name.value_or("");
|
2021-10-04 18:52:56 +05:00
|
|
|
mesh.SetCD2Name(geomedgenr, name);
|
2021-09-03 00:48:05 +05:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
(*testout) << "NP = " << mesh.GetNP() << endl;
|
|
|
|
//(*testout) << pnums[pnums.Size()-1] << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-10-28 16:26:55 +05:00
|
|
|
double hpref = OCCGeometry::global_shape_properties[edge.TShape()].hpref;
|
|
|
|
|
2021-08-15 16:29:28 +05:00
|
|
|
// for (size_t i = 1; i <= mp.Size()+1; i++)
|
|
|
|
for (size_t i = 1; i < pnums.Size(); i++)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2021-07-28 23:16:32 +05:00
|
|
|
// edgenr++;
|
2019-07-28 23:22:48 +05:00
|
|
|
Segment seg;
|
|
|
|
|
|
|
|
seg[0] = pnums[i-1];
|
|
|
|
seg[1] = pnums[i];
|
2021-07-28 23:16:32 +05:00
|
|
|
// seg.edgenr = edgenr;
|
|
|
|
seg.edgenr = geomedgenr;
|
2019-07-28 23:22:48 +05:00
|
|
|
seg.si = facenr;
|
|
|
|
seg.epgeominfo[0].dist = params[i-1];
|
|
|
|
seg.epgeominfo[1].dist = params[i];
|
|
|
|
seg.epgeominfo[0].edgenr = geomedgenr;
|
|
|
|
seg.epgeominfo[1].edgenr = geomedgenr;
|
|
|
|
|
2021-08-15 16:29:28 +05:00
|
|
|
double s0 = params[i-1];
|
|
|
|
double s1 = params[i];
|
|
|
|
double delta = s1-s0;
|
|
|
|
s0 += 1e-10*delta; // fixes normal-vector roundoff problem when endpoint is cone-tip
|
|
|
|
s1 -= 1e-10*delta;
|
2021-09-03 00:48:05 +05:00
|
|
|
gp_Pnt2d p2d1 = cof->Value(s0);
|
|
|
|
gp_Pnt2d p2d2 = cof->Value(s1);
|
|
|
|
seg.epgeominfo[0].u = p2d1.X();
|
|
|
|
seg.epgeominfo[0].v = p2d1.Y();
|
|
|
|
seg.epgeominfo[1].u = p2d2.X();
|
|
|
|
seg.epgeominfo[1].v = p2d2.Y();
|
2019-07-28 23:22:48 +05:00
|
|
|
|
2021-10-28 16:26:55 +05:00
|
|
|
seg.singedge_left = hpref;
|
|
|
|
seg.singedge_right = hpref;
|
2019-07-28 23:22:48 +05:00
|
|
|
/*
|
|
|
|
if (occface->IsUPeriodic())
|
|
|
|
{
|
|
|
|
cout << "U Periodic" << endl;
|
|
|
|
if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) >
|
|
|
|
fabs(seg.epgeominfo[1].u-
|
|
|
|
(seg.epgeominfo[0].u-occface->UPeriod())))
|
|
|
|
seg.epgeominfo[0].u = p2d.X()+occface->UPeriod();
|
|
|
|
|
|
|
|
if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) >
|
|
|
|
fabs(seg.epgeominfo[1].u-
|
|
|
|
(seg.epgeominfo[0].u+occface->UPeriod())))
|
|
|
|
seg.epgeominfo[0].u = p2d.X()-occface->UPeriod();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (occface->IsVPeriodic())
|
|
|
|
{
|
|
|
|
cout << "V Periodic" << endl;
|
|
|
|
if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) >
|
|
|
|
fabs(seg.epgeominfo[1].v-
|
|
|
|
(seg.epgeominfo[0].v-occface->VPeriod())))
|
|
|
|
seg.epgeominfo[0].v = p2d.Y()+occface->VPeriod();
|
|
|
|
|
|
|
|
if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) >
|
|
|
|
fabs(seg.epgeominfo[1].v-
|
|
|
|
(seg.epgeominfo[0].v+occface->VPeriod())))
|
|
|
|
seg.epgeominfo[0].v = p2d.Y()-occface->VPeriod();
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (edge.Orientation() == TopAbs_REVERSED)
|
|
|
|
{
|
|
|
|
swap (seg[0], seg[1]);
|
|
|
|
swap (seg.epgeominfo[0].dist, seg.epgeominfo[1].dist);
|
|
|
|
swap (seg.epgeominfo[0].u, seg.epgeominfo[1].u);
|
|
|
|
swap (seg.epgeominfo[0].v, seg.epgeominfo[1].v);
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh.AddSegment (seg);
|
|
|
|
|
|
|
|
//edgesegments[geomedgenr-1]->Append(mesh.GetNSeg());
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// for(i=1; i<=mesh.GetNSeg(); i++)
|
|
|
|
// (*testout) << "edge " << mesh.LineSegment(i).edgenr << " face " << mesh.LineSegment(i).si
|
|
|
|
// << " p1 " << mesh.LineSegment(i)[0] << " p2 " << mesh.LineSegment(i)[1] << endl;
|
|
|
|
// exit(10);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.CalcSurfacesOfNode();
|
|
|
|
multithread.task = savetask;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-28 18:41:31 +05:00
|
|
|
void OCCMeshSurface (const OCCGeometry & geom, Mesh & mesh,
|
2019-10-02 20:20:13 +05:00
|
|
|
const MeshingParameters & mparam)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
static Timer t("OCCMeshSurface"); RegionTimer r(t);
|
|
|
|
|
|
|
|
// int i, j, k;
|
|
|
|
// int changed;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
const char * savetask = multithread.task;
|
|
|
|
multithread.task = "Surface meshing";
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
geom.facemeshstatus = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int noldp = mesh.GetNP();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
double starttime = GetTime();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-08-08 02:32:14 +05:00
|
|
|
NgArray<int, PointIndex::BASE> glob2loc(noldp);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
//int projecttype = PARAMETERSPACE;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int projecttype = PARAMETERSPACE;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int notrys = 1;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int surfmesherror = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int k = 1; k <= mesh.GetNFD(); k++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
if(1==0 && !geom.fvispar[k-1].IsDrawable())
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
(*testout) << "ignoring face " << k << endl;
|
|
|
|
cout << "ignoring face " << k << endl;
|
|
|
|
continue;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
(*testout) << "mesh face " << k << endl;
|
|
|
|
multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
|
|
|
|
geom.facemeshstatus[k-1] = -1;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int oldnf = mesh.GetNSE();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
Box<3> bb = geom.GetBoundingBox();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-07-24 16:14:21 +05:00
|
|
|
// int projecttype = PLANESPACE;
|
2021-07-24 19:18:22 +05:00
|
|
|
// int projecttype = PARAMETERSPACE;
|
2019-07-28 23:22:48 +05:00
|
|
|
|
|
|
|
static Timer tinit("init");
|
|
|
|
tinit.Start();
|
2019-10-28 17:44:51 +05:00
|
|
|
Meshing2OCCSurfaces meshing(geom, TopoDS::Face(geom.fmap(k)), bb, projecttype, mparam);
|
2019-07-28 23:22:48 +05:00
|
|
|
tinit.Stop();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-29 02:22:47 +05:00
|
|
|
|
|
|
|
static Timer tprint("print");
|
|
|
|
tprint.Start();
|
2019-07-28 23:22:48 +05:00
|
|
|
if (meshing.GetProjectionType() == PLANESPACE)
|
|
|
|
PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (plane space projection)");
|
|
|
|
else
|
|
|
|
PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (parameter space projection)");
|
2019-07-29 02:22:47 +05:00
|
|
|
tprint.Stop();
|
2019-07-28 23:22:48 +05:00
|
|
|
if (surfmesherror)
|
|
|
|
cout << "Surface meshing error occurred before (in " << surfmesherror << " faces)" << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// Meshing2OCCSurfaces meshing(f2, bb);
|
|
|
|
meshing.SetStartTime (starttime);
|
|
|
|
//(*testout) << "Face " << k << endl << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (meshing.GetProjectionType() == PLANESPACE)
|
|
|
|
{
|
|
|
|
static Timer t("MeshSurface: Find edges and points - Physical"); RegionTimer r(t);
|
2014-01-26 03:17:16 +06:00
|
|
|
int cntp = 0;
|
|
|
|
glob2loc = 0;
|
2019-08-08 03:17:53 +05:00
|
|
|
|
|
|
|
for (Segment & seg : mesh.LineSegments())
|
|
|
|
if (seg.si == k)
|
|
|
|
for (int j = 0; j < 2; j++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-08-08 03:17:53 +05:00
|
|
|
PointIndex pi = seg[j];
|
|
|
|
if (glob2loc[pi] == 0)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2019-08-08 03:17:53 +05:00
|
|
|
meshing.AddPoint (mesh.Point(pi), pi);
|
|
|
|
cntp++;
|
|
|
|
glob2loc[pi] = cntp;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2019-08-08 03:17:53 +05:00
|
|
|
/*
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 1; i <= mesh.GetNSeg(); i++)
|
|
|
|
{
|
|
|
|
Segment & seg = mesh.LineSegment(i);
|
2019-08-08 03:17:53 +05:00
|
|
|
*/
|
|
|
|
for (Segment & seg : mesh.LineSegments())
|
|
|
|
if (seg.si == k)
|
|
|
|
{
|
|
|
|
PointGeomInfo gi0, gi1;
|
|
|
|
gi0.trignum = gi1.trignum = k;
|
|
|
|
gi0.u = seg.epgeominfo[0].u;
|
|
|
|
gi0.v = seg.epgeominfo[0].v;
|
|
|
|
gi1.u = seg.epgeominfo[1].u;
|
|
|
|
gi1.v = seg.epgeominfo[1].v;
|
|
|
|
|
|
|
|
meshing.AddBoundaryElement (glob2loc[seg[0]], glob2loc[seg[1]], gi0, gi1);
|
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static Timer t("MeshSurface: Find edges and points - Parameter"); RegionTimer r(t);
|
|
|
|
|
2014-01-26 03:17:16 +06:00
|
|
|
int cntp = 0;
|
|
|
|
|
2019-08-08 03:17:53 +05:00
|
|
|
/*
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 1; i <= mesh.GetNSeg(); i++)
|
|
|
|
if (mesh.LineSegment(i).si == k)
|
|
|
|
cntp+=2;
|
2019-08-08 03:17:53 +05:00
|
|
|
*/
|
|
|
|
for (Segment & seg : mesh.LineSegments())
|
|
|
|
if (seg.si == k)
|
|
|
|
cntp += 2;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-08-08 03:17:53 +05:00
|
|
|
NgArray<PointGeomInfo> gis;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
gis.SetAllocSize (cntp);
|
|
|
|
gis.SetSize (0);
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 1; i <= mesh.GetNSeg(); i++)
|
|
|
|
{
|
|
|
|
Segment & seg = mesh.LineSegment(i);
|
|
|
|
if (seg.si == k)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
PointGeomInfo gi0, gi1;
|
|
|
|
gi0.trignum = gi1.trignum = k;
|
|
|
|
gi0.u = seg.epgeominfo[0].u;
|
|
|
|
gi0.v = seg.epgeominfo[0].v;
|
|
|
|
gi1.u = seg.epgeominfo[1].u;
|
|
|
|
gi1.v = seg.epgeominfo[1].v;
|
|
|
|
|
|
|
|
int locpnum[2] = {0, 0};
|
|
|
|
|
|
|
|
for (int j = 0; j < 2; j++)
|
|
|
|
{
|
|
|
|
PointGeomInfo gi = (j == 0) ? gi0 : gi1;
|
|
|
|
|
2019-08-08 03:17:53 +05:00
|
|
|
/*
|
2019-07-28 23:22:48 +05:00
|
|
|
int l;
|
|
|
|
for (l = 0; l < gis.Size() && locpnum[j] == 0; l++)
|
|
|
|
{
|
|
|
|
double dist = sqr (gis[l].u-gi.u)+sqr(gis[l].v-gi.v);
|
|
|
|
|
|
|
|
if (dist < 1e-10)
|
|
|
|
locpnum[j] = l+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (locpnum[j] == 0)
|
|
|
|
{
|
2019-08-08 03:17:53 +05:00
|
|
|
PointIndex pi = seg[j];
|
2019-07-28 23:22:48 +05:00
|
|
|
meshing.AddPoint (mesh.Point(pi), pi);
|
|
|
|
|
|
|
|
gis.SetSize (gis.Size()+1);
|
|
|
|
gis[l] = gi;
|
|
|
|
locpnum[j] = l+1;
|
|
|
|
}
|
2019-08-08 03:17:53 +05:00
|
|
|
*/
|
|
|
|
for (int l = 0; l < gis.Size(); l++)
|
|
|
|
{
|
|
|
|
double dist = sqr (gis[l].u-gi.u)+sqr(gis[l].v-gi.v);
|
|
|
|
if (dist < 1e-10)
|
|
|
|
{
|
|
|
|
locpnum[j] = l+1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (locpnum[j] == 0)
|
|
|
|
{
|
|
|
|
PointIndex pi = seg[j];
|
|
|
|
meshing.AddPoint (mesh.Point(pi), pi);
|
|
|
|
|
|
|
|
gis.Append (gi);
|
|
|
|
locpnum[j] = gis.Size();
|
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
meshing.AddBoundaryElement (locpnum[0], locpnum[1], gi0, gi1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// Philippose - 15/01/2009
|
2021-08-21 01:26:20 +05:00
|
|
|
double maxh = min2(geom.face_maxh[k-1], OCCGeometry::global_shape_properties[TopoDS::Face(geom.fmap(k)).TShape()].maxh);
|
2019-07-28 23:22:48 +05:00
|
|
|
//double maxh = mparam.maxh;
|
|
|
|
// int noldpoints = mesh->GetNP();
|
|
|
|
int noldsurfel = mesh.GetNSE();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-29 02:22:47 +05:00
|
|
|
static Timer tsurfprop("surfprop");
|
|
|
|
tsurfprop.Start();
|
2019-07-28 23:22:48 +05:00
|
|
|
GProp_GProps sprops;
|
|
|
|
BRepGProp::SurfaceProperties(TopoDS::Face(geom.fmap(k)),sprops);
|
2019-07-29 02:22:47 +05:00
|
|
|
tsurfprop.Stop();
|
2019-07-28 23:22:48 +05:00
|
|
|
meshing.SetMaxArea(2.*sprops.Mass());
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
MESHING2_RESULT res;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-10-08 18:48:08 +05:00
|
|
|
// TODO: check overlap not correctly working here
|
|
|
|
MeshingParameters mparam_without_overlap = mparam;
|
|
|
|
mparam_without_overlap.checkoverlap = false;
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
try {
|
|
|
|
static Timer t("GenerateMesh"); RegionTimer reg(t);
|
2019-10-08 18:48:08 +05:00
|
|
|
res = meshing.GenerateMesh (mesh, mparam_without_overlap, maxh, k);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
catch (SingularMatrixException)
|
|
|
|
{
|
2021-09-06 19:26:12 +05:00
|
|
|
// (*myerr) << "Singular Matrix" << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
res = MESHING2_GIVEUP;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
catch (UVBoundsException)
|
|
|
|
{
|
2021-09-06 19:26:12 +05:00
|
|
|
// (*myerr) << "UV bounds exceeded" << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
res = MESHING2_GIVEUP;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
projecttype = PARAMETERSPACE;
|
|
|
|
static Timer t1("rest of loop"); RegionTimer reg1(t1);
|
|
|
|
|
|
|
|
if (res != MESHING2_OK)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
if (notrys == 1)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2019-08-08 11:44:59 +05:00
|
|
|
for (SurfaceElementIndex sei = noldsurfel; sei < mesh.GetNSE(); sei++)
|
|
|
|
mesh.Delete(sei);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.Compress();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
cout << "retry Surface " << k << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
k--;
|
2021-07-24 19:18:22 +05:00
|
|
|
// projecttype*=-1;
|
|
|
|
projecttype = PLANESPACE;
|
2019-07-28 23:22:48 +05:00
|
|
|
notrys++;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
else
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
geom.facemeshstatus[k-1] = -1;
|
|
|
|
PrintError ("Problem in Surface mesh generation");
|
|
|
|
surfmesherror++;
|
|
|
|
// throw NgException ("Problem in Surface mesh generation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
geom.facemeshstatus[k-1] = 1;
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
notrys = 1;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-08-09 03:23:12 +05:00
|
|
|
for (SurfaceElementIndex sei = oldnf; sei < mesh.GetNSE(); sei++)
|
|
|
|
mesh[sei].SetIndex (k);
|
2019-09-30 17:19:12 +05:00
|
|
|
|
|
|
|
auto n_illegal_trigs = mesh.FindIllegalTrigs();
|
|
|
|
PrintMessage (3, n_illegal_trigs, " illegal triangles");
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// ofstream problemfile("occmesh.rep");
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// problemfile << "SURFACEMESHING" << endl << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (surfmesherror)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
cout << "WARNING! NOT ALL FACES HAVE BEEN MESHED" << endl;
|
|
|
|
cout << "SURFACE MESHING ERROR OCCURRED IN " << surfmesherror << " FACES:" << endl;
|
|
|
|
for (int i = 1; i <= geom.fmap.Extent(); i++)
|
|
|
|
if (geom.facemeshstatus[i-1] == -1)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
cout << "Face " << i << endl;
|
|
|
|
// problemfile << "problem with face " << i << endl;
|
|
|
|
// problemfile << "vertices: " << endl;
|
|
|
|
TopExp_Explorer exp0,exp1,exp2;
|
|
|
|
for ( exp0.Init(TopoDS::Face (geom.fmap(i)), TopAbs_WIRE); exp0.More(); exp0.Next() )
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
TopoDS_Wire wire = TopoDS::Wire(exp0.Current());
|
|
|
|
for ( exp1.Init(wire,TopAbs_EDGE); exp1.More(); exp1.Next() )
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
|
|
|
|
for ( exp2.Init(edge,TopAbs_VERTEX); exp2.More(); exp2.Next() )
|
|
|
|
{
|
|
|
|
TopoDS_Vertex vertex = TopoDS::Vertex(exp2.Current());
|
|
|
|
gp_Pnt point = BRep_Tool::Pnt(vertex);
|
|
|
|
// problemfile << point.X() << " " << point.Y() << " " << point.Z() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// problemfile << endl;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
cout << endl << endl;
|
|
|
|
cout << "for more information open IGES/STEP Topology Explorer" << endl;
|
|
|
|
// problemfile.close();
|
|
|
|
throw NgException ("Problem in Surface mesh generation");
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
else
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
// problemfile << "OK" << endl << endl;
|
|
|
|
// problemfile.close();
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
2019-09-30 15:02:08 +05:00
|
|
|
|
|
|
|
for (int i = 0; i < mesh.GetNFD(); i++)
|
|
|
|
mesh.SetBCName (i, mesh.GetFaceDescriptor(i+1).GetBCName());
|
|
|
|
multithread.task = savetask;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-09-30 15:02:08 +05:00
|
|
|
void OCCOptimizeSurface(OCCGeometry & geom, Mesh & mesh,
|
2019-10-02 20:20:13 +05:00
|
|
|
const MeshingParameters & mparam)
|
2019-09-30 15:02:08 +05:00
|
|
|
{
|
|
|
|
const char * savetask = multithread.task;
|
2019-07-28 23:22:48 +05:00
|
|
|
multithread.task = "Optimizing surface";
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
static Timer timer_opt2d("Optimization 2D");
|
|
|
|
timer_opt2d.Start();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int k = 1; k <= mesh.GetNFD(); k++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
// if (k != 42) continue;
|
|
|
|
// if (k != 36) continue;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// (*testout) << "optimize face " << k << endl;
|
|
|
|
multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
PrintMessage (1, "Optimize Surface ", k);
|
|
|
|
for (int i = 1; i <= mparam.optsteps2d; i++)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
// (*testout) << "optstep " << i << endl;
|
|
|
|
if (multithread.terminate) return;
|
|
|
|
|
|
|
|
{
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2019-07-28 23:22:48 +05:00
|
|
|
meshopt.SetFaceIndex (k);
|
|
|
|
meshopt.SetImproveEdges (0);
|
|
|
|
meshopt.SetMetricWeight (mparam.elsizeweight);
|
|
|
|
meshopt.SetWriteStatus (0);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.EdgeSwapping (i > mparam.optsteps2d/2);
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (multithread.terminate) return;
|
|
|
|
{
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2019-07-28 23:22:48 +05:00
|
|
|
meshopt.SetFaceIndex (k);
|
|
|
|
meshopt.SetImproveEdges (0);
|
|
|
|
meshopt.SetMetricWeight (mparam.elsizeweight);
|
|
|
|
meshopt.SetWriteStatus (0);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.ImproveMesh (mparam);
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2019-07-28 23:22:48 +05:00
|
|
|
meshopt.SetFaceIndex (k);
|
|
|
|
meshopt.SetImproveEdges (0);
|
|
|
|
meshopt.SetMetricWeight (mparam.elsizeweight);
|
|
|
|
meshopt.SetWriteStatus (0);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.CombineImprove ();
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (multithread.terminate) return;
|
|
|
|
{
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2019-07-28 23:22:48 +05:00
|
|
|
meshopt.SetFaceIndex (k);
|
|
|
|
meshopt.SetImproveEdges (0);
|
|
|
|
meshopt.SetMetricWeight (mparam.elsizeweight);
|
|
|
|
meshopt.SetWriteStatus (0);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.ImproveMesh (mparam);
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.CalcSurfacesOfNode();
|
|
|
|
mesh.Compress();
|
|
|
|
timer_opt2d.Stop();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
multithread.task = savetask;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-02 20:20:13 +05:00
|
|
|
void OCCSetLocalMeshSize(const OCCGeometry & geom, Mesh & mesh,
|
2019-08-27 13:10:17 +05:00
|
|
|
const MeshingParameters & mparam, const OCCParameters& occparam)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2019-10-04 17:55:36 +05:00
|
|
|
static Timer t1("OCCSetLocalMeshSize");
|
|
|
|
RegionTimer regt(t1);
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.SetGlobalH (mparam.maxh);
|
|
|
|
mesh.SetMinimalH (mparam.minh);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
NgArray<double> maxhdom;
|
|
|
|
maxhdom.SetSize (geom.NrSolids());
|
|
|
|
maxhdom = mparam.maxh;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-09-13 15:47:36 +05:00
|
|
|
int dom = 0;
|
|
|
|
for (TopExp_Explorer e(geom.GetShape(), TopAbs_SOLID); e.More(); e.Next(), dom++)
|
|
|
|
maxhdom[dom] = min2(maxhdom[dom], OCCGeometry::global_shape_properties[e.Current().TShape()].maxh);
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.SetMaxHDomain (maxhdom);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
Box<3> bb = geom.GetBoundingBox();
|
|
|
|
bb.Increase (bb.Diam()/10);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.SetLocalH (bb.PMin(), bb.PMax(), 0.5);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (mparam.uselocalh)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
const char * savetask = multithread.task;
|
|
|
|
multithread.percent = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.SetLocalH (bb.PMin(), bb.PMax(), mparam.grading);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int nedges = geom.emap.Extent();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
double mincurvelength = IGNORECURVELENGTH;
|
|
|
|
double maxedgelen = 0;
|
|
|
|
double minedgelen = 1e99;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if(occparam.resthminedgelenenable)
|
|
|
|
{
|
|
|
|
mincurvelength = occparam.resthminedgelen;
|
|
|
|
if(mincurvelength < IGNORECURVELENGTH) mincurvelength = IGNORECURVELENGTH;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
multithread.task = "Setting local mesh size (elements per edge)";
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
// Philippose - 23/01/2009
|
|
|
|
// Find all the parent faces of a given edge
|
|
|
|
// and limit the mesh size of the edge based on the
|
|
|
|
// mesh size limit of the face
|
|
|
|
TopTools_IndexedDataMapOfShapeListOfShape edge_face_map;
|
|
|
|
edge_face_map.Clear();
|
|
|
|
TopExp::MapShapesAndAncestors(geom.shape, TopAbs_EDGE, TopAbs_FACE, edge_face_map);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
// setting elements per edge
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 1; i <= nedges && !multithread.terminate; i++)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
TopoDS_Edge e = TopoDS::Edge (geom.emap(i));
|
|
|
|
multithread.percent = 100 * (i-1)/double(nedges);
|
|
|
|
if (BRep_Tool::Degenerated(e)) continue;
|
|
|
|
|
|
|
|
GProp_GProps system;
|
|
|
|
BRepGProp::LinearProperties(e, system);
|
|
|
|
double len = system.Mass();
|
|
|
|
|
|
|
|
if (len < mincurvelength)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
(*testout) << "ignored" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
double localh = len/mparam.segmentsperedge;
|
|
|
|
double s0, s1;
|
|
|
|
|
|
|
|
const TopTools_ListOfShape& parent_faces = edge_face_map.FindFromKey(e);
|
|
|
|
|
|
|
|
TopTools_ListIteratorOfListOfShape parent_face_list;
|
|
|
|
|
|
|
|
for(parent_face_list.Initialize(parent_faces); parent_face_list.More(); parent_face_list.Next())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
TopoDS_Face parent_face = TopoDS::Face(parent_face_list.Value());
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int face_index = geom.fmap.FindIndex(parent_face);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if(face_index >= 1) localh = min(localh,geom.face_maxh[face_index - 1]);
|
2021-08-21 01:26:20 +05:00
|
|
|
localh = min2(localh, OCCGeometry::global_shape_properties[parent_face.TShape()].maxh);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
Handle(Geom_Curve) c = BRep_Tool::Curve(e, s0, s1);
|
|
|
|
|
2021-08-21 01:26:20 +05:00
|
|
|
localh = min2(localh, OCCGeometry::global_shape_properties[e.TShape()].maxh);
|
2014-01-26 03:17:16 +06:00
|
|
|
maxedgelen = max (maxedgelen, len);
|
|
|
|
minedgelen = min (minedgelen, len);
|
|
|
|
int maxj = max((int) ceil(len/localh), 2);
|
|
|
|
|
|
|
|
for (int j = 0; j <= maxj; j++)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
gp_Pnt pnt = c->Value (s0+double(j)/maxj*(s1-s0));
|
|
|
|
mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), localh);
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
multithread.task = "Setting local mesh size (edge curvature)";
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// setting edge curvature
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int nsections = 20;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 1; i <= nedges && !multithread.terminate; i++)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
double maxcur = 0;
|
|
|
|
multithread.percent = 100 * (i-1)/double(nedges);
|
|
|
|
TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
|
|
|
|
if (BRep_Tool::Degenerated(edge)) continue;
|
|
|
|
double s0, s1;
|
|
|
|
Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
|
|
|
|
BRepAdaptor_Curve brepc(edge);
|
|
|
|
BRepLProp_CLProps prop(brepc, 2, 1e-5);
|
|
|
|
|
|
|
|
for (int j = 1; j <= nsections; j++)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
double s = s0 + j/(double) nsections * (s1-s0);
|
|
|
|
prop.SetParameter (s);
|
2019-11-19 14:00:05 +05:00
|
|
|
double curvature = 0;
|
|
|
|
if(prop.IsTangentDefined())
|
|
|
|
curvature = prop.Curvature();
|
2019-07-28 23:22:48 +05:00
|
|
|
if(curvature> maxcur) maxcur = curvature;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
if (curvature >= 1e99)
|
2014-01-26 03:17:16 +06:00
|
|
|
continue;
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
gp_Pnt pnt = c->Value (s);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), ComputeH (fabs(curvature), mparam));
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
multithread.task = "Setting local mesh size (face curvature)";
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
// setting face curvature
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
int nfaces = geom.fmap.Extent();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 1; i <= nfaces && !multithread.terminate; i++)
|
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
multithread.percent = 100 * (i-1)/double(nfaces);
|
|
|
|
TopoDS_Face face = TopoDS::Face(geom.fmap(i));
|
|
|
|
TopLoc_Location loc;
|
|
|
|
Handle(Geom_Surface) surf = BRep_Tool::Surface (face);
|
|
|
|
Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc);
|
|
|
|
|
2017-10-20 19:39:37 +05:00
|
|
|
if (triangulation.IsNull())
|
|
|
|
{
|
|
|
|
BRepTools::Clean (geom.shape);
|
|
|
|
BRepMesh_IncrementalMesh (geom.shape, 0.01, true);
|
|
|
|
triangulation = BRep_Tool::Triangulation (face, loc);
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
BRepAdaptor_Surface sf(face, Standard_True);
|
2019-10-04 17:55:36 +05:00
|
|
|
// one prop for evaluating and one for derivatives
|
|
|
|
BRepLProp_SLProps prop(sf, 0, 1e-5);
|
|
|
|
BRepLProp_SLProps prop2(sf, 2, 1e-5);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
int ntriangles = triangulation -> NbTriangles();
|
|
|
|
for (int j = 1; j <= ntriangles; j++)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
gp_Pnt p[3];
|
|
|
|
gp_Pnt2d par[3];
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int k = 1; k <=3; k++)
|
|
|
|
{
|
2021-08-31 03:37:41 +05:00
|
|
|
// int n = triangulation->Triangles()(j)(k);
|
|
|
|
// p[k-1] = triangulation->Nodes()(n).Transformed(loc);
|
|
|
|
// par[k-1] = triangulation->UVNodes()(n);
|
|
|
|
// fix for OCC7.6.0-dev
|
|
|
|
int n = triangulation->Triangle(j)(k);
|
|
|
|
p[k-1] = triangulation->Node(n).Transformed(loc);
|
|
|
|
par[k-1] = triangulation->UVNode(n);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
//double maxside = 0;
|
|
|
|
//maxside = max (maxside, p[0].Distance(p[1]));
|
|
|
|
//maxside = max (maxside, p[0].Distance(p[2]));
|
|
|
|
//maxside = max (maxside, p[1].Distance(p[2]));
|
|
|
|
//cout << "\rFace " << i << " pos11 ntriangles " << ntriangles << " maxside " << maxside << flush;
|
|
|
|
|
2019-10-04 17:55:36 +05:00
|
|
|
RestrictHTriangle (par[0], par[1], par[2], &prop, &prop2, mesh, 0, 0, mparam);
|
2019-07-28 23:22:48 +05:00
|
|
|
//cout << "\rFace " << i << " pos12 ntriangles " << ntriangles << flush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// setting close edges
|
|
|
|
|
2019-11-04 23:34:46 +05:00
|
|
|
if (mparam.closeedgefac.has_value())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2014-01-26 03:17:16 +06:00
|
|
|
multithread.task = "Setting local mesh size (close edges)";
|
|
|
|
|
|
|
|
int sections = 100;
|
|
|
|
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<Line> lines(sections*nedges);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-08-08 03:17:53 +05:00
|
|
|
/*
|
2017-11-10 17:22:20 +05:00
|
|
|
BoxTree<3> * searchtree =
|
|
|
|
new BoxTree<3> (bb.PMin(), bb.PMax());
|
2019-08-08 03:17:53 +05:00
|
|
|
*/
|
|
|
|
BoxTree<3> searchtree(bb.PMin(), bb.PMax());
|
|
|
|
|
2014-01-26 03:17:16 +06:00
|
|
|
int nlines = 0;
|
|
|
|
for (int i = 1; i <= nedges && !multithread.terminate; i++)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
|
|
|
|
if (BRep_Tool::Degenerated(edge)) continue;
|
|
|
|
|
|
|
|
double s0, s1;
|
|
|
|
Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
|
|
|
|
BRepAdaptor_Curve brepc(edge);
|
|
|
|
BRepLProp_CLProps prop(brepc, 1, 1e-5);
|
|
|
|
prop.SetParameter (s0);
|
|
|
|
|
|
|
|
gp_Vec d0 = prop.D1().Normalized();
|
|
|
|
double s_start = s0;
|
|
|
|
int count = 0;
|
|
|
|
for (int j = 1; j <= sections; j++)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2019-07-28 23:22:48 +05:00
|
|
|
double s = s0 + (s1-s0)*(double)j/(double)sections;
|
|
|
|
prop.SetParameter (s);
|
|
|
|
gp_Vec d1 = prop.D1().Normalized();
|
|
|
|
double cosalpha = fabs(d0*d1);
|
|
|
|
if ((j == sections) || (cosalpha < cos(10.0/180.0*M_PI)))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
gp_Pnt p0 = c->Value (s_start);
|
|
|
|
gp_Pnt p1 = c->Value (s);
|
|
|
|
lines[nlines].p0 = Point<3> (p0.X(), p0.Y(), p0.Z());
|
|
|
|
lines[nlines].p1 = Point<3> (p1.X(), p1.Y(), p1.Z());
|
|
|
|
|
|
|
|
Box3d box;
|
|
|
|
box.SetPoint (Point3d(lines[nlines].p0));
|
|
|
|
box.AddPoint (Point3d(lines[nlines].p1));
|
|
|
|
|
2019-08-08 03:17:53 +05:00
|
|
|
searchtree.Insert (box.PMin(), box.PMax(), nlines+1);
|
2019-07-28 23:22:48 +05:00
|
|
|
nlines++;
|
|
|
|
|
|
|
|
s_start = s;
|
|
|
|
d0 = d1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
NgArray<int> linenums;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
for (int i = 0; i < nlines; i++)
|
|
|
|
{
|
|
|
|
multithread.percent = (100*i)/double(nlines);
|
|
|
|
Line & line = lines[i];
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
Box3d box;
|
|
|
|
box.SetPoint (Point3d(line.p0));
|
|
|
|
box.AddPoint (Point3d(line.p1));
|
|
|
|
double maxhline = max (mesh.GetH(box.PMin()),
|
|
|
|
mesh.GetH(box.PMax()));
|
|
|
|
box.Increase(maxhline);
|
|
|
|
|
|
|
|
double mindist = 1e99;
|
|
|
|
linenums.SetSize(0);
|
2019-08-08 03:17:53 +05:00
|
|
|
searchtree.GetIntersecting(box.PMin(),box.PMax(),linenums);
|
2019-07-28 23:22:48 +05:00
|
|
|
|
|
|
|
for (int j = 0; j < linenums.Size(); j++)
|
|
|
|
{
|
|
|
|
int num = linenums[j]-1;
|
|
|
|
if (i == num) continue;
|
|
|
|
if ((line.p0-lines[num].p0).Length2() < 1e-15) continue;
|
|
|
|
if ((line.p0-lines[num].p1).Length2() < 1e-15) continue;
|
|
|
|
if ((line.p1-lines[num].p0).Length2() < 1e-15) continue;
|
|
|
|
if ((line.p1-lines[num].p1).Length2() < 1e-15) continue;
|
|
|
|
mindist = min (mindist, line.Dist(lines[num]));
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2019-11-05 19:19:54 +05:00
|
|
|
mindist /= (*mparam.closeedgefac + VSMALL);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-09-16 18:38:20 +05:00
|
|
|
if (mindist < 1e-3 * bb.Diam())
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
(*testout) << "extremely small local h: " << mindist
|
2019-09-16 18:38:20 +05:00
|
|
|
<< " --> setting to " << 1e-3 * bb.Diam() << endl;
|
2019-07-28 23:22:48 +05:00
|
|
|
(*testout) << "somewhere near " << line.p0 << " - " << line.p1 << endl;
|
2019-09-16 18:38:20 +05:00
|
|
|
mindist = 1e-3 * bb.Diam();
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.RestrictLocalHLine(line.p0, line.p1, mindist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 12:52:51 +05:00
|
|
|
for (auto mspnt : mparam.meshsize_points)
|
|
|
|
mesh.RestrictLocalH(mspnt.pnt, mspnt.h);
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
multithread.task = savetask;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
mesh.LoadLocalMeshSize (mparam.meshsizefilename);
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|