From d84be563f8ca49723865390496de4b3485f11851 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 6 Jun 2016 19:10:58 +0200 Subject: [PATCH] Add hash_value and specialization of hash for OpenMesh --- .../BGL_polyhedron_3/copy_polyhedron.cpp | 7 -- .../graph_traits_PolyMesh_ArrayKernelT.h | 4 +- .../graph/graph_traits_TriMesh_ArrayKernelT.h | 2 + .../doc/STL_Extension/Concepts/Hashable.h | 4 +- STL_Extension/include/CGAL/hash_openmesh.h | 64 +++++++++++++++++++ 5 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 STL_Extension/include/CGAL/hash_openmesh.h diff --git a/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp b/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp index 1092d2b5ef2..3695a0fa227 100644 --- a/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp +++ b/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp @@ -12,13 +12,6 @@ #include #include #include - -namespace OpenMesh { // auxiliary functions so OpenMesh Handles can be hashed -inline std::size_t hash_value(const VertexHandle& i) { return i.idx(); } -inline std::size_t hash_value(const HalfedgeHandle& i) { return i.idx(); } -inline std::size_t hash_value(const FaceHandle& i) { return i.idx(); } -} - #endif #include diff --git a/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h b/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h index ff8ddf22cf6..c8036b06b93 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h @@ -37,6 +37,8 @@ #include +#include + // http://openmesh.org/Documentation/OpenMesh-Doc-Latest/classOpenMesh_1_1Concepts_1_1KernelT.html #if defined(BOOST_MSVC) @@ -672,8 +674,6 @@ void clear(OpenMesh::PolyMesh_ArrayKernelT& sm) } } - - #ifndef CGAL_NO_DEPRECATED_CODE #include diff --git a/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h b/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h index 53e6a5754f4..fad7d6698d6 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h @@ -35,6 +35,8 @@ #include +#include + // http://openmesh.org/Documentation/OpenMesh-Doc-Latest/classOpenMesh_1_1Concepts_1_1KernelT.html #if defined(BOOST_MSVC) diff --git a/STL_Extension/doc/STL_Extension/Concepts/Hashable.h b/STL_Extension/doc/STL_Extension/Concepts/Hashable.h index c5d6e51c292..0c9d436c1f2 100644 --- a/STL_Extension/doc/STL_Extension/Concepts/Hashable.h +++ b/STL_Extension/doc/STL_Extension/Concepts/Hashable.h @@ -7,7 +7,9 @@ A type `Key` is a model of the concept `Hashable` if the specializations `boost::hash` and `std::hash` exist. \cgalHasModel All handles and indices of \cgal data structures. - +\cgalHasModel All handles of OpenMesh, by including the specializations +of the `graph_traits` header files provided by \cgal. +They can be disables by defining the macro `CGAL_DISABLE_HASH_OPENMESH`. \sa `CGAL::Unique_hash_map` \sa `std::unordered_set` diff --git a/STL_Extension/include/CGAL/hash_openmesh.h b/STL_Extension/include/CGAL/hash_openmesh.h new file mode 100644 index 00000000000..757c08b91ea --- /dev/null +++ b/STL_Extension/include/CGAL/hash_openmesh.h @@ -0,0 +1,64 @@ +// Copyright (c) 2016 GeometryFactory (France). All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_HASH_OPENMESH_H +#define CGAL_HASH_OPENMESH_H + + +#ifndef CGAL_DISABLE_HASH_OPENMESH + +#include +#include +namespace OpenMesh { + +inline std::size_t hash_value(const BaseHandle& h) { return h.idx(); } + +} // namespace OpenMesh + +namespace std { + +#if defined(BOOST_MSVC) +# pragma warning(push) +# pragma warning(disable:4099) // For VC10 it is class hash +#endif + +#ifndef CGAL_CFG_NO_STD_HASH + + template <> + struct hash + : public std::unary_function + { + + std::size_t operator()(const OpenMesh::BaseHandle& h) const + { + return h.idx(); + } + }; +#endif // CGAL_CFG_NO_STD_HASH + +#if defined(BOOST_MSVC) +# pragma warning(pop) +#endif + +} // namespace std + +#endif // CGAL_DISABLE_HASH_OPENMESH + + +#endif // CGAL_HASH_OPENMESH_H