From f85d783613d445353e11d0f1795c8d6b77b9bc14 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Mon, 11 Apr 2016 12:15:59 +0200 Subject: [PATCH 1/2] improve computation of a face normal for non-triangular faces triangulating the face naively around v is much simpler and more accurate than iterating on prev/curr/next vertices inside the face --- .../Polygon_mesh_processing/compute_normal.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 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 85153072ad9..6848f81d3a2 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 @@ -54,21 +54,23 @@ void sum_normals(const PM& pmesh, VertexPointMap vpmap, Vector& sum) { + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; halfedge_descriptor he = halfedge(f, pmesh); halfedge_descriptor end = he; - bool f_is_triangle = (he == next(next(next(he, pmesh), pmesh), pmesh)); - /*it is useless to compute the normal 3 times on a triangle*/ - do + + vertex_descriptor v = source(he, pmesh); + const Point& pv = get(vpmap, v); + while (v != target(next(he, pmesh), pmesh)) { - const Point& prv = get(vpmap, target(prev(he, pmesh), pmesh)); - const Point& curr = get(vpmap, target(he, pmesh)); - const Point& nxt = get(vpmap, target(next(he, pmesh), pmesh)); - Vector n = internal::triangle_normal(prv, curr, nxt); + const Point& pvn = get(vpmap, target(he, pmesh)); + const Point& pvnn = get(vpmap, target(next(he, pmesh), pmesh)); + + Vector n = internal::triangle_normal(pv, pvn, pvnn); sum = sum + n; he = next(he, pmesh); - } while (he != end && !f_is_triangle); + } } From c7c8c86a9e7578c040925ab9ebdafcd770a00b61 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 12 Apr 2016 18:17:05 +0200 Subject: [PATCH 2/2] remove unused variable --- .../include/CGAL/Polygon_mesh_processing/compute_normal.h | 3 +-- 1 file changed, 1 insertion(+), 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 6848f81d3a2..ebc0cfd2951 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 @@ -56,9 +56,8 @@ void sum_normals(const PM& pmesh, { typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; - halfedge_descriptor he = halfedge(f, pmesh); - halfedge_descriptor end = he; + halfedge_descriptor he = halfedge(f, pmesh); vertex_descriptor v = source(he, pmesh); const Point& pv = get(vpmap, v); while (v != target(next(he, pmesh), pmesh))