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

void Model3D::tracer3 ( QPainter &  g  ) 

+++++++++++++++++++++++++++++++++++++++++++++++++++////

++++++++++++++++++++++++++++++++++++++++++++++++++++++///

construction of polygones : first case --> No hidden points

two separate shapes

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

Just in case...must be changed

Just in case...must be changed

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.

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

End of if(there_is_hidden_points == -1)

here we have some hidden points to deal with...

two separate shapes

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

Just in case...must be changed

Just in case...must be changed

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.

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];

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.

two separate shapes

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

Just in case...must be changed

Just in case...must be changed

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.

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];

two separate shapes

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

Just in case...must be changed

Just in case...must be changed

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

=======================================================

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

==============================================================================

Optimisation: Trying to eliminate some polygons with the Zbuffer algorithm

==============================================================================

==============================================================================

==============================================================================

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

+++++++++++++++++++++++++++++++++++++++++++++++++ here, we are going to compute all 3 Axes points +++++++++++++++++++++++++++++++++++++++++++++++++

Axes points construction :

Axes points projection construction :

++++++++++++++++++++++++ TRIAGE des POLYGONES de l'axe X ++++++++++++++++++++++++

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

++++++++++++++++++++++++ TRIAGE des POLYGONES de l'axe Y ++++++++++++++++++++++++

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

++++++++++++++++++++++++ TRIAGE des POLYGONES de l'axe Z ++++++++++++++++++++++++

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

============= The last three poly that represents orrows heads====

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

========================================================================= AFFICHAGE DES POLYGONES

Definition at line 549 of file Model3D.cpp.

References Prop_poly::condition_validity, Prop_poly::Norx, Prop_poly::Nory, Prop_poly::pl, Prop_poly::valeur_cos, Prop_poly::valeur_z, and Prop_poly::zbuffer_validity.

                                  {
      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 +300);
moitie_colone = (int)(nb_colone/2);







///+++++++++++++++++++++++++++++++++++++++++++++++++++////



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

caa  = Tre[(i+1)*3+1][j  ] - Tre[i*3+1][j];
bab  = Tre[i*3    +2][j+1] - Tre[i*3+2][j];
cab  = Tre[(i+1)*3+2][j  ] - Tre[i*3+2][j];
baa  = Tre[i*3    +1][j+1] - Tre[i*3+1][j];
ba   = Tre[i*3      ][j+1] - Tre[i*3  ][j];
ca   = Tre[(i+1)*3  ][j  ] - Tre[i*3  ][j];

Nor[i*3  ][j] = caa*bab - cab*baa;
Nor[i*3+1][j] = cab*ba  - ca*bab;
Nor[i*3+2][j] = ca*baa  - caa*ba;


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


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

}


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


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

i = nb_ligne -1; j =nb_colone -1;
Nor[i*3  ][j]= Nor[(i-1)*3  ][j-1];
Nor[i*3+1][j]= Nor[(i-1)*3+1][j-1];
Nor[i*3+2][j]= Nor[(i-1)*3+2][j-1];

///++++++++++++++++++++++++++++++++++++++++++++++++++++++///



















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;
}







/*

///+++++++++++++ This part must be eliminated +++++++++++++++++++///
/// to eliminate some gliches in the drawing area...
a5= (double)sqrt(
     (Nor[i*3  ][j])*(Nor[i*3  ][j])
    +(Nor[i*3+1][j])*(Nor[i*3+1][j])
    +(Nor[i*3+2][j])*(Nor[i*3+2][j]));


if( a5 > 0.00000001) {
Nor[i*3  ][j]/=a5;
Nor[i*3+1][j]/=a5;
Nor[i*3+2][j]/=a5;
}
///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++///

*/




cosinus=(((Obser[0]*Nor[i*3  ][j])+(Obser[1]*Nor[i*3+1][j])+(Obser[2]*Nor[i*3+2][j])));
/// 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;
}











/*
///+++++++++++++ This part must be eliminated +++++++++++++++++++///
/// to eliminate some gliches in the drawing area...
a4= (double)sqrt(
     (Nor[i*3  ][j])*(Nor[i*3  ][j])
    +(Nor[i*3+1][j])*(Nor[i*3+1][j])
    +(Nor[i*3+2][j])*(Nor[i*3+2][j]));


if( a4 > 0.00000001) {
Nor[i*3  ][j]/=a4;
Nor[i*3+1][j]/=a4;
Nor[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;
}











/*
///+++++++++++++ This part must be eliminated +++++++++++++++++++///
/// to eliminate some gliches in the drawing area...
a4= (double)sqrt(
     (Nor[i*3  ][j])*(Nor[i*3  ][j])
    +(Nor[i*3+1][j])*(Nor[i*3+1][j])
    +(Nor[i*3+2][j])*(Nor[i*3+2][j]));


if( a4 > 0.00000001) {
Nor[i*3  ][j]/=a4;
Nor[i*3+1][j]/=a4;
Nor[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]  ));

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]));

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]));

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]));
}

} // 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*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant ]->setPoint(2,
                                         (int)(Tre3[i*3   ][j]),
                                         (int)(Tre3[i*3 +1][j]));
tableaureferences[poly_courant ]->setPoint(3,
                                         (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;
}



/*
///+++++++++++++ This part must be eliminated +++++++++++++++++++///
/// to eliminate some gliches in the drawing area...
a4= (double)sqrt(
     (Nor[i*3  ][j])*(Nor[i*3  ][j])
    +(Nor[i*3+1][j])*(Nor[i*3+1][j])
    +(Nor[i*3+2][j])*(Nor[i*3+2][j]));


if( a4 > 0.00000001) {
Nor[i*3  ][j]/=a4;
Nor[i*3+1][j]/=a4;
Nor[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
///==============================================================================



/// +++++++++++++++++++++++++++++++++++++++++++++++++
/// here, we are going to compute all 3 Axes points
/// +++++++++++++++++++++++++++++++++++++++++++++++++

if(drawaxes_ok == 1) {

/// Axes points construction :

for(i=0; i< nb_licol ; i++){
//X
c4 = D/(Axes_array[0][i*3+2]-Oprime[2]);
 Axes_array_projection[0][i*3  ] = c4*Axes_array[0][i*3  ] + demi_hauteur;
 Axes_array_projection[0][i*3+1] = c4*Axes_array[0][i*3+1] + demi_largeur;
 //Axes_array_projection[0][i*3+2] = Axes_array[0][i*3+2];
//Y
c4 = D/(Axes_array[1][i*3+2]-Oprime[2]);
 Axes_array_projection[1][i*3  ] = c4*Axes_array[1][i*3  ] + demi_hauteur;
 Axes_array_projection[1][i*3+1] = c4*Axes_array[1][i*3+1] + demi_largeur;
 //Axes_array_projection[1][i*3+2] = Axes_array[1][i*3+2];
//Z
c4 = D/(Axes_array[2][i*3+2]-Oprime[2]);
 Axes_array_projection[2][i*3  ] = c4*Axes_array[2][i*3  ] + demi_hauteur;
 Axes_array_projection[2][i*3+1] = c4*Axes_array[2][i*3+1] + demi_largeur;
 //Axes_array_projection[2][i*3+2] = Axes_array[2][i*3+2];

}

/// Axes points projection construction :



///++++++++++++++++++++++++  TRIAGE des POLYGONES de l'axe X ++++++++++++++++++++++++

for(i=0; i< nb_licol -1 ; i++){
poly_courant = 20000 +i;

if((z_tmp = (Axes_array[0][i*3+2] + Axes_array[0][(i+1)*3+2]))/2 < 460 || clipping == -1 ) {
tableaureferences[poly_courant]->setPoint(0,
                                         (int)(Axes_array_projection[0][i*3  ]),
                                         (int)(Axes_array_projection[0][i*3+1]));
tableaureferences[poly_courant]->setPoint(1,
                                         (int)(Axes_array_projection[0][i*3  ]),
                                         (int)(Axes_array_projection[0][i*3+1]));
tableaureferences[poly_courant]->setPoint(2,
                                         (int)(Axes_array_projection[0][(i+1)*3  ]),
                                         (int)(Axes_array_projection[0][(i+1)*3+1]));
tableaureferences[poly_courant]->setPoint(3,
                                         (int)(Axes_array_projection[0][(i+1)*3  ]),
                                         (int)(Axes_array_projection[0][(i+1)*3+1]));
//z_tmp = (Axes_array[0][i*3+2] + Axes_array[0][(i+1)*3+2])/2;
///=============  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 = 0.1357; //this value   can help us to know if this poly belong to an axe X

  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 = 0.1357;

  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 = 0.1357; //this value can help us to know if this poly belong to an axe X
  vecteur_poly.push_back(&tableau[poly_courant]);
}
}
}

///++++++++++++++++++++++++  TRIAGE des POLYGONES de l'axe Y ++++++++++++++++++++++++

for(i=0; i< nb_licol -1 ; i++){
poly_courant = 20100 + i;
if((z_tmp = (Axes_array[1][i*3+2] + Axes_array[1][(i+1)*3+2]))/2 < 460 || clipping == -1 ) {

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

//z_tmp = (Axes_array[1][i*3+2] + Axes_array[1][(i+1)*3+2])/2;
///=============  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 = 0.2357; //this value can help us to know if this poly belong to an axe Y

  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 = 0.2357;

  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 = 0.2357; //this value   can help us to know if this poly belong to an axe Y
  vecteur_poly.push_back(&tableau[poly_courant]);
     }
}
}

///++++++++++++++++++++++++ TRIAGE des POLYGONES de l'axe Z ++++++++++++++++++++++++

for(i=0; i< nb_licol -1 ; i++){
poly_courant = 20200 + i;

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

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

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

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

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

// z_tmp = (Axes_array[2][i*3+2] + Axes_array[2][(i+1)*3+2])/2.;

///=============  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 = 0.3357; //this value   can help us to know if this poly belong to an axe Z

  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 = 0.3357;

  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 = 0.3357; //this value   can help us to know if this poly belong to an axe Z
  vecteur_poly.push_back(&tableau[poly_courant]);
}
}
}// End of if((z_tmp=(Axes_array[2][i*3+2] + Axes_array[2][(i+1)*3+2])/2.)< 460 || clipping == -1 )


///=============  The last three poly that represents orrows heads====

double normale_last_pointX, normale_last_pointY;
if((i = nb_licol -1) > 1) // because we have to compute Axes_array[j][(i-1)*3  ]
 for(j=0; j< 3 ; j++){

poly_courant = 20000 + j*100 + i;

normale_last_pointX = -(Axes_array[j][(i-1)*3+1] - Axes_array[j][i*3+1]);
normale_last_pointY = Axes_array[j][(i-1)*3  ] - Axes_array[j][i*3  ];




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

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

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

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

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


// z_tmp = (Axes_array[2][i*3+2] + Axes_array[2][(i+1)*3+2])/2.;

///=============  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 = (j+1)*0.111123; // valeures aléatoires...

  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 = (j+1)*0.111123;

  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 = (j+1)*0.111123;
  vecteur_poly.push_back(&tableau[poly_courant]);
}
}
}// End of if((z_tmp=(Axes_array[2][i*3+2] + Axes_array[2][(i+1)*3+2])/2.)< 460 || clipping == -1 )


};  //End of if(drawaxes_ok ==1)...


///=========================================================================
///                    AFFICHAGE DES POLYGONES


 nb_poly = vecteur_poly.size();
int Norx2, Nory2, positionx1, positiony1, positionx2, positiony2;
//Some useful variables
QColor redcol(255,0,0);
QColor Xaxecol(255,0,0);
QColor Yaxecol(0,255,0);
QColor Zaxecol(0,255,255);
QColor gridcol(gridliner,gridlineg,gridlineb);
QPen Xaxepen(Xaxecol, axe_width);
QPen Yaxepen(Yaxecol, axe_width);
QPen Zaxepen(Zaxecol, axe_width);


if(mesh ==1) {
g.setPen(gridcol);

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( (drawaxes_ok == 1) && ( cs == 0.1357 || cs == 0.2357 || cs == 0.3357 ||
                            cs == 0.111123 || cs == 0.222246 || cs == 0.333369 )) {
     if(cs == 0.1357){
               g.setPen(Xaxepen);
               g.drawLine ( p->point(0), p->point(2));
               g.setPen(gridcol);
               }
     else if(cs == 0.2357){
               g.setPen(Yaxepen);//setWidth ( uint w );
               g.drawLine ( p->point(0), p->point(2));
               g.setPen(gridcol);
               }
     else if(cs == 0.3357){
               g.setPen(Zaxepen);//setWidth ( uint w );
               g.drawLine ( p->point(0), p->point(2));
               g.setPen(gridcol);
               }
     else if(cs == 0.111123){
               g.setPen(Xaxepen);//setWidth ( uint w );
               p->point(0, &positionx1, &positiony1);
               p->point(1, &positionx2, &positiony2);
               g.drawText(positionx1+(positionx1-positionx2), positiony1+(positiony1-positiony2), "X");
               //g.setBrush(Xaxecol);
               g.drawPolygon ( *p);
               g.setPen(gridcol);
               }
     else if(cs == 0.222246){
               g.setPen(Yaxepen);//setWidth ( uint w );
               p->point(0, &positionx1, &positiony1);
               p->point(1, &positionx2, &positiony2);
               g.drawText(positionx1+(positionx1-positionx2), positiony1+(positiony1-positiony2), "Y");
               //g.setBrush(Yaxecol);
               g.drawPolygon ( *p);
               g.setPen(gridcol);
               }
     else if(cs == 0.333369){
               g.setPen(Zaxepen);//setWidth ( uint w );
               p->point(0, &positionx1, &positiony1);
               p->point(1, &positionx2, &positiony2);
               g.drawText(positionx1+(positionx1-positionx2), positiony1+(positiony1-positiony2), "Z");
               //g.setBrush(Zaxecol);
               g.drawPolygon ( *p);
               g.setPen(gridcol);
                }}
else
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.setPen(gridcol);}
          else {
               g.setBrush(palette_cond_face[(int)(cs*256)]);
               g.drawPolygon(*p);
               }
}
else {  g.setBrush(palette_back_face[(int)(cs*256)]);
        g.drawPolygon(*p);

}
        } // 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));

       if(draw_poly_normals == 1) {
               prop_poly->pl->point(0, &Norx2, &Nory2);
               g.drawLine(prop_poly->Norx, prop_poly->Nory, Norx2, Nory2);

       }
               g.setPen(gridcol);}
          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(gridcol);

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.drawPolygon(*p);
        }
else {
      g.drawPolygon(*p); //!!!!!!! the same instruction !!!
     }
     */ 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-- |");
}
}
  }


Generated by  Doxygen 1.6.0   Back to index