From cb5ed8412cc5648a98cdaa697dcb3ffe659a2f66 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Mon, 22 Jun 2015 16:32:24 +0200 Subject: [PATCH] Vertices inserted to polygon soup only if needed --- ...demo_scale_space_reconstruction_plugin.cpp | 73 ++++++++++++++----- 1 file changed, 54 insertions(+), 19 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp b/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp index 34fec046108..960d429f638 100644 --- a/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Polyhedron_demo_scale_space_reconstruction_plugin.cpp @@ -84,8 +84,8 @@ void Polyhedron_demo_scale_space_reconstruction_plugin::on_actionScaleSpaceRecon time.start(); std::cout << "Scale scape surface reconstruction..."; - typedef CGAL::Scale_space_surface_reconstruction_3 Recontructor; - Recontructor reconstruct( dialog.neighbors(), dialog.samples() ); + typedef CGAL::Scale_space_surface_reconstruction_3 Reconstructor; + Reconstructor reconstruct( dialog.neighbors(), dialog.samples() ); reconstruct.reconstruct_surface( pts_item->point_set()->begin(), pts_item->point_set()->end(), @@ -93,6 +93,23 @@ void Polyhedron_demo_scale_space_reconstruction_plugin::on_actionScaleSpaceRecon ); std::cout << "ok (" << time.elapsed() << " ms)" << std::endl; + std::vector pts; + typedef Point_set::iterator Point_iterator; + for(Point_iterator it = pts_item->point_set()->begin(), + end = pts_item->point_set()->end(); it!=end; ++it) + { + pts.push_back (*it); + } + + std::vector pts_smoothed; + typedef Reconstructor::Point_iterator SS_point_iterator; + + for(SS_point_iterator it = reconstruct.points_begin(), + end = reconstruct.points_end(); it!=end; ++it) + { + pts_smoothed.push_back (*it); + } + for( unsigned int sh = 0; sh < reconstruct.number_of_shells(); ++sh ) { // collect the number of triples. std::ptrdiff_t num = std::distance( reconstruct.shell_begin( sh ), @@ -103,18 +120,26 @@ void Polyhedron_demo_scale_space_reconstruction_plugin::on_actionScaleSpaceRecon new_item->init_polygon_soup(pts_item->point_set()->size(), num ); - typedef Point_set::iterator Point_iterator; + std::map map_i2i; - for(Point_iterator it = pts_item->point_set()->begin(), - end = pts_item->point_set()->end(); it!=end; ++it) - { - new_item->new_vertex(it->x(), it->y(), it->z()); - } - - for (Recontructor::Triple_iterator it=reconstruct.shell_begin( sh ), + unsigned int current_index = 0; + for (Reconstructor::Triple_iterator it=reconstruct.shell_begin( sh ), end=reconstruct.shell_end( sh );it!=end;++it) { - new_item->new_triangle( (*it)[0], (*it)[1], (*it)[2] ); + for (unsigned int ind = 0; ind < 3; ++ ind) + { + if (map_i2i.find ((*it)[ind]) == map_i2i.end ()) + { + map_i2i.insert (std::make_pair ((*it)[ind], current_index ++)); + new_item->new_vertex (pts[(*it)[ind]].x (), + pts[(*it)[ind]].y (), + pts[(*it)[ind]].z ()); + } + + } + new_item->new_triangle( map_i2i[(*it)[0]], + map_i2i[(*it)[1]], + map_i2i[(*it)[2]] ); } new_item->finalize_polygon_soup(); @@ -131,17 +156,27 @@ void Polyhedron_demo_scale_space_reconstruction_plugin::on_actionScaleSpaceRecon new_item_smoothed->init_polygon_soup(pts_item->point_set()->size(), num ); - typedef Recontructor::Point_iterator SS_point_iterator; - for(SS_point_iterator it = reconstruct.points_begin(), - end = reconstruct.points_end(); it!=end; ++it) - { - new_item_smoothed->new_vertex(it->x(), it->y(), it->z()); - } + std::map map_i2i_smoothed; - for (Recontructor::Triple_iterator it=reconstruct.shell_begin( sh ), + unsigned int current_index_smoothed = 0; + for (Reconstructor::Triple_iterator it=reconstruct.shell_begin( sh ), end=reconstruct.shell_end( sh );it!=end;++it) { - new_item_smoothed->new_triangle( (*it)[0], (*it)[1], (*it)[2] ); + for (unsigned int ind = 0; ind < 3; ++ ind) + { + if (map_i2i_smoothed.find ((*it)[ind]) == map_i2i_smoothed.end ()) + { + map_i2i_smoothed.insert (std::make_pair ((*it)[ind], current_index_smoothed ++)); + new_item_smoothed->new_vertex (pts_smoothed[(*it)[ind]].x (), + pts_smoothed[(*it)[ind]].y (), + pts_smoothed[(*it)[ind]].z ()); + } + + } + + new_item_smoothed->new_triangle( map_i2i_smoothed[(*it)[0]], + map_i2i_smoothed[(*it)[1]], + map_i2i_smoothed[(*it)[2]] ); } new_item_smoothed->finalize_polygon_soup();