61 #include "QtBaseViewer.hh"
62 #include "QtGLGraphicsScene.hh"
63 #include "QtGLGraphicsView.hh"
72 static const unsigned int SELECTION_BUFFER_SIZE = 10000;
73 static const unsigned int NAME_STACK_SIZE = 2;
87 const QPoint& _mousePos,
88 unsigned int& _nodeIdx,
89 unsigned int& _targetIdx,
97 y = h - _mousePos.y();
98 GLint viewport[4] = {0,0,w,h};
99 GLuint nameBuffer[ NAME_STACK_SIZE ];
102 std::vector<GLuint> selectionBuffer(SELECTION_BUFFER_SIZE);
116 glSelectBuffer( SELECTION_BUFFER_SIZE, &selectionBuffer[0] );
117 glRenderMode(GL_SELECT);
118 glMatrixMode(GL_PROJECTION);
123 const float deltax = 3.0f, deltay = 3.0f;
124 glTranslatef(
float(viewport[2] - 2 * (x - viewport[0])) / deltax,
125 float(viewport[3] - 2 * (y - viewport[1])) / deltay, 0.0f);
126 glScalef(viewport[2] / deltax, viewport[3] / deltay, 1.0);
129 glMatrixMode(GL_MODELVIEW);
132 glClear(GL_DEPTH_BUFFER_BIT);
138 int hits = glRenderMode(GL_RENDER);
141 glMatrixMode( GL_PROJECTION );
143 glMatrixMode( GL_MODELVIEW );
151 GLuint *ptr = &selectionBuffer[0],
156 for (
int i=0; i<hits; ++i)
158 const GLuint num_names = *ptr++;
159 if ( num_names != NAME_STACK_SIZE )
161 std::cerr <<
"QtBaseViewer::pick() : namestack error\n\n";
165 if ( (z = *ptr++) < min_z )
169 for (
unsigned int j=0; j<num_names; ++j)
170 nameBuffer[j] = *ptr++;
172 else ptr += 1+num_names;
175 _nodeIdx = nameBuffer[0];
176 _targetIdx = nameBuffer[1];
181 GLdouble min_zz = ((GLdouble)min_z) / ((GLdouble)zscale);
182 GLdouble max_zz = ((GLdouble)max_z) / ((GLdouble)zscale);
183 GLdouble zz = 0.5F * (min_zz + max_zz);
190 std::cerr <<
"QtBaseViewer::pick() : selection buffer overflow\n\n";
206 GLint x(_mousePos.x()), y(
glHeight() - _mousePos.y());
211 glPixelStorei(GL_PACK_ALIGNMENT, 1);
212 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
213 glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
259 std::vector<PickMode>::iterator it =
pick_modes_.begin();
279 glView_->setCursor(_cursor);
const std::string & pickMode() const
std::vector< PickMode > pick_modes_
static void enable(GLenum _cap)
replaces glEnable, but supports locking
Namespace providing different geometric functions concerning angles.
unsigned int glWidth() const
get width of QGLWidget
bool pick(SceneGraph::PickTarget _pickTarget, const QPoint &_mousePos, unsigned int &_nodeIdx, unsigned int &_targetIdx, Vec3d *_hitPointPtr=0)
PickTarget
What target to use for picking.
std::string pick_mode_name_
Vec3d unproject(const Vec3d &_winPoint) const
unproject point in window coordinates _winPoint to world coordinates
void setPickModeMouseTracking(const std::string &_name, bool _mouseTracking)
set mouseTracking for the pick mode
virtual void pickingMode()
VectorT< double, 3 > Vec3d
const GLMatrixd & modelview() const
get modelview matrix
const GLMatrixd & projection() const
get projection matrix
void signalPickModeChanged(const std::string &)
void updatePickMenu()
update pick mode menu
bool fast_pick(const QPoint &_mousePos, Vec3d &_hitPoint)
void renderPicking(bool _renderPicking, ACG::SceneGraph::PickTarget _mode)
virtual void makeCurrent()
Makes this widget the current widget for OpenGL operations.
void pick_init(bool _color)
initialize name/color picking stack (like glInitNames())
ACG::SceneGraph::PickTarget pickRendererMode_
void setPickModeCursor(const std::string &_name, QCursor _cursor)
set a new cursor for the pick mode
static void disable(GLenum _cap)
replaces glDisable, but supports locking
void addPickMode(const std::string &_name, bool _mouse_tracking=false, int _pos=-1, bool _visible=true, QCursor _cursor=Qt::ArrowCursor)
add pick mode
void traverse(BaseNode *_node, Action &_action)
void trackMouse(bool _track)
Enable/disable mouse tracking (move events with no button press)
unsigned int glHeight() const
get height of QGLWidget
const Scalar * get_raw_data() const
ActionMode actionMode() const
get action mode