From 5f63f42b121030647448513b97a41913086acb57 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 18 Aug 2010 11:14:58 +0000 Subject: [PATCH] Improved the detection of problem vetices and associated triangles --- src/osgUtil/SmoothingVisitor.cpp | 39 ++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/osgUtil/SmoothingVisitor.cpp b/src/osgUtil/SmoothingVisitor.cpp index 4cca1e2a9..722ae7a85 100644 --- a/src/osgUtil/SmoothingVisitor.cpp +++ b/src/osgUtil/SmoothingVisitor.cpp @@ -200,6 +200,11 @@ struct SmoothTriangleIndexFunctor void operator() (unsigned int p1, unsigned int p2, unsigned int p3) { + if (p1==p2 || p2==p3 || p1==p3) + { + return; + } + const osg::Vec3& v1 = (*_vertices)[p1]; const osg::Vec3& v2 = (*_vertices)[p2]; const osg::Vec3& v3 = (*_vertices)[p3]; @@ -318,23 +323,45 @@ struct FindSharpEdgesFunctor { osg::Vec3 normal( computeNormal(p1, p2, p3) ); + if (p1==p2 || p2==p3 || p1==p3) + { + // OSG_NOTICE<<"NULL triangle ("<_triangles.push_back(tri); + void checkTrianglesForProblemVertices() + { + for(Triangles::iterator itr = _triangles.begin(); + itr != _triangles.end(); + ++itr) + { + Triangle* tri = itr->get(); + insertTriangleIfProblemVertex(tri->_p1, tri); + insertTriangleIfProblemVertex(tri->_p2, tri); + insertTriangleIfProblemVertex(tri->_p3, tri); + } + } + + void insertTriangleIfProblemVertex(unsigned int p, Triangle* tri) + { + if (_problemVertexVector[p]) _problemVertexVector[p]->_triangles.push_back(tri); } bool checkDeviation(unsigned int p, osg::Vec3& normal) @@ -422,6 +449,8 @@ struct FindSharpEdgesFunctor void duplicateProblemVertices() { + checkTrianglesForProblemVertices(); + for(ProblemVertexList::iterator itr = _problemVertexList.begin(); itr != _problemVertexList.end(); ++itr)