我正在QT创建者上创建一个应用程序,并使用CGAL将.off文件读取为Linear_cell_complex_for_bgl_combinatorial_map_helper并使用edge_collapse方法简化它。我想存储折叠边,事件顶点,点位置和其他所需信息的列表,以再次重新插入删除的边。
我的代码
namespace SMS = CGAL::Surface_mesh_simplification ;
typedef CGAL::Simple_cartesian<double> 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<LCC>::vertex_descriptor vertex_descriptor;
typedef SMS::Edge_profile<LCC> Profile ;
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;
}
Stats* stats ;
};
namespace SMS = CGAL::Surface_mesh_simplification ;
SMS::Count_stop_predicate<LCC> stop(1000);
Stats stats ;
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;
我尝试使用Edge_collapse_visitor_base来获取折叠边缘,但我不知道要获取与折叠边缘相关的信息。
我感谢任何帮助。
我在github上有一个branch,我使用访问者记录边缘折叠。我向访问者添加了进一步的回调,以便可以撤消边缘折叠。我让它适用于CGAL::Surface_mesh
以及OpenMesh。
看看定义访问者类的概念:EdgeCollapseSimplificationVisitor
。如果您实现OnCollapsing
方法。它的参数Profile const & profile
具有您需要的所有信息。