Skip to content
Snippets Groups Projects
Commit 9905ea58 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

Fixed orientation of polygons produced by CutTriangle2D so that we can
use a TWO_SIDE light model everywhere. This also fixes the ugly "checkboard
patterns" when using custom scales on continuous maps.
parent ffb67212
No related branches found
No related tags found
No related merge requests found
// $Id: Draw.cpp,v 1.48 2004-03-30 18:17:06 geuzaine Exp $ // $Id: Draw.cpp,v 1.49 2004-04-27 00:11:55 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -45,15 +45,12 @@ void Draw3d(void) ...@@ -45,15 +45,12 @@ void Draw3d(void)
#endif #endif
} }
glPolygonOffset(1.0, 1.0); glPolygonOffset(1.0, 1.0);
for(int i = 0; i < 6; i++)
if(CTX.clip[i])
glEnable((GLenum) (GL_CLIP_PLANE0 + i));
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS); glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
for(int i = 0; i < 6; i++)
if(CTX.clip[i])
glEnable((GLenum) (GL_CLIP_PLANE0 + i));
glPushMatrix(); glPushMatrix();
Draw_Mesh(&M); Draw_Mesh(&M);
...@@ -63,9 +60,6 @@ void Draw3d(void) ...@@ -63,9 +60,6 @@ void Draw3d(void)
void Draw2d(void) void Draw2d(void)
{ {
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glShadeModel(GL_FLAT);
for(int i = 0; i < 6; i++) for(int i = 0; i < 6; i++)
glDisable((GLenum) (GL_CLIP_PLANE0 + i)); glDisable((GLenum) (GL_CLIP_PLANE0 + i));
...@@ -175,6 +169,7 @@ void InitRenderModel(void) ...@@ -175,6 +169,7 @@ void InitRenderModel(void)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 40.); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 40.);
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glShadeModel(GL_SMOOTH);
// let's add some shininess to all these automatically created materials // let's add some shininess to all these automatically created materials
specular[0] = CTX.shine; specular[0] = CTX.shine;
specular[1] = CTX.shine; specular[1] = CTX.shine;
......
// $Id: Iso.cpp,v 1.21 2004-04-26 19:54:16 geuzaine Exp $ // $Id: Iso.cpp,v 1.22 2004-04-27 00:11:55 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -51,15 +51,14 @@ void CutTriangle1D(double *X, double *Y, double *Z, double *Val, ...@@ -51,15 +51,14 @@ void CutTriangle1D(double *X, double *Y, double *Z, double *Val,
} }
// Contour computation for triangles. FIXME: the orientation of the // Contour computation for triangles
// newly created polygons is wrong.
void CutTriangle2D(double *X, double *Y, double *Z, double *Val, void CutTriangle2D(double *X, double *Y, double *Z, double *Val,
double V1, double V2, double *Xp2, double *Yp2, double V1, double V2, double *Xp2, double *Yp2,
double *Zp2, int *Np2, double *Vp2) double *Zp2, int *Np2, double *Vp2)
{ {
int i, io[3], j, iot, Np, Fl; int i, io[3], j, iot, Np, Fl;
double Xp[5], Yp[5], Zp[5], Vp[5]; double Xp[10], Yp[10], Zp[10], Vp[10];
*Np2 = 0; *Np2 = 0;
...@@ -170,8 +169,8 @@ void CutTriangle2D(double *X, double *Y, double *Z, double *Val, ...@@ -170,8 +169,8 @@ void CutTriangle2D(double *X, double *Y, double *Z, double *Val,
*Np2 = 1; *Np2 = 1;
for(i = 1; i < Np; i++) { for(i = 1; i < Np; i++) {
if((Xp[i] != Xp2[(*Np2) - 1]) || (Yp[i] != Yp2[(*Np2) - 1]) if((Xp[i] != Xp2[(*Np2) - 1]) || (Yp[i] != Yp2[(*Np2) - 1]) ||
|| (Zp[i] != Zp2[(*Np2) - 1])) { (Zp[i] != Zp2[(*Np2) - 1])) {
Vp2[*Np2] = Vp[i]; Vp2[*Np2] = Vp[i];
Xp2[*Np2] = Xp[i]; Xp2[*Np2] = Xp[i];
Yp2[*Np2] = Yp[i]; Yp2[*Np2] = Yp[i];
...@@ -180,11 +179,36 @@ void CutTriangle2D(double *X, double *Y, double *Z, double *Val, ...@@ -180,11 +179,36 @@ void CutTriangle2D(double *X, double *Y, double *Z, double *Val,
} }
} }
if(Xp2[0] == Xp2[(*Np2) - 1] && Yp2[0] == Yp2[(*Np2) - 1] if(Xp2[0] == Xp2[(*Np2) - 1] && Yp2[0] == Yp2[(*Np2) - 1] &&
&& Zp2[0] == Zp2[(*Np2) - 1]) { Zp2[0] == Zp2[(*Np2) - 1]) {
(*Np2)--; (*Np2)--;
} }
// check and fix orientation
double in1[3] = { X[1]-X[0], Y[1]-Y[0], Z[1]-Z[0]};
double in2[3] = { X[2]-X[0], Y[2]-Y[0], Z[2]-Z[0]};
double inn[3];
prodve(in1, in2, inn);
double out1[3] = { Xp2[1]-Xp2[0], Yp2[1]-Yp2[0], Zp2[1]-Zp2[0]};
double out2[3] = { Xp2[2]-Xp2[0], Yp2[2]-Yp2[0], Zp2[2]-Zp2[0]};
double outn[3];
prodve(out1, out2, outn);
double res;
prosca(inn, outn, &res);
if(res < 0){
for(i = 0; i < *Np2; i++){
Vp[i] = Vp2[*Np2-i-1];
Xp[i] = Xp2[*Np2-i-1];
Yp[i] = Yp2[*Np2-i-1];
Zp[i] = Zp2[*Np2-i-1];
}
for(i = 0; i < *Np2; i++){
Vp2[i] = Vp[i];
Xp2[i] = Xp[i];
Yp2[i] = Yp[i];
Zp2[i] = Zp[i];
}
}
} }
// Iso for lines // Iso for lines
...@@ -314,7 +338,7 @@ void EnhanceSimplexPolygon(Post_View * View, int nb, // nb of points in polyg ...@@ -314,7 +338,7 @@ void EnhanceSimplexPolygon(Post_View * View, int nb, // nb of points in polyg
double gr[3]; double gr[3];
double n[3], xx; double n[3], xx;
prodve(v1, v2, n); prodve(v1, v2, n);
//norme(n); not necessary since GL_NORMALIZE is enabled norme(n);
gradSimplex(X, Y, Z, Val, gr); gradSimplex(X, Y, Z, Val, gr);
prosca(gr, n, &xx); prosca(gr, n, &xx);
......
// $Id: Post.cpp,v 1.59 2004-04-26 19:56:45 geuzaine Exp $ // $Id: Post.cpp,v 1.60 2004-04-27 00:11:55 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -456,15 +456,6 @@ void Draw_Post(void) ...@@ -456,15 +456,6 @@ void Draw_Post(void)
glLineWidth(v->LineWidth); glLineWidth(v->LineWidth);
gl2psLineWidth(v->LineWidth * CTX.print.eps_line_width_factor); gl2psLineWidth(v->LineWidth * CTX.print.eps_line_width_factor);
// force this
if(v->IntervalsType == DRAW_POST_CONTINUOUS) {
glShadeModel(GL_SMOOTH);
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
}
else { // there is a bug in CutTriangle2D!! See Iso.cpp
glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
}
switch (v->RangeType) { switch (v->RangeType) {
case DRAW_POST_RANGE_DEFAULT: case DRAW_POST_RANGE_DEFAULT:
ValMin = v->Min; ValMin = v->Min;
......
// $Id: PostElement.cpp,v 1.27 2004-04-26 19:54:16 geuzaine Exp $ // $Id: PostElement.cpp,v 1.28 2004-04-27 00:11:55 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -23,12 +23,6 @@ ...@@ -23,12 +23,6 @@
// Laurent Stainier // Laurent Stainier
// Jean-Luc Flejou // Jean-Luc Flejou
// OK, I understand why the Cut2D stuff does not work correctly with a
// TWO_FACE light: the normal has too be coherent with the vertex
// ordering of the polygon. Doing i=nb-1; i>=0; i-- works when the
// classic order does not. So we really have to check the ordering of
// the output of cut2d...
#include "Gmsh.h" #include "Gmsh.h"
#include "GmshUI.h" #include "GmshUI.h"
#include "Geo.h" #include "Geo.h"
...@@ -424,10 +418,9 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, ...@@ -424,10 +418,9 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals,
norms[3 * i] = nn[0]; norms[3 * i] = nn[0];
norms[3 * i + 1] = nn[1]; norms[3 * i + 1] = nn[1];
norms[3 * i + 2] = nn[2]; norms[3 * i + 2] = nn[2];
if(!View-> if(!View->get_normal(X[i] + Raise[0][i], Y[i] + Raise[1][i],
get_normal(X[i] + Raise[0][i], Y[i] + Raise[1][i], Z[i] + Raise[2][i], norms[3 * i], norms[3 * i + 1],
Z[i] + Raise[2][i], norms[3 * i], norms[3 * i + 1], norms[3 * i + 2])) {
norms[3 * i + 2])) {
//don't print this (unless we fix draw_vector_triangle with displacement) //don't print this (unless we fix draw_vector_triangle with displacement)
//Msg(WARNING, "Oups, did not find smoothed normal"); //Msg(WARNING, "Oups, did not find smoothed normal");
} }
...@@ -468,13 +461,12 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, ...@@ -468,13 +461,12 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals,
} }
else { else {
if(View->Light) glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
if(View->IntervalsType == DRAW_POST_CONTINUOUS) { if(View->IntervalsType == DRAW_POST_CONTINUOUS) {
if(Val[0] >= ValMin && Val[0] <= ValMax && if(Val[0] >= ValMin && Val[0] <= ValMax &&
Val[1] >= ValMin && Val[1] <= ValMax && Val[1] >= ValMin && Val[1] <= ValMax &&
Val[2] >= ValMin && Val[2] <= ValMax) { Val[2] >= ValMin && Val[2] <= ValMax) {
if(View->Light) glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
PaletteContinuous(View, ValMin, ValMax, Val[0]); PaletteContinuous(View, ValMin, ValMax, Val[0]);
glNormal3dv(&norms[0]); glNormal3dv(&norms[0]);
...@@ -486,10 +478,14 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, ...@@ -486,10 +478,14 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals,
glNormal3dv(&norms[6]); glNormal3dv(&norms[6]);
glVertex3d(X[2] + Raise[0][2], Y[2] + Raise[1][2], Z[2] + Raise[2][2]); glVertex3d(X[2] + Raise[0][2], Y[2] + Raise[1][2], Z[2] + Raise[2][2]);
glEnd(); glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
} }
else { else {
CutTriangle2D(X, Y, Z, Val, ValMin, ValMax, Xp, Yp, Zp, &nb, value); CutTriangle2D(X, Y, Z, Val, ValMin, ValMax, Xp, Yp, Zp, &nb, value);
if(nb >= 3) { if(nb >= 3) {
if(View->Light) glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
for(int i = 0; i < nb; i++) { for(int i = 0; i < nb; i++) {
PaletteContinuous(View, ValMin, ValMax, value[i]); PaletteContinuous(View, ValMin, ValMax, value[i]);
...@@ -498,6 +494,8 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, ...@@ -498,6 +494,8 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals,
Zp[i] + View->Raise[2] * value[i]); Zp[i] + View->Raise[2] * value[i]);
} }
glEnd(); glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
} }
} }
} }
...@@ -510,12 +508,16 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, ...@@ -510,12 +508,16 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals,
View->GVFI(ValMin, ValMax, View->NbIso + 1, k + 1), View->GVFI(ValMin, ValMax, View->NbIso + 1, k + 1),
Xp, Yp, Zp, &nb, value); Xp, Yp, Zp, &nb, value);
if(nb >= 3) { if(nb >= 3) {
if(View->Light) glEnable(GL_LIGHTING);
glEnable(GL_POLYGON_OFFSET_FILL);
glBegin(GL_POLYGON); glBegin(GL_POLYGON);
for(int i = 0; i < nb; i++) for(int i = 0; i < nb; i++)
glVertex3d(Xp[i] + View->Raise[0] * value[i], glVertex3d(Xp[i] + View->Raise[0] * value[i],
Yp[i] + View->Raise[1] * value[i], Yp[i] + View->Raise[1] * value[i],
Zp[i] + View->Raise[2] * value[i]); Zp[i] + View->Raise[2] * value[i]);
glEnd(); glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
} }
} }
else { else {
...@@ -531,8 +533,6 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, ...@@ -531,8 +533,6 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals,
} }
} }
glDisable(GL_POLYGON_OFFSET_FILL);
glDisable(GL_LIGHTING);
} }
} }
......
// $Id: Scale.cpp,v 1.41 2004-04-20 19:15:14 geuzaine Exp $ // $Id: Scale.cpp,v 1.42 2004-04-27 00:11:55 geuzaine Exp $
// //
// Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle
// //
...@@ -68,11 +68,6 @@ void draw_scale(Post_View * v, ...@@ -68,11 +68,6 @@ void draw_scale(Post_View * v,
glEnd(); glEnd();
} }
if(v->IntervalsType == DRAW_POST_CONTINUOUS)
glShadeModel(GL_SMOOTH);
else
glShadeModel(GL_FLAT);
switch(v->RangeType){ switch(v->RangeType){
case DRAW_POST_RANGE_CUSTOM: case DRAW_POST_RANGE_CUSTOM:
ValMin = v->CustomMin; ValMin = v->CustomMin;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment