# How to constrain edge in refine function in Polygon Mesh Processing Package

3 messages
Open this post in threaded view
|

## How to constrain edge in refine function in Polygon Mesh Processing Package

 Subject: How to constrain edge in refine function in Polygon Mesh Processing PackageHi,I want to use the refine function in Polygon Mesh Processing Package to refine a triangulation mesh. During the mesh, I want to constrain some edges from being deleted. I found that the refine function can add a "edge_is_constrained_map" as parameter, but I don't know how to create a edge map. (I don't know how to get edge_descripter from a polyhedron)Here is my code:#include #include #include #include #include //#include #include #include #include using namespace std;typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;typedef CGAL::Polyhedron_3  Polyhedron;typedef Polyhedron::Vertex_handle   Vertex_handle;typedef boost::graph_traits::edge_descriptor ED;typedef boost::graph_traits::vertex_descriptor VD;typedef Polyhedron::Halfedge    edge;// extract vertices which are at most k (inclusive)// far from vertex v in the graph of edgesvoid extract_k_ring(Vertex_handle v,                    int k,                    std::vector& qv){  std::map  D;  qv.push_back(v);  D[v] = 0;  std::size_t current_index = 0;  int dist_v;  while (current_index < qv.size() && (dist_v = D[qv[current_index]]) < k)  {    v = qv[current_index++];    Polyhedron::Halfedge_around_vertex_circulator e(v->vertex_begin()), e_end(e);    do {      Vertex_handle new_v = e->opposite()->vertex();      if (D.insert(std::make_pair(new_v, dist_v + 1)).second) {        qv.push_back(new_v);      }    } while (++e != e_end);  }}class RMap{private:    map mymap;public:    bool get(ED& ed){        return mymap[ed];    }    void put(ED ed, bool v){        mymap[ed] = v;    }};class VMap{private:    map mymap;public:    bool get(VD& ed){        return mymap[ed];    }    void put(VD ed, bool v){        mymap[ed] = v;    }};int main(int argc, char* argv[]){  const char* filename = (argc > 1) ? argv[1] : "data/OFF.off";  std::ifstream input(filename);  Polyhedron poly;  if ( !input || !(input >> poly) || poly.empty() ) {    std::cerr << "Not a valid off file." << std::endl;    return 1;  }  std::vector  new_facets;  std::vector new_vertices;    RMap mymap;  VMap imap;  ED e1,e2;  //auto it = poly.vertices_begin();  //auto it = poly.halfedges_begin();  //mymap.put(*it, true);    auto a = add_edge(poly);    mymap.put(a, true);  //imap.put(a, true);  //cout << *it << endl;    CGAL::Polygon_mesh_processing::refine(poly,                  faces(poly),                  std::back_inserter(new_facets),                  std::back_inserter(new_vertices),                  CGAL::Polygon_mesh_processing::parameters::density_control_factor(100.).                  protect_constraints(true).                  edge_is_constrained_map(mymap));//.                  //vertex_is_constrained_map(imap));  std::ofstream refined_off("refined.off");  refined_off << poly;  refined_off.close();  std::cout << "Refinement added " << new_vertices.size() << " vertices." << std::endl;  Polyhedron::Vertex_iterator v = poly.vertices_begin();  std::advance(v, 82);  std::vector region;  extract_k_ring(v, 12, region);  //bool success = CGAL::Polygon_mesh_processing::fair(poly, region);  //std::cout << "Fairing : " << (success ? "succeeded" : "failed") << std::endl;  //std::ofstream faired_off("faired.off");  //faired_off << poly;  //faired_off.close();  return 0;}