From 3bd7e95d87b34442b3ed370841d02eab076ad1fb Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Tue, 20 Sep 2016 10:57:38 +0200 Subject: [PATCH 1/2] Optimize - Makes the resizing of the points real fast - Makes the resizing of the normals applied on slider released instead of every tick when the point set size is bigger than 300 000 - sets the initial value of the point size to 2 instead of 5 --- .../Scene_points_with_normal_item.cpp | 71 ++++++++++++------- .../Scene_points_with_normal_item.h | 4 ++ 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index 6668158c330..ddb70f694e7 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -38,10 +38,11 @@ struct Scene_points_with_normal_item_priv nb_points = 0; nb_selected_points = 0; nb_lines = 0; + is_point_slider_moving = false; normal_Slider = new QSlider(Qt::Horizontal); normal_Slider->setValue(20); point_Slider = new QSlider(Qt::Horizontal); - point_Slider->setValue(5); + point_Slider->setValue(2); point_Slider->setMinimum(1); point_Slider->setMaximum(25); } @@ -50,10 +51,11 @@ struct Scene_points_with_normal_item_priv m_has_normals(toCopy.d->m_has_normals) { item = parent; + is_point_slider_moving = false; normal_Slider = new QSlider(Qt::Horizontal); normal_Slider->setValue(20); point_Slider = new QSlider(Qt::Horizontal); - point_Slider->setValue(5); + point_Slider->setValue(2); point_Slider->setMinimum(1); point_Slider->setMaximum(25); } @@ -62,6 +64,7 @@ struct Scene_points_with_normal_item_priv m_has_normals(true) { item = parent; + is_point_slider_moving = false; nb_points = 0; nb_selected_points = 0; nb_lines = 0; @@ -77,7 +80,7 @@ struct Scene_points_with_normal_item_priv normal_Slider = new QSlider(Qt::Horizontal); normal_Slider->setValue(20); point_Slider = new QSlider(Qt::Horizontal); - point_Slider->setValue(5); + point_Slider->setValue(2); point_Slider->setMinimum(1); point_Slider->setMaximum(25); } @@ -88,6 +91,7 @@ struct Scene_points_with_normal_item_priv delete normal_Slider; delete point_Slider; } + bool isPointSliderMoving() { return is_point_slider_moving; } void initializeBuffers(CGAL::Three::Viewer_interface *viewer) const; void compute_normals_and_vertices() const; enum VAOs { @@ -111,6 +115,7 @@ struct Scene_points_with_normal_item_priv QAction* actionSelectDuplicatedPoints; QSlider* normal_Slider; QSlider* point_Slider; + mutable bool is_point_slider_moving; mutable std::vector positions_lines; mutable std::vector positions_points; mutable std::vector positions_selected_points; @@ -287,26 +292,26 @@ void Scene_points_with_normal_item_priv::compute_normals_and_vertices() const Point_set_3 points = *m_points; std::random_shuffle (points.begin(), points.end() - m_points->nb_selected_points()); std::random_shuffle (points.end() - m_points->nb_selected_points(), points.end()); - + //The points { - // The *non-selected* points + // The *non-selected* points for (Point_set_3::const_iterator it = points.begin(); it != points.first_selected(); it++) - { - const UI_point& p = *it; - positions_points.push_back(p.x()); - positions_points.push_back(p.y()); - positions_points.push_back(p.z()); - } + { + const UI_point& p = *it; + positions_points.push_back(p.x()); + positions_points.push_back(p.y()); + positions_points.push_back(p.z()); + } - // Draw *selected* points + // Draw *selected* points for (Point_set_3::const_iterator it = points.first_selected(); it != points.end(); it++) - { - const UI_point& p = *it; - positions_selected_points.push_back(p.x()); - positions_selected_points.push_back(p.y()); - positions_selected_points.push_back(p.z()); - } + { + const UI_point& p = *it; + positions_selected_points.push_back(p.x()); + positions_selected_points.push_back(p.y()); + positions_selected_points.push_back(p.z()); + } } //The lines @@ -599,8 +604,8 @@ void Scene_points_with_normal_item::drawPoints(CGAL::Three::Viewer_interface* vi viewer->glGetFloatv(GL_POINT_SIZE, &point_size); viewer->glPointSize(d->point_Slider->value()); double ratio_displayed = 1.0; - if (viewer->inFastDrawing () && - ((d->nb_points + d->nb_selected_points)/3 > 300000)) // arbitrary large value + if ((viewer->inFastDrawing () || d->isPointSliderMoving()) + &&((d->nb_points + d->nb_selected_points)/3 > 300000)) // arbitrary large value ratio_displayed = 3 * 300000. / (double)(d->nb_points + d->nb_selected_points); vaos[Scene_points_with_normal_item_priv::ThePoints]->bind(); @@ -711,9 +716,16 @@ QMenu* Scene_points_with_normal_item::contextMenu() { QMenu *container = new QMenu(tr("Normals Length")); QWidgetAction *sliderAction = new QWidgetAction(0); - connect(d->normal_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::invalidateOpenGLBuffers); - connect(d->normal_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::itemChanged); - + if((d->nb_points + d->nb_selected_points)/3 <= 300000) + { + connect(d->normal_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::invalidateOpenGLBuffers); + connect(d->normal_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::itemChanged); + } + else + { + connect(d->normal_Slider, &QSlider::sliderReleased, this, &Scene_points_with_normal_item::invalidateOpenGLBuffers); + connect(d->normal_Slider, &QSlider::sliderReleased, this, &Scene_points_with_normal_item::itemChanged); + } sliderAction->setDefaultWidget(d->normal_Slider); container->addAction(sliderAction); @@ -721,7 +733,8 @@ QMenu* Scene_points_with_normal_item::contextMenu() } QMenu *container = new QMenu(tr("Points Size")); QWidgetAction *sliderAction = new QWidgetAction(0); - connect(d->point_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::invalidateOpenGLBuffers); + connect(d->point_Slider, &QSlider::sliderPressed, this, &Scene_points_with_normal_item::pointSliderPressed); + connect(d->point_Slider, &QSlider::sliderReleased, this, &Scene_points_with_normal_item::pointSliderReleased); connect(d->point_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::itemChanged); sliderAction->setDefaultWidget(d->point_Slider); @@ -785,3 +798,13 @@ void Scene_points_with_normal_item::invalidateOpenGLBuffers() compute_bbox(); } +void Scene_points_with_normal_item::pointSliderPressed() +{ + d->is_point_slider_moving = true; +} + +void Scene_points_with_normal_item::pointSliderReleased() +{ + d->is_point_slider_moving = false; +} + diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h index de28c1c9be5..c392446c144 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.h @@ -84,6 +84,10 @@ public Q_SLOTS: void resetSelection(); //Select duplicated points void selectDuplicates(); + //Set the status of the slider as `pressed` + void pointSliderPressed(); + //Set the status of the slider as `released` + void pointSliderReleased(); // Data protected: From b51f064a5554b9ad916c0299c902d65d93790312 Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Wed, 21 Sep 2016 14:55:50 +0200 Subject: [PATCH 2/2] Make the 300 000 a const std::size_t define in the beginning of Scene_point_with_normal_item.cpp --- .../Polyhedron/Scene_points_with_normal_item.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index ddb70f694e7..05174531faa 100644 --- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp +++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp @@ -28,6 +28,8 @@ #include #include +const std::size_t limit_fast_drawing = 300000; //arbitraty large valu + struct Scene_points_with_normal_item_priv { Scene_points_with_normal_item_priv(Scene_points_with_normal_item* parent) @@ -580,8 +582,8 @@ void Scene_points_with_normal_item::drawEdges(CGAL::Three::Viewer_interface* vie { double ratio_displayed = 1.0; if (viewer->inFastDrawing () && - (d->nb_lines/6 > 300000)) // arbitrary large value - ratio_displayed = 6 * 300000. / (double)(d->nb_lines); + (d->nb_lines/6 > limit_fast_drawing)) // arbitrary large value + ratio_displayed = 6 * limit_fast_drawing / (double)(d->nb_lines); if(!are_buffers_filled) d->initializeBuffers(viewer); @@ -605,8 +607,8 @@ void Scene_points_with_normal_item::drawPoints(CGAL::Three::Viewer_interface* vi viewer->glPointSize(d->point_Slider->value()); double ratio_displayed = 1.0; if ((viewer->inFastDrawing () || d->isPointSliderMoving()) - &&((d->nb_points + d->nb_selected_points)/3 > 300000)) // arbitrary large value - ratio_displayed = 3 * 300000. / (double)(d->nb_points + d->nb_selected_points); + &&((d->nb_points + d->nb_selected_points)/3 > limit_fast_drawing)) // arbitrary large value + ratio_displayed = 3 * limit_fast_drawing / (double)(d->nb_points + d->nb_selected_points); vaos[Scene_points_with_normal_item_priv::ThePoints]->bind(); if(has_normals()) @@ -716,7 +718,7 @@ QMenu* Scene_points_with_normal_item::contextMenu() { QMenu *container = new QMenu(tr("Normals Length")); QWidgetAction *sliderAction = new QWidgetAction(0); - if((d->nb_points + d->nb_selected_points)/3 <= 300000) + if((d->nb_points + d->nb_selected_points)/3 <= limit_fast_drawing) { connect(d->normal_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::invalidateOpenGLBuffers); connect(d->normal_Slider, &QSlider::valueChanged, this, &Scene_points_with_normal_item::itemChanged);