OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{CadDocument.cpp} Namespace Reference

Classes

struct  FaceProbe

Functions

std::vector< FaceProbe > face_probes (const std::vector< CadBody > &bodies)
bool outward_normal (const TopoDS_Face &face, double u, double v, gp_Dir &n)
bool interior_point (const TopoDS_Face &face, gp_Pnt &p, gp_Dir &n)
bool on_boundary (const std::vector< FaceProbe > &probes, const gp_Pnt &p, const gp_Dir &n)

Variables

constexpr double kOnFaceTol = 1e-4

Function Documentation

◆ face_probes()

std::vector< FaceProbe > Slic3r::anonymous_namespace{CadDocument.cpp}::face_probes ( const std::vector< CadBody > & bodies)
4251{
4252 std::vector<FaceProbe> out;
4253 for (const CadBody& b : bodies)
4254 for (TopExp_Explorer e(b.shape, TopAbs_FACE); e.More(); e.Next()) {
4255 FaceProbe p;
4256 p.face = TopoDS::Face(e.Current());
4257 p.surface = BRep_Tool::Surface(p.face);
4258 if (p.surface.IsNull()) continue;
4259 BRepBndLib::Add(p.face, p.box);
4260 p.box.Enlarge(kOnFaceTol);
4261 out.push_back(std::move(p));
4262 }
4263 return out;
4264}
constexpr double kOnFaceTol
Definition CadDocument.cpp:4248
Definition CadDocument.hpp:513
TopoDS_Face face
Definition CadDocument.cpp:4240
Bnd_Box box
Definition CadDocument.cpp:4242

References Slic3r::anonymous_namespace{CadDocument.cpp}::FaceProbe::box, Slic3r::anonymous_namespace{CadDocument.cpp}::FaceProbe::face, face_probes(), and kOnFaceTol.

Referenced by face_probes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ interior_point()

bool Slic3r::anonymous_namespace{CadDocument.cpp}::interior_point ( const TopoDS_Face & face,
gp_Pnt & p,
gp_Dir & n )
4280{
4281 TopLoc_Location loc;
4282 const Handle(Poly_Triangulation) tri = BRep_Tool::Triangulation(face, loc);
4283 double u = 0., v = 0., best = -1.;
4284 if (!tri.IsNull() && tri->HasUVNodes())
4285 for (int i = 1; i <= tri->NbTriangles(); ++i) {
4286 int a, b, c;
4287 tri->Triangle(i).Get(a, b, c);
4288 const gp_Pnt pa = tri->Node(a);
4289 const double area = gp_Vec(pa, tri->Node(b)).Crossed(gp_Vec(pa, tri->Node(c))).SquareMagnitude();
4290 if (area <= best) continue;
4291 best = area;
4292 const gp_XY uv = (tri->UVNode(a).XY() + tri->UVNode(b).XY() + tri->UVNode(c).XY()) / 3.;
4293 u = uv.X();
4294 v = uv.Y();
4295 }
4296 if (best < 0.) {
4297 double u0, u1, v0, v1;
4298 BRepTools::UVBounds(face, u0, u1, v0, v1);
4299 u = 0.5 * (u0 + u1);
4300 v = 0.5 * (v0 + v1);
4301 if (BRepClass_FaceClassifier(face, gp_Pnt2d(u, v), Precision::Confusion()).State() != TopAbs_IN)
4302 return false;
4303 }
4304 p = BRepAdaptor_Surface(face).Value(u, v);
4305 return outward_normal(face, u, v, n);
4306}
bool outward_normal(const TopoDS_Face &face, double u, double v, gp_Dir &n)
Definition CadDocument.cpp:4266
double area(const ExPolygon &poly)
Definition ExPolygon.hpp:511

References Slic3r::area(), interior_point(), and outward_normal().

Referenced by interior_point().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ on_boundary()

bool Slic3r::anonymous_namespace{CadDocument.cpp}::on_boundary ( const std::vector< FaceProbe > & probes,
const gp_Pnt & p,
const gp_Dir & n )
4312{
4313 for (const FaceProbe& fp : probes) {
4314 if (fp.box.IsOut(p)) continue;
4315 try {
4316 if (!fp.proj) {
4317 // The setup GeomAPI_ProjectPointOnSurf(p, surface) repeats for every point, done once.
4318 double u0, u1, v0, v1;
4319 fp.surface->Bounds(u0, u1, v0, v1);
4320 fp.proj = std::make_unique<GeomAPI_ProjectPointOnSurf>();
4321 fp.proj->Init(fp.surface, u0, u1, v0, v1, Precision::Confusion());
4322 }
4323 GeomAPI_ProjectPointOnSurf& proj = *fp.proj;
4324 proj.Perform(p);
4325 if (proj.NbPoints() == 0 || proj.LowerDistance() > kOnFaceTol) continue;
4326 double u, v;
4327 proj.LowerDistanceParameters(u, v);
4328 if (BRepClass_FaceClassifier(fp.face, gp_Pnt2d(u, v), kOnFaceTol).State() == TopAbs_OUT) continue;
4329 gp_Dir m;
4330 if (outward_normal(fp.face, u, v, m) && m.Dot(n) > 0.) return true;
4331 } catch (const Standard_Failure&) {
4332 // A surface the projection cannot handle says nothing about the point.
4333 }
4334 }
4335 return false;
4336}

References kOnFaceTol, on_boundary(), and outward_normal().

Referenced by on_boundary().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ outward_normal()

bool Slic3r::anonymous_namespace{CadDocument.cpp}::outward_normal ( const TopoDS_Face & face,
double u,
double v,
gp_Dir & n )
4267{
4268 BRepAdaptor_Surface surf(face);
4269 BRepLProp_SLProps props(surf, u, v, 1, Precision::Confusion());
4270 if (!props.IsNormalDefined()) return false;
4271 n = props.Normal();
4272 if (face.Orientation() == TopAbs_REVERSED) n.Reverse();
4273 return true;
4274}

References outward_normal().

Referenced by interior_point(), on_boundary(), and outward_normal().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kOnFaceTol

double Slic3r::anonymous_namespace{CadDocument.cpp}::kOnFaceTol = 1e-4
constexpr

Referenced by face_probes(), and on_boundary().