Subject: CGAL users discussion list
List archive
Re: [cgal-discuss] How to constrain edge in refine function in Polygon Mesh Processing Package
Chronological Thread
- From: Yongzhou Gu <>
- To:
- Subject: Re: [cgal-discuss] How to constrain edge in refine function in Polygon Mesh Processing Package
- Date: Wed, 5 Apr 2017 19:58:46 -0500
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Neutral ; spf=None
- Ironport-phdr: 9a23:xnS9ShGNcKxciSdYug2wl51GYnF86YWxBRYc798ds5kLTJ78r8uwAkXT6L1XgUPTWs2DsrQf2raQ6/iocFdDyK7JiGoFfp1IWk1NouQttCtkPvS4D1bmJuXhdS0wEZcKflZk+3amLRodQ56mNBXdrXKo8DEdBAj0OxZrKeTpAI7SiNm82/yv95HJbQhFgDWwbaluIBmqsA7cqtQYjYx+J6gr1xDHuGFIe+NYxWNpIVKcgRPx7dqu8ZBg7ipdpesv+9ZPXqvmcas4S6dYDCk9PGAu+MLrrxjDQhCR6XYaT24bjwBHAwnB7BH9Q5fxri73vfdz1SWGIcH7S60/VDK/5KlpVRDokj8KODw38G/XhMJ+j79Vrgy9qBFk2YHYfJuYOeBicq/Bf94XQ3dKUMZLVyxGB4Oxd4kAD+0HPeZXroj9p1wOrQajDgetGePk1zhFh3/53aA4yOkhEAXG3AghH9IIt3TUrc71OL0MXu+o0anF1DPOZO5Y1zf67YjHaBEhofeUULJxd8rR00gvGBnfglWes4zpJyia1uMKs2iA8+psT+Wvi3Qoqwx3vzOhxd8sh5HXio4Jzl3I7yZ0zYYvKdGmVUJ2YcSoHZtNuyycKoB4WNktQ3tytyY/0rAGuYC0fCwNyJk/wh7Qcf2Hc4yR7hLnWuadPS50hHxldb6inRqy/k+gyurzVsmwzllGtDZKkt7JtnwV1hzT7NaISudl80u/xTqC0xrf5+JELEwui6bXNp4szqQwm5YOqUjDGzX5mETyjK+YbEUk/e2o5vznY7XppJKRLI50igX6MqQvnMy/BuU4MhMUU2eF5Ou8yaXv/VflT7VSkv02jq7ZvYjGKsQUvKG5BxZZ3Zsi6xakEzimzc8YnWIcIVJeeBOHipDpNEvULPD5C/e/mVWsny1xy/DIJL2ySqjLNWXJxbf9Ya5muQkb0xs21dkZ5pROC7hHLui0QV70rNWfDxk3NEu/zO/jTdl8zYgDQnncPqjMO6zbtRqE5/kkPvKXTI4Tojf0bfY/tND0inpsqFgbcrup2oZfR23wSuVpfG2YZX7thNAACiEHshdoH7+is0GLTTMGPyX6ZKk7/DxuUI8=
Thanks for your reply !
I've tried the isotropic_remeshing() and boost::associative_property_map. It works!
Best,
Yongzhou Gu
On Wed, Apr 5, 2017 at 2:37 AM, Andreas Fabri <> wrote:
Hello,
I agree that we should improve the manual and add an example
where we use property maps.
A property map must be lightweight and your class RMap is not
as it stores a std::map.
You should follow the example in
http://www.boost.org/doc/libs/1_59_0/libs/property_map/doc/associative_property_map.html
where one wraps a reference to a std::map in a
boost::associative_property_map
Instead of a std::map you might also use a boost::unordered_map.
In case you used the class CGAL::Surface_mesh, it has
a property mechanism, which has the property API for
the Polygon Mesh Procesing package.
Concerning the refine() function it does not offer a way
to constrain edges. Only isotropic_remeshing() does.
Best,
Andreas--
On 05/04/2017 05:54, Yongzhou Gu wrote:
Subject: How to constrain edge in refine function in Polygon Mesh
Processing Package
Hi,
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 <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/Polygon_mesh_processing/refine.h>
//#include <CGAL/Polygon_mesh_processing/fair.h>
#include <boost/graph/graph_traits.hpp>
#include <fstream>
#include <map>
using namespace std;
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef Polyhedron::Vertex_handle Vertex_handle;
typedef boost::graph_traits<Polyhedron>::edge_descriptor ED;
typedef boost::graph_traits<Polyhedron>::vertex_descriptor VD;
typedef Polyhedron::Halfedge edge;
// extract vertices which are at most k (inclusive)
// far from vertex v in the graph of edges
void extract_k_ring(Vertex_handle v,
int k,
std::vector<Vertex_handle>& qv)
{
std::map<Vertex_handle, int> 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<ED, bool> mymap;
public:
bool get(ED& ed){
return mymap[ed];
}
void put(ED ed, bool v){
mymap[ed] = v;
}
};
class VMap{
private:
map<VD, bool> 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<Polyhedron::Facet_handle> new_facets;
std::vector<Vertex_handle> 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<Vertex_handle> 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;
}
Andreas Fabri, PhD
Chief Officer, GeometryFactory
Editor, The CGAL Project
phone: +33.492.954.912 skype: andreas.fabri
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss
- [cgal-discuss] How to constrain edge in refine function in Polygon Mesh Processing Package, Yongzhou Gu, 04/05/2017
- Re: [cgal-discuss] How to constrain edge in refine function in Polygon Mesh Processing Package, Andreas Fabri, 04/05/2017
- Re: [cgal-discuss] How to constrain edge in refine function in Polygon Mesh Processing Package, Yongzhou Gu, 04/06/2017
- Re: [cgal-discuss] How to constrain edge in refine function in Polygon Mesh Processing Package, Andreas Fabri, 04/05/2017
Archive powered by MHonArc 2.6.18.