move getFacets from Path to Part

This commit is contained in:
Eric Trombly
2020-04-01 13:26:57 -05:00
parent db959f1f09
commit b631c5600a
3 changed files with 50 additions and 52 deletions

View File

@@ -290,6 +290,9 @@ public:
add_varargs_method("show",&Module::show,
"show(shape,[string]) -- Add the shape to the active document or create one if no document exists."
);
add_varargs_method("getFacets",&Module::getFacets,
"getFacets(shape): simplified mesh generation"
);
add_varargs_method("makeCompound",&Module::makeCompound,
"makeCompound(list) -- Create a compound out of a list of shapes."
);
@@ -720,6 +723,51 @@ private:
return Py::None();
}
Py::Object getFacets(const Py::Tuple& args)
{
PyObject *shape;
PyObject *list = PyList_New(0);
if (!PyArg_ParseTuple(args.ptr(), "O", &shape))
throw Py::Exception();
auto theShape = static_cast<Part::TopoShapePy*>(shape)->getTopoShapePtr()->getShape();
for(TopExp_Explorer ex(theShape, TopAbs_FACE); ex.More(); ex.Next())
{
TopoDS_Face currentFace = TopoDS::Face(ex.Current());
TopLoc_Location loc;
Handle(Poly_Triangulation) facets = BRep_Tool::Triangulation(currentFace, loc);
const TopAbs_Orientation anOrientation = currentFace.Orientation();
bool flip = (anOrientation == TopAbs_REVERSED);
if(!facets.IsNull()){
auto nodes = facets->Nodes();
auto triangles = facets->Triangles();
for(int i = 1; i <= triangles.Length(); i++){
Standard_Integer n1,n2,n3;
triangles(i).Get(n1, n2, n3);
gp_Pnt p1 = nodes(n1);
gp_Pnt p2 = nodes(n2);
gp_Pnt p3 = nodes(n3);
p1.Transform(loc.Transformation());
p2.Transform(loc.Transformation());
p3.Transform(loc.Transformation());
// TODO: verify if tolerence should be hard coded
if (!p1.IsEqual(p2, 0.01) && !p2.IsEqual(p3, 0.01) && !p3.IsEqual(p1, 0.01)) {
PyObject *t1 = PyTuple_Pack(3, PyFloat_FromDouble(p1.X()), PyFloat_FromDouble(p1.Y()), PyFloat_FromDouble(p1.Z()));
PyObject *t2 = PyTuple_Pack(3, PyFloat_FromDouble(p2.X()), PyFloat_FromDouble(p2.Y()), PyFloat_FromDouble(p2.Z()));
PyObject *t3 = PyTuple_Pack(3, PyFloat_FromDouble(p3.X()), PyFloat_FromDouble(p3.Y()), PyFloat_FromDouble(p3.Z()));
PyObject *points;
if(flip)
{
points = PyTuple_Pack(3, t2, t1, t3);
} else {
points = PyTuple_Pack(3, t1, t2, t3);
}
PyList_Append(list, points);
}
}
}
}
return Py::asObject(list);
}
Py::Object makeCompound(const Py::Tuple& args)
{
PyObject *pcObj;