Fixed wrong normal calculation in calc_face_normal for Poly Meshes.
closes #2427 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1247 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -97,33 +97,38 @@ calc_face_normal(FaceHandle _fh) const
|
|||||||
ConstFaceVertexIter fv_it(this->cfv_iter(_fh));
|
ConstFaceVertexIter fv_it(this->cfv_iter(_fh));
|
||||||
|
|
||||||
Point p0 = this->point(*fv_it);
|
Point p0 = this->point(*fv_it);
|
||||||
Point p0i = p0; //save point of vertex 0
|
const Point p0i = p0; //save point of vertex 0
|
||||||
++fv_it;
|
// Safeguard for 1-gons
|
||||||
|
if (!(++fv_it).is_valid()) return Normal(0, 0, 0);
|
||||||
|
|
||||||
Point p1 = this->point(*fv_it);
|
Point p1 = this->point(*fv_it);
|
||||||
Point p1i = p1; //save point of vertex 1
|
const Point p1i = p1; //save point of vertex 1
|
||||||
++fv_it;
|
++fv_it;
|
||||||
Point p2;
|
// Safeguard for 2-gons
|
||||||
|
if (!(++fv_it).is_valid()) return Normal(0, 0, 0);
|
||||||
|
|
||||||
//calculate area-weighted average normal of polygon's ears
|
//calculate area-weighted average normal of polygon's ears
|
||||||
Normal n(0,0,0);
|
Normal n(0,0,0);
|
||||||
for(; fv_it.is_valid(); ++fv_it)
|
for(; fv_it.is_valid(); ++fv_it)
|
||||||
{
|
{
|
||||||
p2 = this->point(*fv_it);
|
const Point p2 = this->point(*fv_it);
|
||||||
n += vector_cast<Normal>(calc_face_normal(p0, p1, p2));
|
n += vector_cast<Normal>(calc_face_normal(p0, p1, p2));
|
||||||
p0 = p1;
|
p0 = p1;
|
||||||
p1 = p2;
|
p1 = p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
//two additional steps since we started at vertex 2, not 0
|
//two additional steps since we started at vertex 2, not 0
|
||||||
n += vector_cast<Normal>(calc_face_normal(p0i, p0, p1));
|
n += vector_cast<Normal>(calc_face_normal(p0, p1, p0i));
|
||||||
n += vector_cast<Normal>(calc_face_normal(p1i, p0i, p1));
|
n += vector_cast<Normal>(calc_face_normal(p1, p0i, p1i));
|
||||||
|
|
||||||
typename vector_traits<Normal>::value_type norm = n.length();
|
const typename vector_traits<Normal>::value_type norm = n.length();
|
||||||
|
|
||||||
// The expression ((n *= (1.0/norm)),n) is used because the OpenSG
|
// The expression ((n *= (1.0/norm)),n) is used because the OpenSG
|
||||||
// vector class does not return self after component-wise
|
// vector class does not return self after component-wise
|
||||||
// self-multiplication with a scalar!!!
|
// self-multiplication with a scalar!!!
|
||||||
return (norm != typename vector_traits<Normal>::value_type(0)) ? ((n *= (typename vector_traits<Normal>::value_type(1)/norm)),n) : Normal(0,0,0);
|
return (norm != typename vector_traits<Normal>::value_type(0))
|
||||||
|
? ((n *= (typename vector_traits<Normal>::value_type(1)/norm)), n)
|
||||||
|
: Normal(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user