From ae09625140651423ed7b1035fa59395d206e532f Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 31 Oct 2014 15:57:28 +0100 Subject: [PATCH] + expose function to Python to check for invalid mesh points --- src/Mod/Mesh/App/Mesh.cpp | 6 ++++++ src/Mod/Mesh/App/Mesh.h | 1 + src/Mod/Mesh/App/MeshFeaturePy.xml | 5 +++++ src/Mod/Mesh/App/MeshFeaturePyImp.cpp | 17 +++++++++++++++++ src/Mod/Mesh/App/MeshPy.xml | 10 ++++++++++ src/Mod/Mesh/App/MeshPyImp.cpp | 22 ++++++++++++++++++++++ 6 files changed, 61 insertions(+) diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 2cd47038d..f08de844f 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -1195,6 +1195,12 @@ void MeshObject::removeFullBoundaryFacets() } } +bool MeshObject::hasInvalidPoints() const +{ + MeshCore::MeshEvalNaNPoints nan(_kernel); + return !nan.GetIndices().empty(); +} + void MeshObject::removeInvalidPoints() { MeshCore::MeshEvalNaNPoints nan(_kernel); diff --git a/src/Mod/Mesh/App/Mesh.h b/src/Mod/Mesh/App/Mesh.h index c2ffb3442..becc08f61 100644 --- a/src/Mod/Mesh/App/Mesh.h +++ b/src/Mod/Mesh/App/Mesh.h @@ -268,6 +268,7 @@ public: void removeSelfIntersections(const std::vector&); void removeFoldsOnSurface(); void removeFullBoundaryFacets(); + bool hasInvalidPoints() const; void removeInvalidPoints(); //@} diff --git a/src/Mod/Mesh/App/MeshFeaturePy.xml b/src/Mod/Mesh/App/MeshFeaturePy.xml index 72f885f0e..1ebf3ff8a 100644 --- a/src/Mod/Mesh/App/MeshFeaturePy.xml +++ b/src/Mod/Mesh/App/MeshFeaturePy.xml @@ -72,5 +72,10 @@ d.addObject(\"Mesh::Feature\"). Remove folds on surfaces + + + Remove points with invalid coordinates (NaN) + + diff --git a/src/Mod/Mesh/App/MeshFeaturePyImp.cpp b/src/Mod/Mesh/App/MeshFeaturePyImp.cpp index bdd6e3ec5..c89873ce3 100644 --- a/src/Mod/Mesh/App/MeshFeaturePyImp.cpp +++ b/src/Mod/Mesh/App/MeshFeaturePyImp.cpp @@ -191,6 +191,23 @@ PyObject* MeshFeaturePy::removeFoldsOnSurface(PyObject *args) Py_Return; } +PyObject* MeshFeaturePy::removeInvalidPoints(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + try { + Mesh::Feature* obj = getFeaturePtr(); + MeshObject* kernel = obj->Mesh.startEditing(); + kernel->removeInvalidPoints(); + obj->Mesh.finishEditing(); + } + catch (const Base::Exception& e) { + PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); + return NULL; + } + Py_Return; +} + PyObject *MeshFeaturePy::getCustomAttributes(const char* /*attr*/) const { return 0; diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index 789270f08..46d47a175 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -232,6 +232,16 @@ for c in mesh.getSeparatecomponents(): Get the number of wrong oriented facets + + + Check if the mesh has points with invalid coordinates (NaN) + + + + + Remove points with invalid coordinates (NaN) + + Get the number of topologic independent areas diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index 204fe07d2..a9d30451c 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -833,6 +833,28 @@ PyObject* MeshPy::removeFoldsOnSurface(PyObject *args) Py_Return; } +PyObject* MeshPy::hasInvalidPoints(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + bool ok = getMeshObjectPtr()->hasInvalidPoints(); + return Py_BuildValue("O", (ok ? Py_True : Py_False)); +} + +PyObject* MeshPy::removeInvalidPoints(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + try { + getMeshObjectPtr()->removeInvalidPoints(); + } + catch (const Base::Exception& e) { + PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); + return NULL; + } + Py_Return; +} + PyObject* MeshPy::flipNormals(PyObject *args) { if (!PyArg_ParseTuple(args, ""))