mirror of https://github.com/CGAL/cgal
Merge pull request #556 from sgiraudot/Polyhedron_demo-Quick_moving_display-GF
Polyhedron demo: quick moving display of point sets
This commit is contained in:
commit
d782bc4da8
|
|
@ -248,6 +248,8 @@ MainWindow::MainWindow(QWidget* parent)
|
||||||
|
|
||||||
connect(ui->actionDraw_two_sides, SIGNAL(toggled(bool)),
|
connect(ui->actionDraw_two_sides, SIGNAL(toggled(bool)),
|
||||||
viewer, SLOT(setTwoSides(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
|
// add the "About CGAL..." and "About demo..." entries
|
||||||
this->addAboutCGAL();
|
this->addAboutCGAL();
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@
|
||||||
<addaction name="action_Look_at"/>
|
<addaction name="action_Look_at"/>
|
||||||
<addaction name="actionAntiAliasing"/>
|
<addaction name="actionAntiAliasing"/>
|
||||||
<addaction name="actionDraw_two_sides"/>
|
<addaction name="actionDraw_two_sides"/>
|
||||||
|
<addaction name="actionQuick_camera_mode"/>
|
||||||
<addaction name="actionSetBackgroundColor"/>
|
<addaction name="actionSetBackgroundColor"/>
|
||||||
<addaction name="menuDockWindows"/>
|
<addaction name="menuDockWindows"/>
|
||||||
<addaction name="menuCamera"/>
|
<addaction name="menuCamera"/>
|
||||||
|
|
@ -664,6 +665,17 @@
|
||||||
<string>Load plugin</string>
|
<string>Load plugin</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionQuick_camera_mode">
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Quick camera mode</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <QGLViewer/manipulatedCameraFrame.h>
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
@ -165,10 +166,16 @@ void Scene_points_with_normal_item::compute_normals_and_vertices() const
|
||||||
positions_points.reserve(m_points->size() * 3);
|
positions_points.reserve(m_points->size() * 3);
|
||||||
positions_lines.reserve(m_points->size() * 3 * 2);
|
positions_lines.reserve(m_points->size() * 3 * 2);
|
||||||
|
|
||||||
|
|
||||||
|
//Shuffle container to allow quick display random points
|
||||||
|
Point_set_3<Kernel> 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 points
|
||||||
{
|
{
|
||||||
// The *non-selected* points
|
// The *non-selected* points
|
||||||
for (Point_set_3<Kernel>::const_iterator it = m_points->begin(); it != m_points->first_selected(); it++)
|
for (Point_set_3<Kernel>::const_iterator it = points.begin(); it != points.first_selected(); it++)
|
||||||
{
|
{
|
||||||
const UI_point& p = *it;
|
const UI_point& p = *it;
|
||||||
positions_points.push_back(p.x());
|
positions_points.push_back(p.x());
|
||||||
|
|
@ -177,7 +184,7 @@ void Scene_points_with_normal_item::compute_normals_and_vertices() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw *selected* points
|
// Draw *selected* points
|
||||||
for (Point_set_3<Kernel>::const_iterator it = m_points->first_selected(); it != m_points->end(); it++)
|
for (Point_set_3<Kernel>::const_iterator it = points.first_selected(); it != points.end(); it++)
|
||||||
{
|
{
|
||||||
const UI_point& p = *it;
|
const UI_point& p = *it;
|
||||||
positions_selected_points.push_back(p.x());
|
positions_selected_points.push_back(p.x());
|
||||||
|
|
@ -189,10 +196,10 @@ void Scene_points_with_normal_item::compute_normals_and_vertices() const
|
||||||
//The lines
|
//The lines
|
||||||
{
|
{
|
||||||
// Stock normals
|
// 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.);
|
float normal_length = (float)std::sqrt(region_of_interest.squared_radius() / 1000.);
|
||||||
|
|
||||||
for (Point_set_3<Kernel>::const_iterator it = m_points->begin(); it != m_points->end(); it++)
|
for (Point_set_3<Kernel>::const_iterator it = points.begin(); it != points.end(); it++)
|
||||||
{
|
{
|
||||||
const UI_point& p = *it;
|
const UI_point& p = *it;
|
||||||
const Point_set_3<Kernel>::Vector& n = p.normal();
|
const Point_set_3<Kernel>::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
|
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)
|
if(!are_buffers_filled)
|
||||||
initialize_buffers(viewer);
|
initialize_buffers(viewer);
|
||||||
vaos[Edges]->bind();
|
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);
|
attrib_buffers(viewer,PROGRAM_NO_SELECTION);
|
||||||
program->bind();
|
program->bind();
|
||||||
program->setAttributeValue("colors", this->color());
|
program->setAttributeValue("colors", this->color());
|
||||||
viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(nb_lines/3));
|
viewer->glDrawArrays(GL_LINES, 0,
|
||||||
|
static_cast<GLsizei>(((std::size_t)(ratio_displayed * nb_lines)/3)));
|
||||||
vaos[Edges]->release();
|
vaos[Edges]->release();
|
||||||
program->release();
|
program->release();
|
||||||
}
|
}
|
||||||
|
|
@ -433,12 +446,18 @@ void Scene_points_with_normal_item::draw_points(CGAL::Three::Viewer_interface* v
|
||||||
if(!are_buffers_filled)
|
if(!are_buffers_filled)
|
||||||
initialize_buffers(viewer);
|
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();
|
vaos[ThePoints]->bind();
|
||||||
program=getShaderProgram(PROGRAM_NO_SELECTION);
|
program=getShaderProgram(PROGRAM_NO_SELECTION);
|
||||||
attrib_buffers(viewer,PROGRAM_NO_SELECTION);
|
attrib_buffers(viewer,PROGRAM_NO_SELECTION);
|
||||||
program->bind();
|
program->bind();
|
||||||
program->setAttributeValue("colors", this->color());
|
program->setAttributeValue("colors", this->color());
|
||||||
viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nb_points/3));
|
viewer->glDrawArrays(GL_POINTS, 0,
|
||||||
|
static_cast<GLsizei>(((std::size_t)(ratio_displayed * nb_points)/3)));
|
||||||
vaos[ThePoints]->release();
|
vaos[ThePoints]->release();
|
||||||
program->release();
|
program->release();
|
||||||
GLfloat point_size;
|
GLfloat point_size;
|
||||||
|
|
@ -451,7 +470,7 @@ void Scene_points_with_normal_item::draw_points(CGAL::Three::Viewer_interface* v
|
||||||
program->bind();
|
program->bind();
|
||||||
program->setAttributeValue("colors", QColor(255,0,0));
|
program->setAttributeValue("colors", QColor(255,0,0));
|
||||||
viewer->glDrawArrays(GL_POINTS, 0,
|
viewer->glDrawArrays(GL_POINTS, 0,
|
||||||
static_cast<GLsizei>(nb_selected_points/3));
|
static_cast<GLsizei>(((std::size_t)(ratio_displayed * nb_selected_points)/3)));
|
||||||
vaos[Selected_points]->release();
|
vaos[Selected_points]->release();
|
||||||
program->release();
|
program->release();
|
||||||
viewer->glPointSize(point_size);
|
viewer->glPointSize(point_size);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ Viewer::Viewer(QWidget* parent, bool antialiasing)
|
||||||
d->antialiasing = antialiasing;
|
d->antialiasing = antialiasing;
|
||||||
d->twosides = false;
|
d->twosides = false;
|
||||||
d->macro_mode = false;
|
d->macro_mode = false;
|
||||||
|
d->inFastDrawing = true;
|
||||||
d->shader_programs.resize(NB_OF_PROGRAMS);
|
d->shader_programs.resize(NB_OF_PROGRAMS);
|
||||||
setShortcut(EXIT_VIEWER, 0);
|
setShortcut(EXIT_VIEWER, 0);
|
||||||
setShortcut(DRAW_AXIS, 0);
|
setShortcut(DRAW_AXIS, 0);
|
||||||
|
|
@ -94,22 +95,28 @@ void Viewer::setTwoSides(bool b)
|
||||||
updateGL();
|
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()
|
void Viewer::draw()
|
||||||
{
|
{
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
d->inFastDrawing = false;
|
|
||||||
QGLViewer::draw();
|
|
||||||
d->draw_aux(false, this);
|
d->draw_aux(false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::fastDraw()
|
void Viewer::fastDraw()
|
||||||
{
|
{
|
||||||
d->inFastDrawing = true;
|
|
||||||
QGLViewer::fastDraw();
|
|
||||||
d->draw_aux(false, this);
|
d->draw_aux(false, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,9 @@ public Q_SLOTS:
|
||||||
//! If b is true, facets will be ligted from both internal and external sides.
|
//! 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.
|
//! If b is false, only the side that is exposed to the light source will be lighted.
|
||||||
void setTwoSides(bool b);
|
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.
|
//! Make the camera turn around.
|
||||||
void turnCameraBy180Degres();
|
void turnCameraBy180Degres();
|
||||||
//! @returns a QString containing the position and orientation of the camera.
|
//! @returns a QString containing the position and orientation of the camera.
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,9 @@ public Q_SLOTS:
|
||||||
//! If b is true, facets will be ligted from both internal and external sides.
|
//! 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.
|
//! If b is false, only the side that is exposed to the light source will be lighted.
|
||||||
virtual void setTwoSides(bool b) = 0;
|
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.
|
//! Make the camera turn around.
|
||||||
virtual void turnCameraBy180Degres() = 0;
|
virtual void turnCameraBy180Degres() = 0;
|
||||||
//! @returns a QString containing the position and orientation of the camera.
|
//! @returns a QString containing the position and orientation of the camera.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue