add method to get self-intersections of a mesh via Python
This commit is contained in:
parent
8d3e5a31fb
commit
40b878de4d
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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, ""))
|
||||
|
|
Loading…
Reference in New Issue
Block a user