57 #include "QtColorTranslator.hh" 72 #define MASK(x,y) (mask_[(x)+(y)*mask_width_]) 79 QtLasso(GLState& _glstate) :
104 slotMouseEvent(QMouseEvent* _event)
106 bool emit_signal =
false;
110 unsigned int width = glstate_.viewport_width();
111 unsigned int height = glstate_.viewport_height();
115 glMatrixMode(GL_PROJECTION);
119 orthoProj.ortho(0.0f,
float(width-1), 0.0f,
float(height-1), -1.0f, 1.0f);
120 glLoadMatrixf(orthoProj.data());
123 glMatrixMode(GL_MODELVIEW);
131 glColor3ub(0, 255, 10);
138 switch(_event->type())
140 case QEvent::MouseButtonPress:
142 Vec2i p(_event->pos().x(), height-_event->pos().y()-1);
148 first_point_ = last_point_ = p;
156 last_point_ = rubberband_point_ = p;
161 case QEvent::MouseMove:
165 Vec2i p(_event->pos().x(), height-_event->pos().y());
168 if (_event->modifiers() & Qt::LeftButton)
174 last_point_ = rubberband_point_ = p;
189 rubberband_point_ = p;
196 case QEvent::MouseButtonDblClick:
213 glPointSize(glstate_.point_size());
233 glReadBuffer(GL_BACK);
235 glLineWidth(glstate_.line_width());
236 glColor4fv(glstate_.base_color().data());
239 glMatrixMode(GL_PROJECTION );
242 glMatrixMode(GL_MODELVIEW);
252 if (_event->modifiers() & Qt::ShiftModifier)
253 emit(signalLassoSelection(AddToSelection));
255 else if (_event->modifiers() & Qt::ControlModifier)
256 emit(signalLassoSelection(DelFromSelection));
259 emit(signalLassoSelection(NewSelection));
271 unsigned int x, y, xx, yy, i;
277 const unsigned int w = glstate_.viewport_width();
278 const unsigned int h = glstate_.viewport_height();
279 const unsigned int size = w*h;
284 mask_ =
new unsigned char[size];
290 fbuffer =
new GLubyte[3*size];
295 glReadBuffer( GL_FRONT );
296 glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, fbuffer);
297 glReadBuffer( GL_BACK );
301 borderRgb = qRgb( fbuffer[0], fbuffer[1], fbuffer[2] );
302 fbuffer[0] = fbuffer[1] = fbuffer[2] = 0;
306 for (y = 0; y < h; ++y)
308 const unsigned int offset = y*w;
310 for (x = 0; x < w; ++x)
313 rgb = qRgb(fbuffer[i], fbuffer[i+1], fbuffer[i+2]);
314 mask_[offset+x] = (rgb == borderRgb) ? 3 : 1;
320 std::vector<Vec2i> toDo;
322 toDo.push_back(
Vec2i(0,0));
324 while (!toDo.empty())
326 Vec2i p = toDo.back();
331 unsigned char &s = MASK(x, y);
338 if ((xx<w) && (MASK(xx,yy)==1))
340 toDo.push_back(
Vec2i(xx,yy));
345 if ((xx<w) && (MASK(xx,yy)==1))
347 toDo.push_back(
Vec2i(xx,yy));
352 if ((yy<h) && (MASK(xx,yy)==1))
354 toDo.push_back(
Vec2i(xx,yy));
359 if ((yy<h) && (MASK(xx,yy)==1))
361 toDo.push_back(
Vec2i(xx,yy));
384 mask_width_ = mask_height_ = 0;
394 is_vertex_selected(
const Vec3d& _v)
396 unsigned int x, y, w, h;
400 w = glstate_.viewport_width();
401 h = glstate_.viewport_height();
402 if ((w != mask_width_) || (h != mask_height_))
404 std::cerr <<
"Lasso: viewport size has changed.\n";
410 Vec3d v = glstate_.project(_v);
411 x = (
unsigned int)(v[0] + 0.5);
412 y = (
unsigned int)(v[1] + 0.5);
416 if (v[2] < 0.0 || v[2] > 1.0)
421 return ((v[2]>0.0) && (x<w) && (y<h) && (MASK(x,y)));
static void enable(GLenum _cap, bool _warnRemoved=true)
replaces glEnable, but supports locking
VectorT< signed int, 2 > Vec2i
Namespace providing different geometric functions concerning angles.
void identity()
setup an identity matrix
static void disable(GLenum _cap, bool _warnRemoved=true)
replaces glDisable, but supports locking
void glVertex(const Vec2i &_v)
Wrapper: glVertex for Vec2i.
GLMatrixT< float > GLMatrixf
typedef
static void drawBuffer(GLenum _mode)
replaces glDrawBuffer, supports locking
VectorT< double, 3 > Vec3d