Skip to content

Commit

Permalink
add method to get self-intersections of a mesh via Python
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Aug 8, 2016
1 parent 8d3e5a3 commit 40b878d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Mod/Mesh/App/MeshPy.xml
Expand Up @@ -230,7 +230,12 @@ for c in mesh.getSeparatecomponents():
<UserDocu>Check if the mesh intersects itself</UserDocu>
</Documentation>
</Methode>
<Methode Name="fixSelfIntersections">
<Methode Name="getSelfIntersections" Const="true">
<Documentation>
<UserDocu>Returns a tuple of indices of intersecting triangles</UserDocu>
</Documentation>
</Methode>
<Methode Name="fixSelfIntersections">
<Documentation>
<UserDocu>Repair self-intersections</UserDocu>
</Documentation>
Expand Down
36 changes: 35 additions & 1 deletion src/Mod/Mesh/App/MeshPyImp.cpp
Expand Up @@ -583,7 +583,15 @@ PyObject* MeshPy::addFacet(PyObject *args)
Py_Return;
}

PyErr_SetString(Base::BaseExceptionFreeCADError, "set 9 floats or three vectors");
PyErr_Clear();
PyObject *f;
if (PyArg_ParseTuple(args, "O!",&(Mesh::FacetPy::Type), &f)) {
Mesh::FacetPy* face = static_cast<Mesh::FacetPy*>(f);
getMeshObjectPtr()->addFacet(*face->getFacetPtr());
Py_Return;
}

PyErr_SetString(Base::BaseExceptionFreeCADError, "set 9 floats or three vectors or a facet");
return 0;
}

Expand Down Expand Up @@ -921,6 +929,32 @@ PyObject* MeshPy::hasSelfIntersections(PyObject *args)
return Py_BuildValue("O", (ok ? Py_True : Py_False));
}

PyObject* MeshPy::getSelfIntersections(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;

std::vector<std::pair<unsigned long, unsigned long> > selfIndices;
std::vector<std::pair<Base::Vector3f, Base::Vector3f> > selfPoints;
MeshCore::MeshEvalSelfIntersection eval(getMeshObjectPtr()->getKernel());
eval.GetIntersections(selfIndices);
eval.GetIntersections(selfIndices, selfPoints);

Py::Tuple tuple(selfIndices.size());
if (selfIndices.size() == selfPoints.size()) {
for (std::size_t i=0; i<selfIndices.size(); i++) {
Py::Tuple item(4);
item.setItem(0, Py::Long(selfIndices[i].first));
item.setItem(1, Py::Long(selfIndices[i].second));
item.setItem(2, Py::Vector(selfPoints[i].first));
item.setItem(3, Py::Vector(selfPoints[i].second));
tuple.setItem(i, item);
}
}

return Py::new_reference_to(tuple);
}

PyObject* MeshPy::fixSelfIntersections(PyObject *args)
{
if (!PyArg_ParseTuple(args, ""))
Expand Down

0 comments on commit 40b878d

Please sign in to comment.