Set precision on fix after boolean op

This commit is contained in:
Thomas Krijnen
2018-06-08 14:12:01 +02:00
parent 3205013d20
commit 7f8df04b2a
+22 -12
View File
@@ -3065,6 +3065,7 @@ bool IfcGeom::Kernel::boolean_operation(const TopoDS_Shape& a, const TopoDS_Shap
} }
#else #else
namespace {
TopTools_ListOfShape copy_operand(const TopTools_ListOfShape& l) { TopTools_ListOfShape copy_operand(const TopTools_ListOfShape& l) {
TopTools_ListOfShape r; TopTools_ListOfShape r;
TopTools_ListIteratorOfListOfShape it(l); TopTools_ListIteratorOfListOfShape it(l);
@@ -3078,6 +3079,21 @@ TopoDS_Shape copy_operand(const TopoDS_Shape& s) {
return BRepBuilderAPI_Copy(s); return BRepBuilderAPI_Copy(s);
} }
double min_edge_length(const TopoDS_Shape& a) {
double min_edge_len = std::numeric_limits<double>::infinity();
TopExp_Explorer exp(a, TopAbs_EDGE);
for (; exp.More(); exp.Next()) {
GProp_GProps prop;
BRepGProp::LinearProperties(exp.Current(), prop);
double l = prop.Mass();
if (l < min_edge_len) {
min_edge_len = l;
}
}
return min_edge_len;
}
}
bool IfcGeom::Kernel::boolean_operation(const TopoDS_Shape& a, const TopTools_ListOfShape& b, BOPAlgo_Operation op, TopoDS_Shape& result, double fuzziness) { bool IfcGeom::Kernel::boolean_operation(const TopoDS_Shape& a, const TopTools_ListOfShape& b, BOPAlgo_Operation op, TopoDS_Shape& result, double fuzziness) {
bool success = false; bool success = false;
BRepAlgoAPI_BooleanOperation* builder; BRepAlgoAPI_BooleanOperation* builder;
@@ -3094,21 +3110,12 @@ bool IfcGeom::Kernel::boolean_operation(const TopoDS_Shape& a, const TopTools_Li
fuzziness = getValue(GV_PRECISION); fuzziness = getValue(GV_PRECISION);
} }
double min_edge_len = std::numeric_limits<double>::infinity(); const double min_edge_len = min_edge_length(a);
// ... to be sure to get consecutive edges const double fuzz = (std::min)(min_edge_len / 3., fuzziness);
TopExp_Explorer exp(a, TopAbs_EDGE);
for (; exp.More(); exp.Next()) {
GProp_GProps prop;
BRepGProp::LinearProperties(exp.Current(), prop);
double l = prop.Mass();
if (l < min_edge_len) {
min_edge_len = l;
}
}
TopTools_ListOfShape s1s; TopTools_ListOfShape s1s;
s1s.Append(copy_operand(a)); s1s.Append(copy_operand(a));
builder->SetFuzzyValue((std::min)(min_edge_len / 3., fuzziness)); builder->SetFuzzyValue(fuzz);
builder->SetArguments(s1s); builder->SetArguments(s1s);
builder->SetTools(copy_operand(b)); builder->SetTools(copy_operand(b));
builder->Build(); builder->Build();
@@ -3117,6 +3124,9 @@ bool IfcGeom::Kernel::boolean_operation(const TopoDS_Shape& a, const TopTools_Li
ShapeFix_Shape fix(r); ShapeFix_Shape fix(r);
try { try {
fix.SetMinTolerance(fuzz);
fix.SetMaxTolerance(fuzz);
fix.SetPrecision(fuzz);
fix.Perform(); fix.Perform();
r = fix.Shape(); r = fix.Shape();
} catch (...) { } catch (...) {