From b31589b15f792671ce432a8d791619538ce6acb2 Mon Sep 17 00:00:00 2001 From: Janis Born Date: Mon, 23 Nov 2015 15:03:57 +0100 Subject: [PATCH] fall back to dummy implementation for calc_face_normal on meshes with non-3D points --- src/OpenMesh/Core/Mesh/PolyMeshT.cc | 47 +++++++++++++++++++++++++++-- src/OpenMesh/Core/Mesh/PolyMeshT.hh | 7 +++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/OpenMesh/Core/Mesh/PolyMeshT.cc b/src/OpenMesh/Core/Mesh/PolyMeshT.cc index b4f5fb6e..fb628510 100644 --- a/src/OpenMesh/Core/Mesh/PolyMeshT.cc +++ b/src/OpenMesh/Core/Mesh/PolyMeshT.cc @@ -61,6 +61,7 @@ #include #include +#include #include #include #include @@ -97,8 +98,18 @@ uint PolyMeshT::find_feature_edges(Scalar _angle_tresh) template typename PolyMeshT::Normal -PolyMeshT:: -calc_face_normal(FaceHandle _fh) const +PolyMeshT::calc_face_normal(FaceHandle _fh) const +{ + return calc_face_normal_impl(_fh, typename GenProg::IF< + PolyMeshT::Point::size() == 3, + PointIs3DTag, + PointIsNot3DTag + >::Result()); +} + +template +typename PolyMeshT::Normal +PolyMeshT::calc_face_normal_impl(FaceHandle _fh, PointIs3DTag) const { assert(this->halfedge_handle(_fh).is_valid()); ConstFaceVertexIter fv_it(this->cfv_iter(_fh)); @@ -139,8 +150,15 @@ calc_face_normal(FaceHandle _fh) const : Normal(0, 0, 0); } -//----------------------------------------------------------------------------- +template +typename PolyMeshT::Normal +PolyMeshT::calc_face_normal_impl(FaceHandle, PointIsNot3DTag) const +{ + // Dummy fallback implementation + return Normal(0); +} +//----------------------------------------------------------------------------- template typename PolyMeshT::Normal @@ -148,6 +166,21 @@ PolyMeshT:: calc_face_normal(const Point& _p0, const Point& _p1, const Point& _p2) const +{ + return calc_face_normal_impl(_p0, _p1, _p2, typename GenProg::IF< + PolyMeshT::Point::size() == 3, + PointIs3DTag, + PointIsNot3DTag + >::Result()); +} + +template +typename PolyMeshT::Normal +PolyMeshT:: +calc_face_normal_impl(const Point& _p0, + const Point& _p1, + const Point& _p2, + PointIs3DTag) const { #if 1 // The OpenSG ::operator -= () does not support the type Point @@ -174,6 +207,14 @@ calc_face_normal(const Point& _p0, #endif } +template +typename PolyMeshT::Normal +PolyMeshT:: +calc_face_normal_impl(const Point&, const Point&, const Point&, PointIsNot3DTag) const +{ + return Normal(0); +} + //----------------------------------------------------------------------------- template diff --git a/src/OpenMesh/Core/Mesh/PolyMeshT.hh b/src/OpenMesh/Core/Mesh/PolyMeshT.hh index a3180fb5..9ea65535 100644 --- a/src/OpenMesh/Core/Mesh/PolyMeshT.hh +++ b/src/OpenMesh/Core/Mesh/PolyMeshT.hh @@ -520,6 +520,13 @@ public: inline void split(EdgeHandle _eh, VertexHandle _vh) { Kernel::split_edge(_eh, _vh); } +private: + struct PointIs3DTag {}; + struct PointIsNot3DTag {}; + Normal calc_face_normal_impl(FaceHandle, PointIs3DTag) const; + Normal calc_face_normal_impl(FaceHandle, PointIsNot3DTag) const; + Normal calc_face_normal_impl(const Point&, const Point&, const Point&, PointIs3DTag) const; + Normal calc_face_normal_impl(const Point&, const Point&, const Point&, PointIsNot3DTag) const; }; /**