Closed n-m-ya closed 5 years ago
The same question was already posted on StackOverflow, and I have already made an answer:
https://stackoverflow.com/questions/54840943/how-can-i-store-collapsed-edges-using-cgal
Do you prefer to discuss on Github or on StackOverflow?
Hello, I have a branch afabri/SMS-undo_example-GF where I use the visitor to record edge collapses. And I added further callbacks to the visitor so that one can undo the edge collapses. I made it work for CGAL::Surface_mesh
as well as for OpenMesh.
@afabri thanks a lot , it's very helpful for me but when I tried the following method :
void OnCollapsing(Profile const& profile ,boost::optional<Point_3>placement )
{
std::cout << "My_visitor::OnCollapsing()" << std::endl;
std::cout << profile.v0() << " will collapse into "<< profile.v1()<<std::endl;
}
it's shows the following error :
no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream
The same question was already posted on StackOverflow, and I have already made an answer:
https://stackoverflow.com/questions/54840943/how-can-i-store-collapsed-edges-using-cgal
Do you prefer to discuss on Github or on StackOverflow?
any of them , I need a quick help
@n-m-ya What exactly did you try? You should check out the particular branch, and first reproduce that the example compiles and runs.
I checked undo_edge_collapse_surface_mesh I tried to get no of collapsed edges and the edges in collapsing process , my code :
struct Stats
{
Stats() : collapsed(0) {}
std::size_t collapsed ;
} ;
struct My_visitor : SMS::Edge_collapse_visitor_base<LCC>
{
My_visitor( Stats* s) : stats(s){}
void OnCollapsed( Profile const& , vertex_descriptor )
{
++ stats->collapsed;
Profile::halfedge_descriptor();
}
Stats* stats ;
void OnCollapsing(Profile const& profile,boost::optional<Point> placement )
{
std::cout << "My_visitor::OnCollapsing()" << std::endl;
std::cout <<( profile.v0()) << " will collapse into "<< profile.v1() << std::endl;
}
};
void MainWindow ::simplify()
{
My_visitor vis(&stats) ;
int r = SMS::edge_collapse
(lcc
,stop
,CGAL::parameters::halfedge_index_map(get(CGAL::halfedge_index, lcc))
.vertex_index_map(get(boost::vertex_index, lcc))
.get_cost(SMS::Edge_length_cost<LCC>())
.get_placement(SMS::Midpoint_placement<LCC>()).visitor(vis)
);
std::cout << "\nEdges collapsed: " << stats.collapsed
<< std::endl;
}
As I wrote earlier, I made it work for Surface_mesh. It needs more effort to make it work with Polyhedron or LCC.
As I wrote earlier, I made it work for Surface_mesh. It needs more effort to make it work with Polyhedron or LCC.
ok , thanks a lot
_
Issue Details
I'm creating an application on QT-creator and using CGAL to read .off file as Linear_cell_complex_for_bgl_combinatorial_map_helper and simplify it using edge_collapse method . I want to store the list of collapsed edges,incident vertices, position of points , and other needed information to re-insert the removed edges again .
Source Code
namespace SMS = CGAL::Surface_mesh_simplification ; typedef CGAL::Simple_cartesian Kernel;
typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits;
typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper<2, 3, MyTraits>::type LCC;
typedef boost::graph_traits::vertex_descriptor vertex_descriptor;
typedef SMS::Edge_profile Profile ;
struct Stats
{
Stats() : collapsed(0) {}
std::size_t collapsed ;
} ;
struct My_visitor : SMS::Edge_collapse_visitor_base
{
My_visitor( Stats* s) : stats(s){} void OnCollapsed( Profile const&, vertex_descriptor ) { ++ stats->collapsed; }
Stats* stats ; };
int r = SMS::edge_collapse (lcc ,stop ,CGAL::parameters::halfedge_index_map(get(CGAL::halfedge_index, lcc)) .vertex_index_map(get(boost::vertex_index, lcc)) .get_cost(SMS::Edge_length_cost())
.get_placement(SMS::Midpoint_placement()).visitor(vis)
);
std::cout << "\nEdges collapsed: " << stats.collapsed << std::endl;
Environment
I tried to use Edge_collapse_visitor_base to get no of collapsed edges , but I don't know to to get the information related to the collapsed edges .
I appreciate any help .