mirror of https://github.com/CGAL/cgal
New picking finished. Far more efficient.
This commit is contained in:
parent
c8e1a78a39
commit
24b16b4710
|
|
@ -331,10 +331,10 @@ Scene::drawWithNames(CGAL::Three::Viewer_interface* viewer)
|
||||||
{
|
{
|
||||||
draw_aux(true, viewer);
|
draw_aux(true, viewer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer)
|
Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer)
|
||||||
{
|
{
|
||||||
|
QMap<float, int> picked_item_IDs;
|
||||||
if(!ms_splatting->viewer_is_set)
|
if(!ms_splatting->viewer_is_set)
|
||||||
ms_splatting->setViewer(viewer);
|
ms_splatting->setViewer(viewer);
|
||||||
if(!gl_init)
|
if(!gl_init)
|
||||||
|
|
@ -343,7 +343,8 @@ Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer)
|
||||||
for(int index = 0; index < m_entries.size(); ++index)
|
for(int index = 0; index < m_entries.size(); ++index)
|
||||||
{
|
{
|
||||||
if(with_names) {
|
if(with_names) {
|
||||||
viewer->glPushName(index);
|
glClearDepth(1.0);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
CGAL::Three::Scene_item& item = *m_entries[index];
|
CGAL::Three::Scene_item& item = *m_entries[index];
|
||||||
if(item.visible())
|
if(item.visible())
|
||||||
|
|
@ -375,16 +376,23 @@ Scene::draw_aux(bool with_names, CGAL::Three::Viewer_interface* viewer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(with_names) {
|
if(with_names) {
|
||||||
viewer->glPopName();
|
|
||||||
|
// read depth buffer at pick location;
|
||||||
|
float depth = 1.0;
|
||||||
|
glReadPixels(picked_pixel.x(),picked_pixel.y(),1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
|
||||||
|
if (depth != 1.0)
|
||||||
|
{
|
||||||
|
//add object to list of picked objects;
|
||||||
|
picked_item_IDs[depth] = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
glDepthFunc(GL_LEQUAL);
|
}
|
||||||
|
if(!with_names)
|
||||||
|
{
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
// Wireframe OpenGL drawing
|
// Wireframe OpenGL drawing
|
||||||
for(int index = 0; index < m_entries.size(); ++index)
|
for(int index = 0; index < m_entries.size(); ++index)
|
||||||
{
|
{
|
||||||
if(with_names) {
|
|
||||||
viewer->glPushName(index);
|
|
||||||
}
|
|
||||||
CGAL::Three::Scene_item& item = *m_entries[index];
|
CGAL::Three::Scene_item& item = *m_entries[index];
|
||||||
if(item.visible())
|
if(item.visible())
|
||||||
{
|
{
|
||||||
|
|
@ -433,18 +441,12 @@ glDepthFunc(GL_LEQUAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(with_names) {
|
|
||||||
viewer->glPopName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Points OpenGL drawing
|
// Points OpenGL drawing
|
||||||
for(int index = 0; index < m_entries.size(); ++index)
|
for(int index = 0; index < m_entries.size(); ++index)
|
||||||
{
|
{
|
||||||
if(with_names) {
|
|
||||||
viewer->glPushName(index);
|
|
||||||
}
|
|
||||||
CGAL::Three::Scene_item& item = *m_entries[index];
|
CGAL::Three::Scene_item& item = *m_entries[index];
|
||||||
if(item.visible())
|
if(item.visible())
|
||||||
{
|
{
|
||||||
|
|
@ -461,9 +463,6 @@ glDepthFunc(GL_LEQUAL);
|
||||||
item.draw_points();
|
item.draw_points();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(with_names) {
|
|
||||||
viewer->glPopName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
glDepthFunc(GL_LESS);
|
glDepthFunc(GL_LESS);
|
||||||
// Splatting
|
// Splatting
|
||||||
|
|
@ -501,14 +500,27 @@ glDepthFunc(GL_LEQUAL);
|
||||||
ms_splatting->finalize();
|
ms_splatting->finalize();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//scrolls the sceneView to the selected item's line.
|
else
|
||||||
if(picked)
|
{
|
||||||
Q_EMIT(itemPicked(index_map.key(mainSelectionIndex())));
|
QList<float> depths = picked_item_IDs.keys();
|
||||||
|
if(!depths.isEmpty())
|
||||||
|
{
|
||||||
|
qSort(depths);
|
||||||
|
int id = picked_item_IDs[depths.first()];
|
||||||
|
setSelectedItemIndex(id);
|
||||||
|
viewer->setSelectedName(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
if(with_names)
|
if(with_names)
|
||||||
picked = true;
|
picked = true;
|
||||||
else
|
else
|
||||||
picked = false;
|
picked = false;
|
||||||
|
//scrolls the sceneView to the selected item's line.
|
||||||
|
if(picked)
|
||||||
|
{
|
||||||
|
Q_EMIT(itemPicked(index_map.key(mainSelectionIndex())));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,8 @@ public:
|
||||||
void initializeGL();
|
void initializeGL();
|
||||||
/*! Is called by Viewer::draw(). Is deprecated and does nothing.*/
|
/*! Is called by Viewer::draw(). Is deprecated and does nothing.*/
|
||||||
void draw();
|
void draw();
|
||||||
|
/*! Sets the screen coordinates of the currently picked point.*/
|
||||||
|
void setPickedPixel(const QPoint &p) {picked_pixel = p;}
|
||||||
/*! Is deprecated and does nothing.*/
|
/*! Is deprecated and does nothing.*/
|
||||||
void drawWithNames();
|
void drawWithNames();
|
||||||
/*! Is called by Viewer::draw(Viewer_interface*). Calls draw_aux(false, viewer).
|
/*! Is called by Viewer::draw(Viewer_interface*). Calls draw_aux(false, viewer).
|
||||||
|
|
@ -274,6 +276,7 @@ private:
|
||||||
//!Index of the item_B.
|
//!Index of the item_B.
|
||||||
int item_B;
|
int item_B;
|
||||||
bool picked;
|
bool picked;
|
||||||
|
QPoint picked_pixel;
|
||||||
bool gl_init;
|
bool gl_init;
|
||||||
static GlSplat::SplatRenderer* ms_splatting;
|
static GlSplat::SplatRenderer* ms_splatting;
|
||||||
static int ms_splattingCounter;
|
static int ms_splattingCounter;
|
||||||
|
|
|
||||||
|
|
@ -237,6 +237,7 @@ void Viewer::mousePressEvent(QMouseEvent* event)
|
||||||
if(event->button() == Qt::RightButton &&
|
if(event->button() == Qt::RightButton &&
|
||||||
event->modifiers().testFlag(Qt::ShiftModifier))
|
event->modifiers().testFlag(Qt::ShiftModifier))
|
||||||
{
|
{
|
||||||
|
|
||||||
select(event->pos());
|
select(event->pos());
|
||||||
requestContextMenu(event->globalPos());
|
requestContextMenu(event->globalPos());
|
||||||
event->accept();
|
event->accept();
|
||||||
|
|
@ -435,7 +436,6 @@ void Viewer::attrib_buffers(int program_name) const {
|
||||||
mv_mat.data()[i] = GLfloat(d_mat[i]);
|
mv_mat.data()[i] = GLfloat(d_mat[i]);
|
||||||
for (int i=0; i<16; ++i)
|
for (int i=0; i<16; ++i)
|
||||||
pick_mat.data()[i] = this->pickMatrix_[i];
|
pick_mat.data()[i] = this->pickMatrix_[i];
|
||||||
|
|
||||||
mvp_mat = pick_mat * mvp_mat;
|
mvp_mat = pick_mat * mvp_mat;
|
||||||
|
|
||||||
const_cast<Viewer*>(this)->glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE,
|
const_cast<Viewer*>(this)->glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE,
|
||||||
|
|
@ -546,7 +546,7 @@ void Viewer::attrib_buffers(int program_name) const {
|
||||||
|
|
||||||
|
|
||||||
void Viewer::pickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height,
|
void Viewer::pickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height,
|
||||||
GLint viewport[4])
|
GLint viewport[4]) const
|
||||||
{
|
{
|
||||||
//GLfloat m[16];
|
//GLfloat m[16];
|
||||||
GLfloat sx, sy;
|
GLfloat sx, sy;
|
||||||
|
|
@ -575,21 +575,25 @@ GLint viewport[4])
|
||||||
M(3, 2) = 0.0;
|
M(3, 2) = 0.0;
|
||||||
M(3, 3) = 1.0;
|
M(3, 3) = 1.0;
|
||||||
#undef M
|
#undef M
|
||||||
|
|
||||||
//pickMatrix_[i] = m[i];
|
|
||||||
}
|
}
|
||||||
void Viewer::beginSelection(const QPoint &point)
|
void Viewer::beginSelection(const QPoint &point)
|
||||||
{
|
{
|
||||||
QGLViewer::beginSelection(point);
|
// QGLViewer::beginSelection(point);
|
||||||
|
makeCurrent();
|
||||||
//set the picking matrix to allow the picking
|
//set the picking matrix to allow the picking
|
||||||
static GLint viewport[4];
|
static GLint viewport[4];
|
||||||
camera()->getViewport(viewport);
|
camera()->getViewport(viewport);
|
||||||
pickMatrix(point.x(), point.y(), selectRegionWidth(), selectRegionHeight(), viewport);
|
pickMatrix(point.x(), point.y(), 1, 1, viewport);
|
||||||
|
glEnable(GL_SCISSOR_TEST);
|
||||||
|
glScissor(point.x(), point.y(), 1, 1);
|
||||||
|
d->scene->setPickedPixel(point);
|
||||||
|
|
||||||
}
|
}
|
||||||
void Viewer::endSelection(const QPoint& point)
|
void Viewer::endSelection(const QPoint&)
|
||||||
{
|
{
|
||||||
QGLViewer::endSelection(point);
|
//QGLViewer::endSelection(point);
|
||||||
|
glDisable(GL_SCISSOR_TEST);
|
||||||
|
|
||||||
//set the pick matrix to Identity
|
//set the pick matrix to Identity
|
||||||
for(int i=0; i<16; i++)
|
for(int i=0; i<16; i++)
|
||||||
pickMatrix_[i]=0;
|
pickMatrix_[i]=0;
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,7 @@ protected:
|
||||||
* the drawing system changed to use shaders, and these need this value. pickMatrix_ is passed to the shaders in
|
* the drawing system changed to use shaders, and these need this value. pickMatrix_ is passed to the shaders in
|
||||||
* Scene_item::attrib_buffers(CGAL::Three::Viewer_interface* viewer, int program_name).*/
|
* Scene_item::attrib_buffers(CGAL::Three::Viewer_interface* viewer, int program_name).*/
|
||||||
void pickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height,
|
void pickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height,
|
||||||
GLint viewport[4]);
|
GLint viewport[4]) const;
|
||||||
/*!
|
/*!
|
||||||
* \brief makeArrow creates an arrow and stores it in a struct of vectors.
|
* \brief makeArrow creates an arrow and stores it in a struct of vectors.
|
||||||
* \param R the radius of the arrow.
|
* \param R the radius of the arrow.
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#define SCENE_DRAW_INTERFACE_H
|
#define SCENE_DRAW_INTERFACE_H
|
||||||
|
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
|
class QPoint;
|
||||||
namespace CGAL
|
namespace CGAL
|
||||||
{
|
{
|
||||||
namespace Three {
|
namespace Three {
|
||||||
|
|
@ -36,6 +37,8 @@ public:
|
||||||
virtual void draw() = 0;
|
virtual void draw() = 0;
|
||||||
virtual void draw(CGAL::Three::Viewer_interface*) { draw(); };
|
virtual void draw(CGAL::Three::Viewer_interface*) { draw(); };
|
||||||
virtual void drawWithNames() = 0;
|
virtual void drawWithNames() = 0;
|
||||||
|
/*! Sets the screen coordinates of the currently picked point.*/
|
||||||
|
virtual void setPickedPixel(const QPoint &e) = 0;
|
||||||
virtual void drawWithNames(CGAL::Three::Viewer_interface*) { drawWithNames(); }
|
virtual void drawWithNames(CGAL::Three::Viewer_interface*) { drawWithNames(); }
|
||||||
virtual bool keyPressEvent(QKeyEvent* e) = 0;
|
virtual bool keyPressEvent(QKeyEvent* e) = 0;
|
||||||
virtual float get_bbox_length() const = 0;
|
virtual float get_bbox_length() const = 0;
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ public:
|
||||||
//! Used by the items to avoid SEGFAULT.
|
//! Used by the items to avoid SEGFAULT.
|
||||||
bool extension_is_found;
|
bool extension_is_found;
|
||||||
//!The matrix used for the picking.
|
//!The matrix used for the picking.
|
||||||
GLfloat pickMatrix_[16];
|
mutable GLfloat pickMatrix_[16];
|
||||||
//!Sets the binding for SHIFT+LEFT CLICK to SELECT (initially used in Scene_polyhedron_selection_item.h)
|
//!Sets the binding for SHIFT+LEFT CLICK to SELECT (initially used in Scene_polyhedron_selection_item.h)
|
||||||
void setBindingSelect()
|
void setBindingSelect()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue