Experiment with boolean cut for slicing

This commit is contained in:
wmayer 2013-08-24 16:21:21 +02:00
parent 730866e384
commit 16bb7af20f

View File

@ -23,12 +23,19 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <BRepAdaptor_Surface.hxx>
# include <BRepAlgoAPI_Cut.hxx>
# include <BRepAlgoAPI_Section.hxx>
# include <BRepBuilderAPI_MakeFace.hxx>
# include <BRepBuilderAPI_MakeWire.hxx>
# include <BRepGProp_Face.hxx>
# include <BRepPrimAPI_MakeHalfSpace.hxx>
# include <gp_Pln.hxx>
# include <Precision.hxx>
# include <ShapeFix_Wire.hxx>
# include <TopExp.hxx>
# include <TopExp_Explorer.hxx>
# include <TopTools_IndexedMapOfShape.hxx>
# include <TopoDS.hxx>
# include <TopoDS_Edge.hxx>
# include <TopoDS_Wire.hxx>
@ -47,6 +54,40 @@ 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> wires;
#if 0
// Fixes: 0001228: Cross section of Torus in Part Workbench fails or give wrong results
if (s.ShapeType() == TopAbs_SOLID) {
gp_Pln slicePlane(a,b,c,-d);
BRepBuilderAPI_MakeFace mkFace(slicePlane);
TopoDS_Face face = mkFace.Face();
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;
@ -55,7 +96,8 @@ std::list<TopoDS_Wire> CrossSection::section(double d) const
edges.push_back(TopoDS::Edge(xp.Current()));
connectEdges(edges, wires);
}
}
#endif
return wires;
}