2014-01-26 03:17:16 +06:00
|
|
|
#ifdef OCCGEOMETRY
|
|
|
|
|
|
|
|
#include <mystdlib.h>
|
|
|
|
#include <meshing.hpp>
|
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
#include "occgeom.hpp"
|
2022-03-30 15:47:07 +05:00
|
|
|
#include "occ_face.hpp"
|
2021-11-28 20:14:41 +05:00
|
|
|
#include "occmeshsurf.hpp"
|
|
|
|
|
|
|
|
#include <BRepAdaptor_Curve.hxx>
|
|
|
|
#include <BRepGProp.hxx>
|
|
|
|
#include <BRepLProp_CLProps.hxx>
|
|
|
|
#include <BRepLProp_SLProps.hxx>
|
|
|
|
#include <BRepMesh_IncrementalMesh.hxx>
|
|
|
|
#include <BRepTools.hxx>
|
|
|
|
#include <GProp_GProps.hxx>
|
|
|
|
#include <Quantity_Color.hxx>
|
|
|
|
#include <ShapeAnalysis.hxx>
|
|
|
|
#include <TopExp.hxx>
|
|
|
|
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
|
|
|
|
#include <TopoDS_Edge.hxx>
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
namespace netgen
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
#define TCL_OK 0
|
|
|
|
#define TCL_ERROR 1
|
|
|
|
|
2021-08-15 16:29:28 +05:00
|
|
|
#define DIVIDEEDGESECTIONS 10000 // better solution to come soon
|
2022-01-18 22:21:16 +05:00
|
|
|
#define IGNORECURVELENGTH 0
|
2014-01-26 03:17:16 +06:00
|
|
|
#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,
|
2022-03-10 23:04:44 +05:00
|
|
|
BRepLProp_SLProps * prop, BRepLProp_SLProps * prop2, Mesh & mesh, int depth, double h, int layer, const MeshingParameters & mparam)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
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()));
|
2022-03-10 23:04:44 +05:00
|
|
|
RestrictHTriangle(pm, par2, par0, prop, prop2, mesh, depth+1, h, layer, mparam);
|
|
|
|
RestrictHTriangle(pm, par0, par1, prop, prop2, mesh, depth+1, h, layer, 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()));
|
2022-03-10 23:04:44 +05:00
|
|
|
RestrictHTriangle(pm, par1, par2, prop, prop2, mesh, depth+1, h, layer, mparam);
|
|
|
|
RestrictHTriangle(pm, par0, par1, prop, prop2, mesh, depth+1, h, layer, 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()));
|
2022-03-10 23:04:44 +05:00
|
|
|
RestrictHTriangle(pm, par1, par2, prop, prop2, mesh, depth+1, h, layer, mparam);
|
|
|
|
RestrictHTriangle(pm, par2, par0, prop, prop2, mesh, depth+1, h, layer, 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());
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalH (p3d, h, layer);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
p3d = Point3d(pnt0.X(), pnt0.Y(), pnt0.Z());
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalH (p3d, h, layer);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
p3d = Point3d(pnt1.X(), pnt1.Y(), pnt1.Z());
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalH (p3d, h, layer);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
p3d = Point3d(pnt2.X(), pnt2.Y(), pnt2.Z());
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalH (p3d, h, layer);
|
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
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
bool OCCMeshFace (const OCCGeometry & geom, Mesh & mesh, FlatArray<int, PointIndex> glob2loc,
|
|
|
|
const MeshingParameters & mparam, int nr, int projecttype, bool delete_on_failure)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2021-11-28 20:14:41 +05:00
|
|
|
auto k = nr+1;
|
|
|
|
if(1==0 && !geom.fvispar[k-1].IsDrawable())
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2021-11-28 20:14:41 +05:00
|
|
|
(*testout) << "ignoring face " << k << endl;
|
|
|
|
cout << "ignoring face " << k << endl;
|
|
|
|
return true;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
// if(master_faces[k]!=k)
|
|
|
|
// continue;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +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
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
|
|
|
|
auto face = TopoDS::Face(geom.fmap(k));
|
2022-03-30 15:47:07 +05:00
|
|
|
const auto& occface = dynamic_cast<const OCCFace&>(geom.GetFace(k-1));
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
int oldnf = mesh.GetNSE();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
Box<3> bb = geom.GetBoundingBox();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
// int projecttype = PLANESPACE;
|
|
|
|
// int projecttype = PARAMETERSPACE;
|
|
|
|
|
|
|
|
static Timer tinit("init");
|
|
|
|
tinit.Start();
|
|
|
|
Meshing2OCCSurfaces meshing(geom, face, bb, projecttype, mparam);
|
|
|
|
tinit.Stop();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
static Timer tprint("print");
|
|
|
|
tprint.Start();
|
|
|
|
if (meshing.GetProjectionType() == PLANESPACE)
|
2021-12-01 00:26:35 +05:00
|
|
|
PrintMessage (2, "Face ", k, " / ", geom.GetNFaces(), " (plane space projection)");
|
2021-11-28 20:14:41 +05:00
|
|
|
else
|
2021-12-01 00:26:35 +05:00
|
|
|
PrintMessage (2, "Face ", k, " / ", geom.GetNFaces(), " (parameter space projection)");
|
2021-11-28 20:14:41 +05:00
|
|
|
tprint.Stop();
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
// Meshing2OCCSurfaces meshing(f2, bb);
|
|
|
|
// meshing.SetStartTime (starttime);
|
|
|
|
//(*testout) << "Face " << k << endl << endl;
|
2021-09-03 00:48:05 +05:00
|
|
|
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
auto segments = geom.GetFace(k-1).GetBoundary(mesh);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
if (meshing.GetProjectionType() == PLANESPACE)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2021-11-28 20:14:41 +05:00
|
|
|
static Timer t("MeshSurface: Find edges and points - Physical"); RegionTimer r(t);
|
|
|
|
int cntp = 0;
|
|
|
|
glob2loc = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
for (Segment & seg : segments)
|
|
|
|
// if (seg.si == k)
|
|
|
|
for (int j = 0; j < 2; j++)
|
|
|
|
{
|
|
|
|
PointIndex pi = seg[j];
|
|
|
|
if (glob2loc[pi] == 0)
|
|
|
|
{
|
|
|
|
meshing.AddPoint (mesh.Point(pi), pi);
|
|
|
|
cntp++;
|
|
|
|
glob2loc[pi] = cntp;
|
|
|
|
}
|
|
|
|
}
|
2022-03-30 15:47:07 +05:00
|
|
|
for(const auto& vert : geom.GetFaceVertices(geom.GetFace(k-1)))
|
|
|
|
{
|
|
|
|
PointIndex pi = vert->nr + 1;
|
|
|
|
if(glob2loc[pi] == 0)
|
|
|
|
{
|
|
|
|
auto gi = occface.Project(mesh[pi]);
|
|
|
|
MultiPointGeomInfo mgi;
|
|
|
|
mgi.AddPointGeomInfo(gi);
|
|
|
|
meshing.AddPoint(mesh[pi], pi, &mgi);
|
|
|
|
cntp++;
|
|
|
|
glob2loc[pi] = cntp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
/*
|
|
|
|
for (int i = 1; i <= mesh.GetNSeg(); i++)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
2021-11-28 20:14:41 +05:00
|
|
|
Segment & seg = mesh.LineSegment(i);
|
|
|
|
*/
|
|
|
|
// for (Segment & seg : mesh.LineSegments())
|
|
|
|
for (Segment & seg : segments)
|
|
|
|
//if (seg.si == k)
|
2021-11-07 04:16:57 +05:00
|
|
|
{
|
2021-11-28 20:14:41 +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;
|
|
|
|
|
|
|
|
//if(orientation & 1)
|
|
|
|
meshing.AddBoundaryElement (glob2loc[seg[0]], glob2loc[seg[1]], gi0, gi1);
|
|
|
|
|
2021-11-07 04:16:57 +05:00
|
|
|
}
|
|
|
|
}
|
2021-11-28 20:14:41 +05:00
|
|
|
else
|
2021-11-06 20:14:19 +05:00
|
|
|
{
|
2021-11-28 20:14:41 +05:00
|
|
|
static Timer t("MeshSurface: Find edges and points - Parameter"); RegionTimer r(t);
|
2022-03-30 15:47:07 +05:00
|
|
|
|
2021-12-01 15:36:28 +05:00
|
|
|
Array<PointGeomInfo> gis(2*segments.Size());
|
|
|
|
gis.SetSize (0);
|
2022-03-30 15:47:07 +05:00
|
|
|
glob2loc = 0;
|
|
|
|
int cntpt = 0;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-12-01 15:36:28 +05:00
|
|
|
Box<2> uv_box(Box<2>::EMPTY_BOX);
|
|
|
|
for(auto & seg : segments)
|
|
|
|
for(auto i : Range(2))
|
|
|
|
uv_box.Add( {seg.epgeominfo[i].u, seg.epgeominfo[i].v } );
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-12-01 15:36:28 +05:00
|
|
|
BoxTree<2> uv_tree(uv_box);
|
2023-01-16 23:57:48 +05:00
|
|
|
double tol = 1e99;
|
|
|
|
for(auto& seg : segments)
|
|
|
|
{
|
|
|
|
Point<2> p1 = { seg.epgeominfo[0].u, seg.epgeominfo[0].v };
|
|
|
|
Point<2> p2 = { seg.epgeominfo[1].u, seg.epgeominfo[1].v };
|
|
|
|
tol = min2(tol, Dist(p1, p2));
|
|
|
|
}
|
|
|
|
uv_tree.SetTolerance(0.9 * tol);
|
2021-12-01 15:36:28 +05:00
|
|
|
Array<int> found_points;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
for(auto & seg : segments)
|
2021-12-01 15:36:28 +05:00
|
|
|
{
|
|
|
|
PointGeomInfo gi[2];
|
|
|
|
gi[0].trignum = gi[1].trignum = k;
|
|
|
|
gi[0].u = seg.epgeominfo[0].u;
|
|
|
|
gi[0].v = seg.epgeominfo[0].v;
|
|
|
|
gi[1].u = seg.epgeominfo[1].u;
|
|
|
|
gi[1].v = seg.epgeominfo[1].v;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-12-01 15:36:28 +05:00
|
|
|
int locpnum[2] = {0, 0};
|
2019-07-28 23:22:48 +05:00
|
|
|
|
2021-12-01 15:36:28 +05:00
|
|
|
for (int j = 0; j < 2; j++)
|
|
|
|
{
|
|
|
|
Point<2> uv = {gi[j].u, gi[j].v};
|
|
|
|
uv_tree.GetIntersecting(uv, uv, found_points);
|
|
|
|
|
2023-01-16 23:57:48 +05:00
|
|
|
bool found = false;
|
|
|
|
for(auto& fp : found_points)
|
|
|
|
{
|
|
|
|
if(meshing.GetGlobalIndex(fp - 1) == seg[j])
|
|
|
|
{
|
|
|
|
locpnum[j] = fp;
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!found)
|
2021-12-01 15:36:28 +05:00
|
|
|
{
|
|
|
|
PointIndex pi = seg[j];
|
2023-01-16 23:57:48 +05:00
|
|
|
locpnum[j] = meshing.AddPoint (mesh.Point(pi), pi) + 1;
|
|
|
|
glob2loc[pi] = locpnum[j];
|
2021-12-01 15:36:28 +05:00
|
|
|
gis.Append (gi[j]);
|
|
|
|
uv_tree.Insert(uv, locpnum[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
meshing.AddBoundaryElement (locpnum[0], locpnum[1], gi[0], gi[1]);
|
|
|
|
}
|
2022-03-30 15:47:07 +05:00
|
|
|
for(const auto& vert : geom.GetFaceVertices(geom.GetFace(k-1)))
|
|
|
|
{
|
|
|
|
PointIndex pi = vert->nr + 1;
|
|
|
|
if(glob2loc[pi] == 0)
|
|
|
|
{
|
|
|
|
auto gi = occface.Project(mesh[pi]);
|
|
|
|
MultiPointGeomInfo mgi;
|
|
|
|
mgi.AddPointGeomInfo(gi);
|
2023-01-16 23:57:48 +05:00
|
|
|
glob2loc[pi] = meshing.AddPoint(mesh[pi], pi, &mgi) + 1;
|
2022-03-30 15:47:07 +05:00
|
|
|
gis.Append(gi);
|
|
|
|
Point<2> uv = { gi.u, gi.v };
|
2023-01-16 23:57:48 +05:00
|
|
|
uv_tree.Insert(uv, glob2loc[pi]);
|
2022-03-30 15:47:07 +05:00
|
|
|
}
|
|
|
|
}
|
2021-11-28 20:14:41 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
// Philippose - 15/01/2009
|
2022-12-06 21:51:19 +05:00
|
|
|
auto& props = OCCGeometry::GetProperties(geom.fmap(k));
|
|
|
|
double maxh = min2(geom.face_maxh[k-1], props.maxh);
|
2021-11-28 20:14:41 +05:00
|
|
|
//double maxh = mparam.maxh;
|
|
|
|
// int noldpoints = mesh->GetNP();
|
|
|
|
int noldsurfel = mesh.GetNSE();
|
2022-12-06 21:51:19 +05:00
|
|
|
int layer = props.layer;
|
2019-09-30 17:19:12 +05:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
static Timer tsurfprop("surfprop");
|
|
|
|
tsurfprop.Start();
|
|
|
|
GProp_GProps sprops;
|
|
|
|
BRepGProp::SurfaceProperties(TopoDS::Face(geom.fmap(k)),sprops);
|
|
|
|
tsurfprop.Stop();
|
|
|
|
meshing.SetMaxArea(2.*sprops.Mass());
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
MESHING2_RESULT res;
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
// TODO: check overlap not correctly working here
|
|
|
|
MeshingParameters mparam_without_overlap = mparam;
|
|
|
|
mparam_without_overlap.checkoverlap = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
static Timer t("GenerateMesh"); RegionTimer reg(t);
|
2022-03-10 23:04:44 +05:00
|
|
|
res = meshing.GenerateMesh (mesh, mparam_without_overlap, maxh, k, layer);
|
2021-11-28 20:14:41 +05:00
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
catch (SingularMatrixException)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2021-11-28 20:14:41 +05:00
|
|
|
// (*myerr) << "Singular Matrix" << endl;
|
|
|
|
res = MESHING2_GIVEUP;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
catch (UVBoundsException)
|
2014-01-26 03:17:16 +06:00
|
|
|
{
|
2021-11-28 20:14:41 +05:00
|
|
|
// (*myerr) << "UV bounds exceeded" << endl;
|
|
|
|
res = MESHING2_GIVEUP;
|
2014-01-26 03:17:16 +06:00
|
|
|
}
|
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
static Timer t1("rest of loop"); RegionTimer reg1(t1);
|
|
|
|
|
|
|
|
bool meshing_failed = res != MESHING2_OK;
|
|
|
|
if(meshing_failed && delete_on_failure)
|
|
|
|
{
|
|
|
|
for (SurfaceElementIndex sei = noldsurfel; sei < mesh.GetNSE(); sei++)
|
|
|
|
mesh.Delete(sei);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
mesh.Compress();
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
for (SurfaceElementIndex sei = oldnf; sei < mesh.GetNSE(); sei++)
|
|
|
|
mesh[sei].SetIndex (k);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2021-11-28 20:14:41 +05:00
|
|
|
auto n_illegal_trigs = mesh.FindIllegalTrigs();
|
|
|
|
PrintMessage (3, n_illegal_trigs, " illegal triangles");
|
|
|
|
return meshing_failed;
|
|
|
|
}
|
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;
|
2022-03-10 23:04:44 +05:00
|
|
|
int maxlayer = 1;
|
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++)
|
2022-03-10 23:04:44 +05:00
|
|
|
{
|
2022-12-06 21:51:19 +05:00
|
|
|
auto& props = OCCGeometry::GetProperties(e.Current());
|
|
|
|
maxhdom[dom] = min2(maxhdom[dom], props.maxh);
|
|
|
|
maxlayer = max2(maxlayer, props.layer);
|
2022-03-10 23:04:44 +05:00
|
|
|
}
|
|
|
|
|
2021-09-13 15:47:36 +05:00
|
|
|
|
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
|
|
|
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
|
|
|
|
2022-03-10 23:04:44 +05:00
|
|
|
for(auto layer : Range(1, maxlayer+1))
|
|
|
|
mesh.SetLocalH (bb.PMin(), bb.PMax(), mparam.grading, layer);
|
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));
|
2022-12-06 21:51:19 +05:00
|
|
|
int layer = OCCGeometry::GetProperties(e).layer;
|
2014-01-26 03:17:16 +06:00
|
|
|
multithread.percent = 100 * (i-1)/double(nedges);
|
|
|
|
if (BRep_Tool::Degenerated(e)) continue;
|
|
|
|
|
2023-02-13 19:57:53 +05:00
|
|
|
double len = Mass(e);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
if (len < mincurvelength)
|
2019-07-28 23:22:48 +05:00
|
|
|
{
|
|
|
|
(*testout) << "ignored" << endl;
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2022-01-18 22:24:09 +05:00
|
|
|
bool is_identified_edge = false;
|
|
|
|
// TODO: change to use hash value
|
2022-11-15 16:58:36 +05:00
|
|
|
const auto& gedge = geom.GetEdge(e);
|
2022-01-18 22:24:09 +05:00
|
|
|
auto& v0 = gedge.GetStartVertex();
|
|
|
|
auto& v1 = gedge.GetEndVertex();
|
|
|
|
for(auto & ident : v0.identifications)
|
|
|
|
{
|
|
|
|
auto other = ident.from == &v0 ? ident.to : ident.from;
|
|
|
|
if(other->nr == v1.nr && ident.type == Identifications::CLOSESURFACES)
|
|
|
|
{
|
|
|
|
is_identified_edge = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(is_identified_edge)
|
|
|
|
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]);
|
2022-12-06 21:51:19 +05:00
|
|
|
localh = min2(localh, OCCGeometry::GetProperties(parent_face).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);
|
|
|
|
|
2022-12-06 21:51:19 +05:00
|
|
|
localh = min2(localh, OCCGeometry::GetProperties(e).maxh);
|
2014-01-26 03:17:16 +06:00
|
|
|
maxedgelen = max (maxedgelen, len);
|
|
|
|
minedgelen = min (minedgelen, len);
|
2023-02-13 19:57:53 +05:00
|
|
|
int maxj = max((int) ceil(len/localh)*2, 2);
|
2014-01-26 03:17:16 +06:00
|
|
|
|
|
|
|
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));
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), localh, layer);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
}
|
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));
|
2022-12-06 21:51:19 +05:00
|
|
|
int layer = OCCGeometry::GetProperties(edge).layer;
|
2014-01-26 03:17:16 +06:00
|
|
|
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
|
|
|
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), ComputeH (fabs(curvature), mparam), layer);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
}
|
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));
|
2022-12-06 21:51:19 +05:00
|
|
|
int layer = OCCGeometry::GetProperties(face).layer;
|
2014-01-26 03:17:16 +06:00
|
|
|
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;
|
|
|
|
|
2022-03-10 23:04:44 +05:00
|
|
|
RestrictHTriangle (par[0], par[1], par[2], &prop, &prop2, mesh, 0, 0, layer, 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;
|
2022-02-02 19:09:41 +05:00
|
|
|
Array<int> edgenumber;
|
2014-01-26 03:17:16 +06:00
|
|
|
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));
|
2022-12-06 21:51:19 +05:00
|
|
|
int layer = OCCGeometry::GetProperties(edge).layer;
|
2019-07-28 23:22:48 +05:00
|
|
|
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());
|
2022-03-10 23:04:44 +05:00
|
|
|
lines[nlines].layer = layer;
|
2019-07-28 23:22:48 +05:00
|
|
|
|
|
|
|
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++;
|
2022-02-02 19:09:41 +05:00
|
|
|
edgenumber.Append(i);
|
2019-07-28 23:22:48 +05:00
|
|
|
|
|
|
|
s_start = s;
|
|
|
|
d0 = d1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 03:17:16 +06:00
|
|
|
|
2019-07-28 23:22:48 +05:00
|
|
|
NgArray<int> linenums;
|
2022-02-02 19:09:41 +05:00
|
|
|
auto is_identified_edge = [&](int e0, int e1) {
|
|
|
|
const auto& edge0 = geom.GetEdge(e0-1);
|
|
|
|
const auto& edge1 = geom.GetEdge(e1-1);
|
|
|
|
|
|
|
|
if(edge0.primary == edge1.primary)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Array<const GeometryVertex *> v0 = { &edge0.GetStartVertex(), &edge0.GetEndVertex() };
|
|
|
|
Array<const GeometryVertex *> v1 = { &edge1.GetStartVertex(), &edge1.GetEndVertex() };
|
|
|
|
for(auto i : Range(2))
|
|
|
|
for(auto j : Range(2))
|
|
|
|
if(v0[i]->primary == v1[j]->primary)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
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));
|
2022-03-10 23:04:44 +05:00
|
|
|
double maxhline = max (mesh.GetH(box.PMin(), line.layer),
|
|
|
|
mesh.GetH(box.PMax(), line.layer));
|
2019-07-28 23:22:48 +05:00
|
|
|
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;
|
2022-03-10 23:04:44 +05:00
|
|
|
if (line.layer != lines[num].layer) continue;
|
2022-02-02 19:09:41 +05:00
|
|
|
if( is_identified_edge(edgenumber[i], edgenumber[num]) ) continue;
|
2019-07-28 23:22:48 +05:00
|
|
|
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
|
|
|
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalHLine(line.p0, line.p1, mindist, line.layer);
|
2019-07-28 23:22:48 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-28 12:52:51 +05:00
|
|
|
for (auto mspnt : mparam.meshsize_points)
|
2022-03-10 23:04:44 +05:00
|
|
|
mesh.RestrictLocalH(mspnt.pnt, mspnt.h, mspnt.layer);
|
2019-08-28 12:52:51 +05:00
|
|
|
|
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
|