2008-02-16 13:00:35 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* MeshLab o o *
|
|
|
|
* A versatile mesh processing toolbox o o *
|
|
|
|
* _ O _ *
|
|
|
|
* Copyright(C) 2008 \/)\/ *
|
|
|
|
* Visual Computing Lab /\/| *
|
|
|
|
* ISTI - Italian National Research Council | *
|
|
|
|
* \ *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
|
|
|
|
* for more details. *
|
|
|
|
* *
|
|
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
|
|
History
|
|
|
|
$Log: not supported by cvs2svn $
|
|
|
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <GL/glew.h>
|
|
|
|
#include <wrap/gl/space.h>
|
|
|
|
#include <wrap/gl/picking.h>
|
2013-12-16 13:15:20 +01:00
|
|
|
#include <wrap/qt/device_to_logical.h>
|
2008-02-16 13:00:35 +01:00
|
|
|
|
|
|
|
#include "rubberband.h"
|
|
|
|
|
|
|
|
using namespace vcg;
|
|
|
|
|
|
|
|
Rubberband::Rubberband(Color4b c)
|
2013-12-16 13:15:20 +01:00
|
|
|
:color(c)
|
2008-02-16 13:00:35 +01:00
|
|
|
{
|
2015-11-10 17:51:43 +01:00
|
|
|
this->Reset();
|
2008-02-16 13:00:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Rubberband::Render(QGLWidget* gla)
|
|
|
|
{
|
|
|
|
if(have_to_pick){
|
|
|
|
assert(currentphase!=RUBBER_DRAGGED);
|
|
|
|
Point3f pick_point;
|
2013-12-16 13:15:20 +01:00
|
|
|
bool picked = Pick(QTLogicalToDevice(gla, qt_cursor.x()), QTLogicalToDevice(gla, gla->height() - qt_cursor.y()), pick_point);
|
2008-02-16 13:00:35 +01:00
|
|
|
if(picked){ // we have not picked the background
|
|
|
|
have_to_pick=false;
|
|
|
|
switch(currentphase){
|
|
|
|
case RUBBER_BEGIN:
|
|
|
|
start = pick_point;
|
|
|
|
gla->setMouseTracking(true);
|
|
|
|
currentphase = RUBBER_DRAGGING;
|
|
|
|
break;
|
|
|
|
case RUBBER_DRAGGING:
|
|
|
|
if(pick_point==start){
|
|
|
|
have_to_pick=true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
end = pick_point;
|
|
|
|
gla->setMouseTracking(false);
|
|
|
|
currentphase = RUBBER_DRAGGED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(currentphase==RUBBER_BEGIN) return;
|
2013-12-16 13:15:20 +01:00
|
|
|
|
2008-02-16 13:00:35 +01:00
|
|
|
// Drawing of the current line
|
|
|
|
glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_COLOR_BUFFER_BIT);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDepthMask(false);
|
|
|
|
glLineWidth(2.5);
|
|
|
|
glPointSize(5.0);
|
2015-11-10 17:51:43 +01:00
|
|
|
|
|
|
|
if(currentphase==RUBBER_DRAGGING )
|
|
|
|
{
|
2013-12-16 13:15:20 +01:00
|
|
|
Point2f qt_start_point = DevicePixelConvert(start);
|
2008-02-16 13:00:35 +01:00
|
|
|
glColor(color);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
2015-11-10 17:51:43 +01:00
|
|
|
gluOrtho2D(0, QTLogicalToDevice(gla,gla->width()), QTLogicalToDevice(gla,gla->height()), 0);
|
2008-02-16 13:00:35 +01:00
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glBegin(GL_LINES);
|
2013-12-16 13:15:20 +01:00
|
|
|
glVertex(qt_start_point);
|
2015-11-10 17:51:43 +01:00
|
|
|
glVertex2f(QTLogicalToDevice(gla, qt_cursor.x()), QTLogicalToDevice(gla, qt_cursor.y()));
|
2008-02-16 13:00:35 +01:00
|
|
|
glEnd();
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
glPopMatrix();
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPopMatrix();
|
2015-11-10 17:51:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-16 13:00:35 +01:00
|
|
|
assert(currentphase == RUBBER_DRAGGED);
|
|
|
|
glEnable(GL_BLEND);
|
2015-11-10 17:51:43 +01:00
|
|
|
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR);
|
2008-02-16 13:00:35 +01:00
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
glEnable(GL_POINT_SMOOTH);
|
|
|
|
glColor(color);
|
2015-11-10 17:51:43 +01:00
|
|
|
glLineWidth(2.0);
|
|
|
|
glPointSize(4.0);
|
2008-02-16 13:00:35 +01:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex(start);
|
|
|
|
glVertex(end);
|
|
|
|
glEnd();
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
glVertex(start);
|
|
|
|
glVertex(end);
|
2013-12-16 13:15:20 +01:00
|
|
|
glEnd();
|
2015-11-10 17:51:43 +01:00
|
|
|
glDepthFunc(GL_GREATER);
|
|
|
|
glLineWidth(1.0f);
|
|
|
|
glPointSize(2.0f);
|
2008-02-16 13:00:35 +01:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex(start);
|
|
|
|
glVertex(end);
|
|
|
|
glEnd();
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
glVertex(start);
|
|
|
|
glVertex(end);
|
|
|
|
glEnd();
|
2015-11-10 17:51:43 +01:00
|
|
|
glDepthFunc(GL_LESS);
|
2008-02-16 13:00:35 +01:00
|
|
|
}
|
2015-11-10 17:51:43 +01:00
|
|
|
|
|
|
|
|
2008-02-16 13:00:35 +01:00
|
|
|
glPopAttrib();
|
|
|
|
assert(!glGetError());
|
|
|
|
}
|
|
|
|
|
2015-11-10 17:51:43 +01:00
|
|
|
void Rubberband::RenderLine(QGLWidget* gla, Point3f AA, Point3f BB)
|
|
|
|
{
|
|
|
|
// Drawing of the line from AA to BB
|
|
|
|
glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_LINE_BIT | GL_POINT_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_COLOR_BUFFER_BIT);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glDisable(GL_TEXTURE_2D);
|
|
|
|
glDepthMask(false);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
glEnable(GL_POINT_SMOOTH);
|
|
|
|
glColor(color);
|
2016-10-20 12:24:09 +02:00
|
|
|
|
|
|
|
// IN FRONT OF SURFACE
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
glLineWidth(2.5);
|
|
|
|
glPointSize(6.0);
|
2015-11-10 17:51:43 +01:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex(AA);
|
|
|
|
glVertex(BB);
|
|
|
|
glEnd();
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
glVertex(AA);
|
|
|
|
glVertex(BB);
|
|
|
|
glEnd();
|
2016-10-20 12:24:09 +02:00
|
|
|
|
|
|
|
// BEHIND SURFACE
|
2015-11-10 17:51:43 +01:00
|
|
|
glDepthFunc(GL_GREATER);
|
2016-10-20 12:24:09 +02:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR);
|
|
|
|
glLineWidth(1.5f);
|
|
|
|
glPointSize(4.0f);
|
2015-11-10 17:51:43 +01:00
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex(AA);
|
|
|
|
glVertex(BB);
|
|
|
|
glEnd();
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
glVertex(AA);
|
|
|
|
glVertex(BB);
|
|
|
|
glEnd();
|
|
|
|
|
2016-10-20 12:24:09 +02:00
|
|
|
glDepthFunc(GL_LESS);
|
2015-11-10 17:51:43 +01:00
|
|
|
glPopAttrib();
|
|
|
|
assert(!glGetError());
|
|
|
|
}
|
|
|
|
|
2008-02-16 13:00:35 +01:00
|
|
|
void Rubberband::Drag(QPoint p)
|
|
|
|
{
|
2010-09-30 10:12:54 +02:00
|
|
|
if(currentphase==RUBBER_DRAGGING)
|
2008-02-16 13:00:35 +01:00
|
|
|
qt_cursor=p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rubberband::Pin(QPoint p)
|
|
|
|
{
|
|
|
|
if(IsReady())
|
|
|
|
return;
|
|
|
|
qt_cursor=p;
|
|
|
|
have_to_pick=true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rubberband::Reset()
|
|
|
|
{
|
|
|
|
currentphase = RUBBER_BEGIN;
|
|
|
|
qt_cursor = QPoint();
|
|
|
|
start = Point3f(0,0,0);
|
|
|
|
end = Point3f(0,0,0);
|
|
|
|
have_to_pick = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Rubberband::IsReady()
|
|
|
|
{
|
|
|
|
return currentphase==RUBBER_DRAGGED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rubberband::GetPoints(Point3f &s,Point3f &e)
|
|
|
|
{
|
|
|
|
assert(IsReady());
|
|
|
|
s=start;
|
|
|
|
e=end;
|
|
|
|
}
|
|
|
|
|
2013-12-16 13:15:20 +01:00
|
|
|
Point2f Rubberband::DevicePixelConvert(const Point3f p)
|
2008-02-16 13:00:35 +01:00
|
|
|
{
|
|
|
|
GLint vm[4];
|
|
|
|
GLdouble mm[16];
|
|
|
|
GLdouble pm[16];
|
|
|
|
glGetIntegerv(GL_VIEWPORT, vm);
|
|
|
|
glGetDoublev(GL_MODELVIEW_MATRIX, mm);
|
|
|
|
glGetDoublev(GL_PROJECTION_MATRIX, pm);
|
|
|
|
GLdouble wx,wy,wz;
|
|
|
|
gluProject(p[0], p[1], p[2], mm, pm, vm, &wx, &wy, &wz);
|
2013-12-16 13:15:20 +01:00
|
|
|
return Point2f(wx,vm[3]-wy);
|
2008-02-16 13:00:35 +01:00
|
|
|
}
|