From 9e4de92ce177febdaec21231eb86be5987180407 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 31 Jul 2016 12:13:37 +0200 Subject: [PATCH] expose mesh analyzing functions to Python --- src/Mod/Mesh/App/FacetPy.xml | 9 ++++++++- src/Mod/Mesh/App/FacetPyImp.cpp | 26 +++++++++++++++++++++---- src/Mod/Mesh/App/MeshPy.xml | 7 ++++++- src/Mod/Mesh/App/MeshPyImp.cpp | 16 +++++++++++++++ src/Mod/Mesh/Gui/DlgEvaluateSettings.ui | 2 +- 5 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/Mod/Mesh/App/FacetPy.xml b/src/Mod/Mesh/App/FacetPy.xml index 9d1c8df51a..d1229990f8 100644 --- a/src/Mod/Mesh/App/FacetPy.xml +++ b/src/Mod/Mesh/App/FacetPy.xml @@ -39,7 +39,14 @@ Get a list of intersection points with another triangle. - + + + isDegenerated([float]) -> boolean +Returns true if the facet is degenerated, otherwise false. + + + + The index of this facet in the MeshObject diff --git a/src/Mod/Mesh/App/FacetPyImp.cpp b/src/Mod/Mesh/App/FacetPyImp.cpp index 610264f518..9b307ffeb4 100644 --- a/src/Mod/Mesh/App/FacetPyImp.cpp +++ b/src/Mod/Mesh/App/FacetPyImp.cpp @@ -128,6 +128,22 @@ PyObject* FacetPy::intersect(PyObject *args) } } +PyObject* FacetPy::isDegenerated(PyObject *args) +{ + float fEpsilon = MeshCore::MeshDefinitions::_fMinPointDistanceP2; + if (!PyArg_ParseTuple(args, "|f", &fEpsilon)) + return NULL; + + FacetPy::PointerType face = this->getFacetPtr(); + if (!face->isBound()) { + throw Py::RuntimeError("Unbound facet"); + } + + const MeshCore::MeshKernel& kernel = face->Mesh->getKernel(); + MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index); + return Py::new_reference_to(Py::Boolean(tria.IsDegenerated(fEpsilon))); +} + Py::List FacetPy::getPoints(void) const { FacetPy::PointerType face = this->getFacetPtr(); @@ -160,8 +176,9 @@ Py::Tuple FacetPy::getPointIndices(void) const Py::Tuple FacetPy::getNeighbourIndices(void) const { FacetPy::PointerType face = this->getFacetPtr(); - if (!face->isBound()) - { return Py::Tuple(); } + if (!face->isBound()) { + return Py::Tuple(); + } Py::Tuple idxTuple(3); for (int i=0; i<3; i++) { @@ -173,8 +190,9 @@ Py::Tuple FacetPy::getNeighbourIndices(void) const Py::Float FacetPy::getArea(void) const { FacetPy::PointerType face = this->getFacetPtr(); - if (!face->isBound()) - { return Py::Float(0.0); } + if (!face->isBound()) { + return Py::Float(0.0); + } const MeshCore::MeshKernel& kernel = face->Mesh->getKernel(); MeshCore::MeshGeomFacet tria = kernel.GetFacet(face->Index); diff --git a/src/Mod/Mesh/App/MeshPy.xml b/src/Mod/Mesh/App/MeshPy.xml index caeb82a695..564b5743dc 100644 --- a/src/Mod/Mesh/App/MeshPy.xml +++ b/src/Mod/Mesh/App/MeshPy.xml @@ -250,7 +250,12 @@ for c in mesh.getSeparatecomponents(): Get the number of wrong oriented facets - + + + Get a tuple of wrong oriented facets + + + Check if the mesh has points with invalid coordinates (NaN) diff --git a/src/Mod/Mesh/App/MeshPyImp.cpp b/src/Mod/Mesh/App/MeshPyImp.cpp index d4f5cc091b..9af26708c5 100644 --- a/src/Mod/Mesh/App/MeshPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPyImp.cpp @@ -1000,6 +1000,22 @@ PyObject* MeshPy::countNonUniformOrientedFacets(PyObject *args) return Py_BuildValue("k", count); } +PyObject* MeshPy::getNonUniformOrientedFacets(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + const MeshCore::MeshKernel& kernel = getMeshObjectPtr()->getKernel(); + MeshCore::MeshEvalOrientation cMeshEval(kernel); + std::vector inds = cMeshEval.GetIndices(); + Py::Tuple tuple(inds.size()); + for (std::size_t i=0; i - Consider a face only degenerated if it has no area + Only consider zero area faces as degenerated true