From 1a94e743ad72662292c69a40feac09cd87db9c48 Mon Sep 17 00:00:00 2001 From: Lingjie Zhu Date: Wed, 22 Nov 2017 10:53:37 +0800 Subject: [PATCH] vertex anchor map int -> std::size_t anchor map value type int to std::size_t general invalid tag --- .../include/CGAL/vsa_approximation.h | 70 +++++++++++-------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/Surface_mesh_approximation/include/CGAL/vsa_approximation.h b/Surface_mesh_approximation/include/CGAL/vsa_approximation.h index 6afab6ef84b..858c0a6a067 100644 --- a/Surface_mesh_approximation/include/CGAL/vsa_approximation.h +++ b/Surface_mesh_approximation/include/CGAL/vsa_approximation.h @@ -32,6 +32,8 @@ #include #endif +#define CGAL_VSA_INVALID_TAG std::numeric_limits::max() + namespace CGAL { namespace VSA { @@ -100,7 +102,7 @@ private: typedef typename boost::graph_traits::face_descriptor face_descriptor; // internal typedefs - typedef boost::associative_property_map > Vertex_anchor_map; + typedef boost::associative_property_map > Vertex_anchor_map; typedef std::vector Chord_vector; typedef typename Chord_vector::iterator Chord_vector_iterator; @@ -231,7 +233,7 @@ private: boost::unordered_map internal_fidx_map; boost::associative_property_map > fproxy_map; // The attached anchor index of a vertex. - boost::unordered_map internal_vidx_map; + boost::unordered_map internal_vidx_map; Vertex_anchor_map vanchor_map; // Proxies. @@ -325,11 +327,12 @@ public: // rebuild internal data structure internal_fidx_map.clear(); BOOST_FOREACH(face_descriptor f, faces(*m_pmesh)) - internal_fidx_map[f] = 0; + internal_fidx_map[f] = CGAL_VSA_INVALID_TAG; internal_vidx_map.clear(); BOOST_FOREACH(vertex_descriptor v, vertices(*m_pmesh)) - internal_vidx_map.insert(std::pair(v, 0)); + internal_vidx_map.insert( + std::pair(v, CGAL_VSA_INVALID_TAG)); } /*! @@ -479,9 +482,8 @@ public: * Propagates the proxy seed facets and floods the whole mesh to minimize the fitting error. */ void partition() { -#define CGAL_NOT_TAGGED_ID std::numeric_limits::max() BOOST_FOREACH(face_descriptor f, faces(*m_pmesh)) - fproxy_map[f] = CGAL_NOT_TAGGED_ID; + fproxy_map[f] = CGAL_VSA_INVALID_TAG; std::priority_queue facet_pqueue; for (std::size_t i = 0; i < proxies.size(); ++i) { @@ -490,7 +492,7 @@ public: BOOST_FOREACH(face_descriptor fadj, faces_around_face(halfedge(f, *m_pmesh), *m_pmesh)) { if (fadj != boost::graph_traits::null_face() - && fproxy_map[fadj] == CGAL_NOT_TAGGED_ID) { + && fproxy_map[fadj] == CGAL_VSA_INVALID_TAG) { facet_pqueue.push(Facet_to_integrate( fadj, i, (*fit_error)(fadj, proxies[i].px))); } @@ -500,18 +502,17 @@ public: while (!facet_pqueue.empty()) { const Facet_to_integrate c = facet_pqueue.top(); facet_pqueue.pop(); - if (fproxy_map[c.f] == CGAL_NOT_TAGGED_ID) { + if (fproxy_map[c.f] == CGAL_VSA_INVALID_TAG) { fproxy_map[c.f] = c.px; BOOST_FOREACH(face_descriptor fadj, faces_around_face(halfedge(c.f, *m_pmesh), *m_pmesh)) { if (fadj != boost::graph_traits::null_face() - && fproxy_map[fadj] == CGAL_NOT_TAGGED_ID) { + && fproxy_map[fadj] == CGAL_VSA_INVALID_TAG) { facet_pqueue.push(Facet_to_integrate( fadj, c.px, (*fit_error)(fadj, proxies[c.px].px))); } } } } -#undef CGAL_NOT_TAGGED_ID } /*! @@ -859,9 +860,8 @@ public: template bool extract_mesh(PolyhedronSurface &tm_out, const FT chord_error = FT(0.2), bool pca_plane = false) { // initialize all vertex anchor status - enum Vertex_status { NO_ANCHOR = -1 }; BOOST_FOREACH(vertex_descriptor v, vertices(*m_pmesh)) - internal_vidx_map[v] = static_cast(NO_ANCHOR); + internal_vidx_map[v] = CGAL_VSA_INVALID_TAG; anchors.clear(); borders.clear(); tris.clear(); @@ -872,7 +872,7 @@ public: find_anchors(); find_edges(chord_error); add_anchors(); - pseudo_CDT(); + pseudo_cdt(); return build_polyhedron_surface(tm_out); } @@ -1433,14 +1433,17 @@ private: } /*! - * @brief Runs the pseudo Constrained Delaunay Triangulation at each region, and stores the extracted indexed triangles in @a tris. + * @brief Runs the pseudo Constrained Delaunay Triangulation at each proxy region, + * and stores the extracted indexed triangles in @a tris. + * @pre all anchors are found, i.e. all boundary cycles have been visited + * and attached with at least 3 anchors. */ - void pseudo_CDT() { + void pseudo_cdt() { // subgraph attached with vertex anchor status and edge weight - typedef boost::property > VertexProperty; + typedef boost::property > VertexProperty; typedef boost::property > EdgeProperty; + boost::property > EdgeProperty; typedef boost::subgraph::iterator ditr = vdist.begin() + 1; for (typename Chord_vector::iterator hitr = chord.begin(); hitr != chord.end() - 1; ++hitr, ++ditr) { @@ -1558,14 +1564,14 @@ private: // collect triangles BOOST_FOREACH(face_descriptor f, faces(*m_pmesh)) { halfedge_descriptor he = halfedge(f, *m_pmesh); - int i = global_vtag_map[to_sgv_map[source(he, *m_pmesh)]]; - int j = global_vtag_map[to_sgv_map[target(he, *m_pmesh)]]; - int k = global_vtag_map[to_sgv_map[target(next(he, *m_pmesh), *m_pmesh)]]; + std::size_t i = global_vtag_map[to_sgv_map[source(he, *m_pmesh)]]; + std::size_t j = global_vtag_map[to_sgv_map[target(he, *m_pmesh)]]; + std::size_t k = global_vtag_map[to_sgv_map[target(next(he, *m_pmesh), *m_pmesh)]]; if (i != j && i != k && j != k) { std::vector t; - t.push_back(static_cast(i)); - t.push_back(static_cast(j)); - t.push_back(static_cast(k)); + t.push_back(i); + t.push_back(j); + t.push_back(k); tris.push_back(t); } } @@ -1715,7 +1721,7 @@ private: bool is_anchor_attached( const typename boost::property_traits::key_type &v, const VertexAnchorIndexMap &vertex_anchor_map) const { - return vertex_anchor_map[v] >= 0; + return vertex_anchor_map[v] != CGAL_VSA_INVALID_TAG; } /*! @@ -1723,7 +1729,7 @@ private: * @param vtx vertex */ void attach_anchor(const vertex_descriptor &vtx) { - vanchor_map[vtx] = static_cast(anchors.size()); + vanchor_map[vtx] = anchors.size(); anchors.push_back(Anchor(vtx, compute_anchor_position(vtx))); } @@ -1855,4 +1861,6 @@ private: } // end namespace VSA } // end namespace CGAL +#undef CGAL_VSA_INVALID_TAG + #endif // CGAL_SURFACE_MESH_APPROXIMATION_VSA_APPROXIMATION_H