Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////
- // Imagina
- // ----------------------------------------------------------------------------
- // IN - Synthèse d'images - Modélisation géométrique
- // Auteur : Gilles Gesquière
- // ----------------------------------------------------------------------------
- // Base du TP 1
- // programme permettant de créer des formes de bases.
- // La forme représentée ici est un polygone blanc dessiné sur un fond rouge
- ///////////////////////////////////////////////////////////////////////////////
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string>
- #include "glad/glad.h"
- #include "headers/Point.h"
- #include "headers/Vector.h"
- #include "headers/Voxel.h"
- #include "headers/Octree.h"
- #include <fstream>
- #include <vector>
- #include <iostream>
- #include <iomanip>
- /* Dans les salles de TP, vous avez généralement accès aux glut dans C:\Dev. Si ce n'est pas le cas, téléchargez les .h .lib ...
- Vous pouvez ensuite y faire référence en spécifiant le chemin dans visual. Vous utiliserez alors #include <glut.h>.
- Si vous mettez glut dans le répertoire courant, on aura alors #include "glut.h"
- */
- #include <algorithm>
- #include <GL/glut.h>
- // Définition de la taille de la fenêtre
- #define WIDTH 480
- #define HEIGHT 480
- // Définition de la couleur de la fenêtre
- #define RED 1
- #define GREEN 0
- #define BLUE 0
- #define ALPHA 1
- #define IMG_GAUSS 5689
- #define FILL 1
- #define RAFINEMENT 56765343
- #define BUTTERFLY 5676156
- // Touche echap (Esc) permet de sortir du programme
- #define KEY_ESC 27
- // Entêtes de fonctions
- void init_scene();
- void render_scene();
- GLvoid initGL();
- GLvoid window_display();
- GLvoid window_reshape(GLsizei width, GLsizei height);
- GLvoid window_key(unsigned char key, int x, int y);
- float angle = 0.0f;
- float lx=-1.0f,lz=-1.0f;
- float x=1.0f, z=1.0f;
- float lxp=0.0f,lzp=0.5f;
- float xp=0.0f, zp=-0.5f;
- float deltaAngle = 0.0f;
- float deltaMove = 0;
- int xOrigin = -1;
- float* TabVertices;
- int* TabIndices;
- float* TabNormals;
- int* TabVoisins;
- GLubyte* TabColors;
- float* TabNormalsSom;
- int nbPoints, nbPolys, nbEdges;
- int image_gaussienne = 0;
- int testFill = 0;
- int testSeg = 0;
- int testRafinement = 0;
- int testButterfly = 0;
- float maxX=0, maxY=0, maxZ=0;
- float sizefenetre = 10;
- float sizefenetreX = 10;
- float sizefenetreY = 10;
- float sizefenetreZ = 10;
- double searchSizeOrtho(float* TabVertices) {
- float min = TabVertices[0], max = TabVertices[0];
- for (int i = 0; i<nbPoints; i++) {
- if (TabVertices[i]>max)
- max = TabVertices[i];
- if (TabVertices[i]<min)
- min = TabVertices[i];
- }
- float ret = sqrt(max*max+min*min);
- std::cout<< " RET : "<< ret <<std::endl;
- return ret;
- }
- void searchSizeOrthoXYZ(float* TabVertices) {
- float Xmin = TabVertices[0], Xmax = TabVertices[0];
- float Ymin = TabVertices[1], Ymax = TabVertices[1];
- float Zmin = TabVertices[2], Zmax = TabVertices[2];
- for (int i = 0; i<nbPoints; i++) {
- if (TabVertices[3*i]>Xmax)
- Xmax = TabVertices[3*i];
- if (TabVertices[3*i]<Xmin)
- Xmin = TabVertices[3*i];
- if (TabVertices[3*i+1]>Ymax)
- Ymax = TabVertices[3*i+1];
- if (TabVertices[3*i+1]<Ymin)
- Ymin = TabVertices[3*i+1];
- if (TabVertices[3*i+2]>Zmax)
- Zmax = TabVertices[3*i+2];
- if (TabVertices[3*i+2]<Zmin)
- Zmin = TabVertices[3*i+2];
- }
- sizefenetreX = sqrt(Xmax*Xmax+Xmin*Xmin);
- sizefenetreY = sqrt(Ymax*Ymax+Ymin*Ymin);
- sizefenetreZ = sqrt(Zmax*Zmax+Zmin*Zmin);
- }
- int indiceEquals(int* TabIndices, int i, int j, int k, int l) { // return 0 if tab[i] est voisin avec tab[j]
- // k et l sont les positions des deux triangles à tester dans le tableau d'indice par exemple 0 et 1 ou 1 et 2 ou 2 et 0
- if(
- (
- ((TabIndices[i*3+k] == TabIndices[j*3]) || (TabIndices[i*3+k] == TabIndices[j*3+1]) || (TabIndices[i*3+k] == TabIndices[j*3+2]))
- &&
- ((TabIndices[i*3+l] == TabIndices[j*3]) || (TabIndices[i*3+l] == TabIndices[j*3+1]) || (TabIndices[i*3+l] == TabIndices[j*3+2]))
- )
- )
- return 0;
- else
- return 1;
- }
- int fillVoisinTab(int* TabIndices, int* TabVoisins, int nbPolys) { // Pour chaque triangle, si il a deux indices en commun avec un autre triangle on ajoute cet autre triangle
- // au tableau des voisin du triangle en question
- std::ofstream fichierEcriture("TabVoisins.txt", std::ios::out | std::ios::trunc);
- int ownVoisin = 0, tr1 = 0, tr2 = 0, tr3 = 0;
- if(fichierEcriture)
- {
- for(int i = 0; i<nbPolys; i++)
- {
- //std::cout<<i<<" : ";
- fichierEcriture<<i<<" : ";
- for(int j = 0; j<nbPolys; j++)
- {
- //std::cout<<" compare "<<TabIndices[ i*3 ]<<" et "<<TabIndices[j*3]<<std::endl;
- if( i != j)
- {
- if(indiceEquals(TabIndices, i, j, 0, 1) == 0 && tr1 == 0)
- {
- TabVoisins[i*3] = j;
- fichierEcriture<<(int)j<<" "; // ecriture fichier
- ownVoisin++;
- tr1++;
- }
- else if(indiceEquals(TabIndices, i, j, 0, 1) != 0 && j==nbPolys-1 && tr1 == 0)
- {
- TabVoisins[i*3] = -1;
- fichierEcriture<<(int)-1<<" ";
- ownVoisin++;
- tr1++;
- }
- if(indiceEquals(TabIndices, i, j, 1, 2) == 0 && tr2 == 0)
- {
- TabVoisins[i*3+1] = j;
- fichierEcriture<<(int)j<<" "; // ecriture fichier
- ownVoisin++;
- tr2++;
- }
- else if(indiceEquals(TabIndices, i, j, 1, 2) != 0 && j==nbPolys-1 && tr2 == 0)
- {
- TabVoisins[i*3+1] = -1;
- fichierEcriture<<(int)-1<<" ";
- ownVoisin++;
- tr2++;
- }
- if(indiceEquals(TabIndices, i, j, 2, 0) == 0 && tr3 == 0)
- {
- TabVoisins[i*3+2] = j;
- fichierEcriture<<(int)j<<" "; // ecriture fichier
- ownVoisin++;
- tr3++;
- }
- else if(indiceEquals(TabIndices, i, j, 2, 0) != 0 && j==nbPolys-1 && tr3 == 0)
- {
- TabVoisins[i*3+2] = -1;
- fichierEcriture<<(int)-1<<" ";
- ownVoisin++;
- tr3++;
- }
- }
- if(ownVoisin==3)
- j=nbPolys;
- }
- /* if(ownVoisin != 3)
- {
- //std::cout<<"pas de voisins ta race"<<std::endl;
- TabVoisins[i] = -1;
- fichierEcriture<<(int)-1<<" ";
- }*/
- ownVoisin = 0;
- tr1 = 0;
- tr2 = 0;
- tr3 = 0;
- //std::cout<<std::endl;
- fichierEcriture<<"\n";
- }
- fichierEcriture.close(); //
- }
- else
- {
- std::cerr << "Impossible d'ouvrir le fichier !" << std::endl;
- return -1;
- }
- return 0;
- }
- void traceSegment(Point *A, Point *B,Vector color) {
- glColor3f(color.getX(),color.getY(),color.getZ());
- glBegin(GL_LINES);
- glVertex3f(A->getX(),A->getY(),A->getZ());
- glVertex3f(B->getX(),B->getY(),B->getZ());
- glEnd();
- }
- void tracePoint(Point *A,Vector color) {
- glColor3f(color.getX(),color.getY(),color.getZ());
- glBegin(GL_POINTS);
- glVertex3f(A->getX(),A->getY(),A->getZ());
- glEnd();
- }
- void traceVector(Vector *v,Vector color) {
- glColor3f(color.getX(),color.getY(),color.getZ());
- glBegin(GL_LINES);
- glVertex3f(0,0,0);
- glVertex3f(v->getX(),v->getY(),v->getZ());
- glEnd();
- }
- void traceQuad(Point* A, Point* B,Point* C,Point* D, Vector color) {
- glColor3f(color.getX(),color.getY(),color.getZ());
- glBegin(GL_QUADS);
- glVertex3f(A->getX(),A->getY(),A->getZ());
- glVertex3f(B->getX(),B->getY(),B->getZ());
- glVertex3f(C->getX(),C->getY(),C->getZ());
- glVertex3f(D->getX(),D->getY(),D->getZ());
- glEnd();
- }
- void traceTri(Point* A, Point* B,Point* C, Vector color) {
- glColor3f(color.getX(),color.getY(),color.getZ());
- glBegin(GL_TRIANGLES);
- glVertex3f(A->getX(),A->getY(),A->getZ());
- glVertex3f(B->getX(),B->getY(),B->getZ());
- glVertex3f(C->getX(),C->getY(),C->getZ());
- glEnd();
- }
- int main(int argc, char **argv)
- {
- char fichierLu[250];
- if (argc != 2)
- {
- printf("Usage: file.off \n");
- exit (1);
- }
- sscanf (argv[1],"%s",fichierLu);
- //std::ifstream fichier("MeshSegmentation.off", std::ios::in);
- std::ifstream fichier(fichierLu, std::ios::in);
- float xIn = 0;
- std::string chaine1, chaine2;
- if(fichier)
- {
- fichier >> chaine1;/* >> entier1 >> entier2;*/ /*on lit jusqu'à l'espace et on stocke ce qui est lu dans la variable indiquée */
- if(chaine1 == "OFF")
- {
- std::cout << "Ouverture fichier OFF" << std::endl;
- fichier >> nbPoints >> nbPolys >> nbEdges;
- std::cout << "nbPoints = " <<nbPoints<<", nbPolys = "<<nbPolys<<", nbEdges = "<<nbEdges<<std::endl;
- int i = 0;
- TabVertices = (float*) malloc(sizeof(float)*3*nbPoints);
- TabIndices = (int*) malloc(sizeof(int)*3*nbPolys);
- TabVoisins = (int*) malloc(sizeof(int)*3*nbPolys);
- TabNormals = (float*) malloc(sizeof(float)*3*nbPolys);
- TabNormalsSom = (float*) malloc(sizeof(float)*3*nbPoints);
- TabColors = (GLubyte*) malloc(sizeof(GLubyte)*3*nbPoints);
- while(i<nbPoints*3)
- {
- fichier>>xIn;
- TabVertices[i] = xIn;
- i++;
- }
- i=0;
- while(i<nbPolys*3)
- {
- fichier>>xIn;
- xIn = 0.0;
- fichier>>xIn;
- TabIndices[i] = xIn;
- i++;
- fichier>>xIn;
- TabIndices[i] = xIn;
- i++;
- fichier>>xIn;
- TabIndices[i] = xIn;
- i++;
- }
- }
- fichier.close();
- }
- else
- std::cerr << "Impossible d'ouvrir le fichier !" << std::endl;
- for(int i = 0; i<nbPolys; i++) // Trace les normales aux triangles dans TabNormals
- {
- Point* p1 = new Point(TabVertices[3*(TabIndices[i*3])], TabVertices[3*(TabIndices[i*3])+1], TabVertices[3*(TabIndices[i*3])+2]);
- Point* p2 = new Point(TabVertices[3*(TabIndices[i*3+1])], TabVertices[3*(TabIndices[i*3+1])+1], TabVertices[3*(TabIndices[i*3+1])+2]);
- Point* p3 = new Point(TabVertices[3*(TabIndices[i*3+2])], TabVertices[3*(TabIndices[i*3+2])+1], TabVertices[3*(TabIndices[i*3+2])+2]);
- Vector* v1 = new Vector(p2->getX()-p1->getX(), p2->getY()-p1->getY(), p2->getZ()-p1->getZ());
- Vector* v2 = new Vector(p3->getX()-p1->getX(), p3->getY()-p1->getY(), p3->getZ()-p1->getZ());
- v1->normalize();
- v2->normalize();
- Vector v3 = v1->Vectoriel(v2);
- TabNormals[i*3] = v3.getX();
- TabNormals[i*3+1] = v3.getY();
- TabNormals[i*3+2] = v3.getZ();
- }
- if(fillVoisinTab(TabIndices, TabVoisins, nbPolys) == -1)
- {
- std::cout<<"Erreur ecriture tab voisins"<<std::endl;
- }
- std::cout<<"Ecriture tab voisin réussie"<<std::endl;
- // initialisation des paramètres de GLUT en fonction
- // des arguments sur la ligne de commande
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGBA);
- // définition et création de la fenêtre graphique, ainsi que son titre
- glutInitWindowSize(WIDTH, HEIGHT);
- glutInitWindowPosition(0, 0);
- glutCreateWindow("TP8 - SEGMENTATION");
- if(!gladLoadGL()) {
- printf("Something went wrong!\n");
- exit(-1);
- }
- // initialisation de OpenGL et de la scène
- initGL();
- init_scene();
- // choix des procédures de callback pour
- // le tracé graphique
- glutDisplayFunc(&window_display);
- // le redimensionnement de la fenêtre
- sizefenetre = searchSizeOrtho(TabVertices);
- searchSizeOrthoXYZ(TabVertices);
- //sizefenetre*=1.2;
- glutReshapeFunc(&window_reshape);
- // la gestion des événements clavier
- glutKeyboardFunc(&window_key);
- // la boucle prinicipale de gestion des événements utilisateur
- glutMainLoop();
- return 1;
- }
- // initialisation du fond de la fenêtre graphique : noir opaque
- GLvoid initGL()
- {
- glClearColor(0, 0, 0, ALPHA);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_LIGHT1);
- glEnable(GL_DEPTH_TEST);
- }
- // Initialisation de la scene. Peut servir à stocker des variables de votre programme
- // à initialiser
- void init_scene()
- {
- }
- // fonction de call-back pour l´affichage dans la fenêtre
- GLvoid window_display()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glLoadIdentity();
- // C'est l'endroit où l'on peut dessiner. On peut aussi faire appel
- // à une fonction (render_scene() ici) qui contient les informations
- // que l'on veut dessiner
- render_scene();
- // trace la scène grapnique qui vient juste d'être définie
- glFlush();
- }
- // fonction de call-back pour le redimensionnement de la fenêtre
- GLvoid window_reshape(GLsizei width, GLsizei height)
- {
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- // ici, vous verrez pendant le cours sur les projections qu'en modifiant les valeurs, il est
- // possible de changer la taille de l'objet dans la fenêtre. Augmentez ces valeurs si l'objet est
- // de trop grosse taille par rapport à la fenêtre.
- //glOrtho(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5);
- /*glOrtho(-10,10, -10, 10, -10, 10);*/
- //glOrtho(-2*sizefenetre, 2*sizefenetre, -2*sizefenetre, 2*sizefenetre, -2*sizefenetre, 2*sizefenetre);
- //glOrtho(-1*sizefenetre, 1*sizefenetre, -1*sizefenetre, 1*sizefenetre, -1*sizefenetre, 1*sizefenetre);
- glOrtho(-1*sizefenetreX, 1*sizefenetreX, -1*sizefenetreY, 1*sizefenetreY, -1*sizefenetreZ, 1*sizefenetreZ);
- // toutes les transformations suivantes s´appliquent au modèle de vue
- glMatrixMode(GL_MODELVIEW);
- }
- GLvoid window_key(unsigned char key, int x, int y)
- {
- float fraction = 0.05f;
- switch (key) {
- case KEY_ESC:
- free(TabVertices );
- free(TabIndices );
- free(TabVoisins );
- free(TabNormals );
- free(TabNormalsSom);
- free(TabColors);
- exit(1);
- break;
- case 113:
- angle -= 0.1f;
- lx = sin(angle);
- lz = -cos(angle);
- lxp = sin(angle);
- lzp = -cos(angle);
- break;
- case 100 :
- angle += 0.1f;
- lx = sin(angle);
- lz = -cos(angle);
- lxp = sin(angle);
- lzp = -cos(angle);
- break;
- case 122 :
- x += lx * fraction;
- z += lz * fraction;
- xp += lxp * fraction;
- zp += lzp * fraction;
- break;
- case 115 :
- x -= lx * fraction;
- z -= lz * fraction;
- xp -= lxp * fraction;
- zp -= lzp * fraction;
- break;
- case 'g' :
- std::cout<<"Construction image gaussienne"<<std::endl;
- if(image_gaussienne == IMG_GAUSS)
- image_gaussienne = 0;
- else
- {
- image_gaussienne = IMG_GAUSS;
- }
- break;
- case 'f' :
- if(testFill == FILL)
- testFill = -1;
- else
- testFill = FILL;
- break;
- case 'h' :
- std::cout<<"Segmentation !"<<std::endl;
- if(testSeg >6)
- testSeg = 0;
- else
- testSeg++;
- break;
- case 'r' :
- std::cout<<"Rafinement"<<std::endl;
- if(testRafinement == RAFINEMENT)
- testRafinement = -1;
- else
- testRafinement = RAFINEMENT;
- break;
- case 'b' :
- std::cout<<"Subdivision schema Butterfly"<<std::endl;
- if(testButterfly == BUTTERFLY)
- testButterfly = -1;
- else
- testButterfly = BUTTERFLY;
- break;
- default:
- printf ("La touche %d n´est pas active.\n", key);
- break;
- }
- glutPostRedisplay();
- }
- void text(double x, double y, std::string menu)
- {
- int len = 80;
- len = menu.length();
- glColor3f(1,1,1);
- glMatrixMode( GL_PROJECTION );
- glPushMatrix();
- glLoadIdentity();
- gluOrtho2D( 0, 600, 0, 600 );
- glMatrixMode( GL_MODELVIEW );
- glPushMatrix();
- glLoadIdentity();
- glRasterPos2i(265, 300);
- for ( int i = 0; i < len; ++i )
- {
- glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, menu[i]);
- }
- glPopMatrix();
- glMatrixMode( GL_PROJECTION );
- glPopMatrix();
- glMatrixMode( GL_MODELVIEW );
- }
- Point* Approximate(double t, Point* pt1, Point* pt2)
- {
- double x = pt1->getX() * (1-t) + pt2->getX()* t;
- double y = pt1->getY() * (1-t) + pt2->getY() * t;
- return new Point(x, y, 0);
- }
- void constructImgGauss () { // On fait la moyenne des normales au sommet pour tous les triangles qui disposent de l'indice du sommet à évaluer
- int n = 0;
- float X = 0, Y=0, Z =0;
- for(int i = 0 ; i<nbPoints; i++)
- {
- for(int j = 0; j<nbPolys; j++)
- {
- if((TabIndices[3*j] == i) || (TabIndices[3*j+1] == i) || (TabIndices[3*j+2] == i)) // si le point appartient à un triangle
- {
- x+=TabNormals[3*j];
- Y+=TabNormals[3*j+1];
- Z+=TabNormals[3*j+2];
- n++;
- } // On fait la moyenne des normales des triangles qui possedent ce point i dans TabNormalsSom[i]
- }
- TabNormalsSom[3*i] = (float)(X/n);
- TabNormalsSom[3*i+1] = (float)(Y/n);
- TabNormalsSom[3*i+2] = (float)(Z/n);
- n=0; X=0; Y=0; Z=0;
- }
- for(int i = 0; i<nbPoints; i++) // On trace les normales à chaque sommets
- {
- Point* A = new Point(TabVertices[3*i]+TabNormalsSom[3*i],TabVertices[3*i+1]+TabNormalsSom[3*i+1],TabVertices[3*i+2]+TabNormalsSom[3*i+2]);
- Point* B = new Point(TabVertices[3*i],TabVertices[3*i+1],TabVertices[3*i+2]);
- traceSegment(A, B, Vector(255, 255, 255));
- delete(A);
- delete(B);
- }
- }
- int sontVoisins(int pos1, int pos2) {
- if((pos1 == TabVoisins[3*pos2]) || (pos1 == TabVoisins[3*pos2+1]) || (pos1 == TabVoisins[3*pos2+2]))
- {
- //std::cout<<"les deux triangles sont bien voisins"<<std::endl;
- return 0;
- }
- else
- {
- // std::cout<<"les deux triangles ne sont pas voisins"<<std::endl;
- return -1;
- }
- }
- float computeDiedreAngle (int posAngle1, int posAngle2) { // supposés voisins
- Vector* v1 = new Vector(TabNormals[posAngle1*3],TabNormals[posAngle1*3+1],TabNormals[posAngle1*3+2]);
- Vector* v2 = new Vector(TabNormals[posAngle2*3],TabNormals[posAngle2*3+1],TabNormals[posAngle2*3+2]);
- //std::cout<<"L'angle entre le triangle "<<posAngle1<< " : "<<TabNormals[posAngle1*3]<<" "<<TabNormals[posAngle1*3+1]<<" "<<TabNormals[posAngle1*3+2]<<std::endl;
- //std::cout<<"et le triangle "<<posAngle2<< " : "<<TabNormals[posAngle2*3]<<" "<<TabNormals[posAngle2*3+1]<<" "<<TabNormals[posAngle2*3+2]<<std::endl;
- v1->normalize();
- v2->normalize();
- float ret = 180-(acos(v1->scalar(v2)/(v1->norme(),v2->norme()))*180.0 / M_PI );
- delete(v1);
- delete(v2);
- // std::cout<<"Vaut : "<<ret<<std::endl;
- return ret;
- }
- void coloreAreteCommune(int pos1, int pos2, Vector c) {
- /* std::cout<<"====> "<<pos1<< " : "<< TabIndices[3*pos1]<< ", "<<TabIndices[3*pos1+1]<<", "<<TabIndices[3*pos1+2]<<std::endl;
- std::cout<<"====> "<<pos2<< " : "<< TabIndices[3*pos2]<< ", "<<TabIndices[3*pos2+1]<<", "<<TabIndices[3*pos2+2]<<std::endl;
- std::cout<<"====> "<<pos1<< " et "<<pos2<<" ont les sommets suivants en commun : ";
- */
- if((TabIndices[3*pos1] == TabIndices[3*pos2]) || (TabIndices[3*pos1] ==TabIndices[3*pos2+1]) || (TabIndices[3*pos1] ==TabIndices[3*pos2+2])) {
- /* TabColors[3*pos1] = 255;
- TabColors[3*pos1+1] = 255;
- TabColors[3*pos1+2] = 0;*/
- /* std::cout<<" Premier " <<TabIndices[3*pos1]<<std::endl;
- std::cout<<" Premier " <<TabVertices[3*TabIndices[3*pos1]]<<" "<<TabVertices[3*TabIndices[3*pos1]+1]<<" "<<TabVertices[3*TabIndices[3*pos1]+2]<<std::endl;*/
- Point* p = new Point(TabVertices[3*TabIndices[3*pos1]],TabVertices[3*TabIndices[3*pos1]+1],TabVertices[3*TabIndices[3*pos1]+2]);
- //tracePoint(p, Vector(0, 0, 255));
- if( (TabIndices[3*pos1+1] == TabIndices[3*pos2]) || (TabIndices[3*pos1+1] ==TabIndices[3*pos2+1]) || (TabIndices[3*pos1+1] == TabIndices[3*pos2+2])) {
- Point* p2 = new Point(TabVertices[3*TabIndices[3*pos1+1]],TabVertices[3*TabIndices[3*pos1+1]+1],TabVertices[3*TabIndices[3*pos1+1]+2]);
- //tracePoint(p2, Vector(0, 0, 255));
- traceSegment(p, p2, c);
- delete(p2);
- }
- if((TabIndices[3*pos1+2] == TabIndices[3*pos2]) || (TabIndices[3*pos1+2] == TabIndices[3*pos2+1]) ||(TabIndices[3*pos1+2] == TabIndices[3*pos2+2])) {
- Point* p2 = new Point(TabVertices[3*TabIndices[3*pos1+2]],TabVertices[3*TabIndices[3*pos1+2]+1],TabVertices[3*TabIndices[3*pos1+2]+2]);
- //tracePoint(p2, Vector(0, 0, 255));
- traceSegment(p, p2, c);
- delete(p2);
- }
- delete(p);
- }
- if( (TabIndices[3*pos1+1] == TabIndices[3*pos2]) || (TabIndices[3*pos1+1] ==TabIndices[3*pos2+1]) || (TabIndices[3*pos1+1] == TabIndices[3*pos2+2])) {
- /* TabColors[3*(pos1+1)] = 255;
- TabColors[3*(pos1+1)+1] = 255;
- TabColors[3*(pos1+1)+2] = 0;*/
- // std::cout<<" Deuxieme " <<TabIndices[3*pos1+1]<<std::endl;
- // std::cout<<" Deuxieme " <<TabVertices[3*TabIndices[3*pos1+1]]<<" "<<TabVertices[3*TabIndices[3*pos1+1]+1]<<" "<<TabVertices[3*TabIndices[3*pos1+1]+2]<<std::endl;
- Point* p = new Point(TabVertices[3*TabIndices[3*pos1+1]],TabVertices[3*TabIndices[3*pos1+1]+1],TabVertices[3*TabIndices[3*pos1+1]+2]);
- //tracePoint(p, Vector(0, 0, 255));
- if((TabIndices[3*pos1+2] == TabIndices[3*pos2]) || (TabIndices[3*pos1+2] == TabIndices[3*pos2+1]) ||(TabIndices[3*pos1+2] == TabIndices[3*pos2+2])) {
- Point* p2 = new Point(TabVertices[3*TabIndices[3*pos1+2]],TabVertices[3*TabIndices[3*pos1+2]+1],TabVertices[3*TabIndices[3*pos1+2]+2]);
- //tracePoint(p2, Vector(0, 0, 255));
- traceSegment(p, p2, c);
- delete(p2);
- }
- delete(p);
- }
- //if((TabIndices[3*pos1+2] == TabIndices[3*pos2]) || (TabIndices[3*pos1+2] == TabIndices[3*pos2+1]) ||(TabIndices[3*pos1+2] == TabIndices[3*pos2+2])) {
- /* TabColors[3*(pos1+2)] = 255;
- TabColors[3*(pos1+2)+1] = 255;
- TabColors[3*(pos1+2)+2] = 0;*/
- /* std::cout<<" Troisieme "<<TabIndices[3*pos1+2]<<std::endl;
- std::cout<<" Troisieme "<<TabVertices[3*TabIndices[3*pos1+2]]<<" "<<TabVertices[3*TabIndices[3*pos1+2]+1]<<" "<<TabVertices[3*TabIndices[3*pos1+2]+2]<<std::endl;*/
- // Point* p = new Point(TabVertices[3*TabIndices[3*pos1+2]],TabVertices[3*TabIndices[3*pos1+2]+1],TabVertices[3*TabIndices[3*pos1+2]+2]);
- // tracePoint(p, Vector(0, 0, 255));
- // delete(p);
- //}
- // std::cout<<std::endl<<std::endl;
- }
- void testAretesVives(float angle, Vector c) {
- for(int i = 0; i<nbPolys; i++)
- {
- if(sontVoisins(i, TabVoisins[3*i])==0) {
- //std::cout<<"les triangles "<<i<< " et "<< TabVoisins[3*i]<<" sont voisins"<<std::endl;
- //std::cout<<"Angles entre leurs normales = "<<computeDiedreAngle(i,TabVoisins[3*i])<<std::endl;
- if(computeDiedreAngle(i,TabVoisins[3*i])<angle) {
- coloreAreteCommune(i,TabVoisins[3*i], c);
- }
- }
- if(sontVoisins(i, TabVoisins[3*i+1])==0) {
- //std::cout<<"les triangles "<<i<< " et "<< TabVoisins[3*i+1]<<" sont voisins"<<std::endl;
- //std::cout<<"Angles entre leurs normales = "<<computeDiedreAngle(i,TabVoisins[3*i+1])<<std::endl;
- if(computeDiedreAngle(i,TabVoisins[3*i+1])<angle) {
- coloreAreteCommune(i,TabVoisins[3*i+1], c);
- }
- }
- if(sontVoisins(i, TabVoisins[3*i+2])==0) {
- // std::cout<<"les triangles "<<i<< " et "<< TabVoisins[3*i+2]<<" sont voisins"<<std::endl;
- //std::cout<<"Angles entre leurs normales = "<<computeDiedreAngle(i,TabVoisins[3*i+2])<<std::endl;
- if(computeDiedreAngle(i,TabVoisins[3*i+2])<angle) {
- coloreAreteCommune(i,TabVoisins[3*i+2], c);
- }
- }
- //std::cout<<"********"<<std::endl;
- }
- }
- void coloreTriaangle(int i, Vector c) {
- Point* p1 = new Point(TabVertices[3*(TabIndices[i*3])], TabVertices[3*(TabIndices[i*3])+1], TabVertices[3*(TabIndices[i*3])+2]);
- Point* p2 = new Point(TabVertices[3*(TabIndices[i*3+1])], TabVertices[3*(TabIndices[i*3+1])+1], TabVertices[3*(TabIndices[i*3+1])+2]);
- Point* p3 = new Point(TabVertices[3*(TabIndices[i*3+2])], TabVertices[3*(TabIndices[i*3+2])+1], TabVertices[3*(TabIndices[i*3+2])+2]);
- traceTri(p1, p2, p3, c);
- delete(p1);
- delete(p2);
- delete(p3);
- }
- void segmentationByProgagation(std::vector<int>* triangleTraites, int indice, Vector c, int x, int prof) {
- coloreTriaangle(indice, c);
- triangleTraites->push_back(indice);
- /* std::cout<<"Angle entre le triangle et le premier voisin : "<<computeDiedreAngle(indice,TabVoisins[3*indice])<<std::endl;
- std::cout<<"Angle entre le triangle et le deuxième voisin : "<<computeDiedreAngle(indice,TabVoisins[3*indice+1])<<std::endl;
- std::cout<<"Angle entre le triangle et le troisième voisin : "<<computeDiedreAngle(indice,TabVoisins[3*indice+2])<<std::endl;*/
- if(!(std::find(triangleTraites->begin(), triangleTraites->end(), TabVoisins[3*indice])!= triangleTraites->end()))
- if(computeDiedreAngle(indice,TabVoisins[3*indice])>=160 && computeDiedreAngle(indice,TabVoisins[3*indice])<=180 && x<prof)
- segmentationByProgagation(triangleTraites, TabVoisins[3*indice], c, x+1, prof);
- if(!(std::find(triangleTraites->begin(), triangleTraites->end(), TabVoisins[3*indice+1])!=triangleTraites->end()))
- if(computeDiedreAngle(indice,TabVoisins[3*indice+1])>=160 && computeDiedreAngle(indice,TabVoisins[3*indice+1])<=180 && x<prof)
- segmentationByProgagation(triangleTraites, TabVoisins[3*indice+1], c, x+1, prof);
- if(!(std::find(triangleTraites->begin(), triangleTraites->end(), TabVoisins[3*indice+2]) != triangleTraites->end()))
- if(computeDiedreAngle(indice,TabVoisins[3*indice+2])>=160 && computeDiedreAngle(indice,TabVoisins[3*indice+2])<=180 && x<prof)
- segmentationByProgagation(triangleTraites, TabVoisins[3*indice+2], c, x+1, prof);
- }
- /* Ici on veut faire une fonction découpe tous les triangles en 4.
- Pour chaque triangle de tabIndice,
- pour le 1er et le 2e point
- on calcule les coordonées du point entre
- on incrémente le nombre de sommets
- on augmente la taille de TabVertice
- on ajoute ce point à tabvertice
- pour le 1er et le 3e point
- on calcule les coordonées du point entre
- on incrémente le nombre de sommets
- on augmente la taille de TabVertice
- on ajoute ce point à tabvertice
- pour le 2e et le 3e point
- on calcule les coordonées du point entre
- on incrémente le nombre de sommets
- on augmente la taille de TabVertice
- on ajoute ce point à tabvertice
- */
- void calculNormalesAuxTriangles(int nbPolys) {
- // Reajustement des normales
- for(int i = 0; i<nbPolys; i++) // Trace les normales aux triangles dans TabNormals
- {
- Point* p1 = new Point(TabVertices[3*(TabIndices[i*3])], TabVertices[3*(TabIndices[i*3])+1], TabVertices[3*(TabIndices[i*3])+2]);
- Point* p2 = new Point(TabVertices[3*(TabIndices[i*3+1])], TabVertices[3*(TabIndices[i*3+1])+1], TabVertices[3*(TabIndices[i*3+1])+2]);
- Point* p3 = new Point(TabVertices[3*(TabIndices[i*3+2])], TabVertices[3*(TabIndices[i*3+2])+1], TabVertices[3*(TabIndices[i*3+2])+2]);
- Vector* v1 = new Vector(p2->getX()-p1->getX(), p2->getY()-p1->getY(), p2->getZ()-p1->getZ());
- Vector* v2 = new Vector(p3->getX()-p1->getX(), p3->getY()-p1->getY(), p3->getZ()-p1->getZ());
- v1->normalize();
- v2->normalize();
- Vector v3 = v1->Vectoriel(v2);
- TabNormals[i*3] = v3.getX();
- TabNormals[i*3+1] = v3.getY();
- TabNormals[i*3+2] = v3.getZ();
- }
- }
- void rafinementMaillage() {
- int oldNbPolys = nbPolys;
- nbPolys=nbPolys + 4*nbPolys;
- int oldNbPoints = nbPoints;
- nbPoints= nbPoints + 3*oldNbPolys;
- TabVertices = (float*) realloc(TabVertices, sizeof(float) * (3*nbPoints));
- TabIndices = (int*) realloc(TabIndices, sizeof(int) * (3*nbPolys));
- TabNormals = (float*) realloc(TabNormals, sizeof(int) * (3*nbPolys));
- // Crée les sous triangles du centre
- int k = oldNbPolys;
- for(int i = 0; i< oldNbPolys; i++) {
- TabIndices[3*k] = oldNbPoints+3*i;
- TabIndices[3*k+1] = oldNbPoints+3*i+1;
- TabIndices[3*k+2] = oldNbPoints+3*i+2;
- // std::cout<< TabIndices[3*k] <<std::endl;
- // std::cout<< TabIndices[3*k+1]<<std::endl;
- // std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;
- k++;
- }
- double x1, x2, x3;
- double y1, y2, y3;
- double z1, z2, z3;
- k = 2* oldNbPolys;
- for(int i = 0 ; i< oldNbPolys; i++) {
- // premier sommet
- x1 = (TabVertices[3*(TabIndices[3*i])] + TabVertices[3*(TabIndices[3*i+1]) ]) / 2;
- y1 = (TabVertices[3*(TabIndices[3*i])+1] + TabVertices[3*(TabIndices[3*i+1])+1]) / 2;
- z1 = (TabVertices[3*(TabIndices[3*i])+2] + TabVertices[3*(TabIndices[3*i+1])+2]) / 2;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)]] = x1;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)]+1] = y1;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)]+2] = z1;
- // second sommet
- x2 = (TabVertices[3*(TabIndices[3*i+1])] + TabVertices[3*(TabIndices[3*i+2]) ]) / 2;
- y2 = (TabVertices[3*(TabIndices[3*i+1])+1] + TabVertices[3*(TabIndices[3*i+2])+1]) / 2;
- z2 = (TabVertices[3*(TabIndices[3*i+1])+2] + TabVertices[3*(TabIndices[3*i+2])+2]) / 2;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+1]] = x2;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+1]+1] = y2;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+1]+2] = z2;
- // troisieme sommet
- x3 = (TabVertices[3*(TabIndices[3*i+2]) ] + TabVertices[3*(TabIndices[3*i]) ]) / 2;
- y3 = (TabVertices[3*(TabIndices[3*i+2])+1] + TabVertices[3*(TabIndices[3*i])+1]) / 2;
- z3 = (TabVertices[3*(TabIndices[3*i+2])+2] + TabVertices[3*(TabIndices[3*i])+2]) / 2;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+2]] = x3;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+2]+1] = y3;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+2]+2] = z3;
- // premier triangle
- TabIndices[3*k] = TabIndices[3*(oldNbPolys+i)];
- TabIndices[3*k+1] = TabIndices[3*(oldNbPolys+i)+1];
- TabIndices[3*k+2] = TabIndices[3*i+1];
- /* std::cout<<"premier triangle"<<std::endl;
- std::cout<< TabIndices[3*k] <<std::endl;
- std::cout<< TabIndices[3*k+1]<<std::endl;
- std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;*/
- k++;
- // deuxieme triangle
- TabIndices[3*k] = TabIndices[3*(oldNbPolys+i)];
- TabIndices[3*k+1] = TabIndices[3*i];
- TabIndices[3*k+2] = TabIndices[3*(oldNbPolys+i)+2];
- /* std::cout<<"deuxieme triangle"<<std::endl;
- std::cout<< TabIndices[3*k] <<std::endl;
- std::cout<< TabIndices[3*k+1]<<std::endl;
- std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;*/
- k++;
- // troisieme triangle
- TabIndices[3*k] = TabIndices[3*i+2];
- TabIndices[3*k+1] = TabIndices[3*(oldNbPolys+i)+1];
- TabIndices[3*k+2] = TabIndices[3*(oldNbPolys+i)+2];
- /* std::cout<<"troisieme triangle"<<std::endl;
- std::cout<< TabIndices[3*k] <<std::endl;
- std::cout<< TabIndices[3*k+1]<<std::endl;
- std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;*/
- k++;
- }
- // Reajustement des normales
- calculNormalesAuxTriangles(nbPolys);
- }
- // OK
- int pointsEgaux(int P1, int P2) { // Retourne 0 si deux triangles on deux points en communs
- if( (TabVertices[3*TabIndices[3*P1]] == TabVertices[3*TabIndices[3*P2]]) &&
- (TabVertices[3*TabIndices[3*P1]+1] == TabVertices[3*TabIndices[3*P2]+1]) &&
- (TabVertices[3*TabIndices[3*P1]+2] == TabVertices[3*TabIndices[3*P2]+2]))
- return 0;
- else
- if(( TabVertices[3*TabIndices[3*P1+1]] == TabVertices[3*TabIndices[3*P2]]) &&
- (TabVertices[3*TabIndices[3*P1+1]+1] == TabVertices[3*TabIndices[3*P2]+1]) &&
- (TabVertices[3*TabIndices[3*P1+1]+2] == TabVertices[3*TabIndices[3*P2]+2]))
- return 0;
- else
- if( (TabVertices[3*TabIndices[3*P1+2]] == TabVertices[3*TabIndices[3*P2]]) &&
- (TabVertices[3*TabIndices[3*P1+2]+1] == TabVertices[3*TabIndices[3*P2]+1]) &&
- (TabVertices[3*TabIndices[3*P1+2]+2] == TabVertices[3*TabIndices[3*P2]+2]))
- return 0;
- else
- if( (TabVertices[3*TabIndices[3*P1+2]] == TabVertices[3*TabIndices[3*P2]]) &&
- (TabVertices[3*TabIndices[3*P1+2]+1] == TabVertices[3*TabIndices[3*P2]+1]) &&
- (TabVertices[3*TabIndices[3*P1+2]+2] == TabVertices[3*TabIndices[3*P2]+2]))
- return 0;
- else
- // ..........................
- return -1;
- }
- double deuxTrianglesPtsCommuns(int A, int B, int indice1, int indice2) {
- for(int i =0; i<nbPolys; i++) {
- for(int j =0; j<nbPolys; j++) {
- if(pointsEgaux(i,TabVoisins[3*j])==0){
- indice1 = i;
- indice2 = TabVoisins[3*j];
- }
- else if(pointsEgaux(i,TabVoisins[3*j+1])==0) {
- indice1 = i;
- indice2 = TabVoisins[3*j+1];
- }
- else if(pointsEgaux(i,TabVoisins[3*j+2])==0) {
- indice1 = i;
- indice2 = TabVoisins[3*j+2];
- }
- }
- }
- return 0;
- }
- /* void indicePointRestantTriangle(int A, int B, int oldNbPolys, int &C, int &D) {
- int passe = 1;
- for(int i = 0 ; i< oldNbPolys; i++) {
- if( (TabIndices[3*i] == A) && (TabIndices[3*i+1] ==B)) // Si triangle (A,B,X)
- {
- if(passe==1) {
- C = TabIndices[3*i+2] ;
- passe++; // on attribue X à C pour le premier triangle
- }
- else if(passe == 2)
- D = TabIndices[3*i+2] ; // sinon on attribue X à D pour le 2e triangle (cf schéma)
- }
- if( (TabIndices[3*i] == A) && (TabIndices[3*i+2] == B)) // Si triangle (A,X,B)
- {
- if(passe==1) {
- C = TabIndices[3*i+1];
- passe++; // on attribue X à C pour le premier triangle
- }
- else if(passe == 2)
- D = TabIndices[3*i+1]; // sinon on attribue X à D pour le 2e triangle (cf schéma)
- }
- if( (TabIndices[3*i+1] == A) && (TabIndices[3*i+2] == B)) // Si triangle (X,A,B)
- {
- if(passe==1) {
- C = TabIndices[3*i];
- passe++; // on attribue X à C pour le premier triangle
- }
- else if(passe == 2)
- D = TabIndices[3*i]; // sinon on attribue X à D pour le 2e triangle (cf schéma)
- }
- if( (TabIndices[3*i+2] == A) && (TabIndices[3*i+1] == B)) // Si triangle (X,B,A)
- {
- if(passe==1) {
- C = TabIndices[3*i];
- passe++; // on attribue X à C pour le premier triangle
- }
- else if(passe == 2)
- D = TabIndices[3*i]; // sinon on attribue X à D pour le 2e triangle (cf schéma)
- }
- if( (TabIndices[3*i+2] == A) && (TabIndices[3*i] == B)) // Si triangle (B,X,A)
- {
- if(passe==1) {
- C = TabIndices[3*i+1];
- passe++; // on attribue X à C pour le premier triangle
- }
- else if(passe == 2)
- D = TabIndices[3*i+1]; // sinon on attribue X à D pour le 2e triangle (cf schéma)
- }
- if( (TabIndices[3*i+1] == A) && (TabIndices[3*i] == B)) // Si triangle (B,A,X)
- {
- if(passe==1) {
- C = TabIndices[3*i+2];
- passe++; // on attribue X à C pour le premier triangle
- }
- else if(passe == 2)
- D = TabIndices[3*i+2]; // sinon on attribue X à D pour le 2e triangle (cf schéma)
- }
- }
- }
- */
- int indicePointRestantTriangle(int A, int B, int oldNbPolys, int C) {
- for(int i = 0 ; i< oldNbPolys; i++) {
- if( (TabIndices[3*i] == A) && (TabIndices[3*i+1] ==B) && (TabIndices[3*i+2]!=C)) // Si triangle (A,B,X)
- return TabIndices[3*i+2];
- if( (TabIndices[3*i] == A) && (TabIndices[3*i+2] == B) && (TabIndices[3*i+1]!=C)) // Si triangle (A,X,B)
- return TabIndices[3*i+1];
- if( (TabIndices[3*i+1] == A) && (TabIndices[3*i+2] == B) && (TabIndices[3*i]!=C)) // Si triangle (X,A,B)
- return TabIndices[3*i];
- if( (TabIndices[3*i+2] == A) && (TabIndices[3*i+1] == B) && (TabIndices[3*i]!=C)) // Si triangle (X,B,A)
- return TabIndices[3*i];
- if( (TabIndices[3*i+2] == A) && (TabIndices[3*i] == B) && (TabIndices[3*i+1]!=C)) // Si triangle (B,X,A)
- return TabIndices[3*i+1];
- if( (TabIndices[3*i+1] == A) && (TabIndices[3*i] == B) && (TabIndices[3*i+2]!=C)) // Si triangle (B,A,X)
- return TabIndices[3*i+2];
- }
- return -1;
- }
- double calculCoordButterFlyX(int A, int B) {
- return (TabVertices[A] + TabVertices[B]) / 2;
- }
- double calculCoordButterFly(int A, int B, int C, int D, int E, int F, int G, int H) {
- return ((TabVertices[A]/2) + TabVertices[B]/2 + TabVertices[C]/8 + TabVertices[D]/8 - TabVertices[G]/16 - TabVertices[H]/16 - TabVertices[F]/16 - TabVertices[E]/16);
- }
- void butterFly() {
- int oldNbPolys = nbPolys;
- nbPolys=nbPolys + 7*nbPolys;
- int oldNbPoints = nbPoints;
- nbPoints= nbPoints + 3*oldNbPolys;
- TabVertices = (float*) realloc(TabVertices, sizeof(float) * (3*nbPoints));
- TabIndices = (int*) realloc(TabIndices, sizeof(int) * (3*nbPolys));
- TabNormals = (float*) realloc(TabNormals, sizeof(int) * (3*nbPolys));
- TabVoisins = (int*) realloc(TabVoisins, sizeof(int)*(3*nbPolys));
- // Crée les sous triangles du centre
- int k = oldNbPolys;
- for(int i = 0; i< oldNbPolys; i++) {
- TabIndices[3*k] = oldNbPoints+3*i;
- TabIndices[3*k+1] = oldNbPoints+3*i+1;
- TabIndices[3*k+2] = oldNbPoints+3*i+2;
- /* std::cout<< TabIndices[3*k] <<std::endl;
- std::cout<< TabIndices[3*k+1]<<std::endl;
- std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;*/
- k++;
- }
- double x1, x2, x3;
- double y1, y2, y3;
- double z1, z2, z3;
- k = 2* oldNbPolys;
- for(int i = 0 ; i< oldNbPolys; i++) {
- // Pour chaque arrête du poly en question il faut faire le calcule suivant :
- // Chercher les deux sommets qui font partie des triangles qui contiennent A et B en sommets
- // premier sommet
- int A = TabIndices[3*i];
- int B = TabIndices[3*i+1];
- int C = TabIndices[3*i+2];
- // std::cout<<"Point A :"<<A<<" point B : "<<B<<" point C : "<<C<<"\n";
- int D = -1;
- int G = -1;
- int H = -1;
- int F = -1;
- int E = -1;
- D = indicePointRestantTriangle(A,B, oldNbPolys, C); // Point D, symétrique de C par rapport à AB
- G = indicePointRestantTriangle(D,B, oldNbPolys, A); // Point G, symétrique de A par rapport à DB
- H = indicePointRestantTriangle(A,D, oldNbPolys, B); // Point H, symétrique de B par rapport à AD
- F = indicePointRestantTriangle(A,C, oldNbPolys, B); // Point F, symétrique de B par rapport à AC
- E = indicePointRestantTriangle(C,B, oldNbPolys, A); // Point E, symétrique de A par rapport à CB
- x1 = calculCoordButterFly(3*(A) , 3*(B), 3*C, 3*D, 3*E, 3*F, 3*G, 3*H);
- y1 = calculCoordButterFly(3*(A)+1, 3*(B)+1, 3*C+1, 3*D+1, 3*E+1, 3*F+1, 3*G+1, 3*H+1);
- z1 = calculCoordButterFly(3*(A)+2, 3*(B)+2, 3*C+2, 3*D+2, 3*E+2, 3*F+2, 3*G+2, 3*H+2);
- TabVertices[3*TabIndices[3*(oldNbPolys+i)]] = x1;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)]+1] = y1;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)]+2] = z1;
- TabIndices[3*k] = TabIndices[3*(oldNbPolys+i)]; // Ajout triangle (A,B,MILIEU)
- TabIndices[3*k+1] = A;
- TabIndices[3*k+2] = B;
- k++;
- // second sommet
- A = TabIndices[3*i];
- B = TabIndices[3*i+2];
- C = TabIndices[3*i+1];
- //std::cout<<"Point A :"<<A<<" point B : "<<B<<" point C : "<<C<<"\n";
- D = -1;
- G = -1;
- H = -1;
- F = -1;
- E = -1;
- D = indicePointRestantTriangle(A,B, oldNbPolys, C); // Point D, symétrique de C par rapport à AB
- G = indicePointRestantTriangle(D,B, oldNbPolys, A); // Point G, symétrique de A par rapport à DB
- H = indicePointRestantTriangle(A,D, oldNbPolys, B); // Point H, symétrique de B par rapport à AD
- F = indicePointRestantTriangle(A,C, oldNbPolys, B); // Point F, symétrique de B par rapport à AC
- E = indicePointRestantTriangle(C,B, oldNbPolys, A); // Point E, symétrique de A par rapport à CB
- x2 = calculCoordButterFly(3*(A) , 3*(B), 3*C, 3*D, 3*E, 3*F, 3*G, 3*H);
- y2 = calculCoordButterFly(3*(A)+1, 3*(B)+1, 3*C+1, 3*D+1, 3*E+1, 3*F+1, 3*G+1, 3*H+1);
- z2 = calculCoordButterFly(3*(A)+2, 3*(B)+2, 3*C+2, 3*D+2, 3*E+2, 3*F+2, 3*G+2, 3*H+2);
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+1]] = x2;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+1]+1] = y2;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+1]+2] = z2;
- TabIndices[3*k] = TabIndices[3*(oldNbPolys+i)+1]; // Ajout triangle (A,B,MILIEU)
- TabIndices[3*k+1] = A;
- TabIndices[3*k+2] = B;
- k++;
- // troisieme sommet
- A = TabIndices[3*i+2];
- B = TabIndices[3*i+1];
- C = TabIndices[3*i];
- // std::cout<<"Point A :"<<A<<" point B : "<<B<<" point C : "<<C<<"\n";
- D = -1;
- G = -1;
- H = -1;
- F = -1;
- E = -1;
- D = indicePointRestantTriangle(A,B, oldNbPolys, C); // Point D, symétrique de C par rapport à AB
- G = indicePointRestantTriangle(D,B, oldNbPolys, A); // Point G, symétrique de A par rapport à DB
- H = indicePointRestantTriangle(A,D, oldNbPolys, B); // Point H, symétrique de B par rapport à AD
- F = indicePointRestantTriangle(A,C, oldNbPolys, B); // Point F, symétrique de B par rapport à AC
- E = indicePointRestantTriangle(C,B, oldNbPolys, A); // Point E, symétrique de A par rapport à CB
- x3 = calculCoordButterFly(3*(A) , 3*(B), 3*C, 3*D, 3*E, 3*F, 3*G, 3*H);
- y3 = calculCoordButterFly(3*(A)+1, 3*(B)+1, 3*C+1, 3*D+1, 3*E+1, 3*F+1, 3*G+1, 3*H+1);
- z3 = calculCoordButterFly(3*(A)+2, 3*(B)+2, 3*C+2, 3*D+2, 3*E+2, 3*F+2, 3*G+2, 3*H+2);
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+2]] = x3;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+2]+1] = y3;
- TabVertices[3*TabIndices[3*(oldNbPolys+i)+2]+2] = z3;
- TabIndices[3*k] = TabIndices[3*(oldNbPolys+i)+2]; // Ajout triangle (A,B,MILIEU)
- TabIndices[3*k+1] = A;
- TabIndices[3*k+2] = B;
- k++;
- // premier triangle
- TabIndices[3*k] = TabIndices[3*(oldNbPolys+i)];
- TabIndices[3*k+1] = TabIndices[3*(oldNbPolys+i)+1];
- TabIndices[3*k+2] = TabIndices[3*i+1];
- /* std::cout<<"premier triangle"<<std::endl;
- std::cout<< TabIndices[3*k] <<std::endl;
- std::cout<< TabIndices[3*k+1]<<std::endl;
- std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;*/
- k++;
- // deuxieme triangle
- TabIndices[3*k] = TabIndices[3*(oldNbPolys+i)];
- TabIndices[3*k+1] = TabIndices[3*i];
- TabIndices[3*k+2] = TabIndices[3*(oldNbPolys+i)+2];
- /* std::cout<<"deuxieme triangle"<<std::endl;
- std::cout<< TabIndices[3*k] <<std::endl;
- std::cout<< TabIndices[3*k+1]<<std::endl;
- std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;*/
- k++;
- // troisieme triangle
- TabIndices[3*k] = TabIndices[3*i+2];
- TabIndices[3*k+1] = TabIndices[3*(oldNbPolys+i)+1];
- TabIndices[3*k+2] = TabIndices[3*(oldNbPolys+i)+2];
- /* std::cout<<"troisieme triangle"<<std::endl;
- std::cout<< TabIndices[3*k] <<std::endl;
- std::cout<< TabIndices[3*k+1]<<std::endl;
- std::cout<< TabIndices[3*k+2]<<std::endl<<std::endl;*/
- k++;
- }
- // Reajustement des normales
- calculNormalesAuxTriangles(nbPolys);
- // Recalcul des voisins
- fillVoisinTab(TabIndices, TabVoisins, nbPolys);
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- // Fonction que vous allez modifier afin de dessiner
- /////////////////////////////////////////////////////////////////////////////////////////
- void render_scene()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glColor3f(1.0, 1.0, 0.0); // RED
- //computeDiedreAngle(0, 78);
- //computeDiedreAngle(0,1);
- if(testRafinement == RAFINEMENT)
- rafinementMaillage();
- testRafinement = -1;
- if(testButterfly == BUTTERFLY)
- butterFly();
- testButterfly = -1;
- /* Point* ct = new Point(sizefenetreX/2,sizefenetreY/2,sizefenetreZ/2);
- double l = sizefenetreX ;
- Octree* o = new Octree(ct, l);
- o->displayV();*/
- /*
- std::cout<<"Taille TabVertices : "<<sizeof(TabVertices) / sizeof(TabVertices[0]);
- std::cout<<"Taille TabIndices : "<<sizeof(TabIndices) / sizeof(TabIndices[0]);*/
- // gluLookAt(0,0,-1,0,0,0,0,1,0);
- gluLookAt( xp, 0.0f, zp, xp+lxp, 0.0f, zp+lzp, 0.0f, 0.25f, 0.0f);
- GLfloat lightColor0[] = {1.0f, 1.0f, 1.0f, 1.0f};
- GLfloat lightPos0[] = {3.0f, 10.0f, 3.0f, 1.0f};
- GLfloat Lt0spec[] = {1.0, 1.0, 1.0, 1.0};
- GLfloat ambient0[] = {0.1, 0.1, 0.1, 1.0};
- glLightfv(GL_LIGHT0, GL_POSITION, lightPos0);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0);
- glLightfv(GL_LIGHT0, GL_SPECULAR, Lt0spec);
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
- GLfloat lightColor1[] = {1.0f, 1.0f, 1.0f, 1.0f};
- GLfloat lightPos1[] = {-3.0f, 10.0f, -3.0f, 1.0f};
- glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);
- glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1);
- glLightfv(GL_LIGHT1, GL_SPECULAR, Lt0spec);
- glLightfv(GL_LIGHT1, GL_AMBIENT, ambient0);
- glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
- /* glColorMaterial (GL_FRONT_AND_BACK, GL_SPECULAR);*/
- glEnable (GL_COLOR_MATERIAL);
- glEnableClientState (GL_VERTEX_ARRAY);
- glEnableClientState (GL_NORMAL_ARRAY);
- glVertexPointer (3, GL_FLOAT, 0, TabVertices);
- glNormalPointer(GL_FLOAT, 0, TabNormals);
- if(testFill == FILL)
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glDrawElements (GL_TRIANGLES, 3*(nbPolys), GL_UNSIGNED_INT, TabIndices);
- glDisableClientState (GL_VERTEX_ARRAY);
- glDisableClientState (GL_NORMAL_ARRAY);
- /* if(image_gaussienne == IMG_GAUSS)
- constructImgGauss();*/
- glPointSize(6);
- //testAretesVives(91, Vector (0, 0, 255));
- int profondeur = 1500;
- std::vector<int>* triangleTraites = new std::vector<int>();
- // segmentationByProgagation(triangleTraites, 3, Vector (0, 255, 255), 0, profondeur); // quart du côté du socle en bleu clair
- if(testSeg>0)
- segmentationByProgagation(triangleTraites, 1, Vector (0, 255, 0), 0, profondeur); // cercle du dessus du socle en vert
- if(testSeg>1)
- segmentationByProgagation(triangleTraites, 0, Vector (0, 255, 255), 0, profondeur); // cercle du dessous du socle en jaune
- if(testSeg>2)
- segmentationByProgagation(triangleTraites, 1000, Vector (0, 0, 255), 0, profondeur); // sphere en haut en bleu
- if(testSeg>3)
- segmentationByProgagation(triangleTraites, 103, Vector (255, 0, 255), 0, profondeur); // premier creux
- if(testSeg>4)
- segmentationByProgagation(triangleTraites, 1753, Vector (255, 0, 255), 0, profondeur); // deuxieme creux
- if(testSeg>5)
- segmentationByProgagation(triangleTraites, 1700, Vector (255, 255, 0), 0, profondeur); // tube
- glutSwapBuffers();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement