From 85dce701b976ad42debbf600e7f57cc93dbd3ef3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Tue, 6 Jan 2015 15:32:45 +0100 Subject: [PATCH] move compute_normal in Polygon Mesh Processing package --- .../demo/Mesh_3/include/CGAL/compute_normal.h | 44 ------------------- Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h | 6 +-- .../PackageDescription.txt | 2 + .../Polygon_mesh_processing}/compute_normal.h | 25 ++++++++--- .../include/CGAL/orient_polyhedron_3.h | 4 +- .../include/CGAL/triangulate_polyhedron.h | 4 +- .../Polyhedron_demo_jet_fitting_plugin.cpp | 4 +- ...yhedron_demo_triangulate_facets_plugin.cpp | 7 +-- .../Polyhedron/Scene_edit_polyhedron_item.cpp | 2 +- .../Polyhedron/Scene_edit_polyhedron_item.h | 4 +- .../Scene_points_with_normal_item.cpp | 4 +- .../Scene_polyhedron_selection_item.h | 2 +- .../demo/Polyhedron/include/CGAL/gl_render.h | 7 ++- .../include/compute_normal.h | 44 ------------------- .../poisson_reconstruction.cpp | 5 +-- .../include/compute_normal.h | 44 ------------------- .../poisson_reconstruction_test.cpp | 5 +-- 17 files changed, 46 insertions(+), 167 deletions(-) delete mode 100644 Mesh_3/demo/Mesh_3/include/CGAL/compute_normal.h rename {Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra => Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing}/compute_normal.h (70%) delete mode 100644 Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/include/compute_normal.h delete mode 100644 Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/include/compute_normal.h diff --git a/Mesh_3/demo/Mesh_3/include/CGAL/compute_normal.h b/Mesh_3/demo/Mesh_3/include/CGAL/compute_normal.h deleted file mode 100644 index ad8c190a3d0..00000000000 --- a/Mesh_3/demo/Mesh_3/include/CGAL/compute_normal.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _COMPUTE_NORMAL_ -#define _COMPUTE_NORMAL_ - -template -typename Kernel::Vector_3 compute_facet_normal(const Facet& f) -{ - typedef typename Kernel::Point_3 Point; - typedef typename Kernel::Vector_3 Vector; - typedef typename Facet::Halfedge_around_facet_const_circulator HF_circulator; - Vector normal = CGAL::NULL_VECTOR; - HF_circulator he = f.facet_begin(); - HF_circulator end = he; - CGAL_For_all(he,end) - { - const Point& prev = he->prev()->vertex()->point(); - const Point& curr = he->vertex()->point(); - const Point& next = he->next()->vertex()->point(); - Vector n = CGAL::cross_product(next-curr,prev-curr); - normal = normal + (n / std::sqrt(n*n)); - } - return normal / std::sqrt(normal * normal); -} - -template -typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v) -{ - typedef typename Kernel::Vector_3 Vector; - typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator; - typedef typename Vertex::Facet Facet; - Vector normal = CGAL::NULL_VECTOR; - HV_circulator he = v.vertex_begin(); - HV_circulator end = he; - CGAL_For_all(he,end) - { - if(!he->is_border()) - { - Vector n = compute_facet_normal(*he->facet()); - normal = normal + (n / std::sqrt(n*n)); - } - } - return normal / std::sqrt(normal * normal); -} - -#endif // _COMPUTE_NORMAL_ diff --git a/Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h b/Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h index fe76152afab..f5fbde6e147 100644 --- a/Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h +++ b/Mesh_3/demo/Mesh_3/include/CGAL/gl_render.h @@ -2,7 +2,7 @@ #define _GL_RENDER_ #include -#include +#include template void gl_render_facets(Polyhedron& polyhedron) @@ -28,7 +28,7 @@ void gl_render_facets(Polyhedron& polyhedron) // If Flat shading: 1 normal per polygon if (shading == GL_FLAT) { - Vector n = compute_facet_normal(*f); + Vector n = CGAL::Polygon_mesh_processing::compute_facet_normal(*f); ::glNormal3d(n.x(),n.y(),n.z()); } @@ -40,7 +40,7 @@ void gl_render_facets(Polyhedron& polyhedron) // If Gouraud shading: 1 normal per vertex if (shading == GL_SMOOTH) { - Vector n = compute_vertex_normal(*he->vertex()); + Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal(*he->vertex()); ::glNormal3d(n.x(),n.y(),n.z()); } diff --git a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt index 31ec34330de..98ba0e8c646 100644 --- a/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt +++ b/Polygon_mesh_processing/doc/Polygon_mesh_processing/PackageDescription.txt @@ -41,6 +41,8 @@ - `CGAL::self_intersect()` - `CGAL::do_self_intersect()` - `CGAL::orient_polygon_soup()` +- `CGAL::Polygon_mesh_processing::compute_facet_normal()` +- `CGAL::Polygon_mesh_processing::compute_vertex_normal()` ## Classes ## - `CGAL::Polygon_soup_to_polyhedron_3` diff --git a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/compute_normal.h b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h similarity index 70% rename from Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/compute_normal.h rename to Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h index 569796a2894..60d8b983dcd 100644 --- a/Operations_on_polyhedra/include/CGAL/internal/Operations_on_polyhedra/compute_normal.h +++ b/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/compute_normal.h @@ -19,10 +19,17 @@ // Author(s) : Pierre Alliez -#ifndef CGAL_INTERNAL_OPERATIONS_ON_POLYHEDRA_COMPUTE_NORMAL_H -#define CGAL_INTERNAL_OPERATIONS_ON_POLYHEDRA_COMPUTE_NORMAL_H +#ifndef CGAL_POLYGON_MESH_PROCESSING_COMPUTE_NORMAL_H +#define CGAL_POLYGON_MESH_PROCESSING_COMPUTE_NORMAL_H -template +namespace CGAL{ + +namespace Polygon_mesh_processing{ + +/// \ingroup PkgPolygonMeshProcessing +/// computes the outward unit vector normal to facet `f`. +/// `%Kernel::%FT` should be a model of `FieldWithSqrt` +template typename Kernel::Vector_3 compute_facet_normal(const Facet& f) { typedef typename Kernel::Point_3 Point; @@ -42,12 +49,14 @@ typename Kernel::Vector_3 compute_facet_normal(const Facet& f) return normal / std::sqrt(normal * normal); } -template +/// \ingroup PkgPolygonMeshProcessing +/// computes the unit normal at vertex `v` as the average of the normals of incident facets. +/// `%Kernel::%FT` should be a model of `FieldWithSqrt` +template typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v) { typedef typename Kernel::Vector_3 Vector; typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator; - typedef typename Vertex::Facet Facet; Vector normal = CGAL::NULL_VECTOR; HV_circulator he = v.vertex_begin(); HV_circulator end = he; @@ -55,11 +64,13 @@ typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v) { if(!he->is_border()) { - Vector n = compute_facet_normal(*he->facet()); + Vector n = compute_facet_normal(*he->facet()); normal = normal + (n / std::sqrt(n*n)); } } return normal / std::sqrt(normal * normal); } -#endif // CGAL_INTERNAL_OPERATIONS_ON_POLYHEDRA_COMPUTE_NORMAL_H +} } // end of namespace CGAL::Polygon_mesh_processing + +#endif // CGAL_POLYGON_MESH_PROCESSING_COMPUTE_NORMAL_H diff --git a/Polygon_mesh_processing/include/CGAL/orient_polyhedron_3.h b/Polygon_mesh_processing/include/CGAL/orient_polyhedron_3.h index 7ce5f7bf362..dea6ea7616a 100644 --- a/Polygon_mesh_processing/include/CGAL/orient_polyhedron_3.h +++ b/Polygon_mesh_processing/include/CGAL/orient_polyhedron_3.h @@ -23,7 +23,7 @@ #define CGAL_ORIENT_POLYHEDRON_3 #include -#include +#include namespace CGAL { namespace internal { @@ -69,7 +69,7 @@ bool is_oriented(const Polyhedron& polyhedron) { = std::min_element(polyhedron.vertices_begin(), polyhedron.vertices_end(), internal::Axis_compare()); typedef typename Polyhedron::Traits K; - const typename K::Vector_3& normal_v_min = compute_vertex_normal(*v_min); + const typename K::Vector_3& normal_v_min = Polygon_mesh_processing::compute_vertex_normal(*v_min); CGAL_warning(normal_v_min[axis] != 0); return normal_v_min[axis] < 0; diff --git a/Polygon_mesh_processing/include/CGAL/triangulate_polyhedron.h b/Polygon_mesh_processing/include/CGAL/triangulate_polyhedron.h index f288cf8bcc6..e9d617900f9 100644 --- a/Polygon_mesh_processing/include/CGAL/triangulate_polyhedron.h +++ b/Polygon_mesh_processing/include/CGAL/triangulate_polyhedron.h @@ -29,7 +29,7 @@ #include #include -#include +#include #include #include @@ -103,7 +103,7 @@ public: { Facet_handle fit = *fit_it; typename Traits::Vector_3 normal = - compute_facet_normal(*fit); + Polygon_mesh_processing::compute_facet_normal(*fit); P_traits cdt_traits(normal); CDT cdt(cdt_traits); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp index a985d8a937a..8d8a0f0b6a5 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_jet_fitting_plugin.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include class Polyhedron_demo_jet_fitting_plugin : public QObject, @@ -99,7 +99,7 @@ void Polyhedron_demo_jet_fitting_plugin::on_actionEstimateCurvature_triggered() // make monge form comply with vertex normal (to get correct // orientation) typedef Kernel::Vector_3 Vector; - Vector n = compute_vertex_normal(*v); + Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal(*v); monge_form.comply_wrt_given_normal(n); Vector umin = min_edge_len * monge_form.minimal_principal_direction(); diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp index 89833af3130..bf9af20afcb 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_triangulate_facets_plugin.cpp @@ -77,13 +77,14 @@ public slots: if(!eit_copy->is_border()) { Polyhedron::Facet_handle fh1 = eit_copy->facet(); Polyhedron::Facet_handle fh2 = eit_copy->opposite()->facet(); - typedef Polyhedron::Facet Facet; if( fh1 != fh2 && !eit_copy->vertex()->is_bivalent() && !eit_copy->opposite()->vertex()->is_bivalent()) { - Kernel::Vector_3 v1 = compute_facet_normal(*fh1); - Kernel::Vector_3 v2 = compute_facet_normal(*fh2); + Kernel::Vector_3 v1 = + CGAL::Polygon_mesh_processing::compute_facet_normal(*fh1); + Kernel::Vector_3 v2 = + CGAL::Polygon_mesh_processing::compute_facet_normal(*fh2); if(v1 * v2 > 0.99) { std::cerr << "join\n"; // pMesh->is_valid(true); diff --git a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp index 6910306a90f..bb150a181d5 100644 --- a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.cpp @@ -51,7 +51,7 @@ Scene_edit_polyhedron_item::Scene_edit_polyhedron_item positions[counter*3+2] = vb->point().z(); const Polyhedron::Traits::Vector_3& n = - compute_vertex_normal(*vb); + CGAL::Polygon_mesh_processing::compute_vertex_normal(*vb); normals[counter*3] = n.x(); normals[counter*3+1] = n.y(); diff --git a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h index a8f5f092049..6e1ae90d337 100644 --- a/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_edit_polyhedron_item.h @@ -8,7 +8,7 @@ #include #include -#include +#include #include #include @@ -658,7 +658,7 @@ protected: { std::size_t id = vd->id(); const Polyhedron::Traits::Vector_3& n = - compute_vertex_normal(*vd); + CGAL::Polygon_mesh_processing::compute_vertex_normal(*vd); normals[id*3] = n.x(); normals[id*3+1] = n.y(); normals[id*3+2] = n.z(); diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index 4f23b13a9d5..03edec8329e 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -1,6 +1,6 @@ #include "Scene_points_with_normal_item.h" #include "Polyhedron_type.h" -#include +#include #include #include @@ -53,7 +53,7 @@ Scene_points_with_normal_item::Scene_points_with_normal_item(const Polyhedron& i for (v = input_mesh.vertices_begin(); v != input_mesh.vertices_end(); v++) { const Kernel::Point_3& p = v->point(); - Kernel::Vector_3 n = compute_vertex_normal(*v); + Kernel::Vector_3 n = CGAL::Polygon_mesh_processing::compute_vertex_normal(*v); m_points->push_back(UI_point(p,n)); } diff --git a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h index 22d1a96fb29..940344cd85f 100644 --- a/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_polyhedron_selection_item.h @@ -244,7 +244,7 @@ public: it != end; ++it) { const Kernel::Vector_3 n = - compute_facet_normal(**it); + CGAL::Polygon_mesh_processing::compute_facet_normal(**it); ::glNormal3d(n.x(),n.y(),n.z()); Polyhedron::Halfedge_around_facet_circulator diff --git a/Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h b/Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h index 91163409fd4..8002ba95e7a 100644 --- a/Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h +++ b/Polyhedron/demo/Polyhedron/include/CGAL/gl_render.h @@ -2,7 +2,7 @@ #define _GL_RENDER_ #include -#include +#include @@ -26,7 +26,6 @@ void gl_render_facets(Polyhedron& polyhedron, const std::vector& colors) typedef typename Polyhedron::Traits Kernel; typedef typename Kernel::Point_3 Point; typedef typename Kernel::Vector_3 Vector; - typedef typename Polyhedron::Facet Facet; typedef typename Polyhedron::Facet_iterator Facet_iterator; typedef typename Polyhedron::Halfedge_around_facet_circulator HF_circulator; @@ -51,7 +50,7 @@ void gl_render_facets(Polyhedron& polyhedron, const std::vector& colors) // If Flat shading: 1 normal per polygon if (shading == GL_FLAT) { - Vector n = compute_facet_normal(*f); + Vector n = CGAL::Polygon_mesh_processing::compute_facet_normal(*f); ::glNormal3d(n.x(),n.y(),n.z()); } @@ -63,7 +62,7 @@ void gl_render_facets(Polyhedron& polyhedron, const std::vector& colors) // If Gouraud shading: 1 normal per vertex if (shading == GL_SMOOTH) { - Vector n = compute_vertex_normal(*he->vertex()); + Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal(*he->vertex()); ::glNormal3d(n.x(),n.y(),n.z()); } diff --git a/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/include/compute_normal.h b/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/include/compute_normal.h deleted file mode 100644 index ad8c190a3d0..00000000000 --- a/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/include/compute_normal.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _COMPUTE_NORMAL_ -#define _COMPUTE_NORMAL_ - -template -typename Kernel::Vector_3 compute_facet_normal(const Facet& f) -{ - typedef typename Kernel::Point_3 Point; - typedef typename Kernel::Vector_3 Vector; - typedef typename Facet::Halfedge_around_facet_const_circulator HF_circulator; - Vector normal = CGAL::NULL_VECTOR; - HF_circulator he = f.facet_begin(); - HF_circulator end = he; - CGAL_For_all(he,end) - { - const Point& prev = he->prev()->vertex()->point(); - const Point& curr = he->vertex()->point(); - const Point& next = he->next()->vertex()->point(); - Vector n = CGAL::cross_product(next-curr,prev-curr); - normal = normal + (n / std::sqrt(n*n)); - } - return normal / std::sqrt(normal * normal); -} - -template -typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v) -{ - typedef typename Kernel::Vector_3 Vector; - typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator; - typedef typename Vertex::Facet Facet; - Vector normal = CGAL::NULL_VECTOR; - HV_circulator he = v.vertex_begin(); - HV_circulator end = he; - CGAL_For_all(he,end) - { - if(!he->is_border()) - { - Vector n = compute_facet_normal(*he->facet()); - normal = normal + (n / std::sqrt(n*n)); - } - } - return normal / std::sqrt(normal * normal); -} - -#endif // _COMPUTE_NORMAL_ diff --git a/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/poisson_reconstruction.cpp b/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/poisson_reconstruction.cpp index 8aaa61bfeba..50da05a3d03 100644 --- a/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/poisson_reconstruction.cpp +++ b/Surface_reconstruction_points_3/examples/Surface_reconstruction_points_3/poisson_reconstruction.cpp @@ -25,8 +25,7 @@ #include #include #include - -#include "compute_normal.h" +#include #include #include @@ -183,7 +182,7 @@ int main(int argc, char * argv[]) for (v = input_mesh.vertices_begin(); v != input_mesh.vertices_end(); v++) { const Point& p = v->point(); - Vector n = compute_vertex_normal(*v); + Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal(*v); points.push_back(Point_with_normal(p,n)); } } diff --git a/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/include/compute_normal.h b/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/include/compute_normal.h deleted file mode 100644 index ad8c190a3d0..00000000000 --- a/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/include/compute_normal.h +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _COMPUTE_NORMAL_ -#define _COMPUTE_NORMAL_ - -template -typename Kernel::Vector_3 compute_facet_normal(const Facet& f) -{ - typedef typename Kernel::Point_3 Point; - typedef typename Kernel::Vector_3 Vector; - typedef typename Facet::Halfedge_around_facet_const_circulator HF_circulator; - Vector normal = CGAL::NULL_VECTOR; - HF_circulator he = f.facet_begin(); - HF_circulator end = he; - CGAL_For_all(he,end) - { - const Point& prev = he->prev()->vertex()->point(); - const Point& curr = he->vertex()->point(); - const Point& next = he->next()->vertex()->point(); - Vector n = CGAL::cross_product(next-curr,prev-curr); - normal = normal + (n / std::sqrt(n*n)); - } - return normal / std::sqrt(normal * normal); -} - -template -typename Kernel::Vector_3 compute_vertex_normal(const Vertex& v) -{ - typedef typename Kernel::Vector_3 Vector; - typedef typename Vertex::Halfedge_around_vertex_const_circulator HV_circulator; - typedef typename Vertex::Facet Facet; - Vector normal = CGAL::NULL_VECTOR; - HV_circulator he = v.vertex_begin(); - HV_circulator end = he; - CGAL_For_all(he,end) - { - if(!he->is_border()) - { - Vector n = compute_facet_normal(*he->facet()); - normal = normal + (n / std::sqrt(n*n)); - } - } - return normal / std::sqrt(normal * normal); -} - -#endif // _COMPUTE_NORMAL_ diff --git a/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/poisson_reconstruction_test.cpp b/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/poisson_reconstruction_test.cpp index e2a754bc622..2955cb70ad7 100644 --- a/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/poisson_reconstruction_test.cpp +++ b/Surface_reconstruction_points_3/test/Surface_reconstruction_points_3/poisson_reconstruction_test.cpp @@ -23,8 +23,7 @@ #include #include #include - -#include "compute_normal.h" +#include #include #include @@ -128,7 +127,7 @@ int main(int argc, char * argv[]) for (v = input_mesh.vertices_begin(); v != input_mesh.vertices_end(); v++) { const Point& p = v->point(); - Vector n = compute_vertex_normal(*v); + Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal(*v); points.push_back(Point_with_normal(p,n)); } }