diff --git a/Polyhedron/demo/Polyhedron/MainWindow.cpp b/Polyhedron/demo/Polyhedron/MainWindow.cpp
index be2a5eea915..844f3df0ea8 100644
--- a/Polyhedron/demo/Polyhedron/MainWindow.cpp
+++ b/Polyhedron/demo/Polyhedron/MainWindow.cpp
@@ -248,6 +248,8 @@ MainWindow::MainWindow(QWidget* parent)
connect(ui->actionDraw_two_sides, SIGNAL(toggled(bool)),
viewer, SLOT(setTwoSides(bool)));
+ connect(ui->actionQuick_camera_mode, SIGNAL(toggled(bool)),
+ viewer, SLOT(setFastDrawing(bool)));
// add the "About CGAL..." and "About demo..." entries
this->addAboutCGAL();
diff --git a/Polyhedron/demo/Polyhedron/MainWindow.ui b/Polyhedron/demo/Polyhedron/MainWindow.ui
index 00730f15021..3d4f1a67c3e 100644
--- a/Polyhedron/demo/Polyhedron/MainWindow.ui
+++ b/Polyhedron/demo/Polyhedron/MainWindow.ui
@@ -115,6 +115,7 @@
+
@@ -664,6 +665,17 @@
Load plugin
+
+
+ true
+
+
+ true
+
+
+ Quick camera mode
+
+
diff --git a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp
index 9832f055c80..b682902535c 100644
--- a/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp
+++ b/Polyhedron/demo/Polyhedron/Scene_points_with_normal_item.cpp
@@ -17,6 +17,7 @@
#include
#include
+#include
#include
#include
@@ -165,10 +166,16 @@ void Scene_points_with_normal_item::compute_normals_and_vertices() const
positions_points.reserve(m_points->size() * 3);
positions_lines.reserve(m_points->size() * 3 * 2);
+
+ //Shuffle container to allow quick display random points
+ 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
- for (Point_set_3::const_iterator it = m_points->begin(); it != m_points->first_selected(); it++)
+ 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());
@@ -177,7 +184,7 @@ void Scene_points_with_normal_item::compute_normals_and_vertices() const
}
// Draw *selected* points
- for (Point_set_3::const_iterator it = m_points->first_selected(); it != m_points->end(); it++)
+ 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());
@@ -189,10 +196,10 @@ void Scene_points_with_normal_item::compute_normals_and_vertices() const
//The lines
{
// Stock normals
- Kernel::Sphere_3 region_of_interest = m_points->region_of_interest();
+ Kernel::Sphere_3 region_of_interest = points.region_of_interest();
float normal_length = (float)std::sqrt(region_of_interest.squared_radius() / 1000.);
- for (Point_set_3::const_iterator it = m_points->begin(); it != m_points->end(); it++)
+ for (Point_set_3::const_iterator it = points.begin(); it != points.end(); it++)
{
const UI_point& p = *it;
const Point_set_3::Vector& n = p.normal();
@@ -417,6 +424,11 @@ void Scene_points_with_normal_item::draw_splats(CGAL::Three::Viewer_interface* v
void Scene_points_with_normal_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const
{
+ double ratio_displayed = 1.0;
+ if (viewer->inFastDrawing () &&
+ (nb_lines/6 > 300000)) // arbitrary large value
+ ratio_displayed = 6 * 300000. / (double)(nb_lines);
+
if(!are_buffers_filled)
initialize_buffers(viewer);
vaos[Edges]->bind();
@@ -424,7 +436,8 @@ void Scene_points_with_normal_item::draw_edges(CGAL::Three::Viewer_interface* vi
attrib_buffers(viewer,PROGRAM_NO_SELECTION);
program->bind();
program->setAttributeValue("colors", this->color());
- viewer->glDrawArrays(GL_LINES, 0, static_cast(nb_lines/3));
+ viewer->glDrawArrays(GL_LINES, 0,
+ static_cast(((std::size_t)(ratio_displayed * nb_lines)/3)));
vaos[Edges]->release();
program->release();
}
@@ -433,12 +446,18 @@ void Scene_points_with_normal_item::draw_points(CGAL::Three::Viewer_interface* v
if(!are_buffers_filled)
initialize_buffers(viewer);
+ double ratio_displayed = 1.0;
+ if (viewer->inFastDrawing () &&
+ ((nb_points + nb_selected_points)/3 > 300000)) // arbitrary large value
+ ratio_displayed = 3 * 300000. / (double)(nb_points + nb_selected_points);
+
vaos[ThePoints]->bind();
program=getShaderProgram(PROGRAM_NO_SELECTION);
attrib_buffers(viewer,PROGRAM_NO_SELECTION);
program->bind();
program->setAttributeValue("colors", this->color());
- viewer->glDrawArrays(GL_POINTS, 0, static_cast(nb_points/3));
+ viewer->glDrawArrays(GL_POINTS, 0,
+ static_cast(((std::size_t)(ratio_displayed * nb_points)/3)));
vaos[ThePoints]->release();
program->release();
GLfloat point_size;
@@ -451,7 +470,7 @@ void Scene_points_with_normal_item::draw_points(CGAL::Three::Viewer_interface* v
program->bind();
program->setAttributeValue("colors", QColor(255,0,0));
viewer->glDrawArrays(GL_POINTS, 0,
- static_cast(nb_selected_points/3));
+ static_cast(((std::size_t)(ratio_displayed * nb_selected_points)/3)));
vaos[Selected_points]->release();
program->release();
viewer->glPointSize(point_size);
diff --git a/Polyhedron/demo/Polyhedron/Viewer.cpp b/Polyhedron/demo/Polyhedron/Viewer.cpp
index c28d4660ff7..48f4cb706ca 100644
--- a/Polyhedron/demo/Polyhedron/Viewer.cpp
+++ b/Polyhedron/demo/Polyhedron/Viewer.cpp
@@ -16,7 +16,7 @@ public:
bool twosides;
bool macro_mode;
bool inFastDrawing;
-
+
void draw_aux(bool with_names, Viewer*);
//! Contains all the programs for the item rendering.
@@ -30,6 +30,7 @@ Viewer::Viewer(QWidget* parent, bool antialiasing)
d->antialiasing = antialiasing;
d->twosides = false;
d->macro_mode = false;
+ d->inFastDrawing = true;
d->shader_programs.resize(NB_OF_PROGRAMS);
setShortcut(EXIT_VIEWER, 0);
setShortcut(DRAW_AXIS, 0);
@@ -94,22 +95,28 @@ void Viewer::setTwoSides(bool b)
updateGL();
}
-bool Viewer::inFastDrawing() const {
- return d->inFastDrawing;
+
+void Viewer::setFastDrawing(bool b)
+{
+ d->inFastDrawing = b;
+ updateGL();
+}
+
+bool Viewer::inFastDrawing() const
+{
+ return (d->inFastDrawing
+ && (camera()->frame()->isSpinning()
+ || camera()->frame()->isManipulated()));
}
void Viewer::draw()
{
glEnable(GL_DEPTH_TEST);
- d->inFastDrawing = false;
- QGLViewer::draw();
d->draw_aux(false, this);
}
void Viewer::fastDraw()
{
- d->inFastDrawing = true;
- QGLViewer::fastDraw();
d->draw_aux(false, this);
}
diff --git a/Polyhedron/demo/Polyhedron/Viewer.h b/Polyhedron/demo/Polyhedron/Viewer.h
index 6e9e343cee9..3435ebe047d 100644
--- a/Polyhedron/demo/Polyhedron/Viewer.h
+++ b/Polyhedron/demo/Polyhedron/Viewer.h
@@ -70,6 +70,9 @@ public Q_SLOTS:
//! If b is true, facets will be ligted from both internal and external sides.
//! If b is false, only the side that is exposed to the light source will be lighted.
void setTwoSides(bool b);
+ //! If b is true, some items are displayed in a simplified version when moving the camera.
+ //! If b is false, items display is never altered, even when moving.
+ void setFastDrawing(bool b);
//! Make the camera turn around.
void turnCameraBy180Degres();
//! @returns a QString containing the position and orientation of the camera.
diff --git a/Three/include/CGAL/Three/Viewer_interface.h b/Three/include/CGAL/Three/Viewer_interface.h
index ea1da1a5153..dd42964ec67 100644
--- a/Three/include/CGAL/Three/Viewer_interface.h
+++ b/Three/include/CGAL/Three/Viewer_interface.h
@@ -59,7 +59,7 @@ public:
virtual void setScene(CGAL::Three::Scene_draw_interface* scene) = 0;
//! @returns the antialiasing state.
virtual bool antiAliasing() const = 0;
-
+
// Those two functions are defined in Viewer.cpp
//!Sets the position and orientation of a frame using a QString.
//!@returns true if it worked.
@@ -138,6 +138,9 @@ public Q_SLOTS:
//! If b is true, facets will be ligted from both internal and external sides.
//! If b is false, only the side that is exposed to the light source will be lighted.
virtual void setTwoSides(bool b) = 0;
+ //! If b is true, some items are displayed in a simplified version when moving the camera.
+ //! If b is false, items display is never altered, even when moving.
+ virtual void setFastDrawing(bool b) = 0;
//! Make the camera turn around.
virtual void turnCameraBy180Degres() = 0;
//! @returns a QString containing the position and orientation of the camera.