diff --git a/src/OpenMesh/Core/Mesh/PolyMeshT.hh b/src/OpenMesh/Core/Mesh/PolyMeshT.hh index b6c70bb7..a09bbf8c 100644 --- a/src/OpenMesh/Core/Mesh/PolyMeshT.hh +++ b/src/OpenMesh/Core/Mesh/PolyMeshT.hh @@ -456,13 +456,7 @@ public: } /// calculated and returns the average of the two vertex normals - Normal calc_normal(EdgeHandle _eh) const - { - HalfedgeHandle _heh = this->halfedge_handle(_eh, 0); - VertexHandle vh0 = this->from_vertex_handle(_heh); - VertexHandle vh1 = this->to_vertex_handle(_heh); - return 0.5 * (this->calc_normal(vh0) + this->calc_normal(vh1)); - } + Normal calc_normal(EdgeHandle _eh) const; /** defines a consistent representation of a sector geometry: the halfedge _in_heh defines the sector orientation diff --git a/src/OpenMesh/Core/Mesh/PolyMeshT_impl.hh b/src/OpenMesh/Core/Mesh/PolyMeshT_impl.hh index 96a00cd1..e998dcc9 100644 --- a/src/OpenMesh/Core/Mesh/PolyMeshT_impl.hh +++ b/src/OpenMesh/Core/Mesh/PolyMeshT_impl.hh @@ -109,7 +109,7 @@ PolyMeshT::calc_face_normal_impl(FaceHandle _fh, PointIs3DTag) const { assert(this->halfedge_handle(_fh).is_valid()); ConstFaceVertexIter fv_it(this->cfv_iter(_fh)); - + // Safeguard for 1-gons if (!(++fv_it).is_valid()) return Normal(0, 0, 0); @@ -140,7 +140,7 @@ PolyMeshT::calc_face_normal_impl(FaceHandle _fh, PointIs3DTag) const } const typename vector_traits::value_type length = norm(n); - + // The expression ((n *= (1.0/norm)),n) is used because the OpenSG // vector class does not return self after component-wise // self-multiplication with a scalar!!! @@ -424,6 +424,28 @@ calc_normal(HalfedgeHandle _heh, const double _feature_angle) const //----------------------------------------------------------------------------- +template +typename PolyMeshT::Normal +PolyMeshT:: +calc_normal(EdgeHandle _eh) const +{ + Normal n(0); + for (int i = 0; i < 2; ++i) + { + const auto heh = this->halfedge_handle(_eh, i); + const auto fh = this->face_handle(heh); + if (fh.is_valid()) + n += calc_normal(fh); + } + const auto length = norm(n); + if (length != 0) + n /= length; + return n; +} + +//----------------------------------------------------------------------------- + + template bool PolyMeshT::