[TD]add ability to filter obvious geometry errors
- also add checks for geometry errors
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#include <gp_Elips.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <BRep_Builder.hxx>
|
||||
#include <BRepAdaptor_Curve.hxx>
|
||||
@@ -52,6 +53,7 @@
|
||||
#include <TopTools_IndexedMapOfShape.hxx>
|
||||
#include <TopExp.hxx>
|
||||
#include <TopExp_Explorer.hxx>
|
||||
#include <GCPnts_AbscissaPoint.hxx>
|
||||
#include <GProp_GProps.hxx>
|
||||
#include <GeomLProp_SLProps.hxx>
|
||||
#include <BRepAdaptor_Surface.hxx>
|
||||
@@ -641,6 +643,69 @@ PyObject* DrawUtil::colorToPyTuple(App::Color color)
|
||||
return pTuple;
|
||||
}
|
||||
|
||||
//check for crazy edge. This is probably a geometry error of some sort.
|
||||
bool DrawUtil::isCrazy(TopoDS_Edge e)
|
||||
{
|
||||
bool result = false;
|
||||
double ratio = 1.0;
|
||||
|
||||
if (e.IsNull()) {
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
|
||||
GetGroup("Preferences")->GetGroup("Mod/TechDraw/debug");
|
||||
bool crazyOK = hGrp->GetBool("allowCrazyEdge", true);
|
||||
if (crazyOK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BRepAdaptor_Curve adapt(e);
|
||||
|
||||
double edgeLength = GCPnts_AbscissaPoint::Length(adapt, Precision::Confusion());
|
||||
if (edgeLength < 0.00001) { //edge is scaled. this is 0.00001 mm on paper
|
||||
Base::Console().Log("DU::isCrazy - edge crazy short: %.7f\n", edgeLength);
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
if (edgeLength > 9999.9) { //edge is scaled. this is 10 m on paper. can't be right?
|
||||
Base::Console().Log("DU::isCrazy - edge crazy long: %.3f\n", edgeLength);
|
||||
result = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
double start = BRepLProp_CurveTool::FirstParameter(adapt);
|
||||
double end = BRepLProp_CurveTool::LastParameter(adapt);
|
||||
BRepLProp_CLProps propStart(adapt,start,0,Precision::Confusion());
|
||||
const gp_Pnt& vStart = propStart.Value();
|
||||
BRepLProp_CLProps propEnd(adapt,end,0,Precision::Confusion());
|
||||
const gp_Pnt& vEnd = propEnd.Value();
|
||||
double distance = vStart.Distance(vEnd);
|
||||
if (adapt.GetType() == GeomAbs_BSplineCurve) {
|
||||
if (distance > 0.001) { // not a closed loop
|
||||
ratio = edgeLength / distance;
|
||||
if (ratio > 9999.9) { // 10,000x
|
||||
result = true; //this is crazy edge
|
||||
}
|
||||
}
|
||||
} else if (adapt.GetType() == GeomAbs_Ellipse) {
|
||||
gp_Elips ellp = adapt.Ellipse();
|
||||
double major = ellp.MajorRadius();
|
||||
double minor = ellp.MinorRadius();
|
||||
if (minor < 0.001) { //too narrow
|
||||
Base::Console().Log("DU::isCrazy - ellipse is crazy narrow: %.7f\n", minor);
|
||||
result = true;
|
||||
} else if (major > 9999.9) { //too big
|
||||
Base::Console().Log("DU::isCrazy - ellipse is crazy wide: %.3f\n", major);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Base::Console().Message("DU::isCrazy - returns: %d ratio: %.3f\n", result, ratio);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Supplementary mathematical functions
|
||||
// ====================================
|
||||
|
||||
@@ -1048,7 +1113,6 @@ void DrawUtil::dumpEdges(const char* text, const TopoDS_Shape& s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawUtil::dump1Vertex(const char* text, const TopoDS_Vertex& v)
|
||||
{
|
||||
Base::Console().Message("DUMP - dump1Vertex - %s\n",text);
|
||||
@@ -1069,7 +1133,11 @@ void DrawUtil::dumpEdge(const char* label, int i, TopoDS_Edge e)
|
||||
// vStart.X(),vStart.Y(),vStart.Z(),start,vEnd.X(),vEnd.Y(),vEnd.Z(),end);
|
||||
Base::Console().Message("%s edge:%d start:(%.3f,%.3f,%.3f) end:(%.2f,%.3f,%.3f) Orient: %d\n",label,i,
|
||||
vStart.X(),vStart.Y(),vStart.Z(),vEnd.X(),vEnd.Y(),vEnd.Z(), e.Orientation());
|
||||
double edgeLength = GCPnts_AbscissaPoint::Length(adapt, Precision::Confusion());
|
||||
Base::Console().Message(">>>>>>> length: %.3f distance: %.3f ration: %.3f type: %d\n", edgeLength,
|
||||
vStart.Distance(vEnd), edgeLength / vStart.Distance(vEnd), adapt.GetType());
|
||||
}
|
||||
|
||||
const char* DrawUtil::printBool(bool b)
|
||||
{
|
||||
return (b ? "True" : "False");
|
||||
|
||||
Reference in New Issue
Block a user