mirror of https://github.com/CGAL/cgal
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.
This commit is contained in:
parent
035a35e78f
commit
cb5b3acf98
|
|
@ -24,25 +24,12 @@
|
|||
|
||||
#include <CGAL/Kernel/global_functions_3.h>
|
||||
#include <CGAL/Mesh_3/Detect_features_in_polyhedra_fwd.h>
|
||||
#include <CGAL/Compare_handles_with_or_without_timestamps.h>
|
||||
#include <set>
|
||||
|
||||
namespace CGAL {
|
||||
namespace Mesh_3 {
|
||||
|
||||
struct Detect_features_less
|
||||
{
|
||||
template<typename Handle>
|
||||
bool operator()(const Handle& h1, const Handle& h2) const
|
||||
{
|
||||
typedef typename std::iterator_traits<Handle>::value_type Type;
|
||||
typedef typename boost::mpl::if_c<
|
||||
CGAL::internal::Has_timestamp<Type>::value,
|
||||
CGAL_with_time_stamp<Handle>,
|
||||
CGAL_no_time_stamp<Handle> >::type Comparator;
|
||||
return Comparator::less(h1, h2);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Polyhedron>
|
||||
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, Detect_features_less> Facet_handle_set;
|
||||
typedef std::set<Halfedge_handle, Detect_features_less> He_handle_set;
|
||||
typedef std::set<Facet_handle, Compare_handles> Facet_handle_set;
|
||||
typedef std::set<Halfedge_handle, Compare_handles> He_handle_set;
|
||||
|
||||
public:
|
||||
Detect_features_in_polyhedra() : current_surface_index_(1) {}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
#define CGAL_MESH_3_DETECT_POLYLINES_IN_POLYHEDRA_H
|
||||
|
||||
#include <CGAL/Mesh_3/Detect_polylines_in_polyhedra_fwd.h>
|
||||
#include <CGAL/Has_timestamp.h>
|
||||
#include <CGAL/Compare_handles_with_or_without_timestamps.h>
|
||||
#include <CGAL/Default.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
|
@ -32,40 +32,6 @@
|
|||
|
||||
namespace CGAL { namespace Mesh_3 {
|
||||
|
||||
template <typename Handle>
|
||||
struct CGAL_with_time_stamp
|
||||
{
|
||||
public:
|
||||
static bool less(Handle h1, Handle h2)
|
||||
{
|
||||
return h1->time_stamp() < h2->time_stamp();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Handle>
|
||||
struct CGAL_no_time_stamp
|
||||
{
|
||||
public:
|
||||
static bool less(Handle h1, Handle h2)
|
||||
{
|
||||
return &*h1 < &*h2;
|
||||
}
|
||||
};
|
||||
|
||||
struct Detect_polyline_less
|
||||
{
|
||||
template<typename Handle>
|
||||
bool operator()(const Handle& h1, const Handle& h2) const
|
||||
{
|
||||
typedef typename std::iterator_traits<Handle>::value_type Type;
|
||||
typedef typename boost::mpl::if_c<
|
||||
CGAL::internal::Has_timestamp<Type>::value,
|
||||
CGAL_with_time_stamp<Handle>,
|
||||
CGAL_no_time_stamp<Handle> >::type Comparator;
|
||||
return Comparator::less(h1, h2);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Polyhedron>
|
||||
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<Vertex_handle, Detect_polyline_less> Vertices_set;
|
||||
typedef std::set<Vertex_handle, Compare_handles> Vertices_set;
|
||||
typedef std::map<Vertex_handle,
|
||||
size_type,
|
||||
Detect_polyline_less> Vertices_counter;
|
||||
Compare_handles> Vertices_counter;
|
||||
|
||||
typedef std::set<Halfedge_handle, Detect_polyline_less> Feature_edges_set;
|
||||
typedef std::set<Halfedge_handle, Compare_handles> 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;
|
||||
|
|
|
|||
|
|
@ -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 <CGAL/Has_timestamp.h>
|
||||
#include <CGAL/tags.h>
|
||||
#include <iterator>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
struct Compare_handles_with_or_without_timestamps
|
||||
{
|
||||
template<typename Handle>
|
||||
bool operator()(const Handle h1, const Handle h2) const
|
||||
{
|
||||
typedef typename std::iterator_traits<Handle>::value_type Type;
|
||||
return less(h1, h2,
|
||||
Boolean_tag<CGAL::internal::Has_timestamp<Type>::value>());
|
||||
}
|
||||
|
||||
template<typename Handle>
|
||||
bool less(const Handle h1, const Handle h2, Tag_false) const
|
||||
{
|
||||
return &*h1 < &*h2;
|
||||
}
|
||||
|
||||
template<typename Handle>
|
||||
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
|
||||
|
|
@ -16,11 +16,11 @@
|
|||
//
|
||||
// Author(s) : Jane Tournois
|
||||
|
||||
#include <CGAL/Has_timestamp.h>
|
||||
|
||||
#ifndef CGAL_TIME_STAMPER_H
|
||||
#define CGAL_TIME_STAMPER_H
|
||||
|
||||
#include <CGAL/Has_timestamp.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template <typename T>
|
||||
|
|
|
|||
Loading…
Reference in New Issue