From 1edb7d2c63055f73b2b8948bf8fd99ef982cc1b2 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Mon, 18 Jul 2016 15:26:34 +0200 Subject: [PATCH] Apply PSP algorithms to selection only (if selection isn't empty) --- .../Point_set_average_spacing_plugin.cpp | 5 ++- .../Point_set_bilateral_smoothing_plugin.cpp | 5 ++- .../Point_set_interference_plugin.cpp | 11 ++++-- .../Point_set_normal_estimation_plugin.cpp | 21 ++++++----- .../Point_set/Point_set_smoothing_plugin.cpp | 5 ++- .../Point_set/Point_set_upsampling_plugin.cpp | 19 +++++++--- .../Point_set/Point_set_wlop_plugin.cpp | 8 +++-- .../Surface_reconstruction_plugin.cpp | 36 ++++++++++++------- .../Surface_reconstruction_plugin_impl.cpp | 11 +++--- 9 files changed, 84 insertions(+), 37 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_average_spacing_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_average_spacing_plugin.cpp index 4945a70df90..c986de12e47 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_average_spacing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_average_spacing_plugin.cpp @@ -91,9 +91,12 @@ void Polyhedron_demo_point_set_average_spacing_plugin::on_actionAverageSpacing_t CGAL::Timer task_timer; task_timer.start(); std::cerr << "Average spacing (k=" << nb_neighbors <<")...\n"; + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); + // Computes average spacing double average_spacing = CGAL::compute_average_spacing( - points->begin(), points->end(), + points_begin, points->end(), nb_neighbors); // Print result diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_bilateral_smoothing_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_bilateral_smoothing_plugin.cpp index fe3e669497c..a7792e66551 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_bilateral_smoothing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_bilateral_smoothing_plugin.cpp @@ -109,9 +109,12 @@ void Polyhedron_demo_point_set_bilateral_smoothing_plugin::on_actionBilateralSmo for (unsigned int i = 0; i < dialog.iterations (); ++i) { + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); + /* double error = */ CGAL::bilateral_smooth_point_set - (points->begin(), + (points_begin, points->end(), CGAL::make_identity_property_map(Point_set::value_type()), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type()), diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_interference_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_interference_plugin.cpp index 258de75df5c..7f70f696f63 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_interference_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_interference_plugin.cpp @@ -67,8 +67,15 @@ private Q_SLOTS: flags |= Qt::CustomizeWindowHint; flags |= Qt::WindowCloseButtonHint; + Point_set* points = item->point_set(); + if(points == NULL) + return; + + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); + double average_spacing = CGAL::compute_average_spacing( - item->point_set()->begin(), item->point_set()->end(), + points_begin, points->end(), 6 /* knn = 1 ring */); const double max_dist = @@ -85,7 +92,7 @@ private Q_SLOTS: CGAL::Random_points_in_sphere_3 generator(max_dist); - for(Point_set::iterator psit = item->point_set()->begin(); psit != item->point_set()->end(); ++psit) + for(Point_set::iterator psit = points_begin; psit != points->end(); ++psit) { *psit = *psit+(*generator - CGAL::ORIGIN); ++generator; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_normal_estimation_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_normal_estimation_plugin.cpp index e5a4d124919..f3999c54ab3 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_normal_estimation_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_normal_estimation_plugin.cpp @@ -129,8 +129,11 @@ void Polyhedron_demo_point_set_normal_estimation_plugin::on_actionNormalInversio Point_set* points = item->point_set(); if(points == NULL) return; - - for(Point_set::iterator it = points->begin(); it != points->end(); ++it){ + + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); + + for(Point_set::iterator it = points_begin; it != points->end(); ++it){ it->normal() = -1 * it->normal(); } item->invalidateOpenGLBuffers(); @@ -166,14 +169,16 @@ void Polyhedron_demo_point_set_normal_estimation_plugin::on_actionNormalEstimati //*************************************** // normal estimation //*************************************** + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); if (dialog.method() == 0) // PCA { CGAL::Timer task_timer; task_timer.start(); std::cerr << "Estimates normal direction by PCA (k=" << dialog.pca_neighbors() <<")...\n"; - + // Estimates normals direction. - CGAL::pca_estimate_normals(points->begin(), points->end(), + CGAL::pca_estimate_normals(points_begin, points->end(), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type()), dialog.pca_neighbors()); @@ -188,7 +193,7 @@ void Polyhedron_demo_point_set_normal_estimation_plugin::on_actionNormalEstimati std::cerr << "Estimates normal direction by Jet Fitting (k=" << dialog.jet_neighbors() <<")...\n"; // Estimates normals direction. - CGAL::jet_estimate_normals(points->begin(), points->end(), + CGAL::jet_estimate_normals(points_begin, points->end(), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type()), dialog.jet_neighbors()); @@ -206,7 +211,7 @@ void Polyhedron_demo_point_set_normal_estimation_plugin::on_actionNormalEstimati std::cerr << "Estimates Normals Direction using VCM (R=" << dialog.offset_radius() << " and r=" << dialog.convolution_radius() << ")...\n"; - CGAL::vcm_estimate_normals(points->begin(), points->end(), + CGAL::vcm_estimate_normals(points_begin, points->end(), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type()), dialog.offset_radius(), dialog.convolution_radius()); } @@ -240,12 +245,12 @@ void Polyhedron_demo_point_set_normal_estimation_plugin::on_actionNormalEstimati // Tries to orient normals first_unoriented_point = - CGAL::mst_orient_normals(points->begin(), points->end(), + CGAL::mst_orient_normals(points_begin, points->end(), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type()), dialog.orient_neighbors()); //indicates that the point set has normals - if (first_unoriented_point!=points->begin()){ + if (first_unoriented_point!=points_begin){ item->set_has_normals(true); item->setRenderingMode(PointsPlusNormals); } diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_smoothing_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_smoothing_plugin.cpp index be9d1e09aa4..a37f7557ce5 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_smoothing_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_smoothing_plugin.cpp @@ -81,7 +81,10 @@ void Polyhedron_demo_point_set_smoothing_plugin::on_actionJetSmoothing_triggered QApplication::setOverrideCursor(Qt::WaitCursor); - CGAL::jet_smooth_point_set(points->begin(), points->end(), nb_neighbors); + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); + + CGAL::jet_smooth_point_set(points_begin, points->end(), nb_neighbors); points->invalidate_bounds(); diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_upsampling_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_upsampling_plugin.cpp index a97dbbc214f..25e6eafdb15 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_upsampling_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_upsampling_plugin.cpp @@ -114,9 +114,13 @@ void Polyhedron_demo_point_set_upsampling_plugin::on_actionEdgeAwareUpsampling_t double average_spacing = CGAL::compute_average_spacing( points->begin(), points->end(), 6 /* knn = 1 ring */); - + + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); + std::size_t nb_selected = points->nb_selected_points(); + std::vector > new_points; - CGAL::edge_aware_upsample_point_set(points->begin(), + CGAL::edge_aware_upsample_point_set(points_begin, points->end(), std::back_inserter(new_points), CGAL::make_identity_property_map(Point_set::value_type()), @@ -125,10 +129,15 @@ void Polyhedron_demo_point_set_upsampling_plugin::on_actionEdgeAwareUpsampling_t dialog.edge_sensitivity(), dialog.neighborhood_radius() * average_spacing, output_size); - + nb_selected += new_points.size(); + for (unsigned int i = 0; i < new_points.size (); ++ i) - points->push_back (Point_set::Point_with_normal (new_points[i].first, - new_points[i].second)); + { + points->push_back (Point_set::Point_with_normal (new_points[i].first, + new_points[i].second)); + } + if (nb_selected != new_points.size()) + points->set_first_selected (points->end() - nb_selected); std::size_t memory = CGAL::Memory_sizer().virtual_size(); std::cerr << task_timer.time() << " seconds, " diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_wlop_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_wlop_plugin.cpp index 2bfb47bd0fc..48a854abbc4 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_wlop_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Point_set_wlop_plugin.cpp @@ -98,7 +98,9 @@ void Polyhedron_demo_point_set_wlop_plugin::on_actionSimplifyAndRegularize_trigg << dialog.neighborhoodRadius() <<" * average spacing)...\n"; // Computes average spacing - double average_spacing = CGAL::compute_average_spacing(points->begin(), points->end(), + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); + double average_spacing = CGAL::compute_average_spacing(points_begin, points->end(), 6 /* knn = 1 ring */); Scene_points_with_normal_item* new_item @@ -106,9 +108,9 @@ void Polyhedron_demo_point_set_wlop_plugin::on_actionSimplifyAndRegularize_trigg new_item->setName (tr("%1 (WLOP processed)").arg(item->name())); new_item->setVisible(true); scene->addItem(new_item); - + CGAL::wlop_simplify_and_regularize_point_set - (points->begin(), + (points_begin, points->end(), std::back_inserter(*(new_item->point_set ())), dialog.retainedPercentage (), diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin.cpp index 425c76e875a..162d41b12af 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin.cpp @@ -123,7 +123,10 @@ namespace SurfaceReconstruction unsigned int scale_of_anisotropy (const Point_set& points, double& size) { - Tree tree(points.begin(), points.end()); + Point_set::const_iterator points_begin = (points.nb_selected_points() == 0 + ? points.begin() : points.first_selected()); + + Tree tree(points_begin, points.end()); double ratio_kept = (points.size() < 1000) ? 1. : 1000. / (points.size()); @@ -191,6 +194,9 @@ namespace SurfaceReconstruction unsigned int scale_of_noise (const Point_set& points, double& size) { + Point_set::const_iterator points_begin = (points.nb_selected_points() == 0 + ? points.begin() : points.first_selected()); + Tree tree(points.begin(), points.end()); double ratio_kept = (points.size() < 1000) @@ -272,8 +278,11 @@ namespace SurfaceReconstruction bool separate_shells = false, bool force_manifold = true, unsigned int samples = 300, unsigned int iterations = 4) { + Point_set::const_iterator points_begin = (points.nb_selected_points() == 0 + ? points.begin() : points.first_selected()); + ScaleSpace reconstruct (scale, samples); - reconstruct.reconstruct_surface(points.begin (), points.end (), iterations, + reconstruct.reconstruct_surface(points_begin, points.end (), iterations, separate_shells, force_manifold); for( unsigned int sh = 0; sh < reconstruct.number_of_shells(); ++sh ) @@ -304,7 +313,7 @@ namespace SurfaceReconstruction if (map_i2i.find ((*it)[ind]) == map_i2i.end ()) { map_i2i.insert (std::make_pair ((*it)[ind], current_index ++)); - Point p = points[(*it)[ind]].position(); + Point p = (points_begin + (*it)[ind])->position(); new_item->new_vertex (p.x (), p.y (), p.z ()); if (generate_smooth) @@ -360,7 +369,7 @@ namespace SurfaceReconstruction if (map_i2i.find ((*it)[ind]) == map_i2i.end ()) { map_i2i.insert (std::make_pair ((*it)[ind], current_index ++)); - Point p = points[(*it)[ind]].position(); + Point p = (points_begin + (*it)[ind])->position(); new_item->new_vertex (p.x (), p.y (), p.z ()); if (generate_smooth) @@ -392,22 +401,22 @@ namespace SurfaceReconstruction { Polyhedron& P = * const_cast(new_item->polyhedron()); Radius filter (size); + Point_set::const_iterator points_begin = (points.nb_selected_points() == 0 + ? points.begin() : points.first_selected()); - CGAL::advancing_front_surface_reconstruction (points.begin (), points.end (), P, filter, + CGAL::advancing_front_surface_reconstruction (points_begin, points.end (), P, filter, radius_ratio_bound, beta); } void compute_normals (Point_set& points, unsigned int neighbors) { - CGAL::jet_estimate_normals(points.begin(), points.end(), + Point_set::iterator points_begin = (points.nb_selected_points() == 0 + ? points.begin() : points.first_selected()); + + CGAL::jet_estimate_normals(points_begin, points.end(), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type()), 2 * neighbors); - - points.erase (CGAL::mst_orient_normals (points.begin(), points.end(), - CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type()), - 2 * neighbors), - points.end ()); } } @@ -546,6 +555,8 @@ void Polyhedron_demo_surface_reconstruction_plugin::automatic_reconstruction { // Gets point set Point_set* points = pts_item->point_set(); + Point_set::iterator points_begin = (points->nb_selected_points() == 0 + ? points->begin() : points->first_selected()); // wait cursor QApplication::setOverrideCursor(Qt::WaitCursor); @@ -569,8 +580,9 @@ void Polyhedron_demo_surface_reconstruction_plugin::automatic_reconstruction new_item->invalidateOpenGLBuffers(); points = new_item->point_set(); - std::copy (pts_item->point_set()->begin(), pts_item->point_set()->end(), + std::copy (points_begin, pts_item->point_set()->end(), std::back_inserter (*points)); + points_begin = points->begin(); } std::cerr << "Analysing isotropy of point set... "; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin_impl.cpp b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin_impl.cpp index 1b701f14d94..4244ca3f946 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin_impl.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Point_set/Surface_reconstruction_plugin_impl.cpp @@ -71,7 +71,10 @@ Polyhedron* poisson_reconstruct(const Point_set& points, return NULL; } - bool points_have_normals = (points.begin()->normal() != CGAL::NULL_VECTOR); + Point_set::const_iterator points_begin = (points.nb_selected_points() == 0 + ? points.begin() : points.first_selected()); + + bool points_have_normals = (points_begin->normal() != CGAL::NULL_VECTOR); if ( ! points_have_normals ) { std::cerr << "Input point set not supported: this reconstruction method requires oriented normals" << std::endl; @@ -94,7 +97,7 @@ Polyhedron* poisson_reconstruct(const Point_set& points, // + property maps to access each point's position and normal. // The position property map can be omitted here as we use iterators over Point_3 elements. Poisson_reconstruction_function function( - points.begin(), points.end(), + points_begin, points.end(), CGAL::make_normal_of_point_with_normal_pmap(Point_set::value_type())); bool ok = false; @@ -132,7 +135,7 @@ Polyhedron* poisson_reconstruct(const Point_set& points, std::cerr << "Surface meshing...\n"; // Computes average spacing - Kernel::FT average_spacing = CGAL::compute_average_spacing(points.begin(), points.end(), + Kernel::FT average_spacing = CGAL::compute_average_spacing(points_begin, points.end(), 6 /* knn = 1 ring */); // Gets one point inside the implicit surface @@ -208,7 +211,7 @@ Polyhedron* poisson_reconstruct(const Point_set& points, std::set faces_to_keep; - for (Point_set::const_iterator p=points.begin(); p!=points.end(); p++) + for (Point_set::const_iterator p=points_begin; p!=points.end(); p++) { AABB_traits::Point_and_primitive_id pap = tree.closest_point_and_primitive (*p); double distance = std::sqrt(CGAL::squared_distance (pap.first, *p));