Logo Search packages:      
Sourcecode: k3dsurf version File versions  Download package

Model3D.cpp

/***************************************************************************
 *   Copyright (C) 2005 by Abderrahman Taha                                *
 *                                                                         *
 *                                                                         *
 *   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 for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
#include <qpixmap.h>
#include "Model3D.h"

using std::vector;
using std::list;


void Model3D::twistex(double nb_twiste, double coeff_rayon) {
double rayon = coeff_rayon;// *sqrt(DIFY_save*DIFY_save + DIFZ_save*DIFZ_save);
/*
      expression_Y = expression_Y_save+" + "+
    QString::number(rayon)+
    " * cos(("+expression_X_save+" - "+
    QString::number(MINX_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFX_save)+")";
      
      
      expression_Z = expression_Z_save+" + "+
    QString::number(rayon)+
    " * sin(("+expression_X_save+" - "+
    QString::number(MINX_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFX_save)+")"; 

*/
      expression_Y = QString::number(rayon)+" * ("+expression_Y_save+
    " * cos(("+expression_X_save+" - "+
    QString::number(MINX_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFX_save)+") - "+
    expression_Z_save+" * sin(("+expression_X_save+" - "+
    QString::number(MINX_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFX_save)+"))  ";
    
      expression_Z = QString::number(rayon)+" * ("+expression_Y_save+
    " * sin(("+expression_X_save+" - "+
    QString::number(MINX_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFX_save)+") + "+
    expression_Z_save+" * cos(("+expression_X_save+" - "+
    QString::number(MINX_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFX_save)+"))  ";    
    
    
    expression_X = expression_X_save;


      
      fct_calcul3();
      
}  

void Model3D::twistey(double nb_twiste, double coeff_rayon) {
double rayon = coeff_rayon;//*sqrt(DIFX_save*DIFX_save + DIFZ_save*DIFZ_save);      
/*
      expression_X = expression_X_save+" + "+
    QString::number(rayon)+
    " * cos(("+expression_Y_save+" - "+
    QString::number(MINY_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFY_save)+")";
      
      
      expression_Z = expression_Z_save+" + "+
    QString::number(rayon)+
    " * sin(("+expression_Y_save+" - "+
    QString::number(MINY_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFY_save)+")"; 
*/


      expression_X = QString::number(rayon)+" * ("+expression_X_save+
    " * cos(("+expression_Y_save+" - "+
    QString::number(MINY_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFY_save)+") - "+
    expression_Z_save+" * sin(("+expression_Y_save+" - "+
    QString::number(MINY_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFY_save)+"))  ";
    
      expression_Z = QString::number(rayon)+" * ("+expression_X_save+
    " * sin(("+expression_Y_save+" - "+
    QString::number(MINY_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFY_save)+") + "+
    expression_Z_save+" * cos(("+expression_Y_save+" - "+
    QString::number(MINY_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFY_save)+"))  ";    
    
    
    expression_Y = expression_Y_save;



      
      fct_calcul3();
      
}  

  
void Model3D::twistez(double nb_twiste, double coeff_rayon) {
 double rayonz = coeff_rayon;// *sqrt(DIFX_save*DIFX_save + DIFY_save*DIFY_save);   
/*
      expression_X = expression_X_save+" + "+
    QString::number(rayon)+
    " * cos(("+expression_Z_save+" - "+
    QString::number(MINZ_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFZ_save)+")";

      
      expression_Y = expression_Y_save+" + "+
    QString::number(rayon)+
    " * sin(("+expression_Z_save+" - "+
    QString::number(MINZ_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFZ_save)+")";

      expression_Z = expression_Z_save;
*/

      expression_X = QString::number(rayonz)+" * ("+expression_X_save+
    " * cos(("+expression_Z_save+" - "+
    QString::number(MINZ_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFZ_save)+") - "+
    expression_Y_save+" * sin(("+expression_Z_save+" - "+
    QString::number(MINZ_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFZ_save)+"))  ";
    
      expression_Y = QString::number(rayonz)+" * ("+expression_X_save+
    " * sin(("+expression_Z_save+" - "+
    QString::number(MINZ_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFZ_save)+") + "+
    expression_Y_save+" * cos(("+expression_Z_save+" - "+
    QString::number(MINZ_save)+")*2*pi*"+QString::number(nb_twiste)+"/"+
    QString::number(DIFZ_save)+"))  ";    
    
    
    expression_Z = expression_Z_save;



      
    fct_calcul3();
      
}  

00160 void Model3D::scalex(int coeff) {
 newscalex = (double)coeff/(double)10; ///(double)(oldcoeff);
    
    if(newscalex != 1)
      expression_X = QString::number(newscalex)+"*("+expression_X_save+")";
      else expression_X = expression_X_save;
      
      if(newscaley != 1)
    expression_Y = QString::number(newscaley)+"*("+expression_Y_save+")";
    else expression_Y = expression_Y_save;
    
    if(newscalez != 1)
    expression_Z = QString::number(newscalez)+"*("+expression_Z_save+")";
    else expression_Z = expression_Z_save;
        
      fct_calcul3();        
      
}

00179 void Model3D::scaley(int coeff) {
    newscaley = (double)coeff/(double)10; ///(double)(oldcoeff);
    
    if(newscalex != 1)
      expression_X = QString::number(newscalex)+"*("+expression_X_save+")";
      else expression_X = expression_X_save;
      
      if(newscaley != 1)
    expression_Y = QString::number(newscaley)+"*("+expression_Y_save+")";
    else expression_Y = expression_Y_save;
    
    if(newscalez != 1)
    expression_Z = QString::number(newscalez)+"*("+expression_Z_save+")";
    else expression_Z = expression_Z_save;
    
          
  
      fct_calcul3();
}

00199 void Model3D::scalez(int coeff) {
    newscalez = (double)coeff/(double)10; ///(double)(oldcoeff);
    
    if(newscalex != 1)
      expression_X = QString::number(newscalex)+"*("+expression_X_save+")";
      else expression_X = expression_X_save;
      
      if(newscaley != 1)
    expression_Y = QString::number(newscaley)+"*("+expression_Y_save+")";
    else expression_Y = expression_Y_save;
    
    if(newscalez != 1)
    expression_Z = QString::number(newscalez)+"*("+expression_Z_save+")";
    else expression_Z = expression_Z_save;
    
       
      fct_calcul3();
}

void Model3D::initialisecoeffscale(){
    newscalex = newscaley = newscalez = 1; 
      }
      
/*****************************************************************************/
/*****************************************************************************/

   Model3D::Model3D( )
        {
         //=========== La premiere figure " klein" a dessiner au lancement======
        nb_licol = 25;
        backtrans  = -1; 
          fronttrans = -1;
          /*
        for (int j=0; j < 100; j++)
            for (int i=0; i < 200 ; i++) 
                  tableaureferences[j*(99) + i] = new QPointArray(4);
        */
        for (int j=0; j < 20000; j++)
           tableaureferences[j] = new QPointArray(4);
        tableau = new Prop_poly[2* 100 * 100];
      //anglex = angley = (double) 60;

        expression_X = "(3*(1+sin(v)) + 2*(1-cos(v)/2)*cos(u))*cos(v)"; 
          expression_Y = "(4+2*(1-cos(v)/2)*cos(u))*sin(v)";
        expression_Z = "-2*(1-cos(v)/2) * sin(u)";    
        inf_u        = "0";
        sup_u        = "2*pi";
        inf_v        = "0";
        sup_v        = "pi";
/*
sm1="0"; sa_1="1"; sb_1="1"; sn1_1="0.48"; sn2_1="30.25"; sn3_1="0.35";
sm2="5"; sa_2="1"; sb_2="1"; sn1_2="15.44"; sn2_2="-0.45"; sn3_2="87";
        inf_u        = "-pi";
        sup_u        = "pi";
        inf_v        = "-pi/2";
        sup_v        = "pi/2";
*/        
        
      two_system = 1;  //risky 
      
        expression_X_2 = "3*(1+sin(v))*cos(v) - 2*(1-cos(v)/2)*cos(u)";
          expression_Y_2 = "4*sin(v)";
          expression_Z_2 = "-2*(1-cos(v)/2)* sin(u)";
        inf_u_2        = "0";
        sup_u_2        = "2*pi";
        inf_v_2        = "pi";
        sup_v_2        = "2*pi";

      keyboard ="";
      coupure_ligne = coupure_col = 0;
      
    backsurfr = 249;
      backsurfg = 170;
    backsurfb = 0;
      
    frontsurfr = 0;
      frontsurfg = 210;
    frontsurfb = 0;


        gridliner = 0;
        gridlineg = 100;
        gridlineb = 4;


    initialiser_palette();
      initialiser_parametres3();
      initialiser_parseur3();
      parse_expression();
      calcul_objet3();  // Utilisation du parseur..
    boite_englobante3();
      normalisation3(); // Calcul des normales
      
      mat.unit(); // On applique la matrice unite a la matrice principale 3D
      mat4D.unit(); // On applique la matrice unite a la matrice principale 4D
      rotation3();      // rotation de l'objet....
      homothetie3();    // pour faire entrer l'objet ds la boite englobante..
      calcul_points3(); // On applique la rotation et l'homothetie      

           }
         
/*****************************************************************************/
/*****************************************************************************/


void Model3D::initialiser_parametres3() {
// Incredible...gcc don't complain for "," caractere...
        nb_ligne = nb_licol; 
        nb_colone = nb_licol;
      largeur_fenetre = hauteur_fenetre = 650; 
      demi_hauteur = hauteur_fenetre/2;
      demi_largeur = largeur_fenetre/2;
      //facteur = (double)1.0;                    
        Oprime[0]=(double)0.0;
        Oprime[1]=(double)0.0;
        Oprime[2]=(double)800.0;
        D=460; 
        coefficient =  1.0f ;
      mesh = 1, box = 1; clipping =1; morph_param = 1; step = 0.1;
      DefineNewFct = -1, infos =1, latence = 30; implicitdef = -1; 
      fourdimshapes = -1; fivedimshapes = -1; sixdimshapes = -1; 
      sphericaldef = -1; cylindricaldef = -1;
      zbuffer_active_ok = -1;
      zbuffer_quality   = 5; //maximum
      
        there_is_condition = -1; // No condition imposed to the ploting
      //condition_expression = "(x^2 + y^2 + z^2) > 1";
      condition_expression = "((x^2 + y^2) > 0.05) & ((t*x+y+z) > -1) ";
      //condition_expression = "((x+y+z) > 0.004)";
      //condition_expression = "(x+y+z) > 1";
        precision = 10; //used for calculating points to replace hidden points
                      //equivalent to a grid with (nb_ligne * precision) points
      there_is_hidden_points = -1; // there is no hidden points
      draw_hidden_poly_and_nonhidden = -1;
      draw_cond_mesh = 1;
      draw_poly_normals    = -1;
      two_separate_objects = -1;  // we have one object
      change_first_object  =  1;  // draw first object
      change_second_object =  1;  // draw second object
      showhelp = -1;
      supershape = -1;
      
      center[0] = center[1] = center[2] = 0;
    exterior_surface = 1; 
      interior_surface = 1;
      independantwindow = -1;
      tetaxy = 3; tetaxz = 3; tetayz = 3; 
      tetaxw = 3; tetayw = 3; tetazw = 3; 
      tetaxt = 3; tetayt = 3; tetazt = 3; tetawt = 3;
      tetaxs = 3; tetays = 3; tetazs = 3; tetaws = 3; tetats = 3; 
      tetaxy_ok = -1; tetaxz_ok = -1; tetayz_ok = -1;
      tetaxw_ok = -1; tetayw_ok = -1; tetazw_ok = -1;
      tetaxt_ok = -1; tetayt_ok = -1; tetazt_ok = -1; tetawt_ok = -1;
      tetaxs_ok = -1; tetays_ok = -1; tetazs_ok = -1; tetaws_ok = -1; tetats_ok = -1;
      // initialisation des matrices 3D
        mat = Matrix3D();
      mat_first_obj  = Matrix3D();
      mat_second_obj = Matrix3D();
      mat_rotation_first_save   = Matrix3D();
      mat_rotation_second_save  = Matrix3D();
        
      mat_rotation      = Matrix3D();
        mat_rotation_save = Matrix3D();
        mat_homothetie    = Matrix3D();
        mat_translation   = Matrix3D();
        mat_inversetranslation = Matrix3D();
      
      // initialisation des matrices 4D
        mat4D                    = Matrix4D();
        mat_rotation4D           = Matrix4D();
        mat_rotation_save4D      = Matrix4D();
        mat_homothetie4D         = Matrix4D();
        mat_translation4D        = Matrix4D();
        mat_inversetranslation4D = Matrix4D();
      
      // initialisation des matrices 5D
        mat5D                    = Matrix5D();
        mat_rotation5D           = Matrix5D();
        mat_rotation_save5D      = Matrix5D();
        mat_homothetie5D         = Matrix5D();
        mat_translation5D        = Matrix5D();
        mat_inversetranslation5D = Matrix5D();  
      
      // initialisation des matrices 6D
        mat6D                    = Matrix6D();
        mat_rotation6D           = Matrix6D();
        mat_rotation_save6D      = Matrix6D();
        mat_homothetie6D         = Matrix6D();
        mat_translation6D        = Matrix6D();
        mat_inversetranslation6D = Matrix6D();  
      
      }

/*****************************************************************************/
/*****************************************************************************/  
 void Model3D::initialiser_palette(){

 int i;

 double  coef;



 for(i=0; i<256; i++) {

 coef = (double)i/256;

 

 palette_front_face[i] = QBrush(QColor((int)((double)(frontsurfr)*coef), (int)((double)(frontsurfg)*coef), (int)((double)(frontsurfb)*coef)));

 palette_back_face[i] = QBrush(QColor((int)((double)(backsurfr)*coef), (int)((double)(backsurfg)*coef),(int)((double)(backsurfb)*coef)));

 palette_cond_face[i] = QBrush(QColor((int)((double)(250)*coef),0,0));

 if(fronttrans == 1)  palette_front_face[i].setStyle(Qt::Dense6Pattern);

 if(backtrans  == 1)  palette_back_face[i].setStyle(Qt::Dense6Pattern); 

 }



 

 } 
 
/*****************************************************************************/
/*****************************************************************************/  


00430 void Model3D::tracer3(QPainter & g) {
      int i, j, poly_courant, tmp, nb_poly, nb_valid_pts;
      double a4, cosinus, c4, z_tmp;
//list<Prop_poly *>::iterator itVectorData;  // List slower thant Vector !!!!!!
vector<Prop_poly *>::iterator itVectorData;

// memory reservation
vecteur_poly.reserve(nb_licol*nb_licol +1);
moitie_colone = (int)(nb_colone/2);




if (box ==1) {





for (i=0; i<4; i++) {

c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(i,
                              (int)(c4*boiteenglobante[i*3]  +demi_hauteur),
                              (int)(c4*boiteenglobante[i*3+1]+demi_largeur));



}



g.setPen(QColor(0, 0, 250));
g.drawPolygon(*tableaureferences[0]);

/******************************************************************/




for (i=4; i<8; i++) {

c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(i-4,
                              (int)(c4*boiteenglobante[i*3] +demi_hauteur), 
                              (int)(c4*boiteenglobante[i*3 + 1]+demi_largeur));



}


g.setPen(QColor(0, 0, 250));
g.drawPolygon(*tableaureferences[0]);



/******************************************************************/



for (i=0; i<2; i++) {

c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(i,
                            (int)(c4*boiteenglobante[i*3]+demi_hauteur),
                            (int)(c4*boiteenglobante[i*3+1]+demi_largeur));

}



i = 5; 
c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(2,
                            (int)(c4*boiteenglobante[i*3]+demi_hauteur),
                            (int)(c4*boiteenglobante[i*3+1]+demi_largeur));



i = 4;

c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(3,
                            (int)(c4*boiteenglobante[i*3]+demi_hauteur),
                            (int)(c4*boiteenglobante[i*3+1]+demi_largeur));



g.setPen(QColor(250,0, 0));
g.drawPolygon(*tableaureferences[0]);





//================================================

g.setPen(QColor(250,250,0));
g.drawText(tableaureferences[0]->at(2).x() ,

         tableaureferences[0]->at(2).y()+12,
           inf_u);
g.drawText(tableaureferences[0]->at(3).x(),
           tableaureferences[0]->at(3).y()+12,
           "U="+sup_u);

g.setPen(QColor(0,250,250));

g.drawText(tableaureferences[0]->at(3).x()-12,

         tableaureferences[0]->at(3).y(),
           inf_v);
g.drawText(tableaureferences[0]->at(0).x()-12,
           tableaureferences[0]->at(0).y(),
           "V="+sup_v);



//================================================



for (i=2; i<4; i++) {

c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(i-2,
(int)(c4*boiteenglobante[i*3    ]  +demi_hauteur),
(int)(c4*boiteenglobante[i*3 + 1]  +demi_largeur));


}


i = 7; 

c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(2,
(int)(c4*boiteenglobante[i*3]+demi_hauteur),
(int)(c4*boiteenglobante[i*3+1]+demi_largeur));



i = 6;

c4 = D/(boiteenglobante[i*3 +2]-Oprime[2]);

tableaureferences[0]->setPoint(3,
(int)(c4*boiteenglobante[i*3]+demi_hauteur),
(int)(c4*boiteenglobante[i*3+1]+demi_largeur));



g.setPen(QColor(10,200,200));
g.drawPolygon(*tableaureferences[0]);

}

// End of if(box ==1)



//=====================================================

// Map projection...

//if(mesh ==1) {


for ( i=0; i < nb_ligne - coupure_ligne; ++i)
      for ( j=0; j < nb_colone - coupure_col  ; ++j) {
c4 = D/(Tre[i*3+2][j]-Oprime[2]);
Tre3[i*3  ][j] = c4*Tre[i*3    ][j]  +demi_hauteur;
Tre3[i*3+1][j] = c4*Tre[i*3 + 1][j]  +demi_largeur;
Tre3[i*3+2][j] = Tre[i*3 + 2][j];
}





//=======================================================

if(draw_poly_normals == 1) {
for ( i=0; i < nb_ligne - coupure_ligne; ++i)
      for ( j=0; j < nb_colone - coupure_col  ; ++j) {
Nor3[i*3  ][j] = 20*Nor[i*3    ][j] + Tre[i*3    ][j];
Nor3[i*3+1][j] = 20*Nor[i*3 + 1][j] + Tre[i*3 + 1][j];
Nor3[i*3+2][j] = 20*Nor[i*3 + 2][j] + Tre[i*3 + 2][j];
}                     
                     
for ( i=0; i < nb_ligne - coupure_ligne; ++i)
      for ( j=0; j < nb_colone - coupure_col  ; ++j) {
c4 = D/(Nor3[i*3+2][j]-Oprime[2]);
Nor3[i*3  ][j] = c4*Nor3[i*3    ][j]  ;
Nor3[i*3+1][j] = c4*Nor3[i*3 + 1][j]  ;
//Nor3[i*3+2][j] = Nor3[i*3 + 2][j];
}

}

//=======================================================





// We verify if there is a condition...if yes, we compute
// projections of arrays DR, DL, HR, HL
if(there_is_condition == 1) {
                      
for ( i=0; i < nb_ligne - coupure_ligne; ++i)
      for ( j=0; j < nb_colone - coupure_col  ; ++j) 
    if(hidden_points[i][j] == 0){

//DR
c4 = D/(DR[i*3+2][j]-Oprime[2]);
DR3[i*3  ][j] = c4*DR[i*3    ][j]  +demi_hauteur;
DR3[i*3+1][j] = c4*DR[i*3 + 1][j]  +demi_largeur;
DR3[i*3+2][j] =    DR[i*3 + 2][j];

//DL
c4 = D/(DL[i*3+2][j]-Oprime[2]);
DL3[i*3  ][j] = c4*DL[i*3    ][j]  +demi_hauteur;
DL3[i*3+1][j] = c4*DL[i*3 + 1][j]  +demi_largeur;
DL3[i*3+2][j] =    DL[i*3 + 2][j];

//HR
c4 = D/(HR[i*3+2][j]-Oprime[2]);
HR3[i*3  ][j] = c4*HR[i*3    ][j]  +demi_hauteur;
HR3[i*3+1][j] = c4*HR[i*3 + 1][j]  +demi_largeur;
HR3[i*3+2][j] =    HR[i*3 + 2][j];

//HL
c4 = D/(HL[i*3+2][j]-Oprime[2]);
HL3[i*3  ][j] = c4*HL[i*3    ][j]  +demi_hauteur;
HL3[i*3+1][j] = c4*HL[i*3 + 1][j]  +demi_largeur;
HL3[i*3+2][j] =    HL[i*3 + 2][j];



} 
                      } // End of if(there_is_condition == 1)...


//=================================================================

if(draw_poly_normals == 1)
for ( i=0; i < nb_ligne - 1 - coupure_ligne; ++i)
for ( j=0; j < nb_colone - 1 - coupure_col  ; ++j)
{  
poly_courant = j*(nb_ligne-1 ) + i;
Nor3[i*3  ][j] = -30 * Nor[i*3    ][j]  + Tre[i*3    ][j];
Nor3[i*3+1][j] = -30 * Nor[i*3 + 1][j]  + Tre[i*3 + 1][j];
Nor3[i*3+2][j] = -30 * Nor[i*3 + 2][j]  + Tre[i*3 + 2][j];

c4 = D/(Nor3[i*3+2][j]-Oprime[2]);
Nor3[i*3  ][j] = c4*Nor3[i*3    ][j] +demi_hauteur;
Nor3[i*3+1][j] = c4*Nor3[i*3 + 1][j] +demi_largeur;
                                             
tableau[poly_courant].Norx = (int)Nor3[i*3   ][j];
tableau[poly_courant].Nory = (int)Nor3[i*3 +1][j];

tableau[poly_courant + 10000].Norx = (int)Nor3[i*3   ][j];
tableau[poly_courant + 10000].Nory = (int)Nor3[i*3 +1][j];
}

//=================================================================



//================================================

 moitie_colone = (int)(nb_colone/2);
 
 
if(there_is_condition != 1 || implicitdef == 1) {
 
/// construction of polygones : first case --> No hidden points
if(there_is_hidden_points == -1) {

for ( i=0; i < nb_ligne - 1 - coupure_ligne; ++i)
for ( j=0; j < nb_colone - 1 - coupure_col  ; ++j)
 if(two_separate_objects == -1 || j != (moitie_colone -2))  ///two separate shapes  
if((z_tmp=Tre[i*3+2][j]+Tre[(i+1)*3+2][j]+Tre[i*3+2][j+1]+Tre[(i+1)*3+2][j+1])/4 < 460 ||
 clipping == -1 )
 {

/// Cette partie calcule le vecteur normalise qui vient de l'observateur            

a4= (double)sqrt(
     (Oprime[0]-Tre[i*3  ][j] )*(Oprime[0]-Tre[i*3  ][j] )
    +(Oprime[1]-Tre[i*3+1][j] )*(Oprime[1]-Tre[i*3+1][j] ) 
    +(Oprime[2]-Tre[i*3+2][j] )*(Oprime[2]-Tre[i*3+2][j] ));

/// Just in case...must be changed
if( a4 > 0.00000001) {    
Obser[0]=(Oprime[0]-Tre[i*3  ][j] )/a4;
Obser[1]=(Oprime[1]-Tre[i*3+1][j] )/a4;
Obser[2]=(Oprime[2]-Tre[i*3+2][j] )/a4;   
}

cosinus=(((Obser[0]*Nor[i*3  ][j])+(Obser[1]*Nor[i*3+1][j])+(Obser[2]*Nor[i*3+2][j]))/(1));
/// Just in case...must be changed
if(cosinus >1 ) cosinus = 1;
if(cosinus < -1) cosinus = -1;
/*
tableau[poly_courant].Norx = (int)Nor3[i*3  ][j];
tableau[poly_courant].Nory = (int)Nor3[i*3+1][j];
*/
///                      TRIAGE des POLYGONES
///========== triage des polygone selon leurs veleurs Z et creation d'une liste
///========== de polygones TRIES qu'on utilisera apres pour l'affichage final.


poly_courant = j*(nb_ligne-1 ) + i;

tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));

tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));




///=============  Triage des polygones selon la valeurs de leurs profondeurs Z====

 
 itVectorData = vecteur_poly.begin();
 tmp=0; 




 nb_poly = vecteur_poly.size();
if( nb_poly > 0)
{ 
           while( tmp < nb_poly) {   
         
               if( z_tmp < vecteur_poly[tmp]->valeur_z )
  {

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;   
   

  vecteur_poly.insert(itVectorData, &tableau[poly_courant]);
  tmp = nb_poly ;

  }
  
  else   {
      if( tmp==(nb_poly -1)) {

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;   


  vecteur_poly.push_back(&tableau[poly_courant]);
  tmp = nb_poly ;
                             }
      else    {     
      tmp++ ;
      itVectorData++;
      }

                      }


                      }

}
else { 
  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;     
  vecteur_poly.push_back(&tableau[poly_courant]);
}
                }
} /// End of if(there_is_hidden_points == -1)


/// here we have some hidden points to deal with...
else {

for ( i=0; i < nb_ligne - 1 - coupure_ligne; ++i)
for ( j=0; j < nb_colone - 1 - coupure_col  ; ++j)
      if( (nb_valid_pts = 
         (hidden_points[i][j]     +  
          hidden_points[i+1][j]   +  
        hidden_points[i+1][j+1] + 
        hidden_points[i][j+1])  )  >=3)  

    if(two_separate_objects == -1 || j != (moitie_colone -2))     ///two separate shapes  

if((z_tmp=Tre[i*3+2][j]+Tre[(i+1)*3+2][j]+Tre[i*3+2][j+1]+Tre[(i+1)*3+2][j+1])/4 < 460 ||
 clipping == -1 )
 {

/// Cette partie calcule le vecteur normalise qui vient de l'observateur            

a4= (double)sqrt(
     (Oprime[0]-Tre[i*3  ][j] )*(Oprime[0]-Tre[i*3  ][j] )
    +(Oprime[1]-Tre[i*3+1][j] )*(Oprime[1]-Tre[i*3+1][j] ) 
    +(Oprime[2]-Tre[i*3+2][j] )*(Oprime[2]-Tre[i*3+2][j] ));

/// Just in case...must be changed
if( a4 > 0.00000001) {    
Obser[0]=(Oprime[0]-Tre[i*3  ][j] )/a4;
Obser[1]=(Oprime[1]-Tre[i*3+1][j] )/a4;
Obser[2]=(Oprime[2]-Tre[i*3+2][j] )/a4;   
}

cosinus=(((Obser[0]*Nor[i*3  ][j])+(Obser[1]*Nor[i*3+1][j])+(Obser[2]*Nor[i*3+2][j]))/(1));
/// Just in case...must be changed
if(cosinus >1 ) cosinus = 1;
if(cosinus < -1) cosinus = -1;
/*
tableau[poly_courant].Norx = (int)Nor3[i*3  ][j];
tableau[poly_courant].Nory = (int)Nor3[i*3+1][j];
*/
///                      TRIAGE des POLYGONES
///========== triage des polygone selon leurs veleurs Z et creation d'une liste
///========== de polygones TRIES qu'on utilisera apres pour l'affichage final.


poly_courant = j*(nb_ligne-1 ) + i;

if(nb_valid_pts == 4){
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));

tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));

} else { 

if(hidden_points[i][j] == 0) {

tableaureferences[poly_courant]->setPoint(0,
                                         (int)((Tre3[i*3   ][j+1]+Tre3[(i+1)*3   ][j])/2),
                                         (int)((Tre3[i*3 +1][j+1] + Tre3[(i+1)*3 +1][j])/2));

tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));

}

else if(hidden_points[i+1][j] == 0) {
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(  (Tre3[i*3][j] + Tre3[(i+1)*3][j+1] )/2),
                                         (int)(  (Tre3[i*3 +1][j] + Tre3[(i+1)*3 +1][j+1])/2));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));
     }

else if(hidden_points[i+1][j+1] == 0) {

tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)((Tre3[(i+1)*3][j] +Tre3[i*3][j+1] )/2),
                                         (int)((Tre3[(i+1)*3 +1][j] + Tre3[i*3 +1][j+1])/2));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));

}

else {

tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)((Tre3[(i+1)*3][j+1] + Tre3[i*3][j])/2),
                                         (int)((Tre3[(i+1)*3 +1][j+1] +Tre3[i*3 +1][j] )/2));
}

}


//=============  Triage des polygones selon la valeurs de leurs profondeurs Z====

 tmp=0;
 itVectorData = vecteur_poly.begin();



 
 nb_poly = vecteur_poly.size();
if( nb_poly > 0)
{  /// z_tmp= Tre[i*3+2][j]+ Tre[(i+1)*3+2][j]+ Tre[i*3+2][j+1]+ Tre[(i+1)*3+2][j+1];
           while( tmp < nb_poly) {   
         
               if( z_tmp < vecteur_poly[tmp]->valeur_z )
               //if( z_tmp < (*itVectorData)->valeur_z )
  {

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;   
   

  vecteur_poly.insert(itVectorData, &tableau[poly_courant]);
  tmp = nb_poly ;

  }
  
  else   {
      if( tmp==(nb_poly -1)) {

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;   


  vecteur_poly.push_back(&tableau[poly_courant]);
  tmp = nb_poly ;
                             }
      else    {     
      tmp++ ;
      itVectorData++;
      }

                      }


                      }

}
else { 
//
  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;   
  
  vecteur_poly.push_back(&tableau[poly_courant]);


}


}
}

} // End of if(there_is_condition != 1)....
/// Fin de la construction du vecteur de polygones tri�.




































/// cette partie doit etre changee pour fusionner avec ce qui vient en bas (
/// quant ca va etre test�et optimiser.
 
else {
     
     
/*     
//=================================================================

if(draw_poly_normals == 1)
for ( i=0; i < nb_ligne - 1 - coupure_ligne; ++i)
for ( j=0; j < nb_colone - 1 - coupure_col  ; ++j)
{  
poly_courant = j*(nb_ligne-1 ) + i;
Nor3[i*3  ][j] = -30 * Nor[i*3    ][j]  + Tre[i*3    ][j];
Nor3[i*3+1][j] = -30 * Nor[i*3 + 1][j]  + Tre[i*3 + 1][j];
Nor3[i*3+2][j] = -30 * Nor[i*3 + 2][j]  + Tre[i*3 + 2][j];

c4 = D/(Nor3[i*3+2][j]-Oprime[2]);
Nor3[i*3  ][j] = c4*Nor3[i*3    ][j] +demi_hauteur;
Nor3[i*3+1][j] = c4*Nor3[i*3 + 1][j] +demi_largeur;
                                             
tableau[poly_courant].Norx = (int)Nor3[i*3   ][j];
tableau[poly_courant].Nory = (int)Nor3[i*3 +1][j];

tableau[poly_courant + 10000].Norx = (int)Nor3[i*3   ][j];
tableau[poly_courant + 10000].Nory = (int)Nor3[i*3 +1][j];
}

//=================================================================
*/     
     
     
for ( i=0; i < nb_ligne - 1 - coupure_ligne; ++i)
for ( j=0; j < nb_colone - 1 - coupure_col  ; ++j)
      if( (nb_valid_pts = 
         (hidden_points[i  ][j  ] +  
          hidden_points[i+1][j  ] +  
          hidden_points[i+1][j+1] + 
            hidden_points[i  ][j+1]  )) >=2)
       {
    if(two_separate_objects == -1 || j != (moitie_colone -2))     ///two separate shapes  

if((z_tmp=Tre[i*3+2][j]+Tre[(i+1)*3+2][j]+Tre[i*3+2][j+1]+Tre[(i+1)*3+2][j+1])/4 < 460 ||
 clipping == -1 )
 {

/// Cette partie calcule le vecteur normalise qui vient de l'observateur            

a4= (double)sqrt(
     (Oprime[0]-Tre[i*3  ][j] )*(Oprime[0]-Tre[i*3  ][j] )
    +(Oprime[1]-Tre[i*3+1][j] )*(Oprime[1]-Tre[i*3+1][j] ) 
    +(Oprime[2]-Tre[i*3+2][j] )*(Oprime[2]-Tre[i*3+2][j] ));

/// Just in case...must be changed
if( a4 > 0.00000001) {    
Obser[0]=(Oprime[0]-Tre[i*3  ][j] )/a4;
Obser[1]=(Oprime[1]-Tre[i*3+1][j] )/a4;
Obser[2]=(Oprime[2]-Tre[i*3+2][j] )/a4;   
}

cosinus=(((Obser[0]*Nor[i*3  ][j])+(Obser[1]*Nor[i*3+1][j])+(Obser[2]*Nor[i*3+2][j]))/(1));
/// Just in case...must be changed
if(cosinus >1 ) cosinus = 1;
if(cosinus < -1) cosinus = -1;



/*
//=================================================================

if(draw_poly_normals == 1){  
poly_courant = j*(nb_ligne-1 ) + i;
Nor3[i*3  ][j] = -30 * Nor[i*3    ][j]  + Tre[i*3    ][j];
Nor3[i*3+1][j] = -30 * Nor[i*3 + 1][j]  + Tre[i*3 + 1][j];
Nor3[i*3+2][j] = -30 * Nor[i*3 + 2][j]  + Tre[i*3 + 2][j];

c4 = D/(Nor3[i*3+2][j]-Oprime[2]);
Nor3[i*3  ][j] = c4*Nor3[i*3    ][j] +demi_hauteur;
Nor3[i*3+1][j] = c4*Nor3[i*3 + 1][j] +demi_largeur;
                                             
tableau[poly_courant].Norx = (int)Nor3[i*3   ][j];
tableau[poly_courant].Nory = (int)Nor3[i*3 +1][j];

tableau[poly_courant + 10000].Norx = (int)Nor3[i*3   ][j];
tableau[poly_courant + 10000].Nory = (int)Nor3[i*3 +1][j];
}

//=================================================================
*/

///                      TRIAGE des POLYGONES
///========== triage des polygone selon leurs veleurs Z et creation d'une liste
///========== de polygones TRIES qu'on utilisera apres pour l'affichage final.


poly_courant = j*(nb_ligne-1 ) + i;
if(nb_valid_pts == 4){
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));

tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3   ][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3   ][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3   ][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));

} // End if(nb_valid_pts == 4)
 
else if(nb_valid_pts == 3 ){ 



  if(  draw_hidden_poly_and_nonhidden == 1 ) {
poly_courant = j*(nb_ligne-1 ) + i ;

tableaureferences[poly_courant + 10000]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));

tableaureferences[poly_courant + 10000]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant + 10000]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant + 10000]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));
                                         
      }

if(hidden_points[i][j] == 0) {

tableaureferences[poly_courant]->setPoint(0,
                                         (int)(DL3[(i)*3   ][j]  ),
                                         (int)(DL3[(i)*3 +1][j]  ));
                                         //(int)(DL3[(i+1)*3   ][j+1]  ),
                                         //(int)(DL3[(i+1)*3 +1][j+1]  ));

tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));

}

else if(hidden_points[i+1][j] == 0) {
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(HL3[(i+1)*3   ][j]),
                                         (int)(HL3[(i+1)*3 +1][j]));
                                         //(int)(HL3[i*3   ][j+1]),
                                         //(int)(HL3[i*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));
     }

else if(hidden_points[i+1][j+1] == 0) {

tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3   ][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(HR3[(i+1)*3   ][j+1]),
                                         (int)(HR3[(i+1)*3 +1][j+1]));
                                         //(int)(HR3[i*3   ][j]),
                                         //(int)(HR3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3   ][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));
}

else {

tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(DR3[i*3   ][j+1]),
                                         (int)(DR3[i*3 +1][j+1]));
                                         //(int)(DR3[(i+1)*3   ][j]),
                                         //(int)(DR3[(i+1)*3 +1][j]));
}

} // End if(nb_valid_pts == 3 )


else if(nb_valid_pts == 2 ){ 
poly_courant = j*(nb_ligne-1 ) + i;

  if(  draw_hidden_poly_and_nonhidden == 1 ) {


tableaureferences[poly_courant + 10000]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));

tableaureferences[poly_courant + 10000]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant + 10000]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant + 10000]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));                                        
      }

     if(hidden_points[i][j+1] == 0 && hidden_points[i][j] == 0) {
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(DL3[i*3   ][j]),
                                         (int)(DL3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(DR3[i*3   ][j+1]),
                                         (int)(DR3[i*3 +1][j+1]));                              
                              
                              }
     else if (hidden_points[i][j] == 0 && hidden_points[i+1][j] == 0){
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(DL3[i*3   ][j]),
                                         (int)(DL3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(HL3[(i+1)*3][j]),
                                         (int)(HL3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3   ][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));        
          }
     else if(hidden_points[i+1][j] == 0 && hidden_points[i+1][j+1] == 0){
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(HL3[(i+1)*3][j]),
                                         (int)(HL3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(HR3[(i+1)*3][j+1]),
                                         (int)(HR3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3   ][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));                    
          }
     else if(hidden_points[i+1][j+1] == 0 && hidden_points[i][j+1] == 0){
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(HR3[(i+1)*3][j+1]),
                                         (int)(HR3[(i+1)*3 +1][j+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(DR3[i*3   ][j+1]),
                                         (int)(DR3[i*3 +1][j+1]));          
          }
// if we have to draw the shape along with the Hidden polygon 

else {
/*  if(  draw_hidden_poly_and_nonhidden == 1 ) */ {
poly_courant = j*(nb_ligne-1 ) + i;

tableaureferences[poly_courant  ]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));

tableaureferences[poly_courant ]->setPoint(1,
                                         //(int)(Tre3[(i+1)*3][j]),
                                         //(int)(Tre3[(i+1)*3 +1][j]));
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant ]->setPoint(2,
                                         //(int)(Tre3[(i+1)*3][j+1]),
                                         //(int)(Tre3[(i+1)*3 +1][j+1]));
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant ]->setPoint(3,
                                         //(int)(Tre3[i*3][j+1]),
                                         //(int)(Tre3[i*3 +1][j+1]));
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));                                         
      }
     }

// END of : if we have to draw the shape along with the Hidden polygon






    
     } // End if(nb_valid_pts == 2 )



//=============  Triage des polygones selon la valeurs de leurs profondeurs Z====

 tmp=0;
 itVectorData = vecteur_poly.begin();
 
 nb_poly = vecteur_poly.size();
if( nb_poly > 0)
{  /// z_tmp= Tre[i*3+2][j]+ Tre[(i+1)*3+2][j]+ Tre[i*3+2][j+1]+ Tre[(i+1)*3+2][j+1];
           while( tmp < nb_poly) {   
         
               if( z_tmp < vecteur_poly[tmp]->valeur_z )
               //if( z_tmp < (*itVectorData)->valeur_z )
  {

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;
  
  vecteur_poly.insert(itVectorData, &tableau[poly_courant]);
  
  
  
if(  draw_hidden_poly_and_nonhidden == 1 && (nb_valid_pts == 3 || nb_valid_pts == 2) )  {

  tableau[poly_courant + 10000].pl = tableaureferences[poly_courant + 10000];
  tableau[poly_courant + 10000].valeur_z = z_tmp;
  tableau[poly_courant + 10000].valeur_cos = cosinus;
  tableau[poly_courant + 10000].condition_validity = -1;  

vecteur_poly.insert(itVectorData, &tableau[poly_courant + 10000]);  
}



  tmp = nb_poly ;

  }
  
  else   {
      if( tmp==(nb_poly -1)) {

      



  
if(  draw_hidden_poly_and_nonhidden == 1 && (nb_valid_pts == 3 || nb_valid_pts == 2) ) {

  tableau[poly_courant + 10000].pl = tableaureferences[poly_courant + 10000];
  tableau[poly_courant + 10000].valeur_z = z_tmp;
  tableau[poly_courant + 10000].valeur_cos = cosinus;
  tableau[poly_courant + 10000].condition_validity = -1;      
     
  vecteur_poly.push_back(&tableau[poly_courant + 10000]);
}  


  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;
  vecteur_poly.push_back(&tableau[poly_courant]);



  tmp = nb_poly ;
                             }
      else    {     
      tmp++ ;
      itVectorData++;
      }

                      }


                      }

}
else { 
//

  
if(  draw_hidden_poly_and_nonhidden == 1 && (nb_valid_pts == 3 || nb_valid_pts == 2) ) {
  tableau[poly_courant + 10000].pl = tableaureferences[poly_courant + 10000];
  tableau[poly_courant + 10000].valeur_z = z_tmp;
  tableau[poly_courant + 10000].valeur_cos = cosinus;
  tableau[poly_courant + 10000].condition_validity = -1;   
  vecteur_poly.push_back(&tableau[poly_courant + 10000]);
}

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;     
  vecteur_poly.push_back(&tableau[poly_courant]);



}

}
} // End if(HP[][] +... >=2 )




// Here we are going to store the hidden polygone
// only if it's needed by user : draw_hidden_poly_and_nonhidden == 1
else 
{
  
 // ========================================================================== 
  if(  draw_hidden_poly_and_nonhidden == 1 )
    if(two_separate_objects == -1 || j != (moitie_colone -2))     ///two separate shapes  

if((z_tmp=Tre[i*3+2][j]+Tre[(i+1)*3+2][j]+Tre[i*3+2][j+1]+Tre[(i+1)*3+2][j+1])/4 < 460 ||
 clipping == -1 )
 {

/// Cette partie calcule le vecteur normalise qui vient de l'observateur            

a4= (double)sqrt(
     (Oprime[0]-Tre[i*3  ][j] )*(Oprime[0]-Tre[i*3  ][j] )
    +(Oprime[1]-Tre[i*3+1][j] )*(Oprime[1]-Tre[i*3+1][j] ) 
    +(Oprime[2]-Tre[i*3+2][j] )*(Oprime[2]-Tre[i*3+2][j] ));

/// Just in case...must be changed
if( a4 > 0.00000001) {    
Obser[0]=(Oprime[0]-Tre[i*3  ][j] )/a4;
Obser[1]=(Oprime[1]-Tre[i*3+1][j] )/a4;
Obser[2]=(Oprime[2]-Tre[i*3+2][j] )/a4;   
}

cosinus=(((Obser[0]*Nor[i*3  ][j])+(Obser[1]*Nor[i*3+1][j])+(Obser[2]*Nor[i*3+2][j]))/(1));
/// Just in case...must be changed
if(cosinus >1 ) cosinus = 1;
if(cosinus < -1) cosinus = -1;


poly_courant = j*(nb_ligne-1 ) + i + 10000;

tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));

tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Tre3[(i+1)*3][j]),
                                         (int)(Tre3[(i+1)*3 +1][j]));

tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Tre3[(i+1)*3][j+1]),
                                         (int)(Tre3[(i+1)*3 +1][j+1]));

tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Tre3[i*3][j+1]),
                                         (int)(Tre3[i*3 +1][j+1]));




///=============  Triage des polygones selon la valeurs de leurs profondeurs Z====

 
 itVectorData = vecteur_poly.begin();
 tmp=0; 




 nb_poly = vecteur_poly.size();
if( nb_poly > 0)
{ 
           while( tmp < nb_poly) {   
         
               if( z_tmp < vecteur_poly[tmp]->valeur_z )
  {

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;   
  tableau[poly_courant].condition_validity = -1;   

  vecteur_poly.insert(itVectorData, &tableau[poly_courant]);
  tmp = nb_poly ;

  }
  
  else   {
      if( tmp==(nb_poly -1)) {

  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;   
  tableau[poly_courant].condition_validity = -1;

  vecteur_poly.push_back(&tableau[poly_courant]);
  tmp = nb_poly ;
                             }
      else    {     
      tmp++ ;
      itVectorData++;
      }

                      }


                      }

}
else { 
  tableau[poly_courant].pl = tableaureferences[poly_courant];
  tableau[poly_courant].valeur_z = z_tmp;
  tableau[poly_courant].valeur_cos = cosinus;
  tableau[poly_courant].condition_validity = -1;        
  vecteur_poly.push_back(&tableau[poly_courant]);
}


}                  
 // ==========================================================================



  
     
} // End else
} // End else...(there is a condition)

















///                      Fin du triage des polygones
///=============================================================================


///==============================================================================

/// Optimisation: Trying to eliminate some polygons with the Zbuffer algorithm

///==============================================================================



double cs;

Prop_poly * prop_poly;

QPointArray * p;

itVectorData = vecteur_poly.begin();

nb_poly = vecteur_poly.size();



if(zbuffer_active_ok == 1)  {


for (j=0; j < nb_poly   ; j++) {

prop_poly = vecteur_poly.at(j);    

p = prop_poly->pl;    



prop_poly->zbuffer_validity = 1;

p->point(0, &zbuffer[0][j], &zbuffer[1][j]);
p->point(1, &zbuffer[2][j], &zbuffer[3][j]);
p->point(2, &zbuffer[4][j], &zbuffer[5][j]);
p->point(3, &zbuffer[6][j], &zbuffer[7][j]);

// Polygon center

zbuffer[8][j] = (zbuffer[0][j]+zbuffer[2][j]+zbuffer[4][j]+zbuffer[6][j])/4;

zbuffer[9][j] = (zbuffer[1][j]+zbuffer[3][j]+zbuffer[5][j]+zbuffer[7][j])/4;

// Recherche du rayon du cerle engloban le polygon

r1 = sqrt((zbuffer[8][j]-zbuffer[0][j])*(zbuffer[8][j]-zbuffer[0][j]) +

          (zbuffer[9][j]-zbuffer[1][j])*(zbuffer[9][j]-zbuffer[1][j]));

          

r2 = sqrt((zbuffer[8][j]-zbuffer[2][j])*(zbuffer[8][j]-zbuffer[2][j]) +

          (zbuffer[9][j]-zbuffer[3][j])*(zbuffer[9][j]-zbuffer[3][j]));

          

r3 = sqrt((zbuffer[8][j]-zbuffer[4][j])*(zbuffer[8][j]-zbuffer[4][j]) +

          (zbuffer[9][j]-zbuffer[5][j])*(zbuffer[9][j]-zbuffer[5][j]));

          

r4 = sqrt((zbuffer[8][j]-zbuffer[6][j])*(zbuffer[8][j]-zbuffer[6][j]) +

          (zbuffer[9][j]-zbuffer[7][j])*(zbuffer[9][j]-zbuffer[7][j]));

maxr = r1;

if(maxr<r2) maxr = r2; 

if(maxr<r3) maxr = r3; 

if(maxr<r4) maxr = r4;

rayon[j] = maxr;  // rayon du cerle engloban le polygon

if(rayon[j] < 4) zbuffer[10][j] =  1; //Polygon too small
else zbuffer[10][j] =  -1 ;     

itVectorData++;



}







///==============================================================================


for (j=0; j < nb_poly   ; j++) {

    

X_averege1  = 6*(zbuffer[0][j]-zbuffer[4][j])/7 + zbuffer[4][j];

Y_averege1  = 6*(zbuffer[1][j]-zbuffer[5][j])/7 + zbuffer[5][j];



X_averege2 =  (zbuffer[0][j]-zbuffer[4][j])/7 + zbuffer[4][j];

Y_averege2 =  (zbuffer[1][j]-zbuffer[5][j])/7 + zbuffer[5][j];



X_averege3 =  6*(zbuffer[2][j]-zbuffer[6][j])/7 + zbuffer[6][j];

Y_averege3 =  6*(zbuffer[3][j]-zbuffer[7][j])/7 + zbuffer[7][j];



X_averege4 =  (zbuffer[2][j]-zbuffer[6][j])/7 + zbuffer[6][j];

Y_averege4 =  (zbuffer[3][j]-zbuffer[7][j])/7 + zbuffer[7][j];



X_averege = zbuffer[8][j];

Y_averege = zbuffer[9][j];









// we are going to test if one of the remaining poly has

// the point(X_averege,Y_averege) in it's interior.





point_interior  = -1;

point_interior1 = -1;

point_interior2 = -1;

point_interior3 = -1;

point_interior4 = -1;



nb_intersection  = -1;

nb_intersection1 = -1;

nb_intersection2 = -1;

nb_intersection3 = -1;

nb_intersection4 = -1;



for(i = nb_poly -1; i > j ; i--) {



// Compute distance between the two polygons centers

r1 = sqrt((zbuffer[8][i]-zbuffer[8][j])*(zbuffer[8][i]-zbuffer[8][j]) + 

          (zbuffer[9][i]-zbuffer[9][j])*(zbuffer[9][i]-zbuffer[9][j]));



// Perform calculation only if two cercls intersect

//if( r1 < (zbuffer[10][i] + zbuffer[10][j]))  {

if( r1 < (rayon[i] + rayon[j]))  {

if(point_interior  == -1) nb_intersection  = -1;

if(point_interior1 == -1) nb_intersection1 = -1;

if(point_interior2 == -1) nb_intersection2 = -1;

if(point_interior3 == -1) nb_intersection3 = -1;

if(point_interior4 == -1) nb_intersection4 = -1;





//=================== We work with the first point ==========================

if( (zbuffer_quality == 1 || zbuffer_quality == 5 ) && point_interior  == -1/*nb_intersection == -1*/ ){                              

        if ((((zbuffer[1][i]<=Y_averege) && (Y_averege<zbuffer[7][i])) ||

             ((zbuffer[7][i]<=Y_averege) && (Y_averege<zbuffer[1][i]))) &&

            (X_averege <  (zbuffer[6][i] - zbuffer[0][i]) * (Y_averege - zbuffer[1][i])/(zbuffer[7][i] - zbuffer[1][i]) + zbuffer[0][i]))

                  nb_intersection*=-1;                                





        if ((((zbuffer[3][i]<=Y_averege) && (Y_averege<zbuffer[1][i])) ||

             ((zbuffer[1][i]<=Y_averege) && (Y_averege<zbuffer[3][i]))) &&

            (X_averege <  (zbuffer[0][i] - zbuffer[2][i]) * (Y_averege - zbuffer[3][i])/(zbuffer[1][i] - zbuffer[3][i]) + zbuffer[2][i]))

                  nb_intersection*=-1; 



        if ((((zbuffer[5][i]<=Y_averege) && (Y_averege<zbuffer[3][i])) ||

             ((zbuffer[3][i]<=Y_averege) && (Y_averege<zbuffer[5][i]))) &&

            (X_averege <  (zbuffer[2][i] - zbuffer[4][i]) * (Y_averege - zbuffer[5][i])/(zbuffer[3][i] - zbuffer[5][i])  + zbuffer[4][i]))

                  nb_intersection*=-1; 





        if ((((zbuffer[7][i]<=Y_averege) && (Y_averege<zbuffer[5][i])) ||

             ((zbuffer[5][i]<=Y_averege) && (Y_averege<zbuffer[7][i]))) &&

            (X_averege <  (zbuffer[4][i] - zbuffer[6][i]) * (Y_averege - zbuffer[7][i])/(zbuffer[5][i] - zbuffer[7][i]) + zbuffer[6][i]))

                  nb_intersection*=-1; 



if(nb_intersection == 1 ) {
   point_interior = 1;
   /*
   if(zbuffer[10][i] == 1) {
     nb_intersection1 = 
     nb_intersection2 = 
     nb_intersection3 =
     nb_intersection4 = 1;  // if Poly too small, we stop looking for another intersections              
                          
     point_interior1 = 
     point_interior2 = 
     point_interior3 =
     point_interior4 = 1;                          
                     }
     */
                 } // end of if(nb_intersection == 1 )



} 
else point_interior  = 1;


//End of  if( nb_intersection == -1 )...

//=================== We work with the second point =========================





if(zbuffer_quality > 1  && point_interior1  == -1 /*nb_intersection1 == -1*/ ){                              

        if ((((zbuffer[1][i]<=Y_averege1) && (Y_averege1<zbuffer[7][i])) ||

             ((zbuffer[7][i]<=Y_averege1) && (Y_averege1<zbuffer[1][i]))) &&

            (X_averege1 < (zbuffer[6][i] - zbuffer[0][i]) * (Y_averege1 - zbuffer[1][i])/(zbuffer[7][i] - zbuffer[1][i]) + zbuffer[0][i]))

                  nb_intersection1*=-1;                                





        if ((((zbuffer[3][i]<=Y_averege1) && (Y_averege1<zbuffer[1][i])) ||

             ((zbuffer[1][i]<=Y_averege1) && (Y_averege1<zbuffer[3][i]))) &&

            (X_averege1 < (zbuffer[0][i] - zbuffer[2][i]) * (Y_averege1 - zbuffer[3][i])/(zbuffer[1][i] - zbuffer[3][i]) + zbuffer[2][i]))

                  nb_intersection1*=-1; 



        if ((((zbuffer[5][i]<=Y_averege1) && (Y_averege1<zbuffer[3][i])) ||

             ((zbuffer[3][i]<=Y_averege1) && (Y_averege1<zbuffer[5][i]))) &&

            (X_averege1 < (zbuffer[2][i] - zbuffer[4][i]) * (Y_averege1 - zbuffer[5][i])/(zbuffer[3][i] - zbuffer[5][i])  + zbuffer[4][i]))

                  nb_intersection1*=-1; 





        if ((((zbuffer[7][i]<=Y_averege1) && (Y_averege1<zbuffer[5][i])) ||

             ((zbuffer[5][i]<=Y_averege1) && (Y_averege1<zbuffer[7][i]))) &&

            (X_averege1 < (zbuffer[4][i] - zbuffer[6][i]) * (Y_averege1 - zbuffer[7][i])/(zbuffer[5][i] - zbuffer[7][i]) + zbuffer[6][i]))

                  nb_intersection1*=-1; 



if(nb_intersection1 == 1 ) {

point_interior1 = 1;
/*
   if(zbuffer[10][i] == 1) {
     nb_intersection  = 
     nb_intersection2 = 
     nb_intersection3 =
     nb_intersection4 = 1;  // if Poly too small, we stop looking for another intersections              
                          
     point_interior  = 
     point_interior2 = 
     point_interior3 =
     point_interior4 = 1;
                         }
*/
}

} 
else point_interior1 = 1; //End of  if( nb_intersection1 == -1 )...

//===================== We work with the third point ========================



if((zbuffer_quality > 1 ) &&  point_interior2  == -1 /*nb_intersection2 == -1*/ ){                              

        if ((((zbuffer[1][i]<=Y_averege2) && (Y_averege2<zbuffer[7][i])) ||

             ((zbuffer[7][i]<=Y_averege2) && (Y_averege2<zbuffer[1][i]))) &&

            (X_averege2 < (zbuffer[6][i] - zbuffer[0][i]) * (Y_averege2 - zbuffer[1][i])/(zbuffer[7][i] - zbuffer[1][i]) + zbuffer[0][i]))

                  nb_intersection2*=-1;                                





        if ((((zbuffer[3][i]<=Y_averege2) && (Y_averege2<zbuffer[1][i])) ||

             ((zbuffer[1][i]<=Y_averege2) && (Y_averege2<zbuffer[3][i]))) &&

            (X_averege2 < (zbuffer[0][i] - zbuffer[2][i]) * (Y_averege2 - zbuffer[3][i])/(zbuffer[1][i] - zbuffer[3][i]) + zbuffer[2][i]))

                  nb_intersection2*=-1; 



        if ((((zbuffer[5][i]<=Y_averege2) && (Y_averege2<zbuffer[3][i])) ||

             ((zbuffer[3][i]<=Y_averege2) && (Y_averege2<zbuffer[5][i]))) &&

            (X_averege2 <  (zbuffer[2][i] - zbuffer[4][i]) * (Y_averege2 - zbuffer[5][i])/(zbuffer[3][i] - zbuffer[5][i])  + zbuffer[4][i]))

                  nb_intersection2*=-1; 





        if ((((zbuffer[7][i]<=Y_averege2) && (Y_averege2<zbuffer[5][i])) ||

             ((zbuffer[5][i]<=Y_averege2) && (Y_averege2<zbuffer[7][i]))) &&

            (X_averege2 < (zbuffer[4][i] - zbuffer[6][i]) * (Y_averege2 - zbuffer[7][i])/(zbuffer[5][i] - zbuffer[7][i]) + zbuffer[6][i]))

                  nb_intersection2*=-1; 



if(nb_intersection2 == 1 ) {

point_interior2 = 1;
/*
   if(zbuffer[10][i] == 1) {
     nb_intersection = 
     nb_intersection1 = 
     nb_intersection3 =
     nb_intersection4 = 1;  // if Poly too small, we stop looking for another intersections              
                          
     point_interior = 
     point_interior1 = 
     point_interior3 =
     point_interior4 = 1;
                           }
*/
}

} 


else point_interior2 = 1 ; //End of  if( nb_intersection == -1 )...




//===================== We work with the fourth point ========================



if( (zbuffer_quality > 2 ) && point_interior3  == -1 /*nb_intersection3 == -1*/ ){                              

        if ((((zbuffer[1][i]<=Y_averege3) && (Y_averege3<zbuffer[7][i])) ||

             ((zbuffer[7][i]<=Y_averege3) && (Y_averege3<zbuffer[1][i]))) &&

            (X_averege3 <  (zbuffer[6][i] - zbuffer[0][i]) * (Y_averege3 - zbuffer[1][i])/(zbuffer[7][i] - zbuffer[1][i]) + zbuffer[0][i]))

                  nb_intersection3*=-1;                                





        if ((((zbuffer[3][i]<=Y_averege3) && (Y_averege3<zbuffer[1][i])) ||

             ((zbuffer[1][i]<=Y_averege3) && (Y_averege3<zbuffer[3][i]))) &&

            (X_averege3 < (zbuffer[0][i] - zbuffer[2][i]) * (Y_averege3 - zbuffer[3][i])/(zbuffer[1][i] - zbuffer[3][i]) + zbuffer[2][i]))

                  nb_intersection3*=-1; 



        if ((((zbuffer[5][i]<=Y_averege3) && (Y_averege3<zbuffer[3][i])) ||

             ((zbuffer[3][i]<=Y_averege3) && (Y_averege3<zbuffer[5][i]))) &&

            (X_averege3 <  (zbuffer[2][i] - zbuffer[4][i]) * (Y_averege3 - zbuffer[5][i])/(zbuffer[3][i] - zbuffer[5][i])  + zbuffer[4][i]))

                  nb_intersection3*=-1; 





        if ((((zbuffer[7][i]<=Y_averege3) && (Y_averege3<zbuffer[5][i])) ||

             ((zbuffer[5][i]<=Y_averege3) && (Y_averege3<zbuffer[7][i]))) &&

            (X_averege3 < (zbuffer[4][i] - zbuffer[6][i]) * (Y_averege3 - zbuffer[7][i])/(zbuffer[5][i] - zbuffer[7][i]) + zbuffer[6][i]))

                  nb_intersection3*=-1; 



if(nb_intersection3 == 1 ) {

point_interior3 = 1;
/*
   if(zbuffer[10][i] == 1) {
     nb_intersection  =
     nb_intersection1 = 
     nb_intersection2 =
     nb_intersection4 = 1;  // if Poly too small, we stop looking for another intersections              

     point_interior  =                          
     point_interior1 = 
     point_interior2 = 
     point_interior4 = 1;
                           }
*/
}

} //End of  if( nb_intersection == -1 )...



else  point_interior3 = 1;

//===================== We work with the fifth point ========================







if( zbuffer_quality > 3  && point_interior4  == -1  /*nb_intersection4 == -1*/ ){                              

        if ((((zbuffer[1][i]<=Y_averege4) && (Y_averege4<zbuffer[7][i])) ||

             ((zbuffer[7][i]<=Y_averege4) && (Y_averege4<zbuffer[1][i]))) &&

            (X_averege4 <  ((zbuffer[6][i] - zbuffer[0][i]) * (Y_averege4 - zbuffer[1][i])+(zbuffer[7][i] - zbuffer[1][i])*zbuffer[0][i])/(zbuffer[7][i] - zbuffer[1][i])))

                  nb_intersection4*=-1;                                





        if ((((zbuffer[3][i]<=Y_averege4) && (Y_averege4<zbuffer[1][i])) ||

             ((zbuffer[1][i]<=Y_averege4) && (Y_averege4<zbuffer[3][i]))) &&

            (X_averege4 < ((zbuffer[0][i] - zbuffer[2][i]) * (Y_averege4 - zbuffer[3][i])+ (zbuffer[1][i] - zbuffer[3][i])*zbuffer[2][i])/(zbuffer[1][i] - zbuffer[3][i])))

                  nb_intersection4*=-1; 



        if ((((zbuffer[5][i]<=Y_averege4) && (Y_averege4<zbuffer[3][i])) ||

             ((zbuffer[3][i]<=Y_averege4) && (Y_averege4<zbuffer[5][i]))) &&

            (X_averege4 < ((zbuffer[2][i] - zbuffer[4][i]) * (Y_averege4 - zbuffer[5][i])+(zbuffer[3][i] - zbuffer[5][i])*zbuffer[4][i])/(zbuffer[3][i] - zbuffer[5][i])))

                  nb_intersection4*=-1; 





        if ((((zbuffer[7][i]<=Y_averege4) && (Y_averege4<zbuffer[5][i])) ||

             ((zbuffer[5][i]<=Y_averege4) && (Y_averege4<zbuffer[7][i]))) &&

            (X_averege4 < ((zbuffer[4][i] - zbuffer[6][i])*(Y_averege4 - zbuffer[7][i])+(zbuffer[5][i] - zbuffer[7][i])*zbuffer[6][i])/(zbuffer[5][i] - zbuffer[7][i])))

                  nb_intersection4*=-1; 



if(nb_intersection4 == 1 ) {

point_interior4 = 1;
/*
   if(zbuffer[10][i] == 1) { 
     nb_intersection  =
     nb_intersection1 = 
     nb_intersection2 =
     nb_intersection3 = 1;  // if Poly too small, we stop looking for another intersections              

     point_interior  =                          
     point_interior1 = 
     point_interior2 = 
     point_interior3 = 1;
                           }
*/
}

} 
else  point_interior4 = 1;

//End of  if( nb_intersection == -1 )...


//===================== We test if ALL points are hidden =====================



if( point_interior  == 1 && 
    point_interior1 == 1 && 
    point_interior2 == 1 && 
    point_interior3 == 1 && 
    point_interior4 == 1   ){  

prop_poly = vecteur_poly.at(j);

i = j;

prop_poly->zbuffer_validity = 0;

                            } 

 } // End of if( r1 < (zbuffer[10][i] + zbuffer[10][j]))    

      } // End of for(i = nb_poly -1; i > j ; i--)



itVectorData++;

}



}

///==============================================================================

/// Optimisation's End 
///==============================================================================












///=========================================================================
///                    AFFICHAGE DES POLYGONES
int Norx2, Nory2;                     
if(mesh ==1) {
g.setPen(QColor(gridliner,gridlineg,gridlineb));

QColor redcol(255,0,0);

if(interior_surface == 1 && exterior_surface == 1)
for (j=0; j < nb_poly   ; j++) {
prop_poly = vecteur_poly.at(j);
p         = prop_poly->pl;
cs        = prop_poly->valeur_cos; 
if( zbuffer_active_ok != 1 || prop_poly->zbuffer_validity == 1) { 
if(cs >0) {
      
if(  draw_hidden_poly_and_nonhidden == 1 && prop_poly->condition_validity == -1) {

          if(draw_cond_mesh == 1){
               g.setPen(redcol);
               g.drawPolyline(*p);
               g.drawLine ( p->point(0), p->point(3)); 
               //g.drawPolygon(*p);   //333333333333333333333333333333333333333333333333333
               /*
               if(draw_poly_normals == 1) {
               prop_poly->pl->point(0, &Norx2, &Nory2);
               //g.drawLine(prop_poly->Norx, prop_poly->Nory, Norx2, Nory2);
               } 
               */              
               g.setPen(QColor(gridliner,gridlineg,gridlineb));}
          else {
               g.setBrush(palette_cond_face[(int)(cs*256)]);
               g.drawPolygon(*p);
               /*
               if(draw_poly_normals == 1) {
               prop_poly->pl->point(0, &Norx2, &Nory2);
               //g.drawLine(prop_poly->Norx, prop_poly->Nory, Norx2, Nory2);
               }
               */
               }
}
else {  g.setBrush(palette_back_face[(int)(cs*256)]); 
        g.drawPolygon(*p);
        /*
       if(draw_poly_normals == 1) {
        prop_poly->pl->point(0, &Norx2, &Nory2);
        //g.drawLine(prop_poly->Norx, prop_poly->Nory, Norx2, Nory2);
        }
        */
        
}
        } // End if(  draw_hidden_poly_and_nonhidden == 1 && ....
else {
  
     
if(  draw_hidden_poly_and_nonhidden == 1 && prop_poly->condition_validity == -1){
 
          if(draw_cond_mesh ==1){
               g.setPen(redcol);
               g.drawPolyline(*p);
               g.drawLine ( p->point(0), p->point(3)); 
               //g.drawPolygon(*p);  //333333333333333333333333333333333333333333333333333
       if(draw_poly_normals == 1) {
               prop_poly->pl->point(0, &Norx2, &Nory2);
               g.drawLine(prop_poly->Norx, prop_poly->Nory, Norx2, Nory2);
               
       }
               g.setPen(QColor(gridliner,gridlineg,gridlineb));}
          else {
               g.setBrush(palette_cond_face[-(int)(cs*256)]);
               g.drawPolygon(*p);
       if(draw_poly_normals == 1) {
               prop_poly->pl->point(0, &Norx2, &Nory2);
               g.drawLine(prop_poly->Norx, prop_poly->Nory, Norx2, Nory2);
              
       }
               }
}
else {
    g.setBrush(palette_front_face[-(int)(cs*256)]);
      g.drawPolygon(*p);
    if(draw_poly_normals == 1) {
       prop_poly->pl->point(0, &Norx2, &Nory2);
       g.drawLine(prop_poly->Norx, prop_poly->Nory, Norx2, Nory2);
       }
     }

     }    
itVectorData++;
} 
} //End of if( prop_poly->zbuffer_validity == 1)
else {
if(interior_surface == 1 ) 
for (j=0; j < nb_poly   ; j++) {
prop_poly = vecteur_poly.at(j);
p         = prop_poly->pl;
cs        = prop_poly->valeur_cos; 
if(cs >0) {
      
      
      
if(  draw_hidden_poly_and_nonhidden == 1 && prop_poly->condition_validity == -1)
g.setBrush(palette_cond_face[(int)(cs*256)]); 
else g.setBrush(palette_back_face[(int)(cs*256)]); 


        g.drawPolygon(*p);
        } 
itVectorData++;
} 

if(exterior_surface == 1 )
for (j=0; j < nb_poly   ; j++) {
prop_poly = vecteur_poly.at(j);
p         = prop_poly->pl;
cs        = prop_poly->valeur_cos; 
if(cs <= 0) {
      
      
if(  draw_hidden_poly_and_nonhidden == 1 && prop_poly->condition_validity == -1)
g.setBrush(palette_cond_face[-(int)(cs*256)]); 
else g.setBrush(palette_front_face[-(int)(cs*256)]);



      g.drawPolygon(*p);
     }    
itVectorData++;
}

}


                               


} // End of if(mesh ==1) 


else {
g.setPen(QColor(gridliner,gridlineg,gridlineb));

if(interior_surface == 1 && exterior_surface == 1)
for (j=0; j < nb_poly   ; j++) {
prop_poly = vecteur_poly.at(j);
p         = prop_poly->pl;
cs        = prop_poly->valeur_cos; 
if( zbuffer_active_ok != 1 || prop_poly->zbuffer_validity == 1) { 
if(cs >0) {
//g.setBrush(palette_back_face[(int)(cs*256)]); 
        g.drawPolygon(*p);
        }
else {
//g.setBrush(palette_front_face[-(int)(cs*256)]);
      g.drawPolygon(*p);
     }    
itVectorData++;
} 
} //End of if( prop_poly->zbuffer_validity == 1)
else {
if(interior_surface == 1 ) 
for (j=0; j < nb_poly   ; j++) {
prop_poly = vecteur_poly.at(j);
p         = prop_poly->pl;
cs        = prop_poly->valeur_cos; 
if(cs >0) {
//g.setBrush(palette_back_face[(int)(cs*256)]); 
        g.drawPolygon(*p);
        } 
itVectorData++;
} 

if(exterior_surface == 1 )
for (j=0; j < nb_poly   ; j++) {
prop_poly = vecteur_poly.at(j);
p         = prop_poly->pl;
cs        = prop_poly->valeur_cos; 
if(cs <= 0) {
//g.setBrush(palette_front_face[-(int)(cs*256)]);
      g.drawPolygon(*p);
     }    
itVectorData++;
}

}




}


// hidden surface removal (HSR) 

 // Delete the vector                         
      vecteur_poly.clear();









if(infos ==1) {


if((i= nb_colone - 1 - coupure_col) <0) i=0;
if((j= nb_ligne - 1 - coupure_ligne) <0) j=0;

g.setPen(QColor(250,0,0));
g.drawText(5,15,"Grid = "+QString::number(i)+" x "+QString::number(j)+" = "+QString::number(i*j));

g.setPen(QColor(0,250,0));
g.drawText(5,
           15,
           "Grid = ");





g.setPen(QColor(250,0,0));
g.drawText(5,30,"Polygn = "+QString::number(nb_poly));

g.setPen(QColor(0,250,0));
g.drawText(5,
           30,
           "Polygn = ");




g.setPen(QColor(250,0,0));
g.drawText(5,45,"t_Step = "+QString::number((int)(1/step)+1));

g.setPen(QColor(0,250,0));
g.drawText(5,
           45,
           "t_Step = ");

g.setPen(QColor(250,0,0));
g.drawText(5,60,"Latency = "+QString::number(latence)+"ms");

g.setPen(QColor(0,250,0));
g.drawText(5,
           60,
           "Latency = ");

if(zbuffer_active_ok == 1 ) {    
g.setPen(QColor(250,0,0));
g.drawText(5,75,"Zbuffer = "+QString::number(zbuffer_quality));

g.setPen(QColor(0,250,0));
g.drawText(5,
           75,
           "Zbuffer = ");
}


if(independantwindow == 1) {
g.setPen(QColor(250,0,0));
g.drawText(5,75,"  h=Help  ");
}        
if(showhelp == 1){
g.setPen(QColor(250,0,0));
g.drawText(5,75,"\
| h=Help | a=Anim | p=Morfh | m=Mesh | b=Box | i=Infos | c=Clip |");    
g.setPen(QColor(250,0,0));
g.drawText(5,95,"\
| key_left=line-- | key_right=line++ | key_up=column++ | key_down=column-- |");
g.setPen(QColor(250,0,0));
g.drawText(5,110,"\
| key_Prior=Grid++ | key_Next=Grid-- |");   
}        
         
}
  }


/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_bouton_gauche3 () {
      
     rotation3();
     calcul_points3();  
}

/*****************************************************************************/
/*****************************************************************************/ 
/*
void Model3D::fct_bouton_gauche4 () {
      
     rotation4();
     calcul_points3();  
}
*/
/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_bouton_milieu3 () {
      
     translation3();
     calcul_points3();  
}


/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_bouton_droit3 () {

     homothetie3();
     calcul_points3();  
}

/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_bouton_Anim3 () {
      
     rotation3();
     calcul_points3(); // On applique la rotation et l'homothetie 
}

/*****************************************************************************/
/*****************************************************************************/

void Model3D::fct_bouton_Morph3() {
      initialiser_parseur3();
      calcul_objet3();  // Utilisation du parseur..
      boite_englobante3(); 
      normalisation3(); // Calcul des normales
      calcul_points3(); // On applique la rotation et l'homothetie      

}
/*****************************************************************************/
/*****************************************************************************/

void Model3D::fct_bouton_AnimMorph() {
      initialiser_parseur3();
        rotation3();
      calcul_objet3();  // Utilisation du parseur..
      boite_englobante3(); 
      normalisation3(); // Calcul des normales
      calcul_points3(); // On applique la rotation et l'homothetie      

}
/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_calcul3 () {
       
      initialiser_parseur3();
      parse_expression();
      calcul_objet3();  // Utilisation du parseur..
      boite_englobante3(); 
      normalisation3(); // Calcul des normales
      calcul_points3(); // On applique la rotation et l'homothetie      

}

/*****************************************************************************/
/*****************************************************************************/ 

void  Model3D::homothetie3() {

mat_homothetie.unit();

 
mat_homothetie.xx = mat_homothetie.yy = mat_homothetie.zz = coefficient;

// Application a la matrice principale:

mat.mult(mat_homothetie);
}

/*****************************************************************************/
/*****************************************************************************/ 

void  Model3D::translation3() {

mat_translation.unit();
translatex = mat_translation.xo = angley ;
translatey = mat_translation.yo = anglex ;
mat_translation.zo = 0 ;

// Application a la matrice principale 
mat.mult(mat_translation);
}

/*****************************************************************************/
/*****************************************************************************/ 

void  Model3D::rotation3(){
      
        mat_rotation.unit();         

// Construction de la matrice de trnsformation
        mat_rotation.xrot(anglex );
        mat_rotation.yrot(angley );
//we have to invert the translation before applaying the rotation

mat_inversetranslation.unit();
mat_inversetranslation.xo = -center[0] ;
mat_inversetranslation.yo = -center[1] ;
mat_inversetranslation.zo = -center[2] ;

            mat.mult(mat_inversetranslation);
// On applique cette transformation a la matrice principale "mat"
          mat.mult(mat_rotation);
    
          
          
// Now we return the object to it's first place..
mat_inversetranslation.unit();
mat_inversetranslation.xo = center[0] ;
mat_inversetranslation.yo = center[1] ;
mat_inversetranslation.zo = center[2] ;

                mat.mult(mat_inversetranslation);     
            mat_rotation_save.mult(mat_rotation);
            
  
      }




/*****************************************************************************/
/*****************************************************************************/ 
void  Model3D::rotation4(){
      
        mat_rotation4D.unit();         
//tetaxy = 4;tetaxz = 4;tetayz = 4;// for testing
//tetaxw = 4;tetayw = 4;tetazw = 4;// for testing
    
// Construction de la matrice de trnsformation
    if(tetaxy_ok == 1)    mat_rotation4D.xyrot(tetaxy);
    if(tetaxz_ok == 1)    mat_rotation4D.xzrot(tetaxz);
    if(tetayz_ok == 1)    mat_rotation4D.yzrot(tetayz);
    
    if(tetaxw_ok == 1)    mat_rotation4D.xwrot(tetaxw);
    if(tetayw_ok == 1)    mat_rotation4D.ywrot(tetayw);
    if(tetazw_ok == 1)    mat_rotation4D.zwrot(tetazw);    
        

// On applique cette transformation a la matrice principale "mat"
          mat4D.mult(mat_rotation4D);           
  
      }
      
/*****************************************************************************/
/*****************************************************************************/ 
void  Model3D::rotation5(){   
// Second version of 5D rotation
// here we don't use special mat_rotation5D
    if(tetaxy_ok == 1)    mat5D.xyrot(tetaxy);
    if(tetaxz_ok == 1)    mat5D.xzrot(tetaxz);
    if(tetayz_ok == 1)    mat5D.yzrot(tetayz);
    
    if(tetaxw_ok == 1)    mat5D.xwrot(tetaxw);
    if(tetayw_ok == 1)    mat5D.ywrot(tetayw);
    if(tetazw_ok == 1)    mat5D.zwrot(tetazw); 
      
    if(tetaxt_ok == 1)    mat5D.xtrot(tetaxt);
    if(tetayt_ok == 1)    mat5D.ytrot(tetayt);   
    if(tetazt_ok == 1)    mat5D.ztrot(tetazt);
    if(tetawt_ok == 1)    mat5D.wtrot(tetawt);
      
      }
/*****************************************************************************/
/*****************************************************************************/ 
void  Model3D::rotation6(){   
// Second version of 5D rotation
// here we don't use special mat_rotation5D
    if(tetaxy_ok == 1)    mat6D.xyrot(tetaxy);
    if(tetaxz_ok == 1)    mat6D.xzrot(tetaxz);
    if(tetayz_ok == 1)    mat6D.yzrot(tetayz);
    
    if(tetaxw_ok == 1)    mat6D.xwrot(tetaxw);
    if(tetayw_ok == 1)    mat6D.ywrot(tetayw);
    if(tetazw_ok == 1)    mat6D.zwrot(tetazw); 
      
    if(tetaxt_ok == 1)    mat6D.xtrot(tetaxt);
    if(tetayt_ok == 1)    mat6D.ytrot(tetayt);   
    if(tetazt_ok == 1)    mat6D.ztrot(tetazt);
    if(tetawt_ok == 1)    mat6D.wtrot(tetawt);
      
    if(tetaxs_ok == 1)    mat6D.xsrot(tetaxs);
    if(tetays_ok == 1)    mat6D.ysrot(tetays);   
    if(tetazs_ok == 1)    mat6D.zsrot(tetazs);
    if(tetaws_ok == 1)    mat6D.wsrot(tetaws);    
    if(tetats_ok == 1)    mat6D.tsrot(tetats);    
      }
/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_bouton_Anim4 () {
      
   rotation4();
   calcul_points4();         // On applique la rotation 4D
   //boite_englobante4D();// pas necessaire...donne resultat bizarre!!!            
   project_4D_to_3D();  
   boite_englobante3(); //<--try to find something else more convenient
   //normalisation3(); // Calcul des normales...doit etre fait prochainement en 4D
   calcul_points3(); // On applique la rotation et l'homothetie               
   mat4D.unit(); 


}

/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_bouton_Anim5 () {
      
   rotation5();
   calcul_points5();         // On applique la rotation 5D          
   project_5D_to_4D();  
   project_4D_to_3D();
   boite_englobante3(); //<--try to find something else more convenien   
   calcul_points3(); // On applique la rotation et l'homothetie  (en 3D)            
   mat5D.unit(); 
/*
   boite_englobante5D();
   project_5D_to_4D();
   //boite_englobante4D();                
   project_4D_to_3D();               
*/
                  
}

/*****************************************************************************/
/*****************************************************************************/ 
void Model3D::fct_bouton_Anim6 () {
      
   rotation6();
   calcul_points6(); // On applique la rotation 5D  
   project_6D_to_5D();                
   project_5D_to_4D();  
   project_4D_to_3D();
   boite_englobante3(); //<--try to find something else more convenien   
   calcul_points3(); // On applique la rotation et l'homothetie  (en 3D)            
   mat6D.unit(); 
/*
   boite_englobante5D();
   project_5D_to_4D();
   //boite_englobante4D();                
   project_4D_to_3D();               
*/
                  
}

/*****************************************************************************/
/*****************************************************************************/ 



void  Model3D::calcul_points4(){
int i,j;

 // Changement de coordonnees des points selon les
 // angles angex et angley

 for (i=0; i < nb_ligne  ; i++)
   for (j=0; j < nb_colone   ; j++)
      {      
        tp1 = shape4D[i*4    ][j];
        tp2 = shape4D[i*4 + 1][j];
        tp3 = shape4D[i*4 + 2][j];
        tp4 = shape4D[i*4 + 3][j];
        
        shape4D[i*4  ][j] = mat4D.xx*tp1 + mat4D.xy*tp2 + mat4D.xz*tp3 + mat4D.xw*tp4 + mat4D.xo;
        shape4D[i*4+1][j] = mat4D.yx*tp1 + mat4D.yy*tp2 + mat4D.yz*tp3 + mat4D.yw*tp4 + mat4D.yo;
        shape4D[i*4+2][j] = mat4D.zx*tp1 + mat4D.zy*tp2 + mat4D.zz*tp3 + mat4D.zw*tp4 + mat4D.zo;
      shape4D[i*4+3][j] = mat4D.wx*tp1 + mat4D.wy*tp2 + mat4D.wz*tp3 + mat4D.ww*tp4 + mat4D.wo;       
                                 }
}

/*****************************************************************************/
/*****************************************************************************/ 



void  Model3D::calcul_points5(){
int i,j;

 // Changement de coordonnees des points selon les
 // angles angex et angley

 for (i=0; i < nb_ligne  ; i++)
   for (j=0; j < nb_colone   ; j++)
      {
        tp1 = shape5D[i*5    ][j];
        tp2 = shape5D[i*5 + 1][j];
        tp3 = shape5D[i*5 + 2][j];
          tp4 = shape5D[i*5 + 3][j];
          tp5 = shape5D[i*5 + 4][j];
      
shape5D[i*5  ][j] = mat5D.xx*tp1 + mat5D.xy*tp2 + mat5D.xz*tp3 + mat5D.xw*tp4 + mat5D.xt*tp5 + mat5D.xo;
shape5D[i*5+1][j] = mat5D.yx*tp1 + mat5D.yy*tp2 + mat5D.yz*tp3 + mat5D.yw*tp4 + mat5D.yt*tp5 + mat5D.yo;
shape5D[i*5+2][j] = mat5D.zx*tp1 + mat5D.zy*tp2 + mat5D.zz*tp3 + mat5D.zw*tp4 + mat5D.zt*tp5 + mat5D.zo;
shape5D[i*5+3][j] = mat5D.wx*tp1 + mat5D.wy*tp2 + mat5D.wz*tp3 + mat5D.ww*tp4 + mat5D.wt*tp5 + mat5D.wo;
shape5D[i*5+4][j] = mat5D.tx*tp1 + mat5D.ty*tp2 + mat5D.tz*tp3 + mat5D.tw*tp4 + mat5D.tt*tp5 + mat5D.to;       
                                 }
}
/*****************************************************************************/
/*****************************************************************************/ 



void  Model3D::calcul_points6(){
int i,j;

 // Changement de coordonnees des points selon les
 // angles angex et angley

 for (i=0; i < nb_ligne  ; i++)
   for (j=0; j < nb_colone   ; j++)
      {
        tp1 = shape6D[i*6    ][j];
        tp2 = shape6D[i*6 + 1][j];
        tp3 = shape6D[i*6 + 2][j];
          tp4 = shape6D[i*6 + 3][j];
          tp5 = shape6D[i*6 + 4][j];
          tp6 = shape6D[i*6 + 5][j];
      
shape6D[i*6  ][j] = mat6D.xx*tp1 + mat6D.xy*tp2 + mat6D.xz*tp3 + mat6D.xw*tp4 + mat6D.xt*tp5 + mat6D.xs*tp6 + mat6D.xo;
shape6D[i*6+1][j] = mat6D.yx*tp1 + mat6D.yy*tp2 + mat6D.yz*tp3 + mat6D.yw*tp4 + mat6D.yt*tp5 + mat6D.ys*tp6 + mat6D.yo;
shape6D[i*6+2][j] = mat6D.zx*tp1 + mat6D.zy*tp2 + mat6D.zz*tp3 + mat6D.zw*tp4 + mat6D.zt*tp5 + mat6D.zs*tp6 + mat6D.zo;
shape6D[i*6+3][j] = mat6D.wx*tp1 + mat6D.wy*tp2 + mat6D.wz*tp3 + mat6D.ww*tp4 + mat6D.wt*tp5 + mat6D.ws*tp6 + mat6D.wo;
shape6D[i*6+4][j] = mat6D.tx*tp1 + mat6D.ty*tp2 + mat6D.tz*tp3 + mat6D.tw*tp4 + mat6D.tt*tp5 + mat6D.ts*tp6 + mat6D.to;
shape6D[i*6+5][j] = mat6D.sx*tp1 + mat6D.sy*tp2 + mat6D.sz*tp3 + mat6D.sw*tp4 + mat6D.st*tp5 + mat6D.ss*tp6 + mat6D.so;      
                                 }
}
/*****************************************************************************/
/*****************************************************************************/ 

void  Model3D::normalisation3(){
int i,j;    
// Construction des normales : (premiere methode )


    for (j=0; j < nb_colone -1   ; j++)
     for (i=0; i < nb_ligne -1  ; i++) {
            
caa  = Tre2[(i+1)*3+1][j  ] - Tre2[i*3+1][j]; 
bab  = Tre2[i*3    +2][j+1] - Tre2[i*3+2][j];
cab  = Tre2[(i+1)*3+2][j  ] - Tre2[i*3+2][j];
baa  = Tre2[i*3    +1][j+1] - Tre2[i*3+1][j];
ba   = Tre2[i*3      ][j+1] - Tre2[i*3  ][j];
ca   = Tre2[(i+1)*3  ][j  ] - Tre2[i*3  ][j];
      
Nor2[i*3  ][j] = caa*bab - cab*baa;
Nor2[i*3+1][j] = cab*ba  - ca*bab;
Nor2[i*3+2][j] = ca*baa  - caa*ba;


double b4 = (double)sqrt((Nor2[i*3  ][j]*Nor2[i*3  ][j]) + 
                         (Nor2[i*3+1][j]*Nor2[i*3+1][j]) +
                         (Nor2[i*3+2][j]*Nor2[i*3+2][j])  );


// This must be changed...
if(b4 > 0.00000001) {
Nor[i*3  ][j]= (Nor2[i*3  ][j]/=b4);
Nor[i*3+1][j]= (Nor2[i*3+1][j]/=b4);
Nor[i*3+2][j]= (Nor2[i*3+2][j]/=b4);
}

}


i = nb_ligne -1;
 for (j=0; j < nb_colone -1   ; j++) {
Nor[i*3  ][j] = Nor2[i*3  ][j] = Nor2[(i-1)*3  ][j];
Nor[i*3+1][j] = Nor2[i*3+1][j] = Nor2[(i-1)*3+1][j];
Nor[i*3+2][j] = Nor2[i*3+2][j] = Nor2[(i-1)*3+2][j];
 }


j =nb_colone -1;
 for (i=0; i < nb_ligne -1  ; i++) {
Nor[i*3  ][j]= Nor2[i*3  ][j]= Nor2[i*3  ][j-1];
Nor[i*3+1][j]= Nor2[i*3+1][j]= Nor2[i*3+1][j-1];
Nor[i*3+2][j]= Nor2[i*3+2][j]= Nor2[i*3+2][j-1];
                                       }

      
      
      }

/*****************************************************************************/
/*****************************************************************************/ 



void  Model3D::calcul_points3(){
int i,j;
 // pour savoir ou se trouve le centre de l'objet

 moitie_colone = (int)(nb_colone/2);
 
 
         center[0] =  mat.xo;
         center[1] =  mat.yo;
         center[2] =  mat.zo;

 // Changement de coordonnees des points selon les
 // angles angex et angley
 if(two_separate_objects == -1 ) {
 mat_first_obj = mat_second_obj = mat;
 mat_rotation_first_save= mat_rotation_second_save = mat_rotation_save;


 for (i=0; i < nb_ligne  ; i++)
   for (j=0; j < nb_colone   ; j++){
        tp1 = Tre2[i*3    ][j];
        tp2 = Tre2[i*3 + 1][j];
        tp3 = Tre2[i*3 + 2][j];
        Tre[i*3  ][j] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        Tre[i*3+1][j] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        Tre[i*3+2][j] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;        
                                 }
                                 
 // here we are testing if there is much more points to transforme
 // in the case we have a conditional equation...
 if( there_is_condition == 1) {
     
   for (i=0; i < nb_ligne  ; i++)
   for (j=0; j < nb_colone   ; j++){
       if(hidden_points[i][j] == 0){
       //DR
        tp1 = DR2[i*3    ][j];
        tp2 = DR2[i*3 + 1][j];
        tp3 = DR2[i*3 + 2][j];
        DR[i*3  ][j] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        DR[i*3+1][j] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        DR[i*3+2][j] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;        
                                 
       //DL
        tp1 = DL2[i*3    ][j];
        tp2 = DL2[i*3 + 1][j];
        tp3 = DL2[i*3 + 2][j];
        DL[i*3  ][j] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        DL[i*3+1][j] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        DL[i*3+2][j] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;                                  
                                 
       //HR
        tp1 = HR2[i*3    ][j];
        tp2 = HR2[i*3 + 1][j];
        tp3 = HR2[i*3 + 2][j];
        HR[i*3  ][j] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        HR[i*3+1][j] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        HR[i*3+2][j] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;                                  
                                 
       //HL
        tp1 = HL2[i*3    ][j];
        tp2 = HL2[i*3 + 1][j];
        tp3 = HL2[i*3 + 2][j];
        HL[i*3  ][j] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        HL[i*3+1][j] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        HL[i*3+2][j] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;                                 
                                 }    
     } // End if(hidden_points[i][j] == 0)... 
     } // End  if( there_is_condition == 1)
     
     
 
 
 
 //Normales
 for (i=0; i < nb_ligne  ; i++)                                                                       
 for (j=0; j < nb_colone    ; j++) {
        tp1 = Nor2[i*3    ][j];
        tp2 = Nor2[i*3 + 1][j];
        tp3 = Nor2[i*3 + 2][j];
        Nor[i*3  ][j] = mat_rotation_save.xx*tp1 + mat_rotation_save.xy*tp2 +mat_rotation_save.xz*tp3 + mat_rotation_save.xo;
        Nor[i*3+1][j] = mat_rotation_save.yx*tp1 + mat_rotation_save.yy*tp2 +mat_rotation_save.yz*tp3 + mat_rotation_save.yo;
        Nor[i*3+2][j] = mat_rotation_save.zx*tp1 + mat_rotation_save.zy*tp2 +mat_rotation_save.zz*tp3 + mat_rotation_save.zo;   

    }
 
 
 
 
 }
 else  {
 
 if(change_first_object == 1) {

  for (i=0; i < nb_ligne  ; i++)
   for (j=0; j < moitie_colone -1  ; j++){
        tp1 = Tre2[i*3    ][j];
        tp2 = Tre2[i*3 + 1][j];
        tp3 = Tre2[i*3 + 2][j];
        Tre[i*3  ][j] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        Tre[i*3+1][j] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        Tre[i*3+2][j] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;        
                                 }

// Normales 
for (i=0; i < nb_ligne  ; i++)                                                                       
for (j=0; j < moitie_colone -1   ; j++) {
        tp1 = Nor2[i*3    ][j];
        tp2 = Nor2[i*3 + 1][j];
        tp3 = Nor2[i*3 + 2][j];
        Nor[i*3  ][j] = mat_rotation_save.xx*tp1 + mat_rotation_save.xy*tp2 +mat_rotation_save.xz*tp3 + mat_rotation_save.xo;
        Nor[i*3+1][j] = mat_rotation_save.yx*tp1 + mat_rotation_save.yy*tp2 +mat_rotation_save.yz*tp3 + mat_rotation_save.yo;
        Nor[i*3+2][j] = mat_rotation_save.zx*tp1 + mat_rotation_save.zy*tp2 +mat_rotation_save.zz*tp3 + mat_rotation_save.zo;   

    }                    
                         
                   
                              
      //mat_first_obj = mat;
      //mat_rotation_first_save= mat_rotation_save;

      }
  if(change_second_object == 1){
  for (i=0; i < nb_ligne  ; i++)
   for (j=moitie_colone -1; j < nb_colone ; j++){
        tp1 = Tre2[i*3    ][j];
        tp2 = Tre2[i*3 + 1][j];
        tp3 = Tre2[i*3 + 2][j];
        Tre[i*3  ][j] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        Tre[i*3+1][j] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        Tre[i*3+2][j] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;        
                                 }
      
// Normales 
for (i=0; i < nb_ligne  ; i++)                                                                       
for (j = moitie_colone -1; j < nb_colone    ; j++) {
        tp1 = Nor2[i*3    ][j];
        tp2 = Nor2[i*3 + 1][j];
        tp3 = Nor2[i*3 + 2][j];
        Nor[i*3  ][j] = mat_rotation_save.xx*tp1 + mat_rotation_save.xy*tp2 +mat_rotation_save.xz*tp3 + mat_rotation_save.xo;
        Nor[i*3+1][j] = mat_rotation_save.yx*tp1 + mat_rotation_save.yy*tp2 +mat_rotation_save.yz*tp3 + mat_rotation_save.yo;
        Nor[i*3+2][j] = mat_rotation_save.zx*tp1 + mat_rotation_save.zy*tp2 +mat_rotation_save.zz*tp3 + mat_rotation_save.zo;
    }                    
                                                 
      //mat_second_obj = mat;
      //mat_rotation_second_save = mat_rotation_save;
      
      }           

      }  
      
                                 
// Boite englobante
    
for (i=0; i < 8  ; i++) {

        tp1 = boiteenglobante2[i*3    ];
        tp2 = boiteenglobante2[i*3 + 1];
        tp3 = boiteenglobante2[i*3 + 2];
        boiteenglobante[i*3    ] = mat.xx*tp1 + mat.xy*tp2 +mat.xz*tp3 + mat.xo;
        boiteenglobante[i*3 + 1] = mat.yx*tp1 + mat.yy*tp2 +mat.yz*tp3 + mat.yo;
        boiteenglobante[i*3 + 2] = mat.zx*tp1 + mat.zy*tp2 +mat.zz*tp3 + mat.zo;        

                                      }                         

/*
// Normales

for (i=0; i < nb_ligne  ; i++)                                                                       for (j=0; j < nb_colone    ; j++) {
        tp1 = Nor2[i*3    ][j];
        tp2 = Nor2[i*3 + 1][j];
        tp3 = Nor2[i*3 + 2][j];
        Nor[i*3  ][j] = mat_rotation_save.xx*tp1 + mat_rotation_save.xy*tp2 +mat_rotation_save.xz*tp3 + mat_rotation_save.xo;
        Nor[i*3+1][j] = mat_rotation_save.yx*tp1 + mat_rotation_save.yy*tp2 +mat_rotation_save.yz*tp3 + mat_rotation_save.yo;
        Nor[i*3+2][j] = mat_rotation_save.zx*tp1 + mat_rotation_save.zy*tp2 +mat_rotation_save.zz*tp3 + mat_rotation_save.zo;   

    }
*/
}


/*****************************************************************************/
/*****************************************************************************/ 

void Model3D::initialiser_parseur3() {
    myParser.AddConstant ("pi", 3.14159265);
    myParserX.AddConstant("pi", 3.14159265);
    myParserY.AddConstant("pi", 3.14159265);
    myParserZ.AddConstant("pi", 3.14159265);
    myParserW.AddConstant("pi", 3.14159265);
    myParserT.AddConstant("pi", 3.14159265);
    myParserS.AddConstant("pi", 3.14159265);
    
    
    myParserX_2.AddConstant("pi", 3.14159265);
    myParserY_2.AddConstant("pi", 3.14159265);
    myParserZ_2.AddConstant("pi", 3.14159265);  
    
    myParser_spherical.AddConstant("pi", 3.14159265);
    myParser_cylindrical.AddConstant("pi", 3.14159265);
    
    myParser_condition.AddConstant("pi", 3.14159265);
    
     }


/*****************************************************************************/
/** This function must be rewriten for more clarity..*************************/
/*****************************************************************************/ 

03180 void  Model3D::parse_expression() {
    double vals[] = { 0,0,0,0,0,0}; // arbitrary values


if(there_is_condition == 1) {
  myParser_condition.AddFunction("k", f1);
  myParser_condition.Parse(condition_expression, "u,v,t,x,y,z");                    
                      }

if ( supershape == 1){
    myParser.Parse(sm1, "u,v,t,x,y,z");
    m1 = myParser.Eval(vals); 
     
    myParser.Parse(sm2, "u,v,t,x,y,z");
    m2 = myParser.Eval(vals);     
     
    myParser.Parse(sa_1, "u,v,t,x,y,z");
    a_1 = myParser.Eval(vals);
    
    myParser.Parse(sa_2, "u,v,t,x,y,z");
    a_2 = myParser.Eval(vals);    
         
    myParser.Parse(sb_1, "u,v,t,x,y,z");
    b_1 = myParser.Eval(vals);
    
    myParser.Parse(sb_2, "u,v,t,x,y,z");
    b_2 = myParser.Eval(vals);

    myParser.Parse(sn1_1, "u,v,t,x,y,z");
    n1_1 = myParser.Eval(vals);
    
    myParser.Parse(sn1_2, "u,v,t,x,y,z");
    n1_2 = myParser.Eval(vals);
    
    myParser.Parse(sn2_1, "u,v,t,x,y,z");
    n2_1 = myParser.Eval(vals);
    
    myParser.Parse(sn2_2, "u,v,t,x,y,z");
    n2_2 = myParser.Eval(vals);    
    
    myParser.Parse(sn3_1, "u,v,t,x,y,z");
    n3_1 = myParser.Eval(vals);
    
    myParser.Parse(sn3_2, "u,v,t,x,y,z");
    n3_2 = myParser.Eval(vals);
    

    myParser.Parse(inf_u, "u,v,t,x,y");
    u_inf = myParser.Eval(vals);
    myParser.Parse(sup_u, "u,v,t,x,y");
    u_sup = myParser.Eval(vals);
    dif_u = u_sup - u_inf;

    myParser.Parse(inf_v, "u,v,t,x,y");
    v_inf = myParser.Eval(vals);
    myParser.Parse(sup_v, "u,v,t,x,y");
    v_sup = myParser.Eval(vals);
    dif_v = v_sup - v_inf;


    
    
    
         
     }
else
 if(  implicitdef != 1 ) {     
    if(DefineNewFct ==1){
    f1.Parse(newfct, "u,v,t,x,y");
    myParserX.AddFunction("k", f1);
    myParserY.AddFunction("k", f1);
    myParserZ.AddFunction("k", f1);
    
    myParserX_2.AddFunction("k", f1);
    myParserY_2.AddFunction("k", f1);
    myParserZ_2.AddFunction("k", f1);
    
    myParser_spherical.AddFunction("k", f1);
    myParser_cylindrical.AddFunction("k", f1);      
                        }      
    myParser.Parse(inf_u, "u,v,t,x,y");
    u_inf = myParser.Eval(vals);
    myParser.Parse(sup_u, "u,v,t,x,y");
    u_sup = myParser.Eval(vals);
    dif_u = u_sup - u_inf;

    myParser.Parse(inf_v, "u,v,t,x,y");
    v_inf = myParser.Eval(vals);
    myParser.Parse(sup_v, "u,v,t,x,y");
    v_sup = myParser.Eval(vals);
    dif_v = v_sup - v_inf;
     
 myParserX.Parse(expression_X, "u,v,t,x,y");
 myParserY.Parse(expression_Y, "u,v,t,x,y");
 myParserZ.Parse(expression_Z, "u,v,t,x,y");

 // if two system activated
 
 if(two_system == 1) {
    myParser.Parse(inf_u_2, "u,v,t,x,y");
    u_inf_2 = myParser.Eval(vals);
    myParser.Parse(sup_u_2, "u,v,t,x,y");
    u_sup_2 = myParser.Eval(vals);
    dif_u_2 = u_sup_2 - u_inf_2;

    myParser.Parse(inf_v_2, "u,v,t,x,y");
    v_inf_2 = myParser.Eval(vals);
    myParser.Parse(sup_v_2, "u,v,t,x,y");
    v_sup_2 = myParser.Eval(vals);
    dif_v_2 = v_sup_2 - v_inf_2;
  
 myParserX_2.Parse(expression_X_2, "u,v,t,x,y");
 myParserY_2.Parse(expression_Y_2, "u,v,t,x,y");
 myParserZ_2.Parse(expression_Z_2, "u,v,t,x,y");
 }
 
 
  // 6D shapes 
 if (sixdimshapes == 1 ) {     
    myParserW.AddFunction("k", f1);    
    myParserW.Parse(expression_W, "u,v,t,x,y"); 
    
    myParserT.AddFunction("k", f1);    
    myParserT.Parse(expression_T, "u,v,t,x,y");  
    
    myParserS.AddFunction("k", f1);    
    myParserS.Parse(expression_S, "u,v,t,x,y");              
     }
     
 // 5D shapes 
 if (fivedimshapes == 1 ) {     
    myParserW.AddFunction("k", f1);    
    myParserW.Parse(expression_W, "u,v,t,x,y"); 
    
    myParserT.AddFunction("k", f1);    
    myParserT.Parse(expression_T, "u,v,t,x,y");                
     }
 // 4D shapes 
 else if (fourdimshapes == 1 ) {     
    myParserW.AddFunction("k", f1);    
    myParserW.Parse(expression_W, "u,v,t,x,y");          
     }
 

 else if(sphericaldef == 1) // spherical equation  r^n = f(u,v,x,y,z)
    { 
     // we are looking for the parity of the coefficient n
    myParser.Parse(coefficient_n, "u,v,t,x,y");
    coefficent_fct_implicite = myParser.Eval(vals);
    coefficent_fct_implicite_parity = fmod(coefficent_fct_implicite, 2);       
    myParser_spherical.Parse(spherical_expression, "u,v,t,x,y,z"); // we have one more variable z    
    }
 else if(cylindricaldef == 1) // spherical equation  r^n = f(u,v,x,y,z)
    { 
     // we are looking for the parity of the coefficient n
    myParser.Parse(coefficient_n, "u,v,t,x,y");
    coefficent_fct_implicite = myParser.Eval(vals);
    coefficent_fct_implicite_parity = fmod(coefficent_fct_implicite, 2);       
    myParser_cylindrical.Parse(cylindrical_expression, "u,v,t,x,y,z"); // we have one more variable z    
    }

    
}


// this part is for the implicit equation...
else {

// We use the borders of the second system to delimite x and y
    myParser.Parse(inf_u, "u,v,t,x,y");
    u_inf = myParser.Eval(vals);
    myParser.Parse(sup_u, "u,v,t,x,y");
    u_sup = myParser.Eval(vals);
    dif_u = u_sup - u_inf;

    myParser.Parse(inf_v, "u,v,t,x,y");
    v_inf = myParser.Eval(vals);
    myParser.Parse(sup_v, "u,v,t,x,y");
    v_sup = myParser.Eval(vals);
    dif_v = v_sup - v_inf;
    
 // we are looking for the parity of the coefficient n
    myParser.Parse(coefficient_n, "u,v,t,x,y");
    coefficent_fct_implicite = myParser.Eval(vals);
    coefficent_fct_implicite_parity = fmod(coefficent_fct_implicite, 2);
 // we set the first and second equation to u and v    
    
    myParserX.Parse("u", "u,v,t,x,y");
    myParserY.Parse("v", "u,v,t,x,y"); 
 // Now we construct the third equation for Implicit equation z^n = f(x,y)...
    expression_Z = expression_implicite;
    myParserZ.Parse(expression_Z, "u,v,t,x,y");
                        

 // just for more security....
    two_system = -1;

}


 
 
 
} 
 


/*****************************************************************************/
/*****************************************************************************/ 
03389 void  Model3D::calcul_objet3() {
    double vals[] = {0,0,0,0,0,0}; 
    double vals2[] = {0,0,0,0,0,0};
    double iprime, jprime, valeur_de_fct_implicite;
    double spherical_val, cylindrical_val, U_step, V_step;

    
   
    
// we initialise the hidden_points array so all points are ready to be drawn    
    
   for(int j=0; j < nb_ligne   ; j++)
    for (int i=0; i < nb_colone  ; i++)
         hidden_points[j][i]  = 1;     
    
   there_is_hidden_points = -1;
    
        
// this is for the morph effect...
if(morph_param >= 0.0) {
 vals[2] = vals2[2] = morph_param ;
}
else {
 vals[2] = vals2[2] = -morph_param ;
}
morph_param -= step ;
if( morph_param <= -1) morph_param = 1;



if ( supershape == 1){
/*     dif_u = 6.28; u_inf = -3.14;
       dif_v = 3.14; v_inf = -1.57; 


     
m1 = 0; a_1 = 1.0; b_1 =1.0; n1_1 = 0.48; n2_1 =30.25; n3_1 =0.35;
m2 = 5; a_2 = 1.0; b_2 =1.0; n1_2 = 15.44; n2_2 =-0.45; n3_2 =87;

m1 = 0.2; a_1 = 1.0; b_1 =1.0; n1_1 = 0.1; n2_1 =1.7; n3_1 =1.7;
m2 = 0.2; a_2 = 1.0; b_2 =1.0; n1_2 = 0.5; n2_2 =0.2; n3_2 =0.2;

m1 = 2; a_1 = 1.0; b_1 =1.0; n1_1 = 1; n2_1 =1; n3_1 =1;
m2 = 4; a_2 = 1.0; b_2 =1.0; n1_2 = 1; n2_2 =1; n3_2 =1;

m1 = 5.7; a_1 = 1.0; b_1 =1.0; n1_1 = 0.5; n2_1 = 1; n3_1 =2.5;
m2 = 10; a_2 = 1.0; b_2 =1.0; n1_2 = 3; n2_2 =0.2; n3_2 = 1;

m1 = 6; a_1 = 1.0; b_1 =1.0; n1_1 = 60; n2_1 = 55; n3_1 =1000;
m2 = 6; a_2 = 1.0; b_2 =1.0; n1_2 =250; n2_2 =100; n3_2 = 100;
 
m1 = 2; a_1 = 1.0; b_1 =1.0; n1_1 = 0.99; n2_1 =97.67; n3_1 =-0.439;
m2 = 7; a_2 = 1.0; b_2 =1.0; n1_2 = -8.11; n2_2 =-0.0807; n3_2 =93;

m1 = 6; a_1 = 1.0; b_1 =1.0; n1_1 = 0.709889; n2_1 =46.82; n3_1 =-0.80;
m2 = 7; a_2 = 1.0; b_2 =1.0; n1_2 = -31.9083; n2_2 =-0.19; n3_2 = 97;
    
m1 = 6; a_1 = 1.0; b_1 =1.0; n1_1 = 3000; n2_1 =1000; n3_1 =1000;
m2 = 6; a_2 = 1.0; b_2 =1.0; n1_2 = 250; n2_2 =100; n3_2 =100;     
     
m1 = 3; a_1 = 1.0; b_1 =1.0; n1_1 = 1; n2_1 =1; n3_1 =1;
m2 = 6; a_2 = 2.0; b_2 =1.0; n1_2 = 2; n2_2 =1; n3_2 =1;
      
m1 = 7; a_1 = 1.0; b_1 =1.0; n1_1 = 0.2; n2_1 =1.7; n3_1 =1.7;
m2 = 7; a_2 = 1.0; b_2 =1.0; n1_2 = 0.2; n2_2 =1.7; n3_2 =1.7;
*/
double r1, r2;
  // Begin First case : n = 1, 3, 5.....  
//  if(coefficent_fct_implicite_parity == 1)   
    for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   r1 = pow(
        pow(fabs(cos(m1*jprime/4)/a_1), n2_1) + 
        pow(fabs(sin(m1*jprime/4)/b_1), n3_1)
        , -1/n1_1);
   

   r2 = pow(
        pow(fabs(cos(m2*iprime/4)/a_2), n2_2) + 
        pow(fabs(sin(m2*iprime/4)/b_2), n3_2)
        , -1/n1_2);

   
   Tre2[j*3    ][i]  = r1 * cos(jprime) * r2 * cos(iprime);
   Tre2[j*3 + 1][i]  = r1 * sin(jprime) * r2 * cos(iprime);
   Tre2[j*3 + 2][i]  = r2 * sin(iprime);
   
   
      
   
        }          }

  // End of first case : n = 1, 3, 5.....  
  
 
}

 else if (cylindricaldef == 1){   

  // Begin First case : n = 1, 3, 5.....  
//  if(coefficent_fct_implicite_parity == 1)   
    for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;   // u = jprime ; v = iprime;

   vals[3] = cos(jprime) ; // because  X = cos(u)
   vals[4] = sin(jprime);  // because  Y = sin(u)
   vals[5] = iprime  ;     // because  Z = v
   cylindrical_val = myParser_cylindrical.Eval(vals) ; 
   
   (cylindrical_val  >= 0 ) ?
   cylindrical_val  =  pow(cylindrical_val, 1/coefficent_fct_implicite) : 
   cylindrical_val  = -pow(-cylindrical_val, 1/coefficent_fct_implicite);
   
   Tre2[j*3    ][i]  = vals[3] * cylindrical_val;
   Tre2[j*3 + 1][i]  = vals[4] * cylindrical_val;
   Tre2[j*3 + 2][i]  = vals[5] ;
   
   
      
   
        }          }

  // End of first case : n = 1, 3, 5.....  
  
 
}
else if (sphericaldef == 1){   

  // Begin First case : n = 1, 3, 5.....  
//  if(coefficent_fct_implicite_parity == 1)   
    for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;   // u = jprime ; v = iprime;

   
//double supershape(double n1, double n2, double n3, int m, double a, double b, double teta)   
   vals[3] = cos(iprime)*cos(jprime) ; // because  X = cos(v)*cos(u)
   vals[4] = sin(iprime)*cos(jprime);  // because  Y = sin(v)*cos(u)
   vals[5] = sin(jprime)  ;            // because  Z = sin(u)
   spherical_val = myParser_spherical.Eval(vals) ; 
   
   (spherical_val  >= 0 ) ?
   spherical_val  =  pow(spherical_val, 1/coefficent_fct_implicite) : 
   spherical_val  = -pow(-spherical_val, 1/coefficent_fct_implicite);
   
   Tre2[j*3    ][i]  = vals[3] * spherical_val;
   Tre2[j*3 + 1][i]  = vals[4] * spherical_val;
   Tre2[j*3 + 2][i]  = vals[5] * spherical_val;

   
        }          }

  // End of first case : n = 1, 3, 5.....   
  
}
else 

if(sixdimshapes == 1){
                  
  for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;    
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;

   shape6D[j*6    ][i]  = vals[3] = myParserX.Eval(vals);
   shape6D[j*6 + 1][i]  = vals[4] = myParserY.Eval(vals);  
   shape6D[j*6 + 2][i]            = myParserZ.Eval(vals);
   shape6D[j*6 + 3][i]            = myParserW.Eval(vals);
   shape6D[j*6 + 4][i]            = myParserT.Eval(vals);
   shape6D[j*6 + 5][i]            = myParserS.Eval(vals);
        }          }                
   
   boite_englobante6D();
   project_6D_to_5D();
   project_5D_to_4D();                
   project_4D_to_3D();               
                  
                  }
else

if(fivedimshapes == 1){
                  
  for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;    
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;

   shape5D[j*5    ][i]  = vals[3] = myParserX.Eval(vals);
   shape5D[j*5 + 1][i]  = vals[4] = myParserY.Eval(vals);  
   shape5D[j*5 + 2][i]            = myParserZ.Eval(vals);
   shape5D[j*5 + 3][i]            = myParserW.Eval(vals);
   shape5D[j*5 + 4][i]            = myParserT.Eval(vals);
        }          }                
   
   boite_englobante5D();
   project_5D_to_4D();               
   project_4D_to_3D();               
                  
                  }

else


if(fourdimshapes == 1){
                  
  for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;    
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;

   vals[3] = shape4D[j*4    ][i]  = myParserX.Eval(vals);
   vals[4] = shape4D[j*4 + 1][i]  = myParserY.Eval(vals);  
   shape4D[j*4 + 2][i]  = myParserZ.Eval(vals);
   shape4D[j*4 + 3][i]  = myParserW.Eval(vals);
        }          }                
   
   boite_englobante4D();                  
   project_4D_to_3D();               
                  
                  }

else



if(two_system == -1)     // Just one system...cooooooooooool
 if(  implicitdef != 1 )    {
 // in this case we have a simple equation system...
  if(there_is_condition == -1) // No condition to verify
  for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;

    
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;

   vals[3] = Tre2[j*3    ][i]  = myParserX.Eval(vals);
   vals[4] = Tre2[j*3 + 1][i]  = myParserY.Eval(vals);
   Tre2[j*3 + 2][i]  = myParserZ.Eval(vals);
        }          
   } // End of if(there_is_condition == -1)

  // Here There is a condition to verify
  else {
       /// Calculate the grid
   for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;   
        for (int i=0; i < nb_colone   ; i++) {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;

   vals[3] = Tre2[j*3    ][i]  = myParserX.Eval(vals);
   vals[4] = Tre2[j*3 + 1][i]  = myParserY.Eval(vals);
   vals[5] = Tre2[j*3 + 2][i]  = myParserZ.Eval(vals);
       if( myParser_condition.Eval(vals) == 0) {
          hidden_points[j][i] = 0;
          there_is_hidden_points = 1; //
                                                }
                                            }           
                                        }      
        /// We will try to resove HP

  } // End  There is a condition to verify

} // End  if(  implicitdef != 1 ) 
        
// here we are going to work with implicit equation...        
         
 else 
   {
  // Begin First case : n = 1, 3, 5.....  
  if(coefficent_fct_implicite_parity == 1)   
    for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;

    
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone-1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;

   vals[3] = Tre2[j*3    ][i]  = jprime; // because  X = u
   vals[4] = Tre2[j*3 + 1][i]  = iprime; // because  Y = v
   //Tre2[j*3 + 2][i]  = pow(myParserZ.Eval(vals), 1/coefficent_fct_implicite);
   
   valeur_de_fct_implicite = myParserZ.Eval(vals) ;
   (valeur_de_fct_implicite  >= 0 ) ?
   Tre2[j*3 + 2][i]  = pow(valeur_de_fct_implicite, 1/coefficent_fct_implicite) : 
   Tre2[j*3 + 2][i]  = -pow(-valeur_de_fct_implicite, 1/coefficent_fct_implicite);
   
        }          }

  // End of first case : n = 1, 3, 5.....  
  
 
  // Begin Second case : n = 2, 4, 6..... 

 else {
 
// We begin with half of the grid...be careful...
  for(int j=0; j < nb_ligne ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
    
        for (int i=0; i < nb_colone   ; i++)
      {
   iprime = (double)i/(double)(nb_colone -1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]= vals[3] = jprime; vals[1] = vals[4] = iprime;

   Tre2[j*3    ][i]  =  jprime;
   Tre2[j*3 + 1][i]  =  iprime;
   valeur_de_fct_implicite = myParserZ.Eval(vals) ;
   
   if (valeur_de_fct_implicite  >= 0 )  Tre2[j*3 + 2][i] =  pow(valeur_de_fct_implicite, 1/coefficent_fct_implicite);

        
   else  { 
   hidden_points[j][i]  = 0;
   there_is_hidden_points = 1; // we give the signal to take care of the fact that we have some HP
   }        
        }
}


//we tray to fix some points of the grid 

  for(int j=0; j < nb_ligne -1   ; j++)
    for (int i=0; i < nb_colone -1  ; i++)        
         {   
      if((hidden_points[j  ][i  ] +  
          hidden_points[j+1][i  ] +  
            hidden_points[j+1][i+1] + 
            hidden_points[j  ][i+1]) >=3) 
             { 
   if(hidden_points[j][i] == 0) 
       Tre2[j*3 + 2][i] = (Tre2[(j+1)*3 + 2][i] + Tre2[j*3 + 2][i+1])/2;
                   
   else if(hidden_points[j+1][i] == 0) 
       Tre2[(j+1)*3 + 2][i] = (Tre2[(j+1)*3 + 2][i+1] + Tre2[j*3 + 2][i])/2;

   else if(hidden_points[j+1][i+1] == 0) 
       Tre2[(j+1)*3 + 2][i+1] = (Tre2[(j+1)*3 + 2][i] + Tre2[j*3 + 2][i+1])/2;

   else if(hidden_points[j][i+1] == 0) 
       Tre2[j*3 + 2][i+1] = (Tre2[j*3 + 2][i] + Tre2[(j+1)*3 + 2][i+1])/2;       
                  }               
          }

/*      
// The new way to calculate the new values to replace HP
if(there_is_hidden_points == 1){

 U_step = (double)dif_u/(double)( (nb_colone-1) * precision) ;
 V_step = (double)dif_v/(double)( (nb_colone-1) * precision) ;

  for(int j=0; j < nb_ligne -1   ; j++)
    for (int i=0; i < nb_colone -1  ; i++)        
           
      if((hidden_points[j][i]     +  
          hidden_points[j+1][i]   +  
        hidden_points[j+1][i+1] + 
        hidden_points[j][i+1])    >=3) 
             {  
   // DL = Down-Left           
   if(hidden_points[j][i] == 0) 
          for(int k=1; k < 11   ; k++)  {  
   DL2[j*3    ][i] = vals[0] = vals[3] = (Tre2[j*3    ][i] + (double)k*(double)U_step);
   DL2[j*3 + 1][i] = vals[1] = vals[4] = (Tre2[j*3 + 1][i] + (double)k*(double)V_step);
   valeur_de_fct_implicite = myParserZ.Eval(vals) ;  
   if(valeur_de_fct_implicite >=0) {
   DL2[j*3 + 2][i] =  pow(valeur_de_fct_implicite, 1/coefficent_fct_implicite);
   k = 10; 
                                   }        
                                      }      
   // HL = Height-Left
   else if(hidden_points[j+1][i] == 0) 
          for(int k=1; k < 11   ; k++)   {
   HL2[(j+1)*3    ][i] = vals[0] = vals[3] = (Tre2[(j+1)*3    ][i] - (double)k*(double)U_step);
   HL2[(j+1)*3 + 1][i] = vals[1] = vals[4] = (Tre2[(j+1)*3 + 1][i] + (double)k*(double)V_step);
   valeur_de_fct_implicite = myParserZ.Eval(vals) ;  
   if(valeur_de_fct_implicite >=0) {
   HL2[(j+1)*3 + 2][i] =  pow(valeur_de_fct_implicite, 1/coefficent_fct_implicite);
   k = 10; 
                                   }        
                                      }       
   // HR = Height-Right
   else if(hidden_points[j+1][i+1] == 0) 
          for(int k=1; k < 11   ; k++)   {
   HR2[(j+1)*3    ][i+1] = vals[0] = vals[3] = (Tre2[(j+1)*3    ][i+1] - (double)k*(double)U_step);
   HR2[(j+1)*3 + 1][i+1] = vals[1] = vals[4] = (Tre2[(j+1)*3 + 1][i+1] - (double)k*(double)V_step);
   valeur_de_fct_implicite = myParserZ.Eval(vals) ;  
   if(valeur_de_fct_implicite >=0) {
   HR2[(j+1)*3 + 2][i+1] =  pow(valeur_de_fct_implicite, 1/coefficent_fct_implicite);
   k = 10; 
                                   }        
                                      }
   // DR = Down-Right
   else if(hidden_points[j][i+1] == 0) 
          for(int k=1; k < 11   ; k++)   {
   DR2[j*3    ][i+1] = vals[0] = vals[3] = (Tre2[j*3    ][i+1] + (double)k*(double)U_step);
   DR2[j*3 + 1][i+1] = vals[1] = vals[4] = (Tre2[j*3 + 1][i+1] - (double)k*(double)V_step);
   valeur_de_fct_implicite = myParserZ.Eval(vals) ;  
   if(valeur_de_fct_implicite >=0) {
   DR2[j*3 + 2][i+1] =  pow(valeur_de_fct_implicite, 1/coefficent_fct_implicite);
   k = 10; 
                                   }        
                                      } 
     
                  }   // End of   if((hidden_points[j][i]+...)           
}; // End of if(there_is_hidden_points == 1)
*/ 

         
         }  // End of Second case : n = 2, 4, 6.....          
   
  
   } // end of implicit equation... 
 
        
//================ Begin treatement of two systemes ============   
 
 else {

moitie_colone = nb_colone/2;  

// We begin with half of the grid...be careful...
  for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u  + u_inf;
    
        for (int i=0; i < moitie_colone   ; i++)
      {
   iprime = (double)i/(double)(moitie_colone -1 ) ;
   iprime = iprime * dif_v + v_inf;
   
   vals[0]=jprime; vals[1]=iprime;

   vals[3] = Tre2[j*3    ][i]  = myParserX.Eval(vals);
   vals[4] = Tre2[j*3 + 1][i]  = myParserY.Eval(vals);
   vals[5] = Tre2[j*3 + 2][i]  = myParserZ.Eval(vals);
   /*
          if( myParser_condition.Eval(vals) == 0) {
          hidden_points[j][i] = 0;
          there_is_hidden_points = 1; //
                                                }
   */
        }
                                       }

// we finish the remaining of the grid...
  for(int j=0; j < nb_ligne   ; j++) {
    jprime = (double)j/(double)(nb_ligne -1 ) ;
    jprime = jprime * dif_u_2  + u_inf_2;
    
        for (int i=moitie_colone-1; i < nb_colone   ; i++)
      {
   iprime = (double)(i - moitie_colone+1)/(double)(nb_colone - moitie_colone ) ;
   iprime = iprime * dif_v_2 + v_inf_2;
   
   vals2[0]=jprime; vals2[1]=iprime;

   vals2[3] = Tre2[j*3    ][i]  = myParserX_2.Eval(vals2);
   vals2[4] = Tre2[j*3 + 1][i]  = myParserY_2.Eval(vals2);
   vals2[5] = Tre2[j*3 + 2][i]  = myParserZ_2.Eval(vals2);
   /*
          if( myParser_condition.Eval(vals2) == 0) {
          hidden_points[j][i] = 0;
          there_is_hidden_points = 1; //
                                                }
   */
        }
                                       }

}            



























/// In This code we attempt resolve some missing Points 
// DB=Defined Border, NDB=Non defined Border, MP = Middle Point

double DB_X, DB_Y, 
       NDB_X, NDB_Y, 
       MP_X, MP_Y;
int    precision_step, i, j;


if(there_is_condition == 1 && implicitdef != 1){
    
 U_step =  dif_u/(double)(nb_ligne  -1);
 V_step =  dif_v/(double)(nb_colone -1);

// In this case, we have just one missing point

  for(j=0; j < nb_ligne -1   ; j++)
    for (i=0; i < nb_colone -1  ; i++)      
           
      if((hidden_points[j  ][i  ]  +  
          hidden_points[j+1][i  ]  +  
            hidden_points[j+1][i+1]  + 
            hidden_points[j  ][i+1]) >=3) 
             {  
///============= First case : DL = Down-Left=====================  
   if(hidden_points[j][i] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j+1)) * U_step + u_inf;
   DB_Y  =  ((double)(i+1)) * V_step + v_inf;
   //DB_X  =  ((double)(j+1)) * U_step + u_inf;
   //DB_Y  =  ((double)(i)) * V_step + v_inf;   
   
   NDB_X =  ((double)(j)) * U_step + u_inf;
   NDB_Y =  ((double)(i)) * V_step + v_inf; 
     
   DL2[j*3    ][i] = Tre2[(j+1)*3    ][i];
   DL2[j*3 + 1][i] = Tre2[(j+1)*3 + 1][i];
   DL2[j*3 + 2][i] = Tre2[(j+1)*3 + 2][i];
   
   precision_step = 0; // Approximation by 2^5
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 
   // We compute this point and look if it fulfill the condition
   // If yes => DB = MP; else NDB = MP;

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   DL2[j*3    ][i] = vals[3];
   DL2[j*3 + 1][i] = vals[4];
   DL2[j*3 + 2][i] = vals[5];        
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...
        
   } // End of if(hidden_points[j][i] == 0)    

 
///============= Second case : HL = Height-Left ============                  
                  
   else if(hidden_points[j+1][i] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j))   * U_step + u_inf;
   DB_Y  =  ((double)(i+1)) * V_step + v_inf;

   //DB_X  =  ((double)(j+1))   * U_step + u_inf;
   //DB_Y  =  ((double)(i+1)) * V_step + v_inf;
      
   NDB_X =  ((double)(j+1)) * U_step + u_inf;
   NDB_Y =  ((double)(i))   * V_step + v_inf; 
     
   HL2[(j+1)*3    ][i] = Tre2[(j+1)*3    ][i+1];
   HL2[(j+1)*3 + 1][i] = Tre2[(j+1)*3 + 1][i+1];
   HL2[(j+1)*3 + 2][i] = Tre2[(j+1)*3 + 2][i+1];
   
   precision_step = 0; // Approximation by 2^5
   
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 
   // We compute this point and look if it fulfill the condition
   // If yes => DB = MP; else NDB = MP;

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   HL2[(j+1)*3    ][i] = vals[3];
   HL2[(j+1)*3 + 1][i] = vals[4];
   HL2[(j+1)*3 + 2][i] = vals[5];        
        }
           
   precision_step++;                                
   }// End of while ( precision_step < 5)...
        
   } // End of if(hidden_points[j][i] == 0)


 
///============= Third case : HR = Height-Right ============                  
                  
   else if(hidden_points[j+1][i+1] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j))   * U_step + u_inf;
   DB_Y  =  ((double)(i))   * V_step + v_inf;
   //DB_X  =  ((double)(j))   * U_step + u_inf;
   //DB_Y  =  ((double)(i+1))   * V_step + v_inf;
   
   NDB_X =  ((double)(j+1)) * U_step + u_inf;
   NDB_Y =  ((double)(i+1)) * V_step + v_inf; 
     
   HR2[(j+1)*3    ][i+1] = Tre2[j*3    ][i+1];
   HR2[(j+1)*3 + 1][i+1] = Tre2[j*3 + 1][i+1];
   HR2[(j+1)*3 + 2][i+1] = Tre2[j*3 + 2][i+1];
   
   precision_step = 0; // Approximation by 2^5
   
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 
   // We compute this point and look if it fulfill the condition
   // If yes => DB = MP; else NDB = MP;

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   HR2[(j+1)*3    ][i+1] = vals[3];
   HR2[(j+1)*3 + 1][i+1] = vals[4];
   HR2[(j+1)*3 + 2][i+1] = vals[5];        
        }
           
   precision_step++;                                
   }// End of while ( precision_step < 5)...
        
   } // End of if(hidden_points[j][i] == 0)



///============= Fourth case : DR = Height-Right ============                  
                  
   else if(hidden_points[j][i+1] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j+1))   * U_step + u_inf;
   DB_Y  =  ((double)(i))   * V_step + v_inf;
   //DB_X  =  ((double)(j))   * U_step + u_inf;
   //DB_Y  =  ((double)(i))   * V_step + v_inf;   
   
   NDB_X =  ((double)(j)) * U_step + u_inf;
   NDB_Y =  ((double)(i+1))   * V_step + v_inf; 
     
   DR2[j*3    ][i+1] = Tre2[j*3    ][i];
   DR2[j*3 + 1][i+1] = Tre2[j*3 + 1][i];
   DR2[j*3 + 2][i+1] = Tre2[j*3 + 2][i];
   
   precision_step = 0; // Approximation by 2^5
   
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 
   // We compute this point and look if it fulfill the condition
   // If yes => DB = MP; else NDB = MP;

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   DR2[j*3    ][i+1] = vals[3];
   DR2[j*3 + 1][i+1] = vals[4];
   DR2[j*3 + 2][i+1] = vals[5];        
        }
           
   precision_step++;                                
   }// End of while ( precision_step < 5)...
        
   } // End of if(hidden_points[j][i] == 0)   
                  
                  } // End of if((hidden_points[j][i] + ...)            
          



double DB2_X, DB2_Y,
    NDB2_X, NDB2_Y,
    MP2_X, MP2_Y;

//==============================================================
//========== In this case, we have two missing point ===========
//==============================================================
  for(j=0; j < nb_ligne -1   ; j++)
    for (i=0; i < nb_colone -1  ; i++)      
           
      if((hidden_points[j  ][i  ]  +  
          hidden_points[j+1][i  ]  +  
            hidden_points[j+1][i+1]  + 
            hidden_points[j  ][i+1]) == 2) 
             {  
///==================================      
   if(hidden_points[j][i] == 0 && hidden_points[j][i+1] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j+1)) * U_step + u_inf;
   DB_Y  =  ((double)(i)) * V_step + v_inf;
   
   NDB_X =  ((double)(j)) * U_step + u_inf;
   NDB_Y =  ((double)(i)) * V_step + v_inf; 
     
   DL2[j*3    ][i] = Tre2[(j+1)*3    ][i];
   DL2[j*3 + 1][i] = Tre2[(j+1)*3 + 1][i];
   DL2[j*3 + 2][i] = Tre2[(j+1)*3 + 2][i];

  
   DB2_X  =  ((double)(j+1))   * U_step + u_inf;
   DB2_Y  =  ((double)(i+1))   * V_step + v_inf;
   
   NDB2_X =  ((double)(j)) * U_step + u_inf;
   NDB2_Y =  ((double)(i+1))   * V_step + v_inf; 
     
   DR2[j*3    ][i+1] = Tre2[(j+1)*3    ][i+1];
   DR2[j*3 + 1][i+1] = Tre2[(j+1)*3 + 1][i+1];
   DR2[j*3 + 2][i+1] = Tre2[(j+1)*3 + 2][i+1];
   
   // First point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   DL2[j*3    ][i] = vals[3];
   DL2[j*3 + 1][i] = vals[4];
   DL2[j*3 + 2][i] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...
   
   
   // Second point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP2_X = (DB2_X + NDB2_X)/2; 
         MP2_Y = (DB2_Y + NDB2_Y)/2; 

   vals[0] = MP2_X;
   vals[1] = MP2_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB2_X = MP2_X;
   NDB2_Y = MP2_Y;       
       } 
   else {
   DB2_X = MP2_X;
   DB2_Y = MP2_Y;
   DR2[j*3    ][i+1] = vals[3];
   DR2[j*3 + 1][i+1] = vals[4];
   DR2[j*3 + 2][i+1] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...
       
        
   } // End of if(hidden_points[j][i] == 0 && hidden_points[j][i+1] == 0)    

 
///=========================                  
                  
   else if(hidden_points[j][i] == 0 && hidden_points[j+1][i] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j)) * U_step + u_inf;
   DB_Y  =  ((double)(i+1)) * V_step + v_inf;
   
   NDB_X =  ((double)(j)) * U_step + u_inf;
   NDB_Y =  ((double)(i)) * V_step + v_inf; 
     
   DL2[j*3    ][i] = Tre2[j*3    ][i+1];
   DL2[j*3 + 1][i] = Tre2[j*3 + 1][i+1];
   DL2[j*3 + 2][i] = Tre2[j*3 + 2][i+1];

  
   DB2_X  =  ((double)(j+1))   * U_step + u_inf;
   DB2_Y  =  ((double)(i+1))   * V_step + v_inf;
   
   NDB2_X =  ((double)(j+1)) * U_step + u_inf;
   NDB2_Y =  ((double)(i))   * V_step + v_inf; 
     
   HL2[(j+1)*3    ][i] = Tre2[(j+1)*3    ][i+1];
   HL2[(j+1)*3 + 1][i] = Tre2[(j+1)*3 + 1][i+1];
   HL2[(j+1)*3 + 2][i] = Tre2[(j+1)*3 + 2][i+1];
   
   // First point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   DL2[j*3    ][i] = vals[3];
   DL2[j*3 + 1][i] = vals[4];
   DL2[j*3 + 2][i] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...
   
   
   // Second point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP2_X = (DB2_X + NDB2_X)/2; 
         MP2_Y = (DB2_Y + NDB2_Y)/2; 

   vals[0] = MP2_X;
   vals[1] = MP2_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB2_X = MP2_X;
   NDB2_Y = MP2_Y;       
       } 
   else {
   DB2_X = MP2_X;
   DB2_Y = MP2_Y;
   HL2[(j+1)*3    ][i] = vals[3];
   HL2[(j+1)*3 + 1][i] = vals[4];
   HL2[(j+1)*3 + 2][i] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...

  
   } // End of if(hidden_points[j][i] == 0 && hidden_points[j+1][i] == 0)


 
///=========================                  
                  
   else if(hidden_points[j+1][i] == 0 && hidden_points[j+1][i+1] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j)) * U_step + u_inf;
   DB_Y  =  ((double)(i+1)) * V_step + v_inf;
   
   NDB_X =  ((double)(j+1)) * U_step + u_inf;
   NDB_Y =  ((double)(i+1)) * V_step + v_inf; 
     
   HR2[(j+1)*3    ][i+1] = Tre2[j*3    ][i+1];
   HR2[(j+1)*3 + 1][i+1] = Tre2[j*3 + 1][i+1];
   HR2[(j+1)*3 + 2][i+1] = Tre2[j*3 + 2][i+1];



   DB2_X  =  ((double)(j))   * U_step + u_inf;
   DB2_Y  =  ((double)(i)) * V_step + v_inf;
   
   NDB2_X =  ((double)(j+1)) * U_step + u_inf;
   NDB2_Y =  ((double)(i))   * V_step + v_inf; 
     
   HL2[(j+1)*3    ][i] = Tre2[j*3    ][i];
   HL2[(j+1)*3 + 1][i] = Tre2[j*3 + 1][i];
   HL2[(j+1)*3 + 2][i] = Tre2[j*3 + 2][i];
   
   // First point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   HR2[(j+1)*3    ][i+1] = vals[3];
   HR2[(j+1)*3 + 1][i+1] = vals[4];
   HR2[(j+1)*3 + 2][i+1] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...
   
   
   // Second point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP2_X = (DB2_X + NDB2_X)/2; 
         MP2_Y = (DB2_Y + NDB2_Y)/2; 

   vals[0] = MP2_X;
   vals[1] = MP2_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB2_X = MP2_X;
   NDB2_Y = MP2_Y;       
       } 
   else {
   DB2_X = MP2_X;
   DB2_Y = MP2_Y;
   HL2[(j+1)*3    ][i] = vals[3];
   HL2[(j+1)*3 + 1][i] = vals[4];
   HL2[(j+1)*3 + 2][i] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...



   } // End of if(hidden_points[j+1][i] == 0 && hidden_points[j+1][i+1] == 0)



///============= Fourth case : DR = Height-Right ============                  
                  
   else if(hidden_points[j+1][i+1] == 0 && hidden_points[j][i+1] == 0) {
   // initialisation                       
   DB_X  =  ((double)(j+1)) * U_step + u_inf;
   DB_Y  =  ((double)(i)) * V_step + v_inf;
   
   NDB_X =  ((double)(j+1)) * U_step + u_inf;
   NDB_Y =  ((double)(i+1)) * V_step + v_inf; 
     
   HR2[(j+1)*3    ][i+1] = Tre2[(j+1)*3    ][i];
   HR2[(j+1)*3 + 1][i+1] = Tre2[(j+1)*3 + 1][i];
   HR2[(j+1)*3 + 2][i+1] = Tre2[(j+1)*3 + 2][i];



   DB2_X  =  ((double)(j)) * U_step + u_inf;
   DB2_Y  =  ((double)(i)) * V_step + v_inf;
   
   NDB2_X =  ((double)(j)) * U_step + u_inf;
   NDB2_Y =  ((double)(i+1))   * V_step + v_inf; 
     
   DR2[j*3    ][i+1] = Tre2[j*3    ][i];
   DR2[j*3 + 1][i+1] = Tre2[j*3 + 1][i];
   DR2[j*3 + 2][i+1] = Tre2[j*3 + 2][i];
   
   // First point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP_X = (DB_X + NDB_X)/2; 
         MP_Y = (DB_Y + NDB_Y)/2; 

   vals[0] = MP_X;
   vals[1] = MP_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB_X = MP_X;
   NDB_Y = MP_Y;       
       } // End of if( myParser_condition.Eval(vals) == 0)
   else {
   DB_X = MP_X;
   DB_Y = MP_Y;
   HR2[(j+1)*3    ][i+1] = vals[3];
   HR2[(j+1)*3 + 1][i+1] = vals[4];
   HR2[(j+1)*3 + 2][i+1] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...
   
   
   // Second point solution 
   precision_step = 0; 
   while ( precision_step < 5){
         MP2_X = (DB2_X + NDB2_X)/2; 
         MP2_Y = (DB2_Y + NDB2_Y)/2; 

   vals[0] = MP2_X;
   vals[1] = MP2_Y;
   vals[3] = myParserX.Eval(vals);
   vals[4] = myParserY.Eval(vals);
   vals[5] = myParserZ.Eval(vals) ; 
    
   if( myParser_condition.Eval(vals) == 0) {
   NDB2_X = MP2_X;
   NDB2_Y = MP2_Y;       
       } 
   else {
   DB2_X = MP2_X;
   DB2_Y = MP2_Y;
   DR2[j*3    ][i+1] = vals[3];
   DR2[j*3 + 1][i+1] = vals[4];
   DR2[j*3 + 2][i+1] = vals[5];          
        }
   
   precision_step++;                                
   }// End of while ( precision_step < 5)...


   } // End of if(hidden_points[j+1][i+1] == 0 && hidden_points[j][i+1] == 0) 
                  
} // End of if((hidden_points[j][i] + ...)  





























}; // End of if(there_is_hidden_points == 1)



/*

  i = 0;  
  for(j=0; j < nb_ligne    ; j++) {
  DR2[j*3    ][i] = HR2[j*3    ][i] = HL2[j*3    ][i];
  DR2[j*3 + 1][i] = HR2[j*3 + 1][i] = HL2[j*3 + 1][i];
  DR2[j*3 + 2][i] = HR2[j*3 + 2][i] = HL2[j*3 + 2][i];
  }
  
  i = nb_colone -1;  
  for(j=0; j < nb_ligne    ; j++) { 
  DL2[j*3    ][i] = HL2[j*3    ][i] = HR2[j*3    ][i];
  DL2[j*3 + 1][i] = HL2[j*3 + 1][i] = HR2[j*3 + 1][i];
  DL2[j*3 + 2][i] = HL2[j*3 + 2][i] = HR2[j*3 + 2][i];
  }

  j = 0;  
  for(i=0; i < nb_colone    ; i++) {
  HR2[j*3    ][i] = HL2[j*3    ][i] = DL2[j*3    ][i];
  HR2[j*3 + 1][i] = HL2[j*3 + 1][i] = DL2[j*3 + 1][i];
  HL2[j*3 + 2][i] = HL2[j*3 + 2][i] = DL2[j*3 + 2][i];
  }

  j = nb_ligne -1;  
  for(i=0; i < nb_colone   ; i++) {
  DR2[j*3    ][i] = DL2[j*3    ][i] = HL2[j*3    ][i];
  DR2[j*3 + 1][i] = DL2[j*3 + 1][i] = HL2[j*3 + 1][i];
  DL2[j*3 + 2][i] = DL2[j*3 + 2][i] = HL2[j*3 + 2][i];
  }
*/




























} // End of the fct calcul_objet3()

/*****************************************************************************/
/*****************************************************************************/ 

void  Model3D::boite_englobante3() {            


// calcul des minimas et des maximas des coordonnees: X,Y et Z

MINX =999999999;//Tre2[0][0];
MINY =999999999;//Tre2[1][0];
MINZ =999999999;//Tre2[2][0];

MAXX =-999999999;//Tre2[0][0];
MAXY =-999999999;//Tre2[1][0];
MAXZ =-999999999;//Tre2[2][0];

 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {
     if(hidden_points[i][j] == 1 || implicitdef != 1) {
     if(MINX > Tre2[i*3    ][j] ) MINX = Tre2[i*3    ][j] ;
     
     if(MINY > Tre2[i*3 + 1][j] ) MINY = Tre2[i*3 + 1][j] ;
     
     if(MINZ > Tre2[i*3 + 2][j] ) MINZ = Tre2[i*3 + 2][j] ;

     if(MAXX < Tre2[i*3    ][j] ) MAXX = Tre2[i*3    ][j] ;
     
     if(MAXY < Tre2[i*3 + 1][j] ) MAXY = Tre2[i*3 + 1][j] ;
     
     if(MAXZ < Tre2[i*3 + 2][j] ) MAXZ = Tre2[i*3 + 2][j] ;
                                  }
    }






/*

// If there is a condition, we have to take in consideration points
// in DR, DL, HR and HL arrays...
  if(there_is_condition == 1 ) {
                        
   // the first array to threat is DR                     
   for (int i=1; i < nb_ligne -1   ; i++)
    for (int j=1; j < nb_colone -1   ; j++) {
     if(hidden_points[i][j] == 0) {
     if(MINX > DR2[i*3    ][j] ) MINX = DR2[i*3    ][j] ;
     
     if(MINY > DR2[i*3 + 1][j] ) MINY = DR2[i*3 + 1][j] ;
     
     if(MINZ > DR2[i*3 + 2][j] ) MINZ = DR2[i*3 + 2][j] ;

     if(MAXX < DR2[i*3    ][j] ) MAXX = DR2[i*3    ][j] ;
     
     if(MAXY < DR2[i*3 + 1][j] ) MAXY = DR2[i*3 + 1][j] ;
     
     if(MAXZ < DR2[i*3 + 2][j] ) MAXZ = DR2[i*3 + 2][j] ;
                                  }
    }                      
                        
  
     // the second array to threat is DL                     
   for (int i=1; i < nb_ligne -1   ; i++)
    for (int j=1; j < nb_colone -1   ; j++) {
     if(hidden_points[i][j] == 0) {
     if(MINX > DL2[i*3    ][j] ) MINX = DL2[i*3    ][j] ;
     
     if(MINY > DL2[i*3 + 1][j] ) MINY = DL2[i*3 + 1][j] ;
     
     if(MINZ > DL2[i*3 + 2][j] ) MINZ = DL2[i*3 + 2][j] ;

     if(MAXX < DL2[i*3    ][j] ) MAXX = DL2[i*3    ][j] ;
     
     if(MAXY < DL2[i*3 + 1][j] ) MAXY = DL2[i*3 + 1][j] ;
     
     if(MAXZ < DL2[i*3 + 2][j] ) MAXZ = DL2[i*3 + 2][j] ;
                                  }
    }                      
       
  
     // the third array to threat is HR                     
   for (int i=1; i < nb_ligne -1   ; i++)
    for (int j=1; j < nb_colone -1   ; j++) {
     if(hidden_points[i][j] == 0) {
     if(MINX > HR2[i*3    ][j] ) MINX = HR2[i*3    ][j] ;
     
     if(MINY > HR2[i*3 + 1][j] ) MINY = HR2[i*3 + 1][j] ;
     
     if(MINZ > HR2[i*3 + 2][j] ) MINZ = HR2[i*3 + 2][j] ;

     if(MAXX < HR2[i*3    ][j] ) MAXX = HR2[i*3    ][j] ;
     
     if(MAXY < HR2[i*3 + 1][j] ) MAXY = HR2[i*3 + 1][j] ;
     
     if(MAXZ < HR2[i*3 + 2][j] ) MAXZ = HR2[i*3 + 2][j] ;
                                  }
    }                      
       
  
     // the fifth array to threat is HL                     
   for (int i=1; i < nb_ligne -1   ; i++)
    for (int j=1; j < nb_colone -1   ; j++) {
     if(hidden_points[i][j] == 0) {
     if(MINX > HL2[i*3    ][j] ) MINX = HL2[i*3    ][j] ;
     
     if(MINY > HL2[i*3 + 1][j] ) MINY = HL2[i*3 + 1][j] ;
     
     if(MINZ > HL2[i*3 + 2][j] ) MINZ = HL2[i*3 + 2][j] ;

     if(MAXX < HL2[i*3    ][j] ) MAXX = HL2[i*3    ][j] ;
     
     if(MAXY < HL2[i*3 + 1][j] ) MAXY = HL2[i*3 + 1][j] ;
     
     if(MAXZ < HL2[i*3 + 2][j] ) MAXZ = HL2[i*3 + 2][j] ;
                                  }
    }                      

  } // End of if(there_is_condition == 1)...

*/

// On recherche la plus grande "difference" de distance entre les points
// pour reduire la figure a un cube d'une longueur de 1.
// On utilisera apres cette figure pour l'agrandir et bien la placer dans
// la fenetre de vue:

  DIFX = MAXX - MINX ;
  DIFY = MAXY - MINY ;
  DIFZ = MAXZ - MINZ ;

// save theses values for the equations generator :
  DIFX_tmp = DIFX; DIFY_tmp = DIFY; DIFZ_tmp = DIFZ;
  MINX_tmp = MINX; MINY_tmp = MINY; MINZ_tmp = MINZ;

// Recherche du maximum :
  DIFMAXIMUM = DIFX;

  if (DIFY > DIFMAXIMUM) {DIFMAXIMUM = DIFY;};
  if (DIFZ > DIFMAXIMUM) {DIFMAXIMUM = DIFZ;};



// On va inclure cet objet dans un cube de langueur maximum
// egale a "hauteur_fenetre"

double decalage_xo = -(MINX +MAXX)/2 ;
double decalage_yo = -(MINY +MAXY)/2 ;
double decalage_zo = -(MINZ +MAXZ)/2 ;

 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {      
    Tre2[i*3    ][j] = hauteur_fenetre * (Tre2[i*3    ][j] + decalage_xo)/DIFMAXIMUM ;
    Tre2[i*3 + 1][j] = hauteur_fenetre * (Tre2[i*3 + 1][j] + decalage_yo)/DIFMAXIMUM ;    
    Tre2[i*3 + 2][j] = hauteur_fenetre * (Tre2[i*3 + 2][j] + decalage_zo)/DIFMAXIMUM ;    
      }

/*
 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {      
    Nor3[i*3    ][j] = hauteur_fenetre * (Nor[i*3    ][j] + decalage_xo)/DIFMAXIMUM ;
    Nor3[i*3 + 1][j] = hauteur_fenetre * (Nor[i*3 + 1][j] + decalage_yo)/DIFMAXIMUM ;     
    Nor3[i*3 + 2][j] = hauteur_fenetre * (Nor[i*3 + 2][j] + decalage_zo)/DIFMAXIMUM ;     
      }

*/

if(there_is_condition == 1 ) 
 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++)
if(hidden_points[i][j] == 0) {
   // HR  
    HR2[i*3    ][j] = hauteur_fenetre * (HR2[i*3    ][j] + decalage_xo)/DIFMAXIMUM ;
    HR2[i*3 + 1][j] = hauteur_fenetre * (HR2[i*3 + 1][j] + decalage_yo)/DIFMAXIMUM ;      
    HR2[i*3 + 2][j] = hauteur_fenetre * (HR2[i*3 + 2][j] + decalage_zo)/DIFMAXIMUM ;     
     
   // DR  
    DR2[i*3    ][j] = hauteur_fenetre * (DR2[i*3    ][j] + decalage_xo)/DIFMAXIMUM ;
    DR2[i*3 + 1][j] = hauteur_fenetre * (DR2[i*3 + 1][j] + decalage_yo)/DIFMAXIMUM ;      
    DR2[i*3 + 2][j] = hauteur_fenetre * (DR2[i*3 + 2][j] + decalage_zo)/DIFMAXIMUM ;     
     
   // HL  
    HL2[i*3    ][j] = hauteur_fenetre * (HL2[i*3    ][j] + decalage_xo)/DIFMAXIMUM ;
    HL2[i*3 + 1][j] = hauteur_fenetre * (HL2[i*3 + 1][j] + decalage_yo)/DIFMAXIMUM ;      
    HL2[i*3 + 2][j] = hauteur_fenetre * (HL2[i*3 + 2][j] + decalage_zo)/DIFMAXIMUM ;     
     
   // DL  
    DL2[i*3    ][j] = hauteur_fenetre * (DL2[i*3    ][j] + decalage_xo)/DIFMAXIMUM ;
    DL2[i*3 + 1][j] = hauteur_fenetre * (DL2[i*3 + 1][j] + decalage_yo)/DIFMAXIMUM ;      
    DL2[i*3 + 2][j] = hauteur_fenetre * (DL2[i*3 + 2][j] + decalage_zo)/DIFMAXIMUM ;      
     
     }







  
MINX = hauteur_fenetre * (MINX + decalage_xo)/DIFMAXIMUM;
MINY = hauteur_fenetre * (MINY + decalage_yo)/DIFMAXIMUM;
MINZ = hauteur_fenetre * (MINZ + decalage_zo)/DIFMAXIMUM;

MAXX = hauteur_fenetre * (MAXX + decalage_xo)/DIFMAXIMUM;
MAXY = hauteur_fenetre * (MAXY + decalage_yo)/DIFMAXIMUM;
MAXZ = hauteur_fenetre * (MAXZ + decalage_zo)/DIFMAXIMUM;


  
  // Construction de la boite englobante...
  
  
  
  boiteenglobante2[0] = MAXX;
  boiteenglobante2[1] = MAXY;
  boiteenglobante2[2] = MAXZ;
  
  boiteenglobante2[3] = MINX;
  boiteenglobante2[4] = MAXY;
  boiteenglobante2[5] = MAXZ;
  
  boiteenglobante2[6] = MINX;
  boiteenglobante2[7] = MAXY;
  boiteenglobante2[8] = MINZ;
  
  boiteenglobante2[9]  = MAXX;
  boiteenglobante2[10] = MAXY;
  boiteenglobante2[11] = MINZ;
  
  boiteenglobante2[12] = MAXX;
  boiteenglobante2[13] = MINY;
  boiteenglobante2[14] = MAXZ;
  
  boiteenglobante2[15] = MINX;
  boiteenglobante2[16] = MINY;
  boiteenglobante2[17] = MAXZ;
  
  boiteenglobante2[18] = MINX;
  boiteenglobante2[19] = MINY;
  boiteenglobante2[20] = MINZ;
  
  boiteenglobante2[21]  = MAXX;
  boiteenglobante2[22]  = MINY;
  boiteenglobante2[23]  = MINZ;
  
  
}

/*****************************************************************************/
/*****************************************************************************/ 
void  Model3D::project_4D_to_3D(){
int i, j;
double c4;
for ( i=0; i < nb_ligne - coupure_ligne; ++i)
      for ( j=0; j < nb_colone - coupure_col  ; ++j){
       c4 = 1/(shape4D[i*4 + 3][j] - 2);
       Tre2[i*3  ][j] = c4*shape4D[i*4    ][j];
       Tre2[i*3+1][j] = c4*shape4D[i*4 + 1][j];
       Tre2[i*3+2][j] = c4*shape4D[i*4 + 2][j];
                                                  }
   
      }
/*****************************************************************************/
/*****************************************************************************/
void  Model3D::boite_englobante4D() {           


// calcul des minimas et des maximas des coordonnees: X,Y et Z

MINX =999999999;
MINY =999999999;
MINZ =999999999;
MINW =999999999;

MAXX =-999999999;
MAXY =-999999999;
MAXZ =-999999999;
MAXW =-999999999;


 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {

     if(MINX > shape4D[i*4    ][j] ) MINX = shape4D[i*4    ][j] ;    
     if(MINY > shape4D[i*4 + 1][j] ) MINY = shape4D[i*4 + 1][j] ;   
     if(MINZ > shape4D[i*4 + 2][j] ) MINZ = shape4D[i*4 + 2][j] ;    
     if(MINW > shape4D[i*4 + 3][j] ) MINW = shape4D[i*4 + 3][j] ;
     

     if(MAXX < shape4D[i*4    ][j] ) MAXX = shape4D[i*4    ][j] ;     
     if(MAXY < shape4D[i*4 + 1][j] ) MAXY = shape4D[i*4 + 1][j] ;     
     if(MAXZ < shape4D[i*4 + 2][j] ) MAXZ = shape4D[i*4 + 2][j] ;    
     if(MAXW < shape4D[i*4 + 3][j] ) MAXW = shape4D[i*4 + 3][j] ;
    }

// On recherche la plus grande "difference" de distance entre les points
// pour reduire la figure a un cube d'une longueur de 1.
// On utilisera apres cette figure pour l'agrandir et bien la placer dans
// la fenetre de vue:

  DIFX = MAXX - MINX ;
  DIFY = MAXY - MINY ;
  DIFZ = MAXZ - MINZ ;
  DIFW = MAXW - MINW ;
  
// Recherche du maximum :
  DIFMAXIMUM = DIFX;

  if (DIFY > DIFMAXIMUM) {DIFMAXIMUM = DIFY;};
  if (DIFZ > DIFMAXIMUM) {DIFMAXIMUM = DIFZ;};
  if (DIFW > DIFMAXIMUM) {DIFMAXIMUM = DIFW;};



// On va inclure cet objet dans un HperCube de langueur maximum
// egale a "hauteur_fenetre"

double decalage_xo = -(MINX +MAXX)/2 ;
double decalage_yo = -(MINY +MAXY)/2 ;
double decalage_zo = -(MINZ +MAXZ)/2 ;
double decalage_wo = -(MINW +MAXW)/2 ;

 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {      
    shape4D[i*4    ][j] = (shape4D[i*4    ][j] + decalage_xo)/DIFMAXIMUM ;
    shape4D[i*4 + 1][j] = (shape4D[i*4 + 1][j] + decalage_yo)/DIFMAXIMUM ;    
    shape4D[i*4 + 2][j] = (shape4D[i*4 + 2][j] + decalage_zo)/DIFMAXIMUM ;
    shape4D[i*4 + 3][j] = (shape4D[i*4 + 3][j] + decalage_wo)/DIFMAXIMUM ;          
        
      }
      
      
}
/*****************************************************************************/
/*****************************************************************************/ 
void  Model3D::project_5D_to_4D(){
int i, j;
double c4;
for ( i=0; i < nb_ligne - coupure_ligne; ++i)
      for ( j=0; j < nb_colone - coupure_col  ; ++j){
       c4 = 1/(shape5D[i*5 + 4][j] - 2);
       shape4D[i*4  ][j] = c4*shape5D[i*5    ][j];
       shape4D[i*4+1][j] = c4*shape5D[i*5 + 1][j];
       shape4D[i*4+2][j] = c4*shape5D[i*5 + 2][j];
       shape4D[i*4+3][j] = c4*shape5D[i*5 + 3][j];   
                                                  }
   
      }
/*****************************************************************************/
/*****************************************************************************/
void  Model3D::boite_englobante5D() {           


// calcul des minimas et des maximas des coordonnees: X,Y et Z

MINX =999999999;
MINY =999999999;
MINZ =999999999;
MINW =999999999;
MINT =999999999;

MAXX =-999999999;
MAXY =-999999999;
MAXZ =-999999999;
MAXW =-999999999;
MAXT =-999999999;


 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {

     if(MINX > shape5D[i*5    ][j] ) MINX = shape5D[i*5    ][j] ;    
     if(MINY > shape5D[i*5 + 1][j] ) MINY = shape5D[i*5 + 1][j] ;   
     if(MINZ > shape5D[i*5 + 2][j] ) MINZ = shape5D[i*5 + 2][j] ;    
     if(MINW > shape5D[i*5 + 3][j] ) MINW = shape5D[i*5 + 3][j] ;
     if(MINT > shape5D[i*5 + 4][j] ) MINT = shape5D[i*5 + 4][j] ;
     

     if(MAXX < shape5D[i*5    ][j] ) MAXX = shape5D[i*5    ][j] ;     
     if(MAXY < shape5D[i*5 + 1][j] ) MAXY = shape5D[i*5 + 1][j] ;     
     if(MAXZ < shape5D[i*5 + 2][j] ) MAXZ = shape5D[i*5 + 2][j] ;    
     if(MAXW < shape5D[i*5 + 3][j] ) MAXW = shape5D[i*5 + 3][j] ;
     if(MAXT < shape5D[i*5 + 4][j] ) MAXT = shape5D[i*5 + 4][j] ;
    }

// On recherche la plus grande "difference" de distance entre les points
// pour reduire la figure a un cube d'une longueur de 1.
// On utilisera apres cette figure pour l'agrandir et bien la placer dans
// la fenetre de vue:

  DIFX = MAXX - MINX ;
  DIFY = MAXY - MINY ;
  DIFZ = MAXZ - MINZ ;
  DIFW = MAXW - MINW ;
  DIFT = MAXT - MINT ;
  
// Recherche du maximum :
  DIFMAXIMUM = DIFX;

  if (DIFY > DIFMAXIMUM) {DIFMAXIMUM = DIFY;};
  if (DIFZ > DIFMAXIMUM) {DIFMAXIMUM = DIFZ;};
  if (DIFW > DIFMAXIMUM) {DIFMAXIMUM = DIFW;};
  if (DIFT > DIFMAXIMUM) {DIFMAXIMUM = DIFT;};



// On va inclure cet objet dans un HyperCube de langueur maximum
// egale a "hauteur_fenetre"

double decalage_xo = -(MINX +MAXX)/2 ;
double decalage_yo = -(MINY +MAXY)/2 ;
double decalage_zo = -(MINZ +MAXZ)/2 ;
double decalage_wo = -(MINW +MAXW)/2 ;
double decalage_to = -(MINT +MAXT)/2 ;

 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {      
    shape5D[i*5    ][j] = (shape5D[i*5    ][j] + decalage_xo)/DIFMAXIMUM ;
    shape5D[i*5 + 1][j] = (shape5D[i*5 + 1][j] + decalage_yo)/DIFMAXIMUM ;    
    shape5D[i*5 + 2][j] = (shape5D[i*5 + 2][j] + decalage_zo)/DIFMAXIMUM ;
    shape5D[i*5 + 3][j] = (shape5D[i*5 + 3][j] + decalage_wo)/DIFMAXIMUM ; 
    shape5D[i*5 + 4][j] = (shape5D[i*5 + 4][j] + decalage_to)/DIFMAXIMUM ;    
        
      }
      
      
}
/*****************************************************************************/
/*****************************************************************************/ 
void  Model3D::project_6D_to_5D(){
int i, j;
double c4;
for ( i=0; i < nb_ligne - coupure_ligne; ++i)
      for ( j=0; j < nb_colone - coupure_col  ; ++j){
       c4 = 1/(shape6D[i*6 + 5][j] - 2);
       shape5D[i*5  ][j] = c4*shape6D[i*6    ][j];
       shape5D[i*5+1][j] = c4*shape6D[i*6 + 1][j];
       shape5D[i*5+2][j] = c4*shape6D[i*6 + 2][j];
       shape5D[i*5+3][j] = c4*shape6D[i*6 + 3][j];
       shape5D[i*5+4][j] = c4*shape6D[i*6 + 4][j];   
                                                  }
   
      }
      
/*****************************************************************************/
/*****************************************************************************/
void  Model3D::boite_englobante6D() {           


// calcul des minimas et des maximas des coordonnees: X,Y et Z

MINX =999999999;
MINY =999999999;
MINZ =999999999;
MINW =999999999;
MINT =999999999;
MINS =999999999;

MAXX =-999999999;
MAXY =-999999999;
MAXZ =-999999999;
MAXW =-999999999;
MAXT =-999999999;
MAXS =-999999999;


 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {

     if(MINX > shape6D[i*6    ][j] ) MINX = shape6D[i*6    ][j] ;    
     if(MINY > shape6D[i*6 + 1][j] ) MINY = shape6D[i*6 + 1][j] ;   
     if(MINZ > shape6D[i*6 + 2][j] ) MINZ = shape6D[i*6 + 2][j] ;    
     if(MINW > shape6D[i*6 + 3][j] ) MINW = shape6D[i*6 + 3][j] ;
     if(MINT > shape6D[i*6 + 4][j] ) MINT = shape6D[i*6 + 4][j] ;
     if(MINS > shape6D[i*6 + 5][j] ) MINS = shape6D[i*6 + 5][j] ;
     

     if(MAXX < shape6D[i*6    ][j] ) MAXX = shape6D[i*6    ][j] ;     
     if(MAXY < shape6D[i*6 + 1][j] ) MAXY = shape6D[i*6 + 1][j] ;     
     if(MAXZ < shape6D[i*6 + 2][j] ) MAXZ = shape6D[i*6 + 2][j] ;    
     if(MAXW < shape6D[i*6 + 3][j] ) MAXW = shape6D[i*6 + 3][j] ;
     if(MAXT < shape6D[i*6 + 4][j] ) MAXT = shape6D[i*6 + 4][j] ;
     if(MAXS < shape6D[i*6 + 5][j] ) MAXS = shape6D[i*6 + 5][j] ;
    }

// On recherche la plus grande "difference" de distance entre les points
// pour reduire la figure a un cube d'une longueur de 1.
// On utilisera apres cette figure pour l'agrandir et bien la placer dans
// la fenetre de vue:

  DIFX = MAXX - MINX ;
  DIFY = MAXY - MINY ;
  DIFZ = MAXZ - MINZ ;
  DIFW = MAXW - MINW ;
  DIFT = MAXT - MINT ;
  DIFS = MAXS - MINS 
  ;
// Recherche du maximum :
  DIFMAXIMUM = DIFX;

  if (DIFY > DIFMAXIMUM) {DIFMAXIMUM = DIFY;};
  if (DIFZ > DIFMAXIMUM) {DIFMAXIMUM = DIFZ;};
  if (DIFW > DIFMAXIMUM) {DIFMAXIMUM = DIFW;};
  if (DIFT > DIFMAXIMUM) {DIFMAXIMUM = DIFT;};
  if (DIFS > DIFMAXIMUM) {DIFMAXIMUM = DIFS;};


// On va inclure cet objet dans un HyperCube de langueur maximum
// egale a "hauteur_fenetre"

double decalage_xo = -(MINX +MAXX)/2 ;
double decalage_yo = -(MINY +MAXY)/2 ;
double decalage_zo = -(MINZ +MAXZ)/2 ;
double decalage_wo = -(MINW +MAXW)/2 ;
double decalage_to = -(MINT +MAXT)/2 ;
double decalage_so = -(MINS +MAXS)/2 ;

 for (int i=0; i < nb_ligne   ; i++)
    for (int j=0; j < nb_colone   ; j++) {      
    shape6D[i*6    ][j] = (shape6D[i*6    ][j] + decalage_xo)/DIFMAXIMUM ;
    shape6D[i*6 + 1][j] = (shape6D[i*6 + 1][j] + decalage_yo)/DIFMAXIMUM ;    
    shape6D[i*6 + 2][j] = (shape6D[i*6 + 2][j] + decalage_zo)/DIFMAXIMUM ;
    shape6D[i*6 + 3][j] = (shape6D[i*6 + 3][j] + decalage_wo)/DIFMAXIMUM ; 
    shape6D[i*6 + 4][j] = (shape6D[i*6 + 4][j] + decalage_to)/DIFMAXIMUM ;    
    shape6D[i*6 + 5][j] = (shape6D[i*6 + 5][j] + decalage_so)/DIFMAXIMUM ;    
      }     
}

Generated by  Doxygen 1.6.0   Back to index