add parameters to IsDeformed method
This commit is contained in:
parent
33bb67edcb
commit
3785cf7631
|
@ -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<unsigned long> MeshEvalDeformedFacets::GetIndices() const
|
||||
{
|
||||
float fCosMinAngle = cos(fMinAngle);
|
||||
float fCosMaxAngle = cos(fMaxAngle);
|
||||
|
||||
std::vector<unsigned long> 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<unsigned long> 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;
|
||||
}
|
||||
|
|
|
@ -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<unsigned long> 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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include <Base/Reader.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <Base/Sequencer.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/ViewProj.h>
|
||||
|
||||
#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; i<cnt; i++) {
|
||||
cF.Set(i);
|
||||
if (!cF->IsDeformed())
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue
Block a user