From e9e07ea874373e21652af17ce1f98934721219d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 20 Jun 2022 16:24:01 +0200 Subject: [PATCH 1/2] fix constness issues without constcast and use initialized Index pmap mechanism --- .../CGAL/Nef_3/polygon_mesh_to_nef_3.h | 34 +++++++------------ Nef_3/include/CGAL/Nef_polyhedron_3.h | 20 ++--------- 2 files changed, 14 insertions(+), 40 deletions(-) diff --git a/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h b/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h index dea41f6eb00..488551158c2 100644 --- a/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h +++ b/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h @@ -111,7 +111,7 @@ class Face_graph_index_adder { typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; public: - Face_graph_index_adder(Polyhedron&, HalfedgeIndexMap ) {} + Face_graph_index_adder(const Polyhedron&, HalfedgeIndexMap ) {} void set_edge(halfedge_descriptor, SHalfedge_handle) {} void resolve_indexes() {} @@ -128,12 +128,12 @@ class Face_graph_index_adder SHalfedges; - PolygonMesh& P; + const PolygonMesh& P; HalfedgeIndexMap him; SHalfedges shalfedges; public: - Face_graph_index_adder(PolygonMesh& P_, HalfedgeIndexMap him) : P(P_), him(him) + Face_graph_index_adder(const PolygonMesh& P_, HalfedgeIndexMap him) : P(P_), him(him) { shalfedges.resize(num_halfedges(P)); } @@ -168,9 +168,9 @@ public: }; template -void polygon_mesh_to_nef_3(PolygonMesh& P, SNC_structure& S, FaceIndexMap fimap, HalfedgeIndexMap himap) +void polygon_mesh_to_nef_3(const PolygonMesh& P, SNC_structure& S, FaceIndexMap fimap, HalfedgeIndexMap himap) { - typedef typename boost::property_map::type PMap; + typedef typename boost::property_map::const_type PMap; typedef typename SNC_structure::Plane_3 Plane; typedef typename SNC_structure::Vector_3 Vector_3; typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; @@ -316,25 +316,15 @@ void polygon_mesh_to_nef_3(PolygonMesh& P, SNC_structure& S, FaceIndexMap fimap, index_adder.resolve_indexes(); } -template -void polyhedron_3_to_nef_3(Polyhedron& P, SNC_structure& S) +template +void polygon_mesh_to_nef_3(const PolygonMesh& pm, SNC_structure& snc) { - typedef typename boost::property_map::type FIMap; - FIMap fimap = get(CGAL::face_external_index,P); - typedef typename boost::property_map::type HIMap; - HIMap himap = get(CGAL::halfedge_external_index,P); - polygon_mesh_to_nef_3(P, S, fimap, himap); -} + typedef typename GetInitializedFaceIndexMap::const_type FaceIndexMap; + FaceIndexMap fimap = get_initialized_face_index_map(pm); + typedef typename GetInitializedHalfedgeIndexMap::const_type HalfedgeIndexMap; + HalfedgeIndexMap himap = get_initialized_halfedge_index_map(pm); -template -void polygon_mesh_to_nef_3(SM& sm, SNC_structure& snc) -{ - typedef typename boost::property_map::type FIMap; - FIMap fimap = get(CGAL::face_index,sm); - typedef typename boost::property_map::type HIMap; - HIMap himap = get(boost::halfedge_index,sm); - - polygon_mesh_to_nef_3(sm, snc, fimap, himap); + polygon_mesh_to_nef_3(pm, snc, fimap, himap); } diff --git a/Nef_3/include/CGAL/Nef_polyhedron_3.h b/Nef_3/include/CGAL/Nef_polyhedron_3.h index 88fb4bf95a0..7d03fafb6aa 100644 --- a/Nef_3/include/CGAL/Nef_polyhedron_3.h +++ b/Nef_3/include/CGAL/Nef_polyhedron_3.h @@ -602,29 +602,13 @@ protected: simplify(); } - template - class T3, class T4 > - Nef_polyhedron_3( CGAL::Polyhedron_3& P) { - CGAL_NEF_TRACEN("construction from Polyhedron_3"); - SNC_structure rsnc; - *this = Nef_polyhedron_3(rsnc, new SNC_point_locator_default, false); - initialize_infibox_vertices(EMPTY); - polyhedron_3_to_nef_3 - , SNC_structure>( P, snc()); - build_external_structure(); - mark_bounded_volumes(); - simplify(); - set_snc(snc()); - } - template explicit Nef_polyhedron_3(const PolygonMesh& pm) { CGAL_NEF_TRACEN("construction from PolygonMesh with internal index maps"); SNC_structure rsnc; *this = Nef_polyhedron_3(rsnc, new SNC_point_locator_default, false); initialize_infibox_vertices(EMPTY); - polygon_mesh_to_nef_3(const_cast(pm), snc()); + polygon_mesh_to_nef_3(pm, snc()); build_external_structure(); mark_bounded_volumes(); simplify(); @@ -644,7 +628,7 @@ protected: SNC_structure rsnc; *this = Nef_polyhedron_3(rsnc, new SNC_point_locator_default, false); initialize_infibox_vertices(EMPTY); - polygon_mesh_to_nef_3(const_cast(pm), snc(), fim, him); + polygon_mesh_to_nef_3(pm, snc(), fim, him); build_external_structure(); mark_bounded_volumes(); simplify(); From 078122cd2e0a0e105f2fab97b8089f0651c6ef3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 20 Jun 2022 16:59:35 +0200 Subject: [PATCH 2/2] test constructor and constness --- Nef_3/test/Nef_3/test_nef_3_io_EPEC.cpp | 3 +++ Nef_3/test/Nef_3/test_nef_3_operator.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/Nef_3/test/Nef_3/test_nef_3_io_EPEC.cpp b/Nef_3/test/Nef_3/test_nef_3_io_EPEC.cpp index bf7aa23f90f..4c99490109d 100644 --- a/Nef_3/test/Nef_3/test_nef_3_io_EPEC.cpp +++ b/Nef_3/test/Nef_3/test_nef_3_io_EPEC.cpp @@ -30,6 +30,9 @@ void test_write_read() Polyhedron P; P.make_tetrahedron( p, q, r, s); Nef_polyhedron nef_1( P ); + const Polyhedron P_bis = P; + Nef_polyhedron nef_1_bis( P_bis ); + assert( nef_1 == nef_1_bis); std::cout << " write...\n"; std::ofstream out ("temp.nef"); diff --git a/Nef_3/test/Nef_3/test_nef_3_operator.cpp b/Nef_3/test/Nef_3/test_nef_3_operator.cpp index 0d8de7f21d9..df82792c016 100644 --- a/Nef_3/test/Nef_3/test_nef_3_operator.cpp +++ b/Nef_3/test/Nef_3/test_nef_3_operator.cpp @@ -25,5 +25,11 @@ int main(int /* argc */, char** /* argv[] */) assert(a1 < a2); assert(a2 > a1); + const Polygon_mesh const_A1 = A1; + const Polygon_mesh& const_A2 = A2; + Nef_polyhedron a1_bis(const_A1), a2_bis(const_A2); + assert(a1_bis==a1); + assert(a2_bis==a2); + return 0; }