From cb5b3acf98fae3f11c7aa3d927ee243f69d666b3 Mon Sep 17 00:00:00 2001 From: Laurent Rineau Date: Wed, 1 Mar 2017 12:06:16 +0100 Subject: [PATCH] Class Compare_handles_with_or_without_timestamps to replace hacks Previously, each file was using its own implementation of the "compare handle" function object. This commits adds a new class `Compare_handles_with_or_without_timestamps` that checks the presence of `Has_timestamp` in the pointed type, and provides a different `operator()` depending on that. --- .../Mesh_3/Detect_features_in_polyhedra.h | 20 ++----- .../Mesh_3/Detect_polylines_in_polyhedra.h | 45 ++------------- ...mpare_handles_with_or_without_timestamps.h | 55 +++++++++++++++++++ STL_Extension/include/CGAL/Time_stamper.h | 4 +- 4 files changed, 67 insertions(+), 57 deletions(-) create mode 100644 STL_Extension/include/CGAL/Compare_handles_with_or_without_timestamps.h diff --git a/Mesh_3/include/CGAL/Mesh_3/Detect_features_in_polyhedra.h b/Mesh_3/include/CGAL/Mesh_3/Detect_features_in_polyhedra.h index 431cd791a87..1e82b54a7b1 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Detect_features_in_polyhedra.h +++ b/Mesh_3/include/CGAL/Mesh_3/Detect_features_in_polyhedra.h @@ -24,25 +24,12 @@ #include #include +#include #include namespace CGAL { namespace Mesh_3 { -struct Detect_features_less -{ - template - bool operator()(const Handle& h1, const Handle& h2) const - { - typedef typename std::iterator_traits::value_type Type; - typedef typename boost::mpl::if_c< - CGAL::internal::Has_timestamp::value, - CGAL_with_time_stamp, - CGAL_no_time_stamp >::type Comparator; - return Comparator::less(h1, h2); - } -}; - template void detect_features(Polyhedron& p, typename Polyhedron::Traits::FT angle_in_deg) @@ -68,9 +55,10 @@ public: typedef typename Polyhedron::Halfedge Halfedge; typedef typename Polyhedron::Facet Facet; typedef typename Facet::Patch_id Patch_id; + typedef CGAL::Compare_handles_with_or_without_timestamps Compare_handles; - typedef std::set Facet_handle_set; - typedef std::set He_handle_set; + typedef std::set Facet_handle_set; + typedef std::set He_handle_set; public: Detect_features_in_polyhedra() : current_surface_index_(1) {} diff --git a/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h b/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h index 975cc4318bb..7fc5de1ffc1 100644 --- a/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h +++ b/Mesh_3/include/CGAL/Mesh_3/Detect_polylines_in_polyhedra.h @@ -23,7 +23,7 @@ #define CGAL_MESH_3_DETECT_POLYLINES_IN_POLYHEDRA_H #include -#include +#include #include #include @@ -32,40 +32,6 @@ namespace CGAL { namespace Mesh_3 { -template -struct CGAL_with_time_stamp -{ -public: - static bool less(Handle h1, Handle h2) - { - return h1->time_stamp() < h2->time_stamp(); - } -}; - -template -struct CGAL_no_time_stamp -{ -public: - static bool less(Handle h1, Handle h2) - { - return &*h1 < &*h2; - } -}; - -struct Detect_polyline_less -{ - template - bool operator()(const Handle& h1, const Handle& h2) const - { - typedef typename std::iterator_traits::value_type Type; - typedef typename boost::mpl::if_c< - CGAL::internal::Has_timestamp::value, - CGAL_with_time_stamp, - CGAL_no_time_stamp >::type Comparator; - return Comparator::less(h1, h2); - } -}; - template struct Detect_polylines { typedef typename Polyhedron::Traits Geom_traits; @@ -75,13 +41,14 @@ struct Detect_polylines { typedef typename Polyhedron::Vertex_const_handle Vertex_const_handle; typedef typename Polyhedron::Vertex_handle Vertex_handle; typedef typename Polyhedron::size_type size_type; + typedef CGAL::Compare_handles_with_or_without_timestamps Compare_handles; - typedef std::set Vertices_set; + typedef std::set Vertices_set; typedef std::map Vertices_counter; + Compare_handles> Vertices_counter; - typedef std::set Feature_edges_set; + typedef std::set Feature_edges_set; Feature_edges_set edges_to_consider; Vertices_set corner_vertices; @@ -143,7 +110,7 @@ struct Detect_polylines { static Halfedge_handle canonical(Halfedge_handle he) { const Halfedge_handle& op = he->opposite(); - if(Detect_polyline_less()(he, op)) + if(Compare_handles()(he, op)) return he; else return op; diff --git a/STL_Extension/include/CGAL/Compare_handles_with_or_without_timestamps.h b/STL_Extension/include/CGAL/Compare_handles_with_or_without_timestamps.h new file mode 100644 index 00000000000..ae09487e265 --- /dev/null +++ b/STL_Extension/include/CGAL/Compare_handles_with_or_without_timestamps.h @@ -0,0 +1,55 @@ +// Copyright (c) 2017 GeometryFactory Sarl (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. +// +// +// +// Author(s) : Laurent Rineau + +#ifndef CGAL_COMPARE_HANDLES_WITH_OR_WITHOUT_TIMESTAMPS_H +#define CGAL_COMPARE_HANDLES_WITH_OR_WITHOUT_TIMESTAMPS_H + +#include +#include +#include + +namespace CGAL { + +struct Compare_handles_with_or_without_timestamps +{ + template + bool operator()(const Handle h1, const Handle h2) const + { + typedef typename std::iterator_traits::value_type Type; + return less(h1, h2, + Boolean_tag::value>()); + } + + template + bool less(const Handle h1, const Handle h2, Tag_false) const + { + return &*h1 < &*h2; + } + + template + bool less(const Handle h1, const Handle h2, Tag_true) const + { + if(h1 == Handle()) return (h2 != Handle()); + else if(h2 == Handle()) return false; + else return h1->time_stamp() < h2->time_stamp(); + } +}; + +} // end namespace CGAL + +#endif // CGAL_COMPARE_HANDLES_WITH_OR_WITHOUT_TIMESTAMPS_H diff --git a/STL_Extension/include/CGAL/Time_stamper.h b/STL_Extension/include/CGAL/Time_stamper.h index c60e0593d1b..1c19f3686a5 100644 --- a/STL_Extension/include/CGAL/Time_stamper.h +++ b/STL_Extension/include/CGAL/Time_stamper.h @@ -16,11 +16,11 @@ // // Author(s) : Jane Tournois -#include - #ifndef CGAL_TIME_STAMPER_H #define CGAL_TIME_STAMPER_H +#include + namespace CGAL { template