From 3785cf763182b2bd10cc82fd9321757ddfcbbe33 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 31 Jul 2016 19:08:42 +0200 Subject: [PATCH] add parameters to IsDeformed method --- src/Mod/Mesh/App/Core/Degeneration.cpp | 23 ++++++++++++++------- src/Mod/Mesh/App/Core/Degeneration.h | 14 ++++++++++--- src/Mod/Mesh/App/Core/Elements.cpp | 28 ++++++++++++-------------- src/Mod/Mesh/App/Core/Elements.h | 9 ++++----- src/Mod/Mesh/App/Mesh.cpp | 10 +++++++-- 5 files changed, 52 insertions(+), 32 deletions(-) diff --git a/src/Mod/Mesh/App/Core/Degeneration.cpp b/src/Mod/Mesh/App/Core/Degeneration.cpp index 47ca4afc1..da3849f5a 100644 --- a/src/Mod/Mesh/App/Core/Degeneration.cpp +++ b/src/Mod/Mesh/App/Core/Degeneration.cpp @@ -603,9 +603,12 @@ unsigned long MeshFixDegeneratedFacets::RemoveEdgeTooSmall (float fMinEdgeLength bool MeshEvalDeformedFacets::Evaluate() { + float fCosMinAngle = cos(fMinAngle); + float fCosMaxAngle = cos(fMaxAngle); + MeshFacetIterator it(_rclMesh); for (it.Init(); it.More(); it.Next()) { - if (it->IsDeformed()) + if (it->IsDeformed(fCosMinAngle, fCosMaxAngle)) return false; } @@ -614,10 +617,13 @@ bool MeshEvalDeformedFacets::Evaluate() std::vector MeshEvalDeformedFacets::GetIndices() const { + float fCosMinAngle = cos(fMinAngle); + float fCosMaxAngle = cos(fMaxAngle); + std::vector aInds; MeshFacetIterator it(_rclMesh); for (it.Init(); it.More(); it.Next()) { - if (it->IsDeformed()) + if (it->IsDeformed(fCosMinAngle, fCosMaxAngle)) aInds.push_back(it.Position()); } @@ -626,6 +632,9 @@ std::vector MeshEvalDeformedFacets::GetIndices() const bool MeshFixDeformedFacets::Fixup() { + float fCosMinAngle = cos(fMinAngle); + float fCosMaxAngle = cos(fMaxAngle); + Base::Vector3f u,v; MeshTopoAlgorithm cTopAlg(_rclMesh); @@ -650,10 +659,10 @@ bool MeshFixDeformedFacets::Fixup() // first check for angle > 120 deg: in this case we swap with the opposite edge for (int i=0; i<3; i++) { float fCosAngle = fCosAngles[i]; - if (fCosAngle < -0.5f) { + if (fCosAngle < fCosMaxAngle) { const MeshFacet& face = it.GetReference(); unsigned long uNeighbour = face._aulNeighbours[(i+1)%3]; - if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxAngle)) { + if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { cTopAlg.SwapEdge(it.Position(), uNeighbour); done = true; } @@ -668,17 +677,17 @@ bool MeshFixDeformedFacets::Fixup() // now check for angle < 30 deg: in this case we swap with one of the edges the corner is part of for (int j=0; j<3; j++) { float fCosAngle = fCosAngles[j]; - if (fCosAngle > 0.86f) { + if (fCosAngle > fCosMinAngle) { const MeshFacet& face = it.GetReference(); unsigned long uNeighbour = face._aulNeighbours[j]; - if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxAngle)) { + if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { cTopAlg.SwapEdge(it.Position(), uNeighbour); break; } uNeighbour = face._aulNeighbours[(j+2)%3]; - if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxAngle)) { + if (uNeighbour!=ULONG_MAX && cTopAlg.ShouldSwapEdge(it.Position(), uNeighbour, fMaxSwapAngle)) { cTopAlg.SwapEdge(it.Position(), uNeighbour); break; } diff --git a/src/Mod/Mesh/App/Core/Degeneration.h b/src/Mod/Mesh/App/Core/Degeneration.h index 08df12851..00c886adf 100644 --- a/src/Mod/Mesh/App/Core/Degeneration.h +++ b/src/Mod/Mesh/App/Core/Degeneration.h @@ -346,7 +346,8 @@ public: /** * Construction. */ - MeshEvalDeformedFacets (const MeshKernel &rclM) : MeshEvaluation( rclM ) { } + MeshEvalDeformedFacets (const MeshKernel &rclM, float fMinAngle, float fMaxAngle) + : MeshEvaluation(rclM), fMinAngle(fMinAngle), fMaxAngle(fMaxAngle) { } /** * Destruction. */ @@ -359,6 +360,10 @@ public: * Returns the indices of deformed facets. */ std::vector GetIndices() const; + +private: + float fMinAngle; + float fMaxAngle; }; /** @@ -374,8 +379,9 @@ public: /** * Construction. */ - MeshFixDeformedFacets (MeshKernel &rclM, float fAngle, float fEps) - : MeshValidation(rclM), fMaxAngle(fAngle), fEpsilon(fEps) { } + MeshFixDeformedFacets (MeshKernel &rclM, float fMinAngle, float fMaxAngle, float fSwapAngle, float fEps) + : MeshValidation(rclM), fMinAngle(fMinAngle), fMaxAngle(fMaxAngle), + fMaxSwapAngle(fSwapAngle), fEpsilon(fEps) { } /** * Destruction. */ @@ -386,7 +392,9 @@ public: bool Fixup (); private: + float fMinAngle; float fMaxAngle; + float fMaxSwapAngle; float fEpsilon; }; diff --git a/src/Mod/Mesh/App/Core/Elements.cpp b/src/Mod/Mesh/App/Core/Elements.cpp index 7dbd74711..32ef85128 100644 --- a/src/Mod/Mesh/App/Core/Elements.cpp +++ b/src/Mod/Mesh/App/Core/Elements.cpp @@ -428,26 +428,24 @@ bool MeshGeomFacet::IsDegenerated(float epsilon) const return false; } -bool MeshGeomFacet::IsDeformed() const +bool MeshGeomFacet::IsDeformed(float fCosOfMinAngle, float fCosOfMaxAngle) const { - float fCosAngle; - Base::Vector3f u,v; + float fCosAngle; + Base::Vector3f u,v; - for (int i=0; i<3; i++) - { - u = _aclPoints[(i+1)%3]-_aclPoints[i]; - v = _aclPoints[(i+2)%3]-_aclPoints[i]; - u.Normalize(); - v.Normalize(); + for (int i=0; i<3; i++) { + u = _aclPoints[(i+1)%3]-_aclPoints[i]; + v = _aclPoints[(i+2)%3]-_aclPoints[i]; + u.Normalize(); + v.Normalize(); - fCosAngle = u * v; + fCosAngle = u * v; - // x < 30 deg => cos(x) > sqrt(3)/2 or x > 120 deg => cos(x) < -0.5 - if (fCosAngle > 0.86f || fCosAngle < -0.5f) - return true; - } + if (fCosAngle > fCosOfMinAngle || fCosAngle < fCosOfMaxAngle) + return true; + } - return false; + return false; } bool MeshGeomFacet::IntersectBoundingBox ( const Base::BoundBox3f &rclBB ) const diff --git a/src/Mod/Mesh/App/Core/Elements.h b/src/Mod/Mesh/App/Core/Elements.h index 46c390c57..edacd3ca4 100644 --- a/src/Mod/Mesh/App/Core/Elements.h +++ b/src/Mod/Mesh/App/Core/Elements.h @@ -360,12 +360,11 @@ public: */ bool IsDegenerated(float epsilon) const; /** - * Checks whether the triangle is deformed. The definition of a deformed triangles is not as strong - * as the definition of a degenerated triangle. A triangle is deformed if the maximum angle exceeds 120 deg - * or the minimum angle falls below 30 deg. - * A degenerated triangle is also a deformed triangle. + * Checks whether the triangle is deformed. A triangle is deformed if the an angle + * exceeds a given maximum angle or falls below a given minimum angle. + * For performance reasons the cosine of minimum and maximum angle is expected. */ - bool IsDeformed() const; + bool IsDeformed(float fCosOfMinAngle, float fCosOfMaxAngle) const; /** * Enlarges the triangle. */ diff --git a/src/Mod/Mesh/App/Mesh.cpp b/src/Mod/Mesh/App/Mesh.cpp index 38fc447b8..5ef5bbf46 100644 --- a/src/Mod/Mesh/App/Mesh.cpp +++ b/src/Mod/Mesh/App/Mesh.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include "Core/Builder.h" @@ -1085,9 +1086,11 @@ void MeshObject::refine() unsigned long cnt = _kernel.CountFacets(); MeshCore::MeshFacetIterator cF(_kernel); MeshCore::MeshTopoAlgorithm topalg(_kernel); + + // x < 30 deg => cos(x) > sqrt(3)/2 or x > 120 deg => cos(x) < -0.5 for (unsigned long i=0; iIsDeformed()) + if (!cF->IsDeformed(0.86f, -0.5f)) topalg.InsertVertexAndSwapEdge(i, cF->GetGravityPoint(), 0.1f); } @@ -1378,7 +1381,10 @@ void MeshObject::validateIndices() void MeshObject::validateDeformations(float fMaxAngle, float fEps) { unsigned long count = _kernel.CountFacets(); - MeshCore::MeshFixDeformedFacets eval(_kernel, fMaxAngle, fEps); + MeshCore::MeshFixDeformedFacets eval(_kernel, + Base::toRadians(30.0f), + Base::toRadians(120.0f), + fMaxAngle, fEps); eval.Fixup(); if (_kernel.CountFacets() < count) this->_segments.clear();