54 #include <ACG/GL/acg_glew.hh> 55 #include "QtBaseViewer.hh" 56 #include "QtGLGraphicsScene.hh" 57 #include "QtGLGraphicsView.hh" 59 #include "../GL/GLState.hh" 60 #include "../Scenegraph/SceneGraph.hh" 69 static const unsigned int SELECTION_BUFFER_SIZE = 10000;
70 static const unsigned int NAME_STACK_SIZE = 2;
84 const QPoint& _mousePos,
85 unsigned int& _nodeIdx,
86 unsigned int& _targetIdx,
94 y = h - _mousePos.y();
95 GLint viewport[4] = {0,0,w,h};
96 GLuint nameBuffer[ NAME_STACK_SIZE ];
99 std::vector<GLuint> selectionBuffer(SELECTION_BUFFER_SIZE);
113 glSelectBuffer( SELECTION_BUFFER_SIZE, &selectionBuffer[0] );
114 glRenderMode(GL_SELECT);
115 glMatrixMode(GL_PROJECTION);
120 const float deltax = 3.0f, deltay = 3.0f;
121 glTranslatef(
float(viewport[2] - 2 * (x - viewport[0])) / deltax,
122 float(viewport[3] - 2 * (y - viewport[1])) / deltay, 0.0f);
123 glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0);
126 glMatrixMode(GL_MODELVIEW);
129 glClear(GL_DEPTH_BUFFER_BIT);
135 int hits = glRenderMode(GL_RENDER);
138 glMatrixMode( GL_PROJECTION );
140 glMatrixMode( GL_MODELVIEW );
148 GLuint *ptr = &selectionBuffer[0],
153 for (
int i=0; i<hits; ++i)
155 const GLuint num_names = *ptr++;
156 if ( num_names != NAME_STACK_SIZE )
158 std::cerr <<
"QtBaseViewer::pick() : namestack error\n\n";
162 if ( (z = *ptr++) < min_z )
166 for (
unsigned int j=0; j<num_names; ++j)
167 nameBuffer[j] = *ptr++;
169 else ptr += 1+num_names;
172 _nodeIdx = nameBuffer[0];
173 _targetIdx = nameBuffer[1];
178 GLdouble min_zz = ((GLdouble)min_z) / ((GLdouble)zscale);
179 GLdouble max_zz = ((GLdouble)max_z) / ((GLdouble)zscale);
180 GLdouble zz = 0.5F * (min_zz + max_zz);
187 std::cerr <<
"QtBaseViewer::pick() : selection buffer overflow\n\n";
203 GLint x(_mousePos.x()), y(
glHeight() - _mousePos.y());
208 glPixelStorei(GL_PACK_ALIGNMENT, 1);
209 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
210 glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
256 std::vector<PickMode>::iterator it =
pick_modes_.begin();
276 glView_->setCursor(_cursor);
Namespace providing different geometric functions concerning angles.
unsigned int glWidth() const
get width of QGLWidget
void trackMouse(bool _track)
Enable/disable mouse tracking (move events with no button press)
std::vector< PickMode > pick_modes_
const GLMatrixd & projection() const
get projection matrix
void addPickMode(const std::string &_name, bool _mouse_tracking=false, int _pos=-1, bool _visible=true, QCursor _cursor=Qt::ArrowCursor)
add pick mode
void renderPicking(bool _renderPicking, ACG::SceneGraph::PickTarget _mode)
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
virtual void pickingMode()
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
void setPickModeCursor(const std::string &_name, QCursor _cursor)
set a new cursor for the pick mode
VectorT< double, 3 > Vec3d
void setPickModeMouseTracking(const std::string &_name, bool _mouseTracking)
set mouseTracking for the pick mode
const Scalar * get_raw_data() const
const std::string & pickMode() const
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
const GLMatrixd & modelview() const
get modelview matrix
std::string pick_mode_name_
PickTarget
What target to use for picking.
void updatePickMenu()
update pick mode menu
void traverse(BaseNode *_node, Action &_action)
bool fast_pick(const QPoint &_mousePos, Vec3d &_hitPoint)
ACG::SceneGraph::PickTarget pickRendererMode_
unsigned int glHeight() const
get height of QGLWidget
ActionMode actionMode() const
get action mode
void signalPickModeChanged(const std::string &)
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
bool pick(SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, Vec3d *_hitPointPtr=0)