n.m
n.m

Reputation: 485

how can I store collapsed edges using CGAL

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 .

my code

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;

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 .

Upvotes: 0

Views: 123

Answers (2)

Andreas Fabri
Andreas Fabri

Reputation: 1235

I have a branch on github 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.

Upvotes: 2

lrineau
lrineau

Reputation: 6294

Have a look at the concept that defines the visitor class: EdgeCollapseSimplificationVisitor. If you implement the OnCollapsing method. Its parameter Profile const & profile has all the information you need.

Upvotes: 1

Related Questions