Skip to content

Commit 0b2a2e8

Browse files
committed
Update branch from master after trailing whitespaces and tabs removal
2 parents 16fc8d1 + d45c6a9 commit 0b2a2e8

File tree

6 files changed

+190
-158
lines changed

6 files changed

+190
-158
lines changed

Mesh_3/include/CGAL/Mesh_3/Sliver_perturber.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,9 @@ class Sliver_perturber
503503
#ifdef CGAL_MESH_3_USE_RELAXED_HEAP
504504
typedef boost::relaxed_heap<PVertex, less_PVertex, PVertex_id> PQueue;
505505
#else
506-
typedef ::CGAL::internal::mutable_queue_with_remove<PVertex,std::vector<PVertex>, less_PVertex, PVertex_id> PQueue;
506+
typedef CGAL::Modifiable_priority_queue<PVertex,less_PVertex,PVertex_id> PQueue;
507507
#endif //CGAL_MESH_3_USE_RELAXED_HEAP
508+
typedef typename boost::unordered_map<std::size_t,typename PQueue::handle> Handle_map;
508509

509510
public:
510511
/**
@@ -718,6 +719,7 @@ class Sliver_perturber
718719
SliverCriterion sliver_criterion_;
719720
Perturbation_vector perturbation_vector_;
720721
C3T3_helpers helper_;
722+
mutable Handle_map h;
721723

722724
// Internal perturbation ordering
723725
int next_perturbation_order_;
@@ -778,8 +780,7 @@ operator()(Visitor visitor)
778780
#endif
779781

780782
// Build priority queue (we use one queue for all steps)
781-
PQueue pqueue(tr_.number_of_vertices());
782-
783+
PQueue pqueue(0,less_PVertex(),PVertex_id());
783784
// Initialize vertices ids
784785
initialize_vertices_id();
785786

@@ -935,10 +936,11 @@ perturb(const FT& sliver_bound, PQueue& pqueue, Visitor& visitor) const
935936
{
936937
this->create_root_task();
937938

938-
while (pqueue.size() > 0)
939+
while (! pqueue.empty() )
939940
{
940941
PVertex pv = pqueue.top();
941942
pqueue.pop();
943+
h.erase(pv.id());
942944
enqueue_task(pv, sliver_bound,
943945
visitor, bad_vertices);
944946
}
@@ -972,6 +974,7 @@ perturb(const FT& sliver_bound, PQueue& pqueue, Visitor& visitor) const
972974
// Get pqueue head
973975
PVertex pv = pqueue.top();
974976
pqueue.pop();
977+
h.erase(pv.id());
975978
--pqueue_size;
976979

977980
CGAL_assertion(pv.is_perturbable());
@@ -1229,24 +1232,29 @@ int
12291232
Sliver_perturber<C3T3,Md,Sc,V_>::
12301233
update_priority_queue(const PVertex& pv, PQueue& pqueue) const
12311234
{
1232-
if ( pqueue.contains(pv) )
1235+
typename Handle_map::iterator pvh =
1236+
h.find(pv.id());
1237+
if ( pvh != h.end() )
12331238
{
12341239
if ( pv.is_perturbable() )
12351240
{
1236-
pqueue.update(pv);
1241+
typename PQueue::handle ex_h = pvh->second;
1242+
pqueue.update(pv, ex_h);
1243+
pvh->second = ex_h;
12371244
return 0;
12381245
}
12391246
else
12401247
{
1241-
pqueue.remove(pv);
1248+
pqueue.erase(pv, pvh->second);
1249+
h.erase(pv.id());
12421250
return -1;
12431251
}
12441252
}
12451253
else
12461254
{
12471255
if ( pv.is_perturbable() )
12481256
{
1249-
pqueue.push(pv);
1257+
h[pv.id()] = pqueue.push(pv);
12501258
return 1;
12511259
}
12521260
}

Polyline_simplification_2/include/CGAL/Polyline_simplification_2/simplify.h

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <CGAL/Polyline_simplification_2/Stop_below_count_threshold.h>
2727
#include <CGAL/Polyline_simplification_2/Stop_above_cost_threshold.h>
2828
#include <CGAL/Modifiable_priority_queue.h>
29+
#include <boost/unordered_map.hpp>
2930
#include <CGAL/algorithm.h>
3031

3132
// Needed for Polygon_2
@@ -80,7 +81,6 @@ class Polyline_simplification_2
8081
return (*x)->cost() < (*y)->cost();
8182
}
8283
} ;
83-
8484
struct Id_map : public boost::put_get_helper<std::size_t, Id_map>
8585
{
8686
typedef boost::readable_property_map_tag category;
@@ -94,7 +94,7 @@ class Polyline_simplification_2
9494
typedef CGAL::Modifiable_priority_queue<Vertices_in_constraint_iterator,Compare_cost,Id_map> MPQ ;
9595

9696
MPQ* mpq;
97-
97+
boost::unordered_map<int,typename MPQ::handle> h;
9898
Polyline_simplification_2(PCT& pct, CostFunction cost, StopFunction stop)
9999
: pct(pct), cost(cost), stop(stop), pct_initial_number_of_vertices(pct.number_of_vertices()), number_of_unremovable_vertices(0)
100100
{
@@ -156,7 +156,7 @@ class Polyline_simplification_2
156156
boost::optional<FT> dist = cost(pct, it);
157157
if(dist){
158158
(*it)->set_cost(*dist);
159-
(*mpq).push(it);
159+
h[it.base()->id]= mpq->push(it);
160160
++n;
161161
} else {
162162
// no need to set the costs as this vertex is not in the priority queue
@@ -254,6 +254,7 @@ operator()()
254254
}
255255
Vertices_in_constraint_iterator v = (*mpq).top();
256256
(*mpq).pop();
257+
h.erase(v.base()->id);
257258
if(stop(pct, *v, (*v)->cost(), pct_initial_number_of_vertices, pct.number_of_vertices())){
258259
return false;
259260
}
@@ -263,36 +264,48 @@ operator()()
263264

264265
if((*u)->is_removable()){
265266
boost::optional<FT> dist = cost(pct, u);
267+
typename boost::unordered_map<int,typename MPQ::handle>::iterator find_result_u =
268+
h.find(u.base()->id);
266269
if(! dist){
267270
// cost is undefined
268-
if( mpq->contains(u) ){
269-
mpq->erase(u);
271+
if( find_result_u != h.end()){
272+
mpq->erase(u, find_result_u->second);
273+
h.erase(u.base()->id);
270274
}
271275
} else {
276+
if(find_result_u != h.end()){
277+
typename MPQ::handle ex_h = find_result_u->second;
272278
(*u)->set_cost(*dist);
273-
if(mpq->contains(u)){
274-
mpq->update(u, true);
279+
mpq->update(u, ex_h);
280+
find_result_u->second = ex_h;
275281
}
276282
else{
277-
mpq->push(u);
283+
(*u)->set_cost(*dist);
284+
h[u.base()->id]=mpq->push(u);
278285
}
279286
}
280287
}
281288

282289
if((*w)->is_removable()){
283290
boost::optional<FT> dist = cost(pct, w);
291+
typename boost::unordered_map<int,typename MPQ::handle>::iterator find_result_w =
292+
h.find(w.base()->id);
284293
if(! dist){
285294
// cost is undefined
286-
if( mpq->contains(w) ){
287-
mpq->erase(w);
295+
if(find_result_w != h.end()){
296+
mpq->erase(w, find_result_w->second);
297+
h.erase(w.base()->id);
288298
}
289299
} else {
300+
if(find_result_w != h.end()){
301+
typename MPQ::handle ex_h = find_result_w->second;
290302
(*w)->set_cost(*dist);
291-
if(mpq->contains(w)){
292-
mpq->update(w, true);
303+
mpq->update(w, ex_h);
304+
find_result_w->second=ex_h;
293305
}
294306
else{
295-
mpq->push(w);
307+
(*w)->set_cost(*dist);
308+
h[w.base()->id]=mpq->push(w);
296309
}
297310

298311
}

STL_Extension/include/CGAL/Modifiable_priority_queue.h

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,8 @@
1616
#ifdef CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP
1717
#include <boost/pending/relaxed_heap.hpp>
1818
#else
19-
#include <CGAL/internal/boost/mutable_queue.hpp>
20-
21-
22-
namespace CGAL {
23-
namespace internal {
24-
template <class IndexedType,
25-
class RandomAccessContainer = std::vector<IndexedType>,
26-
class Comp = std::less<typename RandomAccessContainer::value_type>,
27-
class ID = ::boost::identity_property_map >
28-
class mutable_queue_with_remove : public internal::boost_::mutable_queue<IndexedType,RandomAccessContainer,Comp,ID>
29-
{
30-
typedef internal::boost_::mutable_queue<IndexedType,RandomAccessContainer,Comp,ID> Base;
31-
public:
32-
typedef typename Base::size_type size_type;
33-
typedef typename Base::Node Node;
34-
35-
mutable_queue_with_remove(size_type n, const Comp& x=Comp(), const ID& _id=ID()) : Base(n,x,_id,true)
36-
{}
37-
38-
void remove(const IndexedType& x){
39-
//first place element at the top
40-
size_type current_pos = this->index_array[ get(this->id, x) ];
41-
this->c[current_pos] = x;
42-
43-
Node node(this->c.begin(), this->c.end(), this->c.begin()+current_pos, this->id);
44-
while (node.has_parent())
45-
node.swap(node.parent(), this->index_array);
46-
//then pop it
47-
this->pop();
48-
}
49-
50-
bool contains(const IndexedType& x) const {
51-
return this->index_array[ get(this->id, x) ] !=this->index_array.size();
52-
}
53-
};
54-
55-
} } //namespace CGAL::internal
19+
#include <boost/heap/fibonacci_heap.hpp>
20+
#include <boost/graph/properties.hpp>
5621
#endif //CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP
5722

5823
namespace CGAL {
@@ -73,33 +38,48 @@ class Modifiable_priority_queue
7338

7439
#ifdef CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP
7540
typedef boost::relaxed_heap<IndexedType,Compare,ID> Heap;
76-
#else
77-
typedef internal::mutable_queue_with_remove<IndexedType,std::vector<IndexedType>,Compare,ID> Heap;
78-
#endif //CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP
79-
typedef typename Heap::value_type value_type;
80-
typedef typename Heap::size_type size_type;
81-
8241
typedef bool handle ;
8342

84-
public:
85-
8643
Modifiable_priority_queue( size_type largest_ID, Compare const& c, ID const& id ) : mHeap(largest_ID,c,id) {}
87-
44+
typedef typename Heap::value_type value_type;
45+
typedef typename Heap::size_type size_type;
8846
handle push ( value_type const& v ) { mHeap.push(v) ; return handle(true) ; }
89-
90-
handle update ( value_type const& v, handle h ) { mHeap.update(v); return h ; }
91-
9247
handle erase ( value_type const& v, handle ) { mHeap.remove(v); return null_handle() ; }
9348
handle erase ( value_type const& v ) { mHeap.remove(v); return null_handle() ; }
49+
bool contains ( value_type const& v ) { return mHeap.contains(v) ; }
50+
handle update ( value_type const& v, handle h ) { mHeap.update(v); return h ; }
51+
static handle null_handle() { return handle(false); }
52+
#else
53+
struct Reverse_compare{
54+
const Compare c;
55+
Reverse_compare(){}
56+
Reverse_compare(Compare const& c):c(c){}
57+
template<typename T>
58+
bool operator() (T const& a, T const& b) const
59+
{
60+
return !c(a,b);
61+
}
62+
};
63+
typedef boost::heap::fibonacci_heap<IndexedType,boost::heap::compare<Reverse_compare> > Heap;
64+
typedef typename Heap::handle_type handle;
65+
//the fibonacci_heap uses the inverse of the compare used in the relaxed heap.
66+
typedef typename Heap::value_type value_type;
67+
typedef typename Heap::size_type size_type;
68+
public:
69+
Modifiable_priority_queue( size_type, Compare const& c, ID const& ):mHeap(Reverse_compare(c)) {}
70+
handle push ( value_type const& v ) { return mHeap.push(v) ;}
71+
handle erase ( value_type const& v, handle h) { mHeap.erase(h); return null_handle() ; }
72+
handle update ( value_type const& v, handle h ) { mHeap.update(h); return h ; }
73+
static handle null_handle() { return handle(); }
74+
#endif //CGAL_SURFACE_MESH_SIMPLIFICATION_USE_RELAXED_HEAP
75+
9476

9577
value_type top() const { return mHeap.top() ; }
9678

9779
void pop() { mHeap.pop(); }
9880

9981
bool empty() const { return mHeap.empty() ; }
10082

101-
bool contains ( value_type const& v ) { return mHeap.contains(v) ; }
102-
10383
boost::optional<value_type> extract_top()
10484
{
10585
boost::optional<value_type> r ;
@@ -112,8 +92,6 @@ class Modifiable_priority_queue
11292
return r ;
11393
}
11494

115-
static handle null_handle() { return handle(false); }
116-
11795
private:
11896

11997
Heap mHeap ;

STL_Extension/include/CGAL/iterator.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,7 @@ class Dispatch_output_iterator < std::tuple<V...>, std::tuple<O...> >
13691369

13701370
Dispatch_output_iterator(const Dispatch_output_iterator&)=default;
13711371

1372+
13721373
Self& operator=(const Self& s)
13731374
{
13741375
static_cast<Iterator_tuple&>(*this) = static_cast<const Iterator_tuple&>(s);
@@ -1451,6 +1452,7 @@ class Dispatch_or_drop_output_iterator < std::tuple<V...>, std::tuple<O...> >
14511452
Dispatch_or_drop_output_iterator(const Dispatch_or_drop_output_iterator&)=default;
14521453
Dispatch_or_drop_output_iterator& operator=(const Dispatch_or_drop_output_iterator&)=default;
14531454

1455+
14541456
using Base::operator=;
14551457

14561458
Self& operator*() { return *this; }

STL_Extension/test/STL_Extension/test_Cache.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ struct Int_t : public CGAL::Handle_with_policy< Int_rep, Unify > {
4040
// This is needed to prevent VC7.1 and VC8 to call
4141
// the explicit templated constructor in Base instead of its copy-ctor.
4242
Int_t( Int_t const& rhs ) : Base( static_cast<Base const&>(rhs) ) {}
43+
4344
Int_t& operator=(Int_t const&)=default;
45+
4446
int value() const { return this->ptr()->val; }
4547
void set_value( int i) {
4648
this->copy_on_write();

0 commit comments

Comments
 (0)