Skip to content

Commit

Permalink
[TD]correct face detection to avoid ghost faces
Browse files Browse the repository at this point in the history
  • Loading branch information
WandererFan committed Nov 27, 2019
1 parent 90702da commit fff0029
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 167 deletions.
9 changes: 8 additions & 1 deletion src/Mod/TechDraw/App/DrawViewPart.cpp
Expand Up @@ -518,9 +518,16 @@ void DrawViewPart::extractFaces()

std::vector<TopoDS_Wire> sortedWires = ew.sortStrip(fw,true);

// int idb = 0;
std::vector<TopoDS_Wire>::iterator itWire = sortedWires.begin();
for (; itWire != sortedWires.end(); itWire++) {
//version 1: 1 wire/face - no voids in face
//debug
// std::stringstream ss;
// ss << "DVPSWire" << idb << ".brep";
// std::string wireName = ss.str();
// BRepTools::Write((*itWire), wireName.c_str()); //debug
//debug idb++;
TechDraw::Face* f = new TechDraw::Face();
const TopoDS_Wire& wire = (*itWire);
TechDraw::Wire* w = new TechDraw::Wire(wire);
Expand Down Expand Up @@ -926,7 +933,7 @@ bool DrawViewPart::checkXDirection(void) const
Base::Vector3d origin(0.0,0.0,0.0);
Base::Vector3d xDir = getLegacyX(origin,
dir);
Base::Console().Warning("DVP - %s - XDirection property not set. Trying %s\n",
Base::Console().Log("DVP - %s - XDirection property not set. Trying %s\n",
getNameInDocument(),
DrawUtil::formatVector(xDir).c_str());
return false;
Expand Down
9 changes: 7 additions & 2 deletions src/Mod/TechDraw/App/DrawViewSection.cpp
Expand Up @@ -49,6 +49,7 @@
#include <HLRAlgo_Projector.hxx>
#include <HLRBRep_HLRToShape.hxx>
#include <ShapeAnalysis.hxx>
#include <ShapeFix_Wire.hxx>
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
Expand Down Expand Up @@ -371,14 +372,18 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void)
ss << "DVSScaledFace" << idb << ".brep" ;
std::string faceName = ss.str();
BRepTools::Write(pFace, faceName.c_str()); //debug
std::stringstream ss2;
ss2 << "DVSOuter" << idb << ".brep" ;
TopoDS_Wire owdb = ShapeAnalysis::OuterWire(pFace);
std::string wireName = ss2.str();
BRepTools::Write(owdb, wireName.c_str()); //debug
}
TopoDS_Wire ow = ShapeAnalysis::OuterWire(pFace);
// BRepTools::Write(ow, "outerwire.brep"); //debug
//this check helps prevent "ghost" faces
BRepCheck_Wire chkWire(ow);
TopoDS_Edge e1, e2;
BRepCheck_Status status = chkWire.SelfIntersect(pFace, e1, e2);
if (status == BRepCheck_NoError) {
if (status == BRepCheck_NoError) {
builder.Add(newFaces,pFace);
sectionFaceWires.push_back(ShapeAnalysis::OuterWire(pFace));
}
Expand Down
1 change: 1 addition & 0 deletions src/Mod/TechDraw/App/DrawViewSection.h
Expand Up @@ -39,6 +39,7 @@ class Bnd_Box;
class gp_Pln;
class gp_Pnt;
class TopoDS_Face;
class TopoDS_Wire;
class gp_Ax2;

namespace TechDraw
Expand Down
22 changes: 21 additions & 1 deletion src/Mod/TechDraw/App/Geometry.cpp
Expand Up @@ -426,6 +426,10 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
Handle(Geom_BezierCurve) bez = adapt.Bezier();
//if (bez->Degree() < 4) {
result = new BezierSegment(edge);
if (edge.Orientation() == TopAbs_REVERSED) {
result->reversed = true;
}

//}
// OCC is quite happy with Degree > 3 but QtGui handles only 2,3
} break;
Expand Down Expand Up @@ -456,7 +460,7 @@ BaseGeom* BaseGeom::baseFactory(TopoDS_Edge edge)
delete bspline;
bspline = nullptr;
}
}else {
} else {
result = bspline;
}
}
Expand Down Expand Up @@ -524,6 +528,9 @@ AOE::AOE(const TopoDS_Edge &e) : Ellipse(e)
startPnt = Base::Vector3d(s.X(), s.Y(), s.Z());
endPnt = Base::Vector3d(ePt.X(), ePt.Y(), ePt.Z());
midPnt = Base::Vector3d(m.X(), m.Y(), m.Z());
if (e.Orientation() == TopAbs_REVERSED) {
reversed = true;
}
}


Expand Down Expand Up @@ -634,6 +641,9 @@ AOC::AOC(const TopoDS_Edge &e) : Circle(e)
startPnt = Base::Vector3d(s.X(), s.Y(), s.Z());
endPnt = Base::Vector3d(ePt.X(), ePt.Y(), s.Z());
midPnt = Base::Vector3d(m.X(), m.Y(), s.Z());
if (e.Orientation() == TopAbs_REVERSED) {
reversed = true;
}
}

AOC::AOC(void) : Circle()
Expand Down Expand Up @@ -837,6 +847,9 @@ Generic::Generic(const TopoDS_Edge &e)
p = BRep_Tool::Pnt(TopExp::LastVertex(occEdge));
points.emplace_back(p.X(), p.Y(), p.Z());
}
if (e.Orientation() == TopAbs_REVERSED) {
reversed = true;
}
}


Expand Down Expand Up @@ -1040,6 +1053,9 @@ BSpline::BSpline(const TopoDS_Edge &e)
}
segments.push_back(tempSegment);
}
if (e.Orientation() == TopAbs_REVERSED) {
reversed = true;
}
}


Expand Down Expand Up @@ -1265,6 +1281,7 @@ TopoDS_Edge BSpline::asCircle(bool& arc)
result = newEdge;
}
}

return result;
}

Expand Down Expand Up @@ -1308,6 +1325,9 @@ BezierSegment::BezierSegment(const TopoDS_Edge &e)
gp_Pnt controlPoint = bez->Pole(i);
pnts.emplace_back(controlPoint.X(), controlPoint.Y(), controlPoint.Z());
}
if (e.Orientation() == TopAbs_REVERSED) {
reversed = true;
}
}


Expand Down
11 changes: 11 additions & 0 deletions src/Mod/TechDraw/App/GeometryObject.cpp
Expand Up @@ -25,6 +25,7 @@

#include <BRep_Tool.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRepLib.hxx>
#include <BRepLProp_CurveTool.hxx>
Expand Down Expand Up @@ -131,6 +132,16 @@ const std::vector<BaseGeom *> GeometryObject::getVisibleFaceEdges(const bool smo
}
}
}
//debug
//make compound of edges and save as brep file
// BRep_Builder builder;
// TopoDS_Compound comp;
// builder.MakeCompound(comp);
// for (auto& r: result) {
// builder.Add(comp, r->occEdge);
// }
// BRepTools::Write(comp, "GOVizFaceEdges.brep"); //debug

return result;
}

Expand Down

0 comments on commit fff0029

Please sign in to comment.