From d94ef9467ff4a0f0690fe43b4383b863a8b4a312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 15 Jun 2016 14:29:59 +0200 Subject: [PATCH 1/4] fix the hash for edges it returns the hash value of the smallest edge --- BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h | 6 ++++-- BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h index 1c8e90bb683..a6c90aea31d 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h @@ -137,7 +137,8 @@ struct HDS_edge { friend std::size_t hash_value(const HDS_edge& i) { - return hash_value(i.halfedge()); + return hash_value(i.halfedge()opposite()? + i.halfedge():i.halfedge()->opposite()); } private: @@ -240,7 +241,8 @@ namespace std { std::size_t operator()(const CGAL::internal::HDS_edge& e) const { std::hash fct; - return fct(e.halfedge()); + return fct(e.halfedge()opposite()? + e.halfedge():e.halfedge()->opposite()); } }; diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index 695d15d1494..3c083df82de 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -74,7 +74,8 @@ public: friend std::size_t hash_value(const Edge& e) { - return hash_value(e.first); + return hash_value(e.firstneighbor(e.second)? + e.first:e.first->neighbor(e.second)); } bool operator==(const Edge& other) const From f7090e4b71f32d4d669726c1d33b782a65bedb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Wed, 15 Jun 2016 14:32:44 +0200 Subject: [PATCH 2/4] remove debug output --- BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index 3c083df82de..bbee6dc7a5b 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -847,7 +847,6 @@ namespace std { struct hash > { std::size_t operator()(const CGAL::detail::Edge& e) const { - std::cerr << "Triangulation_2::Edge HashFct" << std::endl; return hash_value(e); } }; @@ -856,7 +855,6 @@ namespace std { struct hash > { std::size_t operator()(const CGAL::detail::T2_halfedge_descriptor& e) const { - std::cerr << "Triangulation_2::halfedge_descriptor HashFct" << std::endl; return hash_value(e); } }; From c3f73103554688b0632b5edd6897892536769f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 16 Jun 2016 16:47:59 +0200 Subject: [PATCH 3/4] handle default constructed edges --- BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h | 3 +++ BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h | 1 + 2 files changed, 4 insertions(+) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h index a6c90aea31d..b6e764277ef 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_HalfedgeDS.h @@ -137,6 +137,7 @@ struct HDS_edge { friend std::size_t hash_value(const HDS_edge& i) { + if (i.halfedge()==Halfedge_handle()) return 0; return hash_value(i.halfedge()opposite()? i.halfedge():i.halfedge()->opposite()); } @@ -154,6 +155,7 @@ namespace handle{ operator()(const HDS_edge& edge) { Halfedge_handle he = edge.halfedge(); + if (he==Halfedge_handle()) return 0; if ( he < he->opposite() ) return Hash_functor()(he); return Hash_functor()(he->opposite()); @@ -241,6 +243,7 @@ namespace std { std::size_t operator()(const CGAL::internal::HDS_edge& e) const { std::hash fct; + if (e.halfedge()==H()) return 0; return fct(e.halfedge()opposite()? e.halfedge():e.halfedge()->opposite()); } diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h index bbee6dc7a5b..325351e649b 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Triangulation_2.h @@ -74,6 +74,7 @@ public: friend std::size_t hash_value(const Edge& e) { + if (e.first==Face_handle()) return 0; return hash_value(e.firstneighbor(e.second)? e.first:e.first->neighbor(e.second)); } From db2f60f636d8b4a69c6c1be45810ac7b366b5109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Thu, 16 Jun 2016 17:26:32 +0200 Subject: [PATCH 4/4] improve Hash test --- Hash_map/test/Hash_map/Hash.cpp | 43 +++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/Hash_map/test/Hash_map/Hash.cpp b/Hash_map/test/Hash_map/Hash.cpp index 36e99a99eeb..3d6b15e91db 100644 --- a/Hash_map/test/Hash_map/Hash.cpp +++ b/Hash_map/test/Hash_map/Hash.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include typedef CGAL::Simple_cartesian Kernel; @@ -21,10 +23,10 @@ typedef CGAL::Arrangement_2 Arrangement_2; typedef CGAL::Polyhedron_3 Polyhedron; typedef CGAL::Surface_mesh Surface_mesh; typedef CGAL::Triangulation_2 Triangulation_2; -#ifdef CGAL_LINKED_WITH_TBB -typedef CGAL::Triangulation_data_structure_3< - CGAL::Triangulation_vertex_base_3, - CGAL::Triangulation_cell_base_3, +#ifdef CGAL_LINKED_WITH_TBB +typedef CGAL::Triangulation_data_structure_3< + CGAL::Triangulation_vertex_base_3, + CGAL::Triangulation_cell_base_3, CGAL::Parallel_tag> Tds; typedef CGAL::Delaunay_triangulation_3 Triangulation_3; #endif @@ -80,6 +82,29 @@ fct3(const P& ) U[vd] = 12; } +template +void test_edge_hash_and_null(const P& p) +{ + typedef boost::graph_traits

GT; + typedef typename GT::halfedge_descriptor halfedge_descriptor; + typedef typename GT::vertex_descriptor vertex_descriptor; + typedef typename GT::face_descriptor face_descriptor; + + BOOST_FOREACH(halfedge_descriptor h, halfedges(p)) + { + assert( + hash_value( edge(h,p) ) == + hash_value( edge(opposite(h,p),p) ) ); + } + face_descriptor f1=GT::null_face(), f2=GT::null_face(); + vertex_descriptor v1=GT::null_vertex(), v2=GT::null_vertex(); + halfedge_descriptor h1=GT::null_halfedge(), h2=GT::null_halfedge(); + + assert(hash_value(f1)==hash_value(f2)); + assert(hash_value(v1)==hash_value(v2)); + assert(hash_value(h1)==hash_value(h2)); +} + template void fct4(const P& p) @@ -88,6 +113,7 @@ fct4(const P& p) fct::halfedge_descriptor>(p); fct::edge_descriptor>(p); fct::face_descriptor>(p); + test_edge_hash_and_null(p); } int main() @@ -96,17 +122,24 @@ int main() fct::vertex_descriptor>(A); fct::edge_descriptor>(A); + Kernel::Point_3 p3; Polyhedron P; + CGAL::make_triangle(p3,p3,p3,P); fct4(P); Surface_mesh S; + CGAL::make_triangle(p3,p3,p3,S); fct4(S); Triangulation_2 T; + T.insert(Kernel::Point_2(0,0)); + T.insert(Kernel::Point_2(0,1)); + T.insert(Kernel::Point_2(1,0)); + T.insert(Kernel::Point_2(1,1)); fct4(T); fct2(); - + #ifdef CGAL_LINKED_WITH_TBB Triangulation_3 T3; fct3(T3);