From f25d87ed9cdf64d48b7fb4bf7a2214ce10a33efa Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 11 Feb 2015 10:18:00 +0100 Subject: [PATCH] Add compute_normals; facet -> face --- .../Polygon_mesh_processing/compute_normal.h | 114 +++++++++++++++--- .../test/Polygon_mesh_processing/normals.cpp | 11 +- 2 files changed, 106 insertions(+), 19 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 919fcea9f3f..8083e7dcf26 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 @@ -27,6 +27,88 @@ namespace CGAL{ namespace Polygon_mesh_processing{ +///\cond SKIP_IN_MANUAL + + template +void +compute_normals(const PolygonMesh& pmesh, + VertexNormalPropertyMap vnpm, + FaceNormalPropertyMap fnpm) +{ + typedef typename Kernel_traits< + typename boost::property_traits< + typename boost::property_map< + PolygonMesh, CGAL::vertex_point_t>::type>::value_type>::Kernel Kernel; + compute_normals(pmesh, vnpm, fnpm, get(vertex_point, pmesh), Kernel()); +} + + +template +void +compute_normals(const PolygonMesh& pmesh, + VertexNormalPropertyMap vnpm, + FaceNormalPropertyMap fnpm, + PointPropertyMap ppmap) +{ + typedef typename Kernel_traits< + typename boost::property_traits< + typename boost::property_map< + PolygonMesh, CGAL::vertex_point_t>::type>::value_type>::Kernel Kernel; + compute_normals(pmesh, vnpm, fnpm, ppmap, Kernel()); +} + +///\endcond +/** +* \ingroup PkgPolygonMeshProcessing +* computes the outward unit vector normal for all vertices and faces of the polygon mesh. +* @tparam Kernel Geometric traits class. It can be omitted and deduced automatically from the point type of `PolygonMesh`. +* @tparam PolygonMesh a model of `FaceGraph` +* @tparam VertexNormalPropertyMap the property map in which the vertex normals are written. +* @tparam FaceNormalPropertyMap the property map in which the face normals are written. +* @tparam PointPropertyMap the property map with the points associated to the vertices. +* +* @param pmesh the polygon mesh +*/ +template ::type +#endif + , typename Kernel +#ifdef DOXYGEN_RUNNING + = typename Kernel_traits< + typename boost::property_traits::value_type>::Kernel +#endif + > +void +compute_normals(const PolygonMesh& pmesh + , VertexNormalPropertyMap vnpm + , FaceNormalPropertyMap fnpm + , PointPropertyMap ppmap +#ifdef DOXYGEN_RUNNING + = get(vertex_point, pmesh) +#endif + ,const Kernel& k +#ifdef DOXYGEN_RUNNING + = Kernel() +#endif + ) +{ + typename boost::graph_traits::vertex_descriptor v; + BOOST_FOREACH(v, vertices(pmesh)){ + typename Kernel::Vector_3 vec = compute_vertex_normal(v,pmesh, ppmap, k); + put(vnpm, v, vec); + } + typename boost::graph_traits::face_descriptor f; + BOOST_FOREACH(f, faces(pmesh)){ + typename Kernel::Vector_3 vec = compute_face_normal(f,pmesh, ppmap, k); + put(fnpm, f, vec); + } +} + + ///\cond SKIP_IN_MANUAL @@ -65,7 +147,7 @@ compute_vertex_normals(const PolygonMesh& pmesh, * @tparam VertexNormalPropertyMap the property map in which the normals are written. * @tparam PointPropertyMap the property map with the points associated to the vertices. * -* @param f the facet on which the normal is computed +* @param f the face on which the normal is computed * @param pmesh the polygon mesh */ template void -compute_facet_normals(const PolygonMesh& pmesh, +compute_face_normals(const PolygonMesh& pmesh, FaceNormalPropertyMap npm) { typedef typename Kernel_traits< typename boost::property_traits< typename boost::property_map< PolygonMesh, CGAL::vertex_point_t>::type>::value_type>::Kernel Kernel; - compute_facet_normals(pmesh, npm, get(vertex_point, pmesh), Kernel()); + compute_face_normals(pmesh, npm, get(vertex_point, pmesh), Kernel()); } template void -compute_facet_normals(const PolygonMesh& pmesh, +compute_face_normals(const PolygonMesh& pmesh, FaceNormalPropertyMap npm, PointPropertyMap ppmap) { @@ -125,7 +207,7 @@ compute_facet_normals(const PolygonMesh& pmesh, typename boost::property_traits< typename boost::property_map< PolygonMesh, CGAL::vertex_point_t>::type>::value_type>::Kernel Kernel; - compute_facet_normals(pmesh, npm, ppmap, Kernel()); + compute_face_normals(pmesh, npm, ppmap, Kernel()); } ///\endcond @@ -154,7 +236,7 @@ template void -compute_facet_normals(const PolygonMesh& pmesh +compute_face_normals(const PolygonMesh& pmesh , FaceNormalPropertyMap npm , PointPropertyMap ppmap #ifdef DOXYGEN_RUNNING @@ -168,7 +250,7 @@ compute_facet_normals(const PolygonMesh& pmesh { typename boost::graph_traits::face_descriptor f; BOOST_FOREACH(f, faces(pmesh)){ - typename Kernel::Vector_3 vec = compute_facet_normal(f,pmesh, ppmap, k); + typename Kernel::Vector_3 vec = compute_face_normal(f,pmesh, ppmap, k); put(npm, f, vec); } } @@ -181,7 +263,7 @@ typename Kernel_traits< typename boost::property_traits< typename boost::property_map< PolygonMesh, CGAL::vertex_point_t>::type>::value_type>::Kernel::Vector_3 -compute_facet_normal( +compute_face_normal( typename boost::graph_traits::face_descriptor f, const PolygonMesh& pmesh) { @@ -189,7 +271,7 @@ compute_facet_normal( typename boost::property_traits< typename boost::property_map< PolygonMesh, CGAL::vertex_point_t>::type>::value_type>::Kernel Kernel; - return compute_facet_normal(f, pmesh, get(vertex_point, pmesh), Kernel()); + return compute_face_normal(f, pmesh, get(vertex_point, pmesh), Kernel()); } @@ -197,14 +279,14 @@ compute_facet_normal( template typename Kernel_traits< typename boost::property_traits::value_type>::Kernel::Vector_3 -compute_facet_normal( +compute_face_normal( typename boost::graph_traits::face_descriptor f, const PolygonMesh& pmesh, PointPropertyMap ppmap) { typedef typename Kernel_traits< typename boost::property_traits::value_type>::Kernel Kernel; - return compute_facet_normal(f, pmesh, ppmap, Kernel()); + return compute_face_normal(f, pmesh, ppmap, Kernel()); } /// \endcond @@ -212,11 +294,11 @@ compute_facet_normal( /** * \ingroup PkgPolygonMeshProcessing -* computes the outward unit vector normal to facet `f`. +* computes the outward unit vector normal to face `f`. * @tparam Kernel Geometric traits class. It can be omitted and deduced automatically from the point type of `PolygonMesh`. * @tparam PolygonMesh a model of `FaceGraph` * -* @param f the facet on which the normal is computed +* @param f the face on which the normal is computed * @param pmesh the polygon mesh to which `f` belongs */ template typename Kernel::Vector_3 -compute_facet_normal(typename boost::graph_traits::face_descriptor f, +compute_face_normal(typename boost::graph_traits::face_descriptor f, const PolygonMesh& pmesh , PointPropertyMap ppmap #ifdef DOXYGEN_RUNNING @@ -304,7 +386,7 @@ compute_vertex_normal( /** * \ingroup PkgPolygonMeshProcessing -* computes the unit normal at vertex `v` as the average of the normals of incident facets. +* computes the unit normal at vertex `v` as the average of the normals of incident faces. * @tparam Kernel a %CGAL `Kernel` with `FT` a model of `FieldWithSqrt` * @tparam PolygonMesh a model of `FaceGraph` * @@ -345,7 +427,7 @@ compute_vertex_normal(typename boost::graph_traits::vertex_descript { if (!is_border(he, pmesh)) { - Vector n = compute_facet_normal(face(he, pmesh), pmesh, ppmap, k); + Vector n = compute_face_normal(face(he, pmesh), pmesh, ppmap, k); normal = normal + (n / std::sqrt(n*n)); } he = opposite(next(he, pmesh), pmesh); diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/normals.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/normals.cpp index d4fe242aaf3..6315330d9e6 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/normals.cpp +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/normals.cpp @@ -32,9 +32,9 @@ void test(const char* file_name) Surface_mesh::Property_map fnormals; bool created; boost::tie(fnormals, created) = mesh.add_property_map("f:normals",Vector(0,0,0)); - CGAL::Polygon_mesh_processing::compute_facet_normals(mesh, fnormals); - CGAL::Polygon_mesh_processing::compute_facet_normals(mesh, fnormals, mesh.points()); - CGAL::Polygon_mesh_processing::compute_facet_normals(mesh, fnormals, mesh.points(), K()); + CGAL::Polygon_mesh_processing::compute_face_normals(mesh, fnormals); + CGAL::Polygon_mesh_processing::compute_face_normals(mesh, fnormals, mesh.points()); + CGAL::Polygon_mesh_processing::compute_face_normals(mesh, fnormals, mesh.points(), K()); Surface_mesh::Property_map vnormals; @@ -43,6 +43,11 @@ void test(const char* file_name) CGAL::Polygon_mesh_processing::compute_vertex_normals(mesh, vnormals, mesh.points()); CGAL::Polygon_mesh_processing::compute_vertex_normals(mesh, vnormals, mesh.points(), K()); + + CGAL::Polygon_mesh_processing::compute_normals(mesh, vnormals, fnormals); + CGAL::Polygon_mesh_processing::compute_normals(mesh, vnormals, fnormals, mesh.points()); + CGAL::Polygon_mesh_processing::compute_normals(mesh, vnormals, fnormals, mesh.points(), K()); + BOOST_FOREACH(face_descriptor fd , faces(mesh)){ std::cout << fnormals[fd] << std::endl; }