Part: for faster execution make sewing optional when creating shape from mesh

This commit is contained in:
wmayer
2021-10-01 19:29:49 +02:00
parent b4f77d3c62
commit 745f8e044d
3 changed files with 24 additions and 14 deletions

View File

@@ -3277,9 +3277,9 @@ TopoDS_Shape TopoShape::removeShape(const std::vector<TopoDS_Shape>& s) const
return reshape.Apply(this->_Shape, TopAbs_SHAPE);
}
void TopoShape::sewShape()
void TopoShape::sewShape(double tolerance)
{
BRepBuilderAPI_Sewing sew;
BRepBuilderAPI_Sewing sew(tolerance);
sew.Load(this->_Shape);
sew.Perform();
@@ -3615,20 +3615,17 @@ void TopoShape::getFaces(std::vector<Base::Vector3d> &aPoints,
}
void TopoShape::setFaces(const std::vector<Base::Vector3d> &Points,
const std::vector<Facet> &Topo, float Accuracy)
const std::vector<Facet> &Topo, double tolerance)
{
gp_XYZ p1, p2, p3;
std::vector<TopoDS_Vertex> Vertexes;
std::map<std::pair<uint32_t, uint32_t>, TopoDS_Edge> Edges;
TopoDS_Face newFace;
TopoDS_Wire newWire;
BRepBuilderAPI_Sewing aSewingTool;
Standard_Real x1, y1, z1;
Standard_Real x2, y2, z2;
Standard_Real x3, y3, z3;
aSewingTool.Init(Accuracy, Standard_True);
TopoDS_Compound aComp;
BRep_Builder BuildTool;
BuildTool.MakeCompound(aComp);
@@ -3707,6 +3704,15 @@ void TopoShape::setFaces(const std::vector<Base::Vector3d> &Points,
}
}
// If performSewing is true BRepBuilderAPI_Sewing creates a compound of
// shells. Since the resulting shape isn't very usable in most use cases
// it's fine to set it to false so the algorithm only performs some control
// checks and creates a compound of faces.
// However, the computing time can be reduced by 90%.
// If a shell is needed then the sewShape() function should be called explicitly.
BRepBuilderAPI_Sewing aSewingTool;
Standard_Boolean performSewing = Standard_False;
aSewingTool.Init(tolerance, performSewing);
aSewingTool.Load(aComp);
#if OCC_VERSION_HEX < 0x070500

View File

@@ -285,7 +285,7 @@ public:
TopoDS_Shape toNurbs() const;
TopoDS_Shape replaceShape(const std::vector< std::pair<TopoDS_Shape,TopoDS_Shape> >& s) const;
TopoDS_Shape removeShape(const std::vector<TopoDS_Shape>& s) const;
void sewShape();
void sewShape(double tolerance = 1.0e-06);
bool fix(double, double, double);
bool removeInternalWires(double);
TopoDS_Shape removeSplitter() const;
@@ -302,7 +302,7 @@ public:
virtual void getFaces(std::vector<Base::Vector3d> &Points,std::vector<Facet> &faces,
float Accuracy, uint16_t flags=0) const;
void setFaces(const std::vector<Base::Vector3d> &Points,
const std::vector<Facet> &faces, float Accuracy=1.0e-06);
const std::vector<Facet> &faces, double tolerance=1.0e-06);
void getDomains(std::vector<Domain>&) const;
//@}

View File

@@ -1185,8 +1185,9 @@ PyObject* TopoShapePy::generalFuse(PyObject *args)
PyObject* TopoShapePy::sewShape(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
double tolerance = 1.0e-06;
if (!PyArg_ParseTuple(args, "|d", &tolerance))
return nullptr;
try {
getTopoShapePtr()->sewShape();
@@ -2132,9 +2133,10 @@ PyObject* TopoShapePy::reflectLines(PyObject *args, PyObject *kwds)
PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args)
{
PyObject *tup;
float tolerance;
if (!PyArg_ParseTuple(args, "O!f",&PyTuple_Type, &tup, &tolerance))
return 0;
double tolerance = 1.0e-06;
PyObject* sewShape = Py_True;
if (!PyArg_ParseTuple(args, "O!|dO!",&PyTuple_Type, &tup, &tolerance, &PyBool_Type, &sewShape))
return nullptr;
try {
Py::Tuple tuple(tup);
@@ -2156,7 +2158,9 @@ PyObject* TopoShapePy::makeShapeFromMesh(PyObject *args)
Facets.push_back(face);
}
getTopoShapePtr()->setFaces(Points, Facets,tolerance);
getTopoShapePtr()->setFaces(Points, Facets, tolerance);
if (PyObject_IsTrue(sewShape))
getTopoShapePtr()->sewShape(tolerance);
Py_Return;
} PY_CATCH_OCC
}