MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / fit_halfspace

Method fit_halfspace

src/ifcgeom/kernels/opencascade/base_utils.cpp:354–449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352}
353
354bool IfcGeom::util::fit_halfspace(const TopoDS_Shape& a, const TopoDS_Shape& b, TopoDS_Shape& box, double& height, double tol) {
355 TopExp_Explorer exp(b, TopAbs_FACE);
356 if (!exp.More()) {
357 return false;
358 }
359
360 TopoDS_Face face = TopoDS::Face(exp.Current());
361 exp.Next();
362
363 if (exp.More()) {
364 return false;
365 }
366
367 Handle(Geom_Surface) surf = BRep_Tool::Surface(face);
368
369 // const gp_XYZ xyz = a.Location().Transformation().TranslationPart();
370 // std::cout << "dz " << xyz.Z() << std::endl;
371
372 if (surf->DynamicType() != STANDARD_TYPE(Geom_Plane)) {
373 return false;
374 }
375
376 Bnd_Box bb;
377 BRepBndLib::Add(a, bb);
378
379 if (bb.IsVoid()) {
380 return false;
381 }
382
383 double xs[2], ys[2], zs[2];
384 bb.Get(xs[0], ys[0], zs[0], xs[1], ys[1], zs[1]);
385
386 gp_Pln pln = Handle(Geom_Plane)::DownCast(surf)->Pln();
387
388 gp_Pnt P = pln.Position().Location();
389 gp_Vec z = pln.Position().Direction();
390 gp_Vec x = pln.Position().XDirection();
391 gp_Vec y = pln.Position().YDirection();
392
393 if (face.Orientation() != TopAbs_REVERSED) {
394 z.Reverse();
395 }
396
397 double D, Umin, Umax, Vmin, Vmax;
398 D = 0.;
399 Umin = Vmin = +std::numeric_limits<double>::infinity();
400 Umax = Vmax = -std::numeric_limits<double>::infinity();
401
402 for (int i = 0; i < 2; ++i) {
403 for (int j = 0; j < 2; ++j) {
404 for (int k = 0; k < 2; ++k) {
405 gp_Pnt p(xs[i], ys[j], zs[k]);
406
407 gp_Vec d = p.XYZ() - P.XYZ();
408 const double u = d.Dot(x);
409 const double v = d.Dot(y);
410 const double w = d.Dot(z);
411

Callers

nothing calls this directly

Calls 4

HandleFunction · 0.85
MoreMethod · 0.80
GetMethod · 0.80
NextMethod · 0.45

Tested by

no test coverage detected