mirror of https://github.com/CGAL/cgal
boost foreach
This commit is contained in:
parent
59a07f908f
commit
92e00f8236
|
|
@ -81,6 +81,10 @@ public:
|
||||||
face_descriptor f;
|
face_descriptor f;
|
||||||
std::size_t i;
|
std::size_t i;
|
||||||
FT fit_error;
|
FT fit_error;
|
||||||
|
|
||||||
|
bool operator=(const PlaneProxy &px) const {
|
||||||
|
return px.fit_error == this->fit_error;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CompFacet {
|
struct CompFacet {
|
||||||
|
|
@ -202,30 +206,23 @@ public:
|
||||||
halfedge_status_pmap(halfedge_status_map),
|
halfedge_status_pmap(halfedge_status_map),
|
||||||
fit_error(traits, normal_pmap, area_pmap) {
|
fit_error(traits, normal_pmap, area_pmap) {
|
||||||
// CGAL_precondition(is_pure_triangle(mesh));
|
// CGAL_precondition(is_pure_triangle(mesh));
|
||||||
// construct facet normal map
|
// construct facet normal & area map
|
||||||
face_iterator fitr, fend;
|
BOOST_FOREACH(face_descriptor f, faces(mesh)) {
|
||||||
for (boost::tie(fitr, fend) = faces(mesh); fitr != fend; ++fitr) {
|
const halfedge_descriptor he = halfedge(f, mesh);
|
||||||
const Point p1 = get(vertex_point_pmap, target(halfedge(*fitr, mesh), mesh));
|
const Point p1 = get(vertex_point_pmap, source(he, mesh));
|
||||||
const Point p2 = get(vertex_point_pmap, target(next(halfedge(*fitr, mesh), mesh), mesh));
|
const Point p2 = get(vertex_point_pmap, target(he, mesh));
|
||||||
const Point p3 = get(vertex_point_pmap, target(prev(halfedge(*fitr, mesh), mesh), mesh));
|
const Point p3 = get(vertex_point_pmap, target(next(he, mesh), mesh));
|
||||||
//const Point center = centroid_functor(p1, p2, p3);
|
//const Point center = centroid_functor(p1, p2, p3);
|
||||||
Vector normal = normal_functor(p1, p2, p3);
|
Vector normal = normal_functor(p1, p2, p3);
|
||||||
normal = scale_functor(normal,
|
normal = scale_functor(normal,
|
||||||
FT(1.0 / std::sqrt(CGAL::to_double(normal.squared_length()))));
|
FT(1.0 / std::sqrt(CGAL::to_double(normal.squared_length()))));
|
||||||
|
facet_normals.insert(std::pair<face_descriptor, Vector>(f, normal));
|
||||||
|
|
||||||
facet_normals.insert(std::pair<face_descriptor, Vector>(*fitr, normal));
|
FT area(std::sqrt(CGAL::to_double(area_functor(p1, p2, p3))));
|
||||||
|
facet_areas.insert(std::pair<face_descriptor, FT>(f, area));
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct facet area map
|
// initialize all vertex anchor status
|
||||||
for (boost::tie(fitr, fend) = faces(mesh); fitr != fend; ++fitr) {
|
|
||||||
const Point p1 = get(vertex_point_pmap, target(halfedge(*fitr, mesh), mesh));
|
|
||||||
const Point p2 = get(vertex_point_pmap, target(next(halfedge(*fitr, mesh), mesh), mesh));
|
|
||||||
const Point p3 = get(vertex_point_pmap, target(prev(halfedge(*fitr, mesh), mesh), mesh));
|
|
||||||
FT area(std::sqrt(CGAL::to_double(area_functor(p2, p1, p3))));
|
|
||||||
facet_areas.insert(std::pair<face_descriptor, FT>(*fitr, area));
|
|
||||||
}
|
|
||||||
|
|
||||||
// tag all vertex without anchor
|
|
||||||
BOOST_FOREACH(vertex_descriptor v, vertices(mesh)) {
|
BOOST_FOREACH(vertex_descriptor v, vertices(mesh)) {
|
||||||
vertex_status_map.insert(std::pair<vertex_descriptor, int>(v, static_cast<int>(NO_ANCHOR)));
|
vertex_status_map.insert(std::pair<vertex_descriptor, int>(v, static_cast<int>(NO_ANCHOR)));
|
||||||
}
|
}
|
||||||
|
|
@ -325,9 +322,8 @@ private:
|
||||||
|
|
||||||
template<typename FacetSegmentMap>
|
template<typename FacetSegmentMap>
|
||||||
void flooding(FacetSegmentMap &seg_pmap) {
|
void flooding(FacetSegmentMap &seg_pmap) {
|
||||||
face_iterator fitr, fend;
|
BOOST_FOREACH(face_descriptor f, faces(mesh))
|
||||||
for (boost::tie(fitr, fend) = faces(mesh); fitr != fend; ++fitr)
|
seg_pmap[f] = CGAL_NOT_TAGGED_ID;
|
||||||
seg_pmap[*fitr] = CGAL_NOT_TAGGED_ID;
|
|
||||||
|
|
||||||
typedef std::multiset<FacetToIntegrate, CompFacet> CandidateSet;
|
typedef std::multiset<FacetToIntegrate, CompFacet> CandidateSet;
|
||||||
|
|
||||||
|
|
@ -337,37 +333,42 @@ private:
|
||||||
face_descriptor f = proxies[i].seed;
|
face_descriptor f = proxies[i].seed;
|
||||||
seg_pmap[f] = i;
|
seg_pmap[f] = i;
|
||||||
|
|
||||||
Halfedge_around_face_circulator<Polyhedron> facet_circulator(halfedge(f, mesh), mesh), done(facet_circulator);
|
BOOST_FOREACH(face_descriptor fadj, faces_around_face(halfedge(f, mesh), mesh)) {
|
||||||
do {
|
if (fadj != boost::graph_traits<Polyhedron>::null_face()) {
|
||||||
if (face(opposite(*facet_circulator, mesh), mesh) != boost::graph_traits<Polyhedron>::null_face()) {
|
|
||||||
FacetToIntegrate cand;
|
FacetToIntegrate cand;
|
||||||
cand.f = face(opposite(*facet_circulator, mesh), mesh);
|
cand.f = fadj;
|
||||||
cand.fit_error = fit_error(cand.f, proxies[i]);
|
cand.fit_error = fit_error(fadj, proxies[i]);
|
||||||
cand.i = i;
|
cand.i = i;
|
||||||
facet_candidates.insert(cand);
|
facet_candidates.insert(cand);
|
||||||
}
|
}
|
||||||
} while (++facet_circulator != done);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CandidateSet::iterator citr = facet_candidates.begin(); citr != facet_candidates.end();) {
|
std::cerr << "multiset" << std::endl;
|
||||||
if (seg_pmap[citr->f] == CGAL_NOT_TAGGED_ID) {
|
while (!facet_candidates.empty()) {
|
||||||
seg_pmap[citr->f] = citr->i;
|
// CandidateSet::iterator citr = facet_candidates.begin();
|
||||||
Halfedge_around_face_circulator<Polyhedron> facet_circulator(halfedge(citr->f, mesh), mesh), done(facet_circulator);
|
const FacetToIntegrate &c = *(facet_candidates.begin());
|
||||||
do {
|
// facet_candidates.erase(c); // erase value, crash or freeze every time, even with self defined operatior=() for FacetToIntegrate
|
||||||
face_descriptor oppo_facet = face(opposite(*facet_circulator, mesh), mesh);
|
facet_candidates.erase(facet_candidates.begin());
|
||||||
if (oppo_facet != boost::graph_traits<Polyhedron>::null_face()
|
if (seg_pmap[c.f] == CGAL_NOT_TAGGED_ID) {
|
||||||
&& seg_pmap[oppo_facet] == CGAL_NOT_TAGGED_ID) {
|
seg_pmap[c.f] = c.i;
|
||||||
|
BOOST_FOREACH(face_descriptor fadj, faces_around_face(halfedge(c.f, mesh), mesh)) {
|
||||||
|
if (fadj != boost::graph_traits<Polyhedron>::null_face()
|
||||||
|
&& seg_pmap[fadj] == CGAL_NOT_TAGGED_ID) {
|
||||||
FacetToIntegrate cand;
|
FacetToIntegrate cand;
|
||||||
cand.f = oppo_facet;
|
cand.f = fadj;
|
||||||
cand.fit_error = fit_error(oppo_facet, proxies[citr->i]);
|
cand.fit_error = fit_error(fadj, proxies[c.i]);
|
||||||
cand.i = citr->i;
|
cand.i = c.i;
|
||||||
facet_candidates.insert(cand);
|
facet_candidates.insert(cand);
|
||||||
}
|
}
|
||||||
} while (++facet_circulator != done);
|
}
|
||||||
}
|
}
|
||||||
facet_candidates.erase(citr);
|
// TODO: confusing crash
|
||||||
citr = facet_candidates.begin();
|
// facet_candidates.erase(c); // erase value, crash after fitting seed updated surprisingly
|
||||||
|
// facet_candidates.erase(*citr); // same surprising crash
|
||||||
|
// facet_candidates.erase(citr); // alright, iterator remains valid even after insertion
|
||||||
}
|
}
|
||||||
|
std::cerr << "-------" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename FacetSegmentMap>
|
template <typename FacetSegmentMap>
|
||||||
|
|
@ -387,6 +388,7 @@ private:
|
||||||
norm = scale_functor(norm, FT(1.0 / std::sqrt(CGAL::to_double(norm.squared_length()))));
|
norm = scale_functor(norm, FT(1.0 / std::sqrt(CGAL::to_double(norm.squared_length()))));
|
||||||
proxies[i].normal = norm;
|
proxies[i].normal = norm;
|
||||||
}
|
}
|
||||||
|
std::cerr << "normal updated" << std::endl;
|
||||||
|
|
||||||
// update seed
|
// update seed
|
||||||
std::vector<std::size_t> facet_px_idx;
|
std::vector<std::size_t> facet_px_idx;
|
||||||
|
|
@ -413,6 +415,7 @@ private:
|
||||||
distance_min[px_idx] = err;
|
distance_min[px_idx] = err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cerr << "seed updated" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert proxy at the facet with the maximum fitting error in the proxy with maximum error
|
// insert proxy at the facet with the maximum fitting error in the proxy with maximum error
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue