56 #include "QtBaseViewer.hh" 57 #include "QtGLGraphicsScene.hh" 58 #include "QtGLGraphicsView.hh" 63 #include <QOpenGLFramebufferObject> 72 const QPoint& _mousePos,
82 int rv =
pickFromCache (_pickTarget, _mousePos, _nodeIdx, _targetIdx, _hitPointPtr);
86 rv =
pickColor (_pickTarget, _mousePos, _nodeIdx, _targetIdx, _hitPointPtr);
102 const QPoint& _mousePos,
110 b = scene()->height () - scenePos().y() - h,
112 y = scene()->height () - _mousePos.y(),
115 GLubyte pixels[9][4];
120 unsigned char order[9] = { 4, 7, 1, 3, 5, 0, 2, 6, 8 };
124 if(OpenFlipper::Options::coreProfile())
151 x = _mousePos.x() - scenePos().x();
152 y =
glHeight() - (_mousePos.y() - scenePos().y());
169 glViewport (l, b, w, h);
173 glMatrixMode(GL_PROJECTION);
177 glMatrixMode(GL_MODELVIEW);
184 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
194 glMatrixMode(GL_PROJECTION);
196 glMatrixMode(GL_MODELVIEW);
208 std::cerr <<
"error - picking color stack invalid" << std::endl;
212 glPixelStorei(GL_PACK_ALIGNMENT, 1);
213 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
233 if (pH != 3 || pW != 3)
236 for (
int i = 0; i < 9; i++)
247 glReadPixels (x, y, pW, pH, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
248 glReadPixels (x, y, pW, pH, GL_DEPTH_COMPONENT, GL_FLOAT, depths);
259 for (
int i = 0; i < 9; i++)
261 if (hit < 0 && (pixels[order[i]][2] != 0 || pixels[order[i]][1] != 0 || pixels[order[i]][0] != 0 || pixels[order[i]][3] != 0))
273 rgba[0] = pixels[hit][0];
274 rgba[1] = pixels[hit][1];
275 rgba[2] = pixels[hit][2];
276 rgba[3] = pixels[hit][3];
283 std::cerr <<
"error - picking color not found in stack" << std::endl;
304 ACG::Vec3d(_mousePos.x(), scene()->height () - _mousePos.y(),depths[hit]));
313 const QPoint& _mousePos,
323 GLint x = _mousePos.x() - scenePos().x(),
324 y =
glHeight() - (_mousePos.y() - scenePos().y()),
327 GLubyte pixels[9][4];
332 unsigned char order[9] = { 4, 7, 1, 3, 5, 0, 2, 6, 8 };
341 glPixelStorei(GL_PACK_ALIGNMENT, 1);
342 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
362 if (pH != 3 || pW != 3)
365 for (
int i = 0; i < 9; i++)
376 glReadPixels (x, y, pW, pH, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
377 glReadPixels (x, y, pW, pH, GL_DEPTH_COMPONENT, GL_FLOAT, depths);
383 for (
int i = 0; i < 9; i++)
385 if (hit < 0 && (pixels[order[i]][2] != 0 || pixels[order[i]][1] != 0 || pixels[order[i]][0] != 0 || pixels[order[i]][3] != 0))
397 rgba[0] = pixels[hit][0];
398 rgba[1] = pixels[hit][1];
399 rgba[2] = pixels[hit][2];
400 rgba[3] = pixels[hit][3];
416 ACG::Vec3d(_mousePos.x(), scene()->height () - _mousePos.y(),depths[hit]));
425 const QRegion& _region,
426 QList<QPair<size_t, size_t> >& _list,
427 QVector<float>* _depths,
428 QVector<ACG::Vec3d>* _points)
430 QRect rect = _region.boundingRect();
434 b = scene()->height () - scenePos().y() - h,
436 y = scene()->height () - rect.bottom();
470 x = rect.x() - scenePos().x();
471 y =
glHeight() - (rect.bottom() - scenePos().y());
488 glViewport (l, b, w, h);
489 glMatrixMode(GL_PROJECTION);
493 glMatrixMode(GL_MODELVIEW);
498 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
506 glMatrixMode( GL_PROJECTION );
508 glMatrixMode( GL_MODELVIEW );
522 buffer =
new GLubyte[4 * rect.width() * rect.height()];
526 glPixelStorei(GL_PACK_ALIGNMENT, 1);
527 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
529 glReadPixels (x, y, rect.width(),
530 rect.height(), GL_RGBA, GL_UNSIGNED_BYTE, buffer);
532 if (_depths || _points ) {
533 depths =
new GLfloat[ rect.width() * rect.height() ];
534 glReadPixels (x, y, rect.width(), rect.height(), GL_DEPTH_COMPONENT, GL_FLOAT, depths);
554 for (
int y = 0; y < rect.height (); y++)
555 for (
int x = 0; x < rect.width (); x++)
559 if (_region.contains (QPoint (rect.x() + x, rect.y() + y)))
563 const int bPos = (((rect.height () - (y + 1)) * rect.width ()) + x) * 4;
566 if (buffer[bPos + 2] != 0 || buffer[bPos + 1] != 0 || buffer[bPos] != 0 || buffer[bPos + 3] != 0)
569 rgba[0] = buffer[bPos];
570 rgba[1] = buffer[bPos + 1];
571 rgba[2] = buffer[bPos + 2];
572 rgba[3] = buffer[bPos + 3];
578 QPair<size_t, size_t> curr(rv[1], rv[0]);
581 if( !_list.contains(curr))
585 if ( _depths || _points ) {
587 const double curr_depth(depths[(rect.height()-(y+1))*rect.width() + x]);
591 (*_depths) << curr_depth;
604 if ( _depths || _points )
627 GLint x(_mousePos.x()), y(
glHeight() - _mousePos.y());
632 glPixelStorei(GL_PACK_ALIGNMENT, 1);
633 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
634 glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
std::vector< size_t > pick_color_to_stack(Vec4uc _rgba) const
bool fast_pick(const QPoint &_mousePos, ACG::Vec3d &_hitPoint)
bool pick_region(ACG::SceneGraph::PickTarget _pickTarget, const QRegion &_region, QList< QPair< size_t, size_t > > &_list, QVector< float > *_depths=0, QVector< ACG::Vec3d > *_points=0)
Perform picking action n a whole region.
const GLMatrixd & projection() const
get projection matrix
QOpenGLFramebufferObject QFramebufferObject
Framebuffer object that holds the pick cache.
ACG::SceneGraph::PickTarget pickCacheTarget_
Pick target stored in pick cache.
const Vec4f & clear_color() const
get background color
bool updatePickCache_
Should the pick cache be updated.
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
void pick_init(bool _color)
initialize name/color picking stack (like glInitNames())
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
Viewer::ViewerProperties & properties_
All properties for this viewer.
int pickColor(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
pick using colors
bool pickCacheSupported_
Is pick caching supported.
unsigned int glHeight() const
get height of QGLWidget
void set_clear_color(const Vec4f &_col)
set background color
const Scalar * get_raw_data() const
int pickFromCache(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
pick from cache
const GLMatrixd & modelview() const
get modelview matrix
void drawMode(ACG::SceneGraph::DrawModes::DrawMode _mode)
set draw mode (No test if this mode is available!)
QFramebufferObject * pickCache_
Framebuffer object that holds the pick cache.
PickTarget
What target to use for picking.
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
void traverse_multipass(BaseNode *_node, Action &_action, const unsigned int &_pass)
ACG::GLState & glState()
Get the glState of the Viewer.
unsigned int glWidth() const
get width of QGLWidget
bool pick(ACG::SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, size_t &_nodeIdx, size_t &_targetIdx, ACG::Vec3d *_hitPointPtr=0)
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking