Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

Window3D Class Reference

#include <window3D.h>

List of all members.

Public Member Functions

 Window3D (QWidget *parent, char *name, int timeInterval=50)
virtual ~Window3D ()
int load (const int &nb_pts, const int &nb_pls, const vector< Point3D * > &L_pts, const vector< int > &L_ref)
void clear ()
void drawAxis ()
int exportOGL (int &nb_pts, int &nb_pls, vector< Point3D * > &L_pts, vector< int > &L_ref)
bool isEmpty ()

Protected Slots

void timeOutSlot ()

Protected Member Functions

void initializeGL ()
void resizeGL (int width, int height)
void paintGL ()
GLuint drawModel ()
void rotate ()
void translate ()
void scale ()
void mousePressEvent (QMouseEvent *event)
void wheelEvent (QWheelEvent *e)
void mouseMoveEvent (QMouseEvent *event)
void keyPressEvent (QKeyEvent *e)
void timeOut ()
void closeEvent (QCloseEvent *)

Private Attributes

QTimer * timer
vector< Point3D * > pointsList
vector< int > referencesList
vector< Vector3D * > normalsList
int nbPoints
int nbPolys
int oldX
int oldY
float angle [3]
float tra [3]
float zoom
int button
GLfloat light1Position [4]
GLfloat light2Position [4]
GLfloat ambientLight [4]
GLfloat diffuseLight [4]
GLfloat specularLight [4]
GLuint model


Detailed Description

La classe Window3D hérite de QGLWidget et permet l'affichage en 3d du résultat de l'extrusion de l'import Vrml ou de l'import PGN.

Author:
Guitteny Fabrice

Idiart Baptiste

Le Goff Erwan


Constructor & Destructor Documentation

Window3D::Window3D QWidget *  parent,
char *  name,
int  timeInterval = 50
 

Constructeur de FenetreOgl

Parameters:
parent pointeur sur le parent (la fenêtre principale)
name nom de la fenetre (Visualisation 3D)
timeInterval temporisateur pour le rafraichissement

00004 : QGLWidget( parent, name ) 00005 { 00006 timer = new QTimer( this ); 00007 if( timeInterval == 0 ) 00008 timer = 0; 00009 else 00010 { 00011 connect( timer, SIGNAL(timeout()), this, SLOT(timeOutSlot()) ); 00012 timer->start( timeInterval ); 00013 } 00014 setCaption(name);//nom de la fenetre Widget 00015 //mouvements 00016 angle[0]=0.0;angle[1]=0.0;angle[2]=0.0; 00017 tra[0]=0; tra[1]=0; tra[2]=0; 00018 zoom=1.0; 00019 //lumiere 00020 //Pour pouvoir observer le modèle sous tous ces angles, deux lumieres sont utilisées 00021 light1Position[0]=0.0;light1Position[1]=400.0;light1Position[2]=0.0;light1Position[3]=1.0; 00022 light2Position[0]=0.0;light2Position[1]=-400.0;light2Position[2]=0.0;light2Position[3]=1.0; 00023 ambientLight[0]=0.5;ambientLight[1]=0.6;ambientLight[2]=0.8;ambientLight[3]=1.0; 00024 diffuseLight[0]=0.8;diffuseLight[1]=0.8;diffuseLight[2]=0.8;diffuseLight[3]=1.0; 00025 specularLight[0]=0.4;specularLight[1]=0.5;specularLight[2]=0.6;specularLight[3]=1.0; 00026 nbPoints = 0;//nombre de points 00027 nbPolys = 0;//nombre de polygones 00028 model = 0;//numéro du model de la displaylist 00029 }

Window3D::~Window3D  )  [virtual]
 

Destructeur de FenetreOgl

00342 { 00343 pointsList.clear(); 00344 referencesList.clear(); 00345 glDeleteLists(model, 1); 00346 }


Member Function Documentation

void Window3D::clear  ) 
 

Effacer la fenêtre Qgl

00070 { 00071 nbPoints = 0; 00072 nbPolys = 0; 00073 pointsList.clear(); 00074 referencesList.clear(); 00075 normalsList.clear(); 00076 glDeleteLists(model, 1); 00077 }

void Window3D::closeEvent QCloseEvent *   )  [protected]
 

Action a effectué lors de la fermeture le corps de cette fonction est vide pour interdire sa fermeture

00351 {}

void Window3D::drawAxis  ) 
 

Dessin des axes du repère 3D

00158 { 00159 glDisable(GL_LIGHTING); 00160 glBegin(GL_LINES); 00161 glColor3f(0.0,1.0,0.0); 00162 glVertex3f(0.0,0.0,0.0); 00163 glVertex3f(5.0,0.0,0.0); 00164 glColor3f(0.0,0.0,1.0); 00165 00166 00167 glVertex3f(0.0,0.0,0.0); 00168 glVertex3f(0.0,5.0,0.0); 00169 glColor3f(1.0,0.0,0.0); 00170 00171 glVertex3f(0.0,0.0,0.0); 00172 glVertex3f(0.0,0.0,5.0); 00173 glEnd(); 00174 glEnable(GL_LIGHTING); 00175 }

GLuint Window3D::drawModel  )  [protected]
 

Modélisation à l'aide d'une display list

00214 { 00215 GLuint list; 00216 list = glGenLists(1); 00217 00218 glNewList(list, GL_COMPILE); 00219 glColor3f(0.0,0.6,0.8); 00220 glBegin(GL_TRIANGLES); 00221 //Les polygones sont uniquement triangulaires donc une facette est référencie 3 points de l'espace 00222 //Ainsi le nombre de références est 3 fois plus important que le nombre de polygones 00223 for(int i=0;i<3*nbPolys;i+=3) 00224 { 00225 glNormal3f ((*normalsList[i/3])[0],(*normalsList[i/3])[1],(*normalsList[i/3])[2]); 00226 00227 glVertex3f( (pointsList[referencesList[i]])->getCoordinate(0), (pointsList[referencesList[i]])->getCoordinate(1), (pointsList[referencesList[i]])->getCoordinate(2)); 00228 00229 glVertex3f( (pointsList[referencesList[i+1]])->getCoordinate(0), (pointsList[referencesList[i+1]])->getCoordinate(1), (pointsList[referencesList[i+1]])->getCoordinate(2)); 00230 00231 glVertex3f( (pointsList[referencesList[i+2]])->getCoordinate(0), (pointsList[referencesList[i+2]])->getCoordinate(1), (pointsList[referencesList[i+2]])->getCoordinate(2)); 00232 00233 } 00234 glEnd(); 00235 glEndList(); 00236 00237 return list; 00238 }

int Window3D::exportOGL int &  nb_pts,
int &  nb_pls,
vector< Point3D * > &  L_pts,
vector< int > &  L_ref
 

export du modele

Parameters:
nb_pts nombre de points
nb_pls nombre de polygônes
L_pts liste de points
L_ref liste contenant les références vers les point on construit des triangles donc un polygone est défini par trois référence (L_ref.size() = 3 *nb_pls)
Returns:
variable de controle d'erreur

00331 { 00332 nbPts = nbPoints; 00333 nbPls = nbPolys; 00334 PtsList = pointsList; 00335 RefList = referencesList; 00336 00337 return 1; 00338 }

void Window3D::initializeGL  )  [protected]
 

Initialisation de la fenêtre Qgl

00081 { 00082 glClearColor (0.0, 0.0, 0.0, 0.0); 00083 glClear (GL_COLOR_BUFFER_BIT); 00084 00085 glViewport (0, 0, WIDTHOGL, HEIGHTOGL); 00086 00087 glMatrixMode (GL_PROJECTION); 00088 glLoadIdentity (); 00089 glOrtho(-1.1, 1.1, -1.1, 1.1, -10, 10); 00090 00091 glMatrixMode (GL_MODELVIEW); 00092 glLoadIdentity (); 00093 setAutoBufferSwap (true); 00094 00095 glEnable(GL_DEPTH_TEST); 00096 00097 glEnable(GL_NORMALIZE); 00098 00099 00100 //Paramètres des 2 lumières 00101 glShadeModel(GL_SMOOTH); 00102 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE); 00103 glEnable(GL_LIGHTING); 00104 glEnable(GL_LIGHT0); 00105 glEnable(GL_LIGHT1); 00106 glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight); 00107 glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight); 00108 glLightfv(GL_LIGHT0,GL_SPECULAR,specularLight); 00109 glLightfv(GL_LIGHT1,GL_AMBIENT,ambientLight); 00110 glLightfv(GL_LIGHT1,GL_DIFFUSE,diffuseLight); 00111 glLightfv(GL_LIGHT1,GL_SPECULAR,specularLight); 00112 00113 00114 }

bool Window3D::isEmpty  )  [inline]
 

Returns:
true si le nombre" de points ou le nombre de polygones est nuls

00155 {return ((nbPoints == 0) || (nbPolys == 0));}

void Window3D::keyPressEvent QKeyEvent *  e  )  [protected]
 

Détection de la pression d'une touche clavier

Parameters:
e touche pressée

00294 { 00295 int key = e->key(); 00296 switch (key) 00297 { 00298 case 4112 : //touche 'home' position de départ 00299 angle[0]=0.0; angle[1]=0.0; angle[2]=0.0; 00300 tra[0]=0.0; tra[1]=0.0; tra[2]=0.0; 00301 zoom=1.0; 00302 break; 00303 case 4118 : //touche 'Page Down' augmentation du zoom 00304 if(zoom < 100 * ZOO_INC) 00305 zoom += ZOO_INC; 00306 break; 00307 case 4119 : //touche 'Page Up' diminution du zoom 00308 if(zoom > 2*ZOO_INC) 00309 zoom -= ZOO_INC; 00310 break; 00311 case 88 : // touche 'x' affichage en mode plein 00312 glEnable(GL_LIGHTING); 00313 glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); 00314 break; 00315 case 87 : //touche 'w' affichage en mode fil de fer 00316 glDisable(GL_LIGHTING); 00317 glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); 00318 break; 00319 case 67 : // touche 'c' affichage en mode sommets seuls 00320 glDisable(GL_LIGHTING); 00321 glPolygonMode(GL_FRONT_AND_BACK,GL_POINT); 00322 break; 00323 } 00324 00325 updateGL(); 00326 }

int Window3D::load const int &  nb_pts,
const int &  nb_pls,
const vector< Point3D * > &  L_pts,
const vector< int > &  L_ref
 

chargement d'un modele 3D

Parameters:
nb_pts nombre de points
nb_pls nombre de polygônes
L_pts liste de points
L_ref liste contenant les références vers les point on construit des triangles donc un polygone est défini par trois référence (L_ref.size() = 3 *nb_pls)
Returns:
variable de controle d'erreur

00035 { 00036 //suppresion du modele existant 00037 glDeleteLists(model, 1 ); 00038 glMatrixMode (GL_MODELVIEW); 00039 glLoadIdentity (); 00040 nbPoints = nbPts; 00041 nbPolys = nbPls; 00042 pointsList = PtsList; 00043 referencesList = RefList; 00044 00045 for (int i = 0; i < nbPolys * 3; i += 3) 00046 { 00047 Point3D pA = *pointsList[referencesList[i]]; 00048 Point3D pC = *pointsList[referencesList[i + 1]]; 00049 Point3D pB = *pointsList[referencesList[i + 2]]; 00050 00051 Vector3D v1 = Vector3D(pA, pC); 00052 Vector3D v2 = Vector3D(pA, pB); 00053 00054 //la normale d'une facette doit être dirigée vers l'extérieur 00055 Vector3D normalFacet = v2^v1; 00056 00057 normalFacet.normalize(); 00058 00059 normalsList.push_back(new Vector3D(normalFacet)); 00060 } 00061 00062 //modele précompilé 00063 model = drawModel(); 00064 return 1; 00065 }

void Window3D::mouseMoveEvent QMouseEvent *  event  )  [protected]
 

Détection de mouvement de la souris

Parameters:
event évenement source (coordonnées, bouton)

00267 { 00268 float dx = event->x() - oldX; 00269 float dy = event->y() - oldY; 00270 00271 if (button == Qt::LeftButton) { 00272 //Le bouton gauche permet les rotations selon l'axe x et y suivant le déplacement 00273 angle[0] += dx; 00274 angle[1] += dy; 00275 00276 } 00277 else if (button == Qt::RightButton) { 00278 //le bouton droit permet les translations dans la profondeur (axe z) 00279 tra [2] += (dy * TRA_INC); 00280 oldY = event->y(); 00281 } 00282 else if (button == Qt::MidButton) { 00283 //le bouton du milieu permet les translations selon l'axe x et l'axe y 00284 tra [0] += dx*TRA_INC; 00285 tra [1] -= dy*TRA_INC; 00286 } 00287 oldX = event->x() ; 00288 oldY = event->y(); 00289 }

void Window3D::mousePressEvent QMouseEvent *  event  )  [protected]
 

Détection de la pression d'un bouton de la souris

Parameters:
event évenement source (coordonnées, bouton)

00250 { 00251 button = event->button(); 00252 oldX = event->x(); 00253 oldY = event->y(); 00254 }

void Window3D::paintGL  )  [protected]
 

Fonction d'affichage

00180 { 00181 glClear (GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); 00182 drawAxis(); 00183 glMatrixMode (GL_PROJECTION); 00184 glLoadIdentity (); 00185 gluPerspective (90, 1, 0.1, 1000); 00186 00187 glMatrixMode (GL_MODELVIEW); 00188 glLoadIdentity (); 00189 gluLookAt(0.0,0.0,50.0,0.0,0.0,-100.0,0.0,1.0,0.0); 00190 glLightfv (GL_LIGHT0, GL_POSITION, light1Position); 00191 glLightfv (GL_LIGHT1, GL_POSITION, light2Position); 00192 00193 translate (); 00194 rotate (); 00195 scale(); 00196 00197 //appel du modele précompilé 00198 glCallList(model); 00199 00200 //affichage en haut à gauche du nombre de triangle et du facteur de mise à l'échelle 00201 glDisable(GL_LIGHTING); 00202 glColor3f(1.0,0.0,0.0); 00203 stringstream infos; 00204 infos << "Triangles : " << nbPolys << " Scale : x" << zoom ; 00205 renderText ( 5, 15, infos.str()); 00206 glEnable(GL_LIGHTING); 00207 00208 glFlush(); 00209 }

void Window3D::resizeGL int  width,
int  height
[protected]
 

Adaptation de la taille de la fenêtre

Parameters:
width nouvelle largeur de la fenêtre
height nouvelle hauteur de la fenêtre

00119 { 00120 height = height?height:1; 00121 00122 glViewport( 0, 0, (GLint)width, (GLint)height ); 00123 00124 glMatrixMode(GL_PROJECTION); 00125 glLoadIdentity(); 00126 gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f); 00127 00128 glMatrixMode(GL_MODELVIEW); 00129 glLoadIdentity(); 00130 }

void Window3D::rotate  )  [protected]
 

Rotation

00135 { 00136 glRotatef (angle[1], 1.0, 0.0, 0.0); 00137 glRotatef (angle[0], 0.0, 1.0, 0.0); 00138 glRotatef (angle[2], 0.0, 0.0, 1.0); 00139 }

void Window3D::scale  )  [protected]
 

Scale (zoom)

00151 { 00152 glScalef (zoom, zoom, zoom); 00153 }

void Window3D::timeOut  )  [protected]
 

Action a effectuée lorsque le timer arrive à terme

00243 { 00244 updateGL(); 00245 }

void Window3D::timeOutSlot  )  [protected, slot]
 

00357 { 00358 timeOut(); 00359 }

void Window3D::translate  )  [protected]
 

Translation

00144 { 00145 glTranslatef (tra [0], tra [1], tra [2]); 00146 }

void Window3D::wheelEvent QWheelEvent *  e  )  [protected]
 

Détection de mouvement de la mollette de la souris

Parameters:
e évenement source (coordonnées, bouton)

00258 { 00259 //la molette de la souris permet de modifier le facteur de mise à l'échelle 00260 if((e->delta() > 0) && (zoom < 100 * ZOO_INC)) 00261 zoom+=ZOO_INC; 00262 if((e->delta() < 0) && (zoom > ZOO_INC)) 00263 zoom -= ZOO_INC; 00264 }


Member Data Documentation

GLfloat Window3D::ambientLight[4] [private]
 

paramètres ambients

float Window3D::angle[3] [private]
 

angle de rotation

int Window3D::button [private]
 

bouton pressé

GLfloat Window3D::diffuseLight[4] [private]
 

paramètres diffusions

GLfloat Window3D::light1Position[4] [private]
 

Pour pouvoir observer le modèle sous tous ces angles, deux lumieres sont utilisées position de la première lampe

GLfloat Window3D::light2Position[4] [private]
 

position de la deuxième lampe

GLuint Window3D::model [private]
 

numéro du modele dans la displaylist l'utilisation d'un modele précompilé permet un gain en fps important

int Window3D::nbPoints [private]
 

nombre de points

int Window3D::nbPolys [private]
 

nombre de polygones

vector<Vector3D*> Window3D::normalsList [private]
 

liste de vecteurs normales

int Window3D::oldX [private]
 

sauvegarde de l'ex position de la souris

int Window3D::oldY [private]
 

sauvegarde de l'ex position de la souris

vector<Point3D*> Window3D::pointsList [private]
 

liste de points

vector<int> Window3D::referencesList [private]
 

liste de références vers les points

GLfloat Window3D::specularLight[4] [private]
 

paramètres spéculaires

QTimer* Window3D::timer [private]
 

Temporisateur utilisé pour un rafraichissement fréquent de la fenetre

float Window3D::tra[3] [private]
 

facteur de translation

float Window3D::zoom [private]
 

zoom (le meme sur les 3 axes)


The documentation for this class was generated from the following files:
Generated on Tue Nov 29 21:59:00 2005 for CylinderGenerator by doxygen 1.3.7