Skip to content

Commit

Permalink
switch to priority_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
aboudev committed Jul 6, 2017
1 parent cae73cc commit b3482a7
Showing 1 changed file with 17 additions and 20 deletions.
Expand Up @@ -15,6 +15,7 @@
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <iostream>
#include <iterator>

Expand Down Expand Up @@ -85,17 +86,6 @@ template <typename Polyhedron,
face_descriptor seed;
};

// The facet candidate to be queued.
struct FacetToIntegrate {
face_descriptor f;
std::size_t i;
FT fit_error;

bool operator<(const FacetToIntegrate &rhs) const {
return this->fit_error < rhs.fit_error;
}
};

// The l21 metric, compute the fitting error from a facet to a plane proxy.
struct L21Metric {
L21Metric(GeomTraits traits,
Expand Down Expand Up @@ -413,14 +403,21 @@ template <typename Polyhedron,
*/
template<typename FacetSegmentMap>
void flooding(FacetSegmentMap &seg_pmap) {
typedef std::multiset<FacetToIntegrate> CandidateSet;
// The facet candidate to be queued.
struct FacetToIntegrate {
face_descriptor f;
std::size_t i;
FT fit_error;
bool operator<(const FacetToIntegrate &rhs) const {
return fit_error > rhs.fit_error;
}
};

BOOST_FOREACH(face_descriptor f, faces(mesh))
seg_pmap[f] = CGAL_NOT_TAGGED_ID;

const std::size_t num_proxies = proxies.size();
CandidateSet facet_candidates;
for (std::size_t i = 0; i < num_proxies; ++i) {
std::priority_queue<FacetToIntegrate> facet_pqueue;
for (std::size_t i = 0; i < proxies.size(); ++i) {
face_descriptor f = proxies[i].seed;
seg_pmap[f] = i;

Expand All @@ -431,14 +428,14 @@ template <typename Polyhedron,
cand.f = fadj;
cand.fit_error = fit_error(fadj, proxies[i]);
cand.i = i;
facet_candidates.insert(cand);
facet_pqueue.push(cand);
}
}
}

while (!facet_candidates.empty()) {
const FacetToIntegrate &c = *(facet_candidates.begin());
facet_candidates.erase(facet_candidates.begin());
while (!facet_pqueue.empty()) {
const FacetToIntegrate c = facet_pqueue.top();
facet_pqueue.pop();
if (seg_pmap[c.f] == CGAL_NOT_TAGGED_ID) {
seg_pmap[c.f] = c.i;
BOOST_FOREACH(face_descriptor fadj, faces_around_face(halfedge(c.f, mesh), mesh)) {
Expand All @@ -448,7 +445,7 @@ template <typename Polyhedron,
cand.f = fadj;
cand.fit_error = fit_error(fadj, proxies[c.i]);
cand.i = c.i;
facet_candidates.insert(cand);
facet_pqueue.push(cand);
}
}
}
Expand Down

0 comments on commit b3482a7

Please sign in to comment.