Experiment with boolean cut for slicing
This commit is contained in:
parent
730866e384
commit
16bb7af20f
|
@ -23,12 +23,19 @@
|
||||||
|
|
||||||
#include "PreCompiled.h"
|
#include "PreCompiled.h"
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
|
# include <BRepAdaptor_Surface.hxx>
|
||||||
|
# include <BRepAlgoAPI_Cut.hxx>
|
||||||
# include <BRepAlgoAPI_Section.hxx>
|
# include <BRepAlgoAPI_Section.hxx>
|
||||||
|
# include <BRepBuilderAPI_MakeFace.hxx>
|
||||||
# include <BRepBuilderAPI_MakeWire.hxx>
|
# include <BRepBuilderAPI_MakeWire.hxx>
|
||||||
|
# include <BRepGProp_Face.hxx>
|
||||||
|
# include <BRepPrimAPI_MakeHalfSpace.hxx>
|
||||||
# include <gp_Pln.hxx>
|
# include <gp_Pln.hxx>
|
||||||
# include <Precision.hxx>
|
# include <Precision.hxx>
|
||||||
# include <ShapeFix_Wire.hxx>
|
# include <ShapeFix_Wire.hxx>
|
||||||
|
# include <TopExp.hxx>
|
||||||
# include <TopExp_Explorer.hxx>
|
# include <TopExp_Explorer.hxx>
|
||||||
|
# include <TopTools_IndexedMapOfShape.hxx>
|
||||||
# include <TopoDS.hxx>
|
# include <TopoDS.hxx>
|
||||||
# include <TopoDS_Edge.hxx>
|
# include <TopoDS_Edge.hxx>
|
||||||
# include <TopoDS_Wire.hxx>
|
# include <TopoDS_Wire.hxx>
|
||||||
|
@ -47,15 +54,50 @@ CrossSection::CrossSection(double a, double b, double c, const TopoDS_Shape& s)
|
||||||
std::list<TopoDS_Wire> CrossSection::section(double d) const
|
std::list<TopoDS_Wire> CrossSection::section(double d) const
|
||||||
{
|
{
|
||||||
std::list<TopoDS_Wire> wires;
|
std::list<TopoDS_Wire> wires;
|
||||||
BRepAlgoAPI_Section cs(s, gp_Pln(a,b,c,-d));
|
#if 0
|
||||||
if (cs.IsDone()) {
|
// Fixes: 0001228: Cross section of Torus in Part Workbench fails or give wrong results
|
||||||
std::list<TopoDS_Edge> edges;
|
if (s.ShapeType() == TopAbs_SOLID) {
|
||||||
TopExp_Explorer xp;
|
gp_Pln slicePlane(a,b,c,-d);
|
||||||
for (xp.Init(cs.Shape(), TopAbs_EDGE); xp.More(); xp.Next())
|
BRepBuilderAPI_MakeFace mkFace(slicePlane);
|
||||||
edges.push_back(TopoDS::Edge(xp.Current()));
|
TopoDS_Face face = mkFace.Face();
|
||||||
connectEdges(edges, wires);
|
BRepPrimAPI_MakeHalfSpace mkSolid(face, gp_Pnt(0,0,d-1));
|
||||||
}
|
TopoDS_Solid solid = mkSolid.Solid();
|
||||||
|
BRepAlgoAPI_Cut mkCut(s,solid);
|
||||||
|
|
||||||
|
if (mkCut.IsDone()) {
|
||||||
|
TopTools_IndexedMapOfShape mapOfFaces;
|
||||||
|
TopExp::MapShapes(mkCut.Shape(), TopAbs_FACE, mapOfFaces);
|
||||||
|
for (int i=1; i<=mapOfFaces.Extent(); i++) {
|
||||||
|
const TopoDS_Face& face = TopoDS::Face(mapOfFaces.FindKey(i));
|
||||||
|
BRepAdaptor_Surface adapt(face);
|
||||||
|
if (adapt.GetType() == GeomAbs_Plane) {
|
||||||
|
gp_Pln plane = adapt.Plane();
|
||||||
|
if (plane.Axis().IsParallel(slicePlane.Axis(), Precision::Confusion()) &&
|
||||||
|
plane.Distance(slicePlane.Location()) < Precision::Confusion()) {
|
||||||
|
TopTools_IndexedMapOfShape mapOfWires;
|
||||||
|
TopExp::MapShapes(face, TopAbs_WIRE, mapOfWires);
|
||||||
|
for (int j=1; j<=mapOfWires.Extent(); j++) {
|
||||||
|
const TopoDS_Wire& wire = TopoDS::Wire(mapOfWires.FindKey(j));
|
||||||
|
wires.push_back(wire);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
BRepAlgoAPI_Section cs(s, gp_Pln(a,b,c,-d));
|
||||||
|
if (cs.IsDone()) {
|
||||||
|
std::list<TopoDS_Edge> edges;
|
||||||
|
TopExp_Explorer xp;
|
||||||
|
for (xp.Init(cs.Shape(), TopAbs_EDGE); xp.More(); xp.Next())
|
||||||
|
edges.push_back(TopoDS::Edge(xp.Current()));
|
||||||
|
connectEdges(edges, wires);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return wires;
|
return wires;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user