diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp index 6668158c330..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) @@ -38,10 +40,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 +53,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 +66,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 +82,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 +93,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 +117,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 +294,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 @@ -575,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); @@ -599,9 +606,9 @@ 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 - ratio_displayed = 3 * 300000. / (double)(d->nb_points + d->nb_selected_points); + if ((viewer->inFastDrawing () || d->isPointSliderMoving()) + &&((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()) @@ -711,9 +718,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 <= 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); + } + 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 +735,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 +800,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: