63 #include "QtColorTranslator.hh" 78 #define MASK(x,y) (mask_[(x)+(y)*mask_width_]) 85 QtLasso(GLState& _glstate) :
110 slotMouseEvent(QMouseEvent* _event)
112 bool emit_signal =
false;
116 unsigned int width = glstate_.viewport_width();
117 unsigned int height = glstate_.viewport_height();
121 glMatrixMode(GL_PROJECTION);
125 orthoProj.ortho(0.0f,
float(width-1), 0.0f,
float(height-1), -1.0f, 1.0f);
126 glLoadMatrixf(orthoProj.data());
129 glMatrixMode(GL_MODELVIEW);
137 glColor3ub(0, 255, 10);
144 switch(_event->type())
146 case QEvent::MouseButtonPress:
148 Vec2i p(_event->pos().x(), height-_event->pos().y()-1);
154 first_point_ = last_point_ = p;
162 last_point_ = rubberband_point_ = p;
167 case QEvent::MouseMove:
171 Vec2i p(_event->pos().x(), height-_event->pos().y());
174 if (_event->modifiers() & Qt::LeftButton)
180 last_point_ = rubberband_point_ = p;
195 rubberband_point_ = p;
202 case QEvent::MouseButtonDblClick:
219 glPointSize(glstate_.point_size());
239 glReadBuffer(GL_BACK);
241 glLineWidth(glstate_.line_width());
242 glColor4fv(glstate_.base_color().data());
245 glMatrixMode(GL_PROJECTION );
248 glMatrixMode(GL_MODELVIEW);
258 if (_event->modifiers() & Qt::ShiftModifier)
259 emit(signalLassoSelection(AddToSelection));
261 else if (_event->modifiers() & Qt::ControlModifier)
262 emit(signalLassoSelection(DelFromSelection));
265 emit(signalLassoSelection(NewSelection));
277 unsigned int x, y, xx, yy, i;
283 const unsigned int w = glstate_.viewport_width();
284 const unsigned int h = glstate_.viewport_height();
285 const unsigned int size = w*h;
290 mask_ =
new unsigned char[size];
296 fbuffer =
new GLubyte[3*size];
301 glReadBuffer( GL_FRONT );
302 glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, fbuffer);
303 glReadBuffer( GL_BACK );
307 borderRgb = qRgb( fbuffer[0], fbuffer[1], fbuffer[2] );
308 fbuffer[0] = fbuffer[1] = fbuffer[2] = 0;
312 for (y = 0; y < h; ++y)
314 const unsigned int offset = y*w;
316 for (x = 0; x < w; ++x)
319 rgb = qRgb(fbuffer[i], fbuffer[i+1], fbuffer[i+2]);
320 mask_[offset+x] = (rgb == borderRgb) ? 3 : 1;
326 std::vector<Vec2i> toDo;
328 toDo.push_back(
Vec2i(0,0));
330 while (!toDo.empty())
332 Vec2i p = toDo.back();
337 unsigned char &s = MASK(x, y);
344 if ((xx<w) && (MASK(xx,yy)==1))
346 toDo.push_back(
Vec2i(xx,yy));
351 if ((xx<w) && (MASK(xx,yy)==1))
353 toDo.push_back(
Vec2i(xx,yy));
358 if ((yy<h) && (MASK(xx,yy)==1))
360 toDo.push_back(
Vec2i(xx,yy));
365 if ((yy<h) && (MASK(xx,yy)==1))
367 toDo.push_back(
Vec2i(xx,yy));
390 mask_width_ = mask_height_ = 0;
400 is_vertex_selected(
const Vec3d& _v)
402 unsigned int x, y, w, h;
406 w = glstate_.viewport_width();
407 h = glstate_.viewport_height();
408 if ((w != mask_width_) || (h != mask_height_))
410 std::cerr <<
"Lasso: viewport size has changed.\n";
416 Vec3d v = glstate_.project(_v);
417 x = (
unsigned int)(v[0] + 0.5);
418 y = (
unsigned int)(v[1] + 0.5);
422 if (v[2] < 0.0 || v[2] > 1.0)
427 return ((v[2]>0.0) && (x<w) && (y<h) && (MASK(x,y)));
static void enable(GLenum _cap)
replaces glEnable, but supports locking
GLMatrixT< float > GLMatrixf
typedef
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
void identity()
setup an identity matrix
VectorT< signed int, 2 > Vec2i
Namespace providing different geometric functions concerning angles.
static void disable(GLenum _cap)
replaces glDisable, but supports locking
static void drawBuffer(GLenum _mode)
replaces glDrawBuffer, supports locking
VectorT< double, 3 > Vec3d