From d3ce97f566c8782f4d6597e19900930d3d0bb3a9 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Fri, 12 Feb 2016 14:19:23 +0100 Subject: [PATCH] use face normals map as input of compute_vertex_normal in the named parameters --- .../Polygon_mesh_processing/compute_normal.h | 15 +++++++++-- .../internal/named_function_params.h | 17 ++++++++++++ .../internal/named_params_helper.h | 26 +++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h index c42fda98040..861301b43b1 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h @@ -32,6 +32,8 @@ #include #include +#include + namespace CGAL{ namespace Polygon_mesh_processing{ @@ -187,6 +189,14 @@ compute_vertex_normal(typename boost::graph_traits::vertex_descript typedef typename GetGeomTraits::type Kernel; typedef typename Kernel::FT FT; + typedef typename GetFaceNormalMap::type FaceNormalMap; + FaceNormalMap fnmap + = boost::choose_param(get_param(np, face_normal), FaceNormalMap()); + bool fnmap_valid + = !boost::is_same::NoMap + >::value; + typedef typename Kernel::Vector_3 Vector; typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; @@ -197,7 +207,8 @@ compute_vertex_normal(typename boost::graph_traits::vertex_descript { if (!is_border(he, pmesh)) { - Vector n = compute_face_normal(face(he, pmesh), pmesh, np); + Vector n = fnmap_valid ? get(fnmap, face(he, pmesh)) + : compute_face_normal(face(he, pmesh), pmesh, np); normal = normal + n; } he = opposite(next(he, pmesh), pmesh); @@ -279,8 +290,8 @@ compute_normals(const PolygonMesh& pmesh , const NamedParameters& np ) { - compute_vertex_normals(pmesh, vnm, np); compute_face_normals(pmesh, fnm, np); + compute_vertex_normals(pmesh, vnm, np.face_normal_map(fnm)); } ///\cond SKIP_IN_MANUAL diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_function_params.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_function_params.h index 0b9697ed63c..441afa983af 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_function_params.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_function_params.h @@ -38,6 +38,7 @@ namespace CGAL{ //to be documented enum smooth_along_features_t { smooth_along_features }; + enum face_normal_t { face_normal }; //internal enum weight_calculator_t { weight_calculator }; @@ -100,6 +101,14 @@ namespace CGAL{ return Params(w, *this); } + template + pmp_bgl_named_params + face_normal_map(const FaceNormalMap& m) const + { + typedef pmp_bgl_named_params Params; + return Params(m, *this); + } + //overload template pmp_bgl_named_params @@ -230,6 +239,14 @@ namespace parameters{ return Params(w); } + template + pmp_bgl_named_params + face_normal_map(const FaceNormalMap& m) + { + typedef pmp_bgl_named_params Params; + return Params(p); + } + //overload template pmp_bgl_named_params diff --git a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_params_helper.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_params_helper.h index c17daf4a0f9..78b3da3b8c5 100644 --- a/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_params_helper.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/named_params_helper.h @@ -100,6 +100,32 @@ public: > ::type type; }; +template +class GetFaceNormalMap +{ + struct DummyNormalPmap + { + typedef typename boost::graph_traits::face_descriptor key_type; + typedef typename GetGeomTraits::type::Vector_3 value_type; + typedef value_type& reference; + typedef boost::lvalue_property_map_tag category; + + reference operator[](key_type&) const { return CGAL::NULL_VECTOR; } + typedef DummyNormalPmap Self; + friend const value_type& get(const Self&, const key_type&) { return CGAL::NULL_VECTOR; } + friend reference get(const Self&, key_type&) { return CGAL::NULL_VECTOR; } + friend void put(const Self&, key_type&, const value_type&) {} + }; + +public: + typedef DummyNormalPmap NoMap; + typedef typename boost::lookup_named_param_def < + CGAL::face_normal_t, + NamedParameters, + DummyNormalPmap//default + > ::type type; +}; + template class GetSolver {