Navigation Menu

Skip to content

Commit

Permalink
add method to get wires of mesh boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 10, 2019
1 parent 17831b7 commit a85ce19
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Mod/MeshPart/App/AppMeshPartPy.cpp
Expand Up @@ -86,7 +86,10 @@ class Module : public Py::ExtensionModule<Module>
"projectPointsOnMesh(list of points, Mesh, Vector, [float]) -> list of points\n"
);
add_varargs_method("wireFromSegment",&Module::wireFromSegment,
"Create wire(s) from boundary of segment\n"
"Create wire(s) from boundary of a mesh segment\n"
);
add_varargs_method("wireFromMesh",&Module::wireFromMesh,
"Create wire(s) from boundary of a mesh\n"
);
add_keyword_method("meshFromShape",&Module::meshFromShape,
"Create surface mesh from shape\n"
Expand Down Expand Up @@ -442,6 +445,34 @@ class Module : public Py::ExtensionModule<Module>

return wires;
}
Py::Object wireFromMesh(const Py::Tuple& args)
{
PyObject *m;
if (!PyArg_ParseTuple(args.ptr(), "O!", &(Mesh::MeshPy::Type), &m))
throw Py::Exception();

Mesh::MeshObject* mesh = static_cast<Mesh::MeshPy*>(m)->getMeshObjectPtr();

std::list<std::vector<Base::Vector3f> > bounds;
MeshCore::MeshAlgorithm algo(mesh->getKernel());
algo.GetMeshBorders(bounds);

Py::List wires;
std::list<std::vector<Base::Vector3f> >::iterator bt;

for (bt = bounds.begin(); bt != bounds.end(); ++bt) {
BRepBuilderAPI_MakePolygon mkPoly;
for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
}
if (mkPoly.IsDone()) {
PyObject* wire = new Part::TopoShapeWirePy(new Part::TopoShape(mkPoly.Wire()));
wires.append(Py::Object(wire, true));
}
}

return wires;
}
Py::Object meshFromShape(const Py::Tuple& args, const Py::Dict& kwds)
{
PyObject *shape;
Expand Down

0 comments on commit a85ce19

Please sign in to comment.