1
/****************************************************************************
3
* Visual and Computer Graphics Library o o *
5
* Copyright(C) 2004 \/)\/ *
6
* Visual Computing Lab /\/| *
7
* ISTI - Italian National Research Council | *
9
* All rights reserved. *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
* This program is distributed in the hope that it will be useful, *
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
22
****************************************************************************/
23
/****************************************************************************
26
$Log: not supported by cvs2svn $
27
Revision 1.4 2007/05/17 09:06:44 ganovelli
30
Revision 1.3 2006/12/10 23:29:57 ganovelli
31
added VFIterator (Pos is disabled in this version)
33
Revision 1.2 2006/12/10 22:17:18 ganovelli
34
cvs problem during frist committ. repeated
44
#include <wrap/io_trimesh/import_PLY.h>
45
#include <wrap/gl/picking.h>
46
#include <wrap/gl/space.h>
47
#include <wrap/gl/pos.h>
48
#include <vcg/complex/trimesh/update/bounding.h>
49
#include <vcg/complex/trimesh/update/normal.h>
50
#include <vcg/complex/trimesh/update/topology.h>
53
GLWidget::GLWidget(QWidget *parent)
58
trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
59
trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
60
track.SetPosition(vcg::Point3f(0.0,0.0,0.0));
72
glDeleteLists(object, 1);
75
QSize GLWidget::minimumSizeHint() const
80
QSize GLWidget::sizeHint() const
82
return QSize(400, 400);
85
void GLWidget::LoadTriMesh(QString &namefile)
87
vcg::tri::io::ImporterPLY<MyStraightMesh>::Open(mesh,namefile.toAscii());
88
vcg::tri::UpdateBounding<MyStraightMesh>::Box(mesh);
89
vcg::tri::UpdateNormals<MyStraightMesh>::PerFace(mesh);
90
vcg::tri::UpdateNormals<MyStraightMesh>::PerVertex(mesh);
91
vcg::tri::UpdateTopology<MyStraightMesh>::FaceFace(mesh);
92
vcg::tri::UpdateTopology<MyStraightMesh>::VertexFace(mesh);
97
void GLWidget::OpenFile(){
101
QString fileName = QFileDialog::getOpenFileName(this,tr("Open File"),".", filters.join("\n"));
103
if (fileName.isEmpty()) return;
105
LoadTriMesh( fileName );
109
void GLWidget::flipV( ){
110
if(pos.f) pos.FlipV();
113
void GLWidget::flipE( ){
114
if(pos.f) pos.FlipE();
117
void GLWidget::flipF( ){
118
if(pos.f) pos.FlipF();
121
void GLWidget::nextE( ){
122
if(pos.f) pos.NextE();
125
void GLWidget::nextB( ){
126
if(pos.f) pos.NextB();
130
void GLWidget::nextVfite( ){
131
if(vfite.F()) ++vfite;
135
void GLWidget::initializeGL()
137
qglClearColor(trolltechPurple.dark());
138
glShadeModel(GL_FLAT);
139
glEnable(GL_DEPTH_TEST);
140
glEnable(GL_CULL_FACE);
143
template <class VertexType>
144
void drawVertex(VertexType & v){
145
glPushAttrib(0xffffffff);
153
void GLWidget::paintGL()
155
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
156
glMatrixMode(GL_MODELVIEW);
158
gluLookAt(0,0,2, 0,0,0, 0,1,0);
164
glScalef(1/glWrap.m->bbox.Diag(),1/glWrap.m->bbox.Diag(),1/glWrap.m->bbox.Diag());
165
glTranslate(-glWrap.m->bbox.Center());
167
// to do some picking
168
MyStraightMesh::FaceType* fp=NULL;
169
MyStraightMesh::VertexType* vp=NULL;
172
std::vector<MyStraightMesh::FaceType*> res;
173
int yes = vcg::Pick<MyStraightMesh::FaceContainer>(pic_x,ScreenH-pic_y+1,mesh.face,res,vcg::glTriangle3<MyStraightMesh::FaceType>,1,1);
176
pos.Set(fp,0,fp->V(0));
182
std::vector<MyStraightMesh::VertexType*> res;
183
int yes = vcg::Pick<MyStraightMesh::VertContainer>(pic_x,ScreenH-pic_y+1,mesh.vert,res,drawVertex<MyStraightMesh::VertexType>,3,3);
186
MyStraightMesh::FaceType* g = vp->VFp();
187
vfite=vcg::face::VFIterator<MyStraightMesh::FaceType>(vp);
193
glWrap.Draw<vcg::GLW::DMFlatWire,vcg::GLW::CMNone,vcg::GLW::TMNone> ();
196
glPushAttrib(0xffffffff);
197
glDisable(GL_LIGHTING);
198
glColor3f(0.0,1.0,0.0);
199
glDepthRange(0.0,0.999);
200
vcg::GlPos<vcg::face::Pos<MyStraightMesh::FaceType> >::Draw(pos);
203
if(vfite.F()!=NULL) {
204
glPushAttrib(0xffffffff);
205
glDisable(GL_LIGHTING);
206
glColor3f(0.0,1.0,0.0);
207
glDepthRange(0.0,0.99);
208
vcg::GlVfIterator<vcg::face::VFIterator<MyStraightMesh::FaceType> >::Draw(vfite);
218
void GLWidget::mouseMoveEvent(QMouseEvent *e)
220
track.MouseMove(e->x(),ScreenH-e->y()+1);
223
//if (event->buttons() & Qt::LeftButton) {
224
// setXRotation(xRot + 8 * dy);
225
//} else if (event->buttons() & Qt::RightButton) {
226
// setXRotation(xRot + 8 * dy);
228
// lastPos = event->pos();
230
void GLWidget::keyPressEvent ( QKeyEvent * e ) {
231
if((keypress == Qt::Key_Control)&&(e->key()==Qt::Key_Control))
236
void GLWidget::mouseDoubleClickEvent(QMouseEvent *e){
237
if(e->button() == Qt::RightButton)
241
void GLWidget:: mousePressEvent(QMouseEvent *e)
243
if( (keypress==Qt::Key_Control) && (e->button() == Qt::LeftButton) )
244
track.MouseDown(e->x(),ScreenH-e->y()+1,vcg::Trackball::KEY_CTRL|vcg::Trackball::BUTTON_LEFT );
246
if(e->button() == Qt::LeftButton )
247
track.MouseDown(e->x(),ScreenH-e->y()+1,vcg::Trackball::BUTTON_LEFT);
249
if(e->button() == Qt::RightButton)
258
void GLWidget::mouseReleaseEvent ( QMouseEvent * e ){
260
if( (keypress==Qt::Key_Control) && (e->button() == Qt::LeftButton) )
261
track.MouseUp(e->x(),ScreenH-e->y()+1,vcg::Trackball::KEY_CTRL );
263
if(e->button() == Qt::LeftButton )
264
track.MouseUp(e->x(),ScreenH-e->y()+1,vcg::Trackball::BUTTON_LEFT);
269
void GLWidget::resizeGL(int w,int h){
270
ScreenW=w; ScreenH=h;
272
glMatrixMode(GL_PROJECTION);
274
gluPerspective(45,ScreenW/(float)ScreenH,0.01,5);
276
void GLWidget::wheelEvent ( QWheelEvent * e ){
277
int v = e->delta()/(float) 120;