62 #include "QtBaseViewer.hh"
63 #include "QtGLGraphicsScene.hh"
64 #include "QtGLGraphicsView.hh"
66 #if QT_VERSION < 0x050000
67 #include <QGLFramebufferObject>
69 #include <QOpenGLFramebufferObject>
78 const QPoint& _mousePos,
79 unsigned int& _nodeIdx,
80 unsigned int& _targetIdx,
88 int rv =
pickFromCache (_pickTarget, _mousePos, _nodeIdx, _targetIdx, _hitPointPtr);
92 rv =
pickColor (_pickTarget, _mousePos, _nodeIdx, _targetIdx, _hitPointPtr);
108 const QPoint& _mousePos,
109 unsigned int& _nodeIdx,
110 unsigned int& _targetIdx,
116 b = scene()->height () - scenePos().y() - h,
118 y = scene()->height () - _mousePos.y(),
121 GLubyte pixels[9][4];
126 unsigned char order[9] = { 4, 7, 1, 3, 5, 0, 2, 6, 8 };
152 x = _mousePos.x() - scenePos().x();
153 y =
glHeight() - (_mousePos.y() - scenePos().y());
172 glViewport (l, b, w, h);
173 glMatrixMode(GL_PROJECTION);
177 glMatrixMode(GL_MODELVIEW);
182 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
190 glMatrixMode( GL_PROJECTION );
192 glMatrixMode( GL_MODELVIEW );
203 std::cerr <<
"error - picking color stack invalid" << std::endl;
207 glPixelStorei(GL_PACK_ALIGNMENT, 1);
208 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
228 if (pH != 3 || pW != 3)
231 for (
int i = 0; i < 9; i++)
242 glReadPixels (x, y, pW, pH, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
243 glReadPixels (x, y, pW, pH, GL_DEPTH_COMPONENT, GL_FLOAT, depths);
254 for (
int i = 0; i < 9; i++)
256 if (hit < 0 && (pixels[order[i]][2] != 0 || pixels[order[i]][1] != 0 || pixels[order[i]][0] != 0 || pixels[order[i]][3] != 0))
268 rgba[0] = pixels[hit][0];
269 rgba[1] = pixels[hit][1];
270 rgba[2] = pixels[hit][2];
271 rgba[3] = pixels[hit][3];
278 std::cerr <<
"error - picking color not found in stack" << std::endl;
299 ACG::Vec3d(_mousePos.x(), scene()->height () - _mousePos.y(),depths[hit]));
308 const QPoint& _mousePos,
309 unsigned int& _nodeIdx,
310 unsigned int& _targetIdx,
318 GLint x = _mousePos.x() - scenePos().x(),
319 y =
glHeight() - (_mousePos.y() - scenePos().y()),
322 GLubyte pixels[9][4];
327 unsigned char order[9] = { 4, 7, 1, 3, 5, 0, 2, 6, 8 };
336 glPixelStorei(GL_PACK_ALIGNMENT, 1);
337 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
357 if (pH != 3 || pW != 3)
360 for (
int i = 0; i < 9; i++)
371 glReadPixels (x, y, pW, pH, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
372 glReadPixels (x, y, pW, pH, GL_DEPTH_COMPONENT, GL_FLOAT, depths);
378 for (
int i = 0; i < 9; i++)
380 if (hit < 0 && (pixels[order[i]][2] != 0 || pixels[order[i]][1] != 0 || pixels[order[i]][0] != 0 || pixels[order[i]][3] != 0))
392 rgba[0] = pixels[hit][0];
393 rgba[1] = pixels[hit][1];
394 rgba[2] = pixels[hit][2];
395 rgba[3] = pixels[hit][3];
409 ACG::Vec3d(_mousePos.x(), scene()->height () - _mousePos.y(),depths[hit]));
418 const QRegion& _region,
419 QList<QPair<unsigned int, unsigned int> >& _list,
420 QVector<float>* _depths,
421 QVector<ACG::Vec3d>* _points)
423 QRect rect = _region.boundingRect();
427 b = scene()->height () - scenePos().y() - h,
429 y = scene()->height () - rect.bottom();
458 x = rect.x() - scenePos().x();
459 y =
glHeight() - (rect.bottom() - scenePos().y());
478 glViewport (l, b, w, h);
479 glMatrixMode(GL_PROJECTION);
483 glMatrixMode(GL_MODELVIEW);
488 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
496 glMatrixMode( GL_PROJECTION );
498 glMatrixMode( GL_MODELVIEW );
512 buffer =
new GLubyte[4 * rect.width() * rect.height()];
516 glPixelStorei(GL_PACK_ALIGNMENT, 1);
517 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
519 glReadPixels (x, y, rect.width(),
520 rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, buffer);
522 if (_depths || _points ) {
523 depths =
new GLfloat[ rect.width() * rect.height() ];
524 glReadPixels (x, y, rect.width(), rect.height(), GL_DEPTH_COMPONENT, GL_FLOAT, depths);
544 for (
int y = 0; y < rect.height (); y++)
545 for (
int x = 0; x < rect.width (); x++)
549 if (_region.contains (QPoint (rect.x() + x, rect.y() + y)))
553 const int bPos = (((rect.height () - (y + 1)) * rect.width ()) + x) * 4;
556 if (buffer[bPos + 2] != 0 || buffer[bPos + 1] != 0 || buffer[bPos] != 0 || buffer[bPos + 3] != 0)
559 rgba[0] = buffer[bPos];
560 rgba[1] = buffer[bPos + 1];
561 rgba[2] = buffer[bPos + 2];
562 rgba[3] = buffer[bPos + 3];
568 QPair<unsigned int, unsigned int> curr(rv[1], rv[0]);
571 if( !_list.contains(curr))
575 if ( _depths || _points ) {
577 const double curr_depth(depths[(rect.height()-(y+1))*rect.width() + x]);
581 (*_depths) << curr_depth;
594 if ( _depths || _points )
617 GLint x(_mousePos.x()), y(
glHeight() - _mousePos.y());
622 glPixelStorei(GL_PACK_ALIGNMENT, 1);
623 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
624 glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
static void enable(GLenum _cap)
replaces glEnable, but supports locking
bool pick_region(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< unsigned int, unsigned int > > &_list, QVector< float > *_depths=0, QVector< ACG::Vec3d > *_points=0)
Perform picking action n a whole region.
PickTarget
What target to use for picking.
const Vec4f & clear_color() const
get background color
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
const GLMatrixd & modelview() const
get modelview matrix
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
const GLMatrixd & projection() const
get projection matrix
unsigned int glWidth() const
get width of QGLWidget
ACG::SceneGraph::PickTarget pickCacheTarget_
Pick target stored in pick cache.
bool pick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
QGLFramebufferObject QFramebufferObject
Framebuffer object that holds the pick cache.
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
bool fast_pick(const QPoint &_mousePos, ACG::Vec3d &_hitPoint)
void pick_init(bool _color)
initialize name/color picking stack (like glInitNames())
bool pickCacheSupported_
Is pick caching supported.
QFramebufferObject * pickCache_
Framebuffer object that holds the pick cache.
static void disable(GLenum _cap)
replaces glDisable, but supports locking
std::vector< unsigned int > pick_color_to_stack(Vec4uc _rgba) const
bool updatePickCache_
Should the pick cache be updated.
unsigned int glHeight() const
get height of QGLWidget
Viewer::ViewerProperties & properties_
All properties for this viewer.
ACG::GLState & glState()
Get the glState of the Viewer.
int pickColor(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
pick using colors
const Scalar * get_raw_data() const
void set_clear_color(const Vec4f &_col)
set background color
int pickFromCache(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
pick from cache