Skip to content

Commit 51f1c92

Browse files
authored
Merge pull request #2099 from gforney/master
preliminary code for drawing sky for terrain cases, fix a problem when only one 'face' in a mesh - addresses smokeview issue #2096
2 parents 2488ee1 + f65dab2 commit 51f1c92

14 files changed

+300
-155
lines changed

Diff for: Source/smokeview/IOobjects.c

+133-59
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include "readgeom.h"
2020

2121
static float *cos_long = NULL, *sin_long = NULL, *cos_lat = NULL, *sin_lat = NULL;
22+
#ifdef pp_SKY
23+
static float *sphere_coords = NULL;
24+
#endif
2225
static float specular[4] = {0.4,0.4,0.4,1.0};
2326
unsigned char *rgbimage = NULL;
2427
int rgbsize = 0;
@@ -1558,22 +1561,27 @@ void DrawHSphere(float diameter, unsigned char *rgbcolor){
15581561
#ifdef pp_SKY
15591562
/* ----------------------- DrawHalfSphere ----------------------------- */
15601563

1561-
void DrawHalfSphere(unsigned char *rgbcolor){
1564+
void DrawHalfSphere(void){
15621565
int i, j;
15631566
float dxFDS, dyFDS, dzFDS, diameter;
1567+
float *c_lat, *s_lat, *c_long, *s_long;
15641568

15651569
dxFDS = xbarFDS - xbar0FDS;
15661570
dyFDS = ybarFDS - ybar0FDS;
15671571
dzFDS = zbarFDS - zbar0FDS;
15681572
diameter = sky_diam*sqrt(dxFDS*dxFDS + dyFDS*dyFDS + dzFDS*dzFDS);
15691573

1570-
if(cos_lat == NULL)InitSphere(NLAT, NLONG);
1574+
if(sphere_coords == NULL)sphere_coords = InitSphere2(nlat_hsphere, nlong_hsphere);
1575+
c_lat = sphere_coords;
1576+
s_lat = c_lat + nlat_hsphere + 1;
1577+
c_long = s_lat + nlat_hsphere + 1;
1578+
s_long = c_long + nlong_hsphere + 1;
15711579

15721580
glPushMatrix();
15731581
glScalef(SCALE2SMV(1.0), SCALE2SMV(1.0), SCALE2SMV(1.0));
15741582
glTranslatef(-xbar0, -ybar0, -zbar0);
15751583
glTranslatef(dxFDS/2.0,dyFDS/2.0,0.0);
1576-
glScalef(diameter / 2.0, diameter / 2.0, diameter / 2.0);
1584+
glScalef(diameter/2.0, diameter/2.0, diameter/2.0);
15771585

15781586
int use_sky;
15791587

@@ -1586,80 +1594,102 @@ void DrawHalfSphere(unsigned char *rgbcolor){
15861594
}
15871595

15881596
glBegin(GL_QUADS);
1589-
if(use_sky == 0){
1590-
if(rgbcolor != NULL){
1591-
glColor3ubv(rgbcolor);
1592-
}
1593-
else{
1594-
glColor3f(0.0, 0.0, 1.0);
1595-
}
1596-
}
1597-
for(j = NLAT / 2; j < NLAT; j++){
1598-
for(i = 0; i < NLONG; i++){
1597+
if(use_sky == 0)glColor3f(0.0, 0.0, 1.0);
1598+
for(j = nlat_hsphere/2; j < nlat_hsphere; j++){
1599+
for(i = 0; i < nlong_hsphere; i++){
15991600
float x[4], y[4], z[4];
1600-
float tx[4], ty[4];
1601+
int ip1;
1602+
1603+
ip1 = i + 1;
16011604

1602-
x[0] = cos_long[i]*cos_lat[j];
1603-
y[0] = sin_long[i]*cos_lat[j];
1604-
z[0] = sin_lat[j];
1605+
x[0] = c_long[i]*c_lat[j];
1606+
y[0] = s_long[i]*c_lat[j];
1607+
z[0] = s_lat[j];
16051608

1606-
x[1] = cos_long[i + 1] * cos_lat[j];
1607-
y[1] = sin_long[i + 1] * cos_lat[j];
1608-
z[1] = sin_lat[j];
1609+
x[1] = c_long[ip1]*c_lat[j];
1610+
y[1] = s_long[ip1]*c_lat[j];
1611+
z[1] = s_lat[j];
16091612

1610-
x[2] = cos_long[i + 1] * cos_lat[j + 1];
1611-
y[2] = sin_long[i + 1] * cos_lat[j + 1];
1612-
z[2] = sin_lat[j + 1];
1613+
x[2] = c_long[ip1]*c_lat[j + 1];
1614+
y[2] = s_long[ip1]*c_lat[j + 1];
1615+
z[2] = s_lat[j + 1];
16131616

1614-
x[3] = cos_long[i] * cos_lat[j + 1];
1615-
y[3] = sin_long[i] * cos_lat[j + 1];
1616-
z[3] = sin_lat[j + 1];
1617+
x[3] = c_long[i]*c_lat[j + 1];
1618+
y[3] = s_long[i]*c_lat[j + 1];
1619+
z[3] = s_lat[j + 1];
16171620

16181621
if(use_sky == 1){
1619-
tx[0] = ( float )i / ( float )(NLONG-1);
1620-
ty[0] = ( float )j / ( float )(NLAT-1);
1622+
float tx[4], ty[4];
16211623

1622-
tx[1] = ( float )(i + 1) / ( float )(NLONG-1);
1623-
ty[1] = ( float )j / ( float )(NLAT-1);
1624+
tx[0] = (float)i/(float)nlong_hsphere;
1625+
ty[0] = (float)j/(float)nlat_hsphere;
16241626

1625-
tx[2] = ( float )(i + 1) / ( float )(NLONG-1);
1626-
ty[2] = ( float )(j + 1) / ( float )(NLAT-1);
1627+
tx[1] = (float)(ip1)/(float)nlong_hsphere;
1628+
ty[1] = (float)j/(float)nlat_hsphere;
16271629

1628-
tx[3] = ( float )i / ( float )(NLONG-1);
1629-
ty[3] = ( float )(j + 1) / ( float )(NLAT-1);
1630-
}
1630+
tx[2] = (float)(ip1)/(float)nlong_hsphere;
1631+
ty[2] = (float)(j + 1)/(float)nlat_hsphere;
1632+
1633+
tx[3] = (float)i/(float)nlong_hsphere;
1634+
ty[3] = (float)(j + 1)/(float)nlat_hsphere;
1635+
1636+
glNormal3f(x[0], y[0], z[0]);
1637+
glTexCoord2f(tx[0],ty[0]);
1638+
glVertex3f(x[0], y[0], z[0]);
1639+
1640+
glNormal3f(x[1], y[1], z[1]);
1641+
glTexCoord2f(tx[1], ty[1]);
1642+
glVertex3f(x[1], y[1], z[1]);
1643+
1644+
glNormal3f(x[2], y[2], z[2]);
1645+
glTexCoord2f(tx[2], ty[2]);
1646+
glVertex3f(x[2], y[2], z[2]);
1647+
1648+
glNormal3f(x[3], y[3], z[3]);
1649+
glTexCoord2f(tx[3], ty[3]);
1650+
glVertex3f(x[3], y[3], z[3]);
1651+
1652+
glNormal3f(-x[0], -y[0], -z[0]);
1653+
glTexCoord2f(tx[0], ty[0]);
1654+
glVertex3f(x[0], y[0], z[0]);
1655+
1656+
glNormal3f(-x[3], -y[3], -z[3]);
1657+
glTexCoord2f(tx[3], ty[3]);
1658+
glVertex3f(x[3], y[3], z[3]);
1659+
1660+
glNormal3f(-x[2], -y[2], -z[2]);
1661+
glTexCoord2f(tx[2], ty[2]);
1662+
glVertex3f(x[2], y[2], z[2]);
16311663

1632-
glNormal3f(x[0], y[0], z[0]);
1633-
if(use_sky==1)glTexCoord2f(tx[0],ty[0]);
1634-
glVertex3f(x[0], y[0], z[0]);
1664+
glNormal3f(-x[1], -y[1], -z[1]);
1665+
glTexCoord2f(tx[1], ty[1]);
1666+
glVertex3f(x[1], y[1], z[1]);
1667+
}
1668+
else{
1669+
glNormal3f(x[0], y[0], z[0]);
1670+
glVertex3f(x[0], y[0], z[0]);
16351671

1636-
glNormal3f(x[1], y[1], z[1]);
1637-
if(use_sky == 1)glTexCoord2f(tx[1], ty[1]);
1638-
glVertex3f(x[1], y[1], z[1]);
1672+
glNormal3f(x[1], y[1], z[1]);
1673+
glVertex3f(x[1], y[1], z[1]);
16391674

1640-
glNormal3f(x[2], y[2], z[2]);
1641-
if(use_sky == 1)glTexCoord2f(tx[2], ty[2]);
1642-
glVertex3f(x[2], y[2], z[2]);
1675+
glNormal3f(x[2], y[2], z[2]);
1676+
glVertex3f(x[2], y[2], z[2]);
16431677

1644-
glNormal3f(x[3], y[3], z[3]);
1645-
if(use_sky == 1)glTexCoord2f(tx[3], ty[3]);
1646-
glVertex3f(x[3], y[3], z[3]);
1678+
glNormal3f(x[3], y[3], z[3]);
1679+
glVertex3f(x[3], y[3], z[3]);
16471680

1648-
glNormal3f(-x[0], -y[0], -z[0]);
1649-
if(use_sky == 1)glTexCoord2f(tx[0], ty[0]);
1650-
glVertex3f(x[0], y[0], z[0]);
1681+
glNormal3f(-x[0], -y[0], -z[0]);
1682+
glVertex3f(x[0], y[0], z[0]);
16511683

1652-
glNormal3f(-x[3], -y[3], -z[3]);
1653-
if(use_sky == 1)glTexCoord2f(tx[3], ty[3]);
1654-
glVertex3f(x[3], y[3], z[3]);
1684+
glNormal3f(-x[3], -y[3], -z[3]);
1685+
glVertex3f(x[3], y[3], z[3]);
16551686

1656-
glNormal3f(-x[2], -y[2], -z[2]);
1657-
if(use_sky == 1)glTexCoord2f(tx[2], ty[2]);
1658-
glVertex3f(x[2], y[2], z[2]);
1687+
glNormal3f(-x[2], -y[2], -z[2]);
1688+
glVertex3f(x[2], y[2], z[2]);
16591689

1660-
glNormal3f(-x[1], -y[1], -z[1]);
1661-
if(use_sky == 1)glTexCoord2f(tx[1], ty[1]);
1662-
glVertex3f(x[1], y[1], z[1]);
1690+
glNormal3f(-x[1], -y[1], -z[1]);
1691+
glVertex3f(x[1], y[1], z[1]);
1692+
}
16631693
}
16641694
}
16651695
glEnd();
@@ -3296,6 +3326,50 @@ void InitSphere(int nlat, int nlong){
32963326
sin_long[nlong]=sin_long[0];
32973327
}
32983328

3329+
#ifdef pp_SKY
3330+
/* ----------------------- InitSphere2 ----------------------------- */
3331+
3332+
float *InitSphere2(int nlat, int nlong){
3333+
int i;
3334+
int ntotal;
3335+
float *sphere;
3336+
float *c_lat, *s_lat, *c_long, *s_long;
3337+
3338+
ntotal = 2*(nlat + 1) + 2*(nlong + 1);
3339+
NewMemory( (void **)&sphere, ntotal*sizeof(float));
3340+
c_lat = sphere;
3341+
s_lat = c_lat + nlat + 1;
3342+
c_long = s_lat + nlat + 1;
3343+
s_long = c_long + nlong + 1;
3344+
3345+
c_lat[0] = 0.0;
3346+
s_lat[0] = -1.0;
3347+
for(i=1;i<nlat;i++){
3348+
float angle;
3349+
3350+
angle = -PI/2.0 + (float)i*PI/(float)nlat;
3351+
c_lat[i] = cos(angle);
3352+
s_lat[i] = sin(angle);
3353+
}
3354+
c_lat[nlat] = 0.0;
3355+
s_lat[nlat] = 1.0;
3356+
3357+
c_long[0] = 1.0;
3358+
s_long[0] = 0.0;
3359+
for(i=1;i<nlong;i++){
3360+
float angle;
3361+
3362+
angle = (float)i*2.0*PI/(float)nlong;
3363+
c_long[i] = cos(angle);
3364+
s_long[i] = sin(angle);
3365+
}
3366+
c_long[nlong] = 1.0;
3367+
s_long[nlong] = 0.0;
3368+
3369+
return sphere;
3370+
}
3371+
#endif
3372+
32993373
/* ----------------------- GetGlobalDeviceBounds ----------------------------- */
33003374

33013375
void GetGlobalDeviceBounds(int type){

Diff for: Source/smokeview/IOscript.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -3088,9 +3088,9 @@ void ScriptXYZView(float x, float y, float z, float az, float elev){
30883088
use_customview = 0;
30893089
GLUISceneMotionCB(CUSTOM_VIEW);
30903090
GLUIViewpointCB(RESTORE_VIEW);
3091-
set_view_xyz[0] = x;
3092-
set_view_xyz[1] = y;
3093-
set_view_xyz[2] = z;
3091+
glui_xyz_fds[0] = x;
3092+
glui_xyz_fds[1] = y;
3093+
glui_xyz_fds[2] = z;
30943094
customview_azimuth = az;
30953095
customview_elevation = elev;
30963096
use_customview = 1;
@@ -3856,9 +3856,9 @@ void SetViewZMAXPersp(void){
38563856
use_customview = 0;
38573857
GLUISceneMotionCB(CUSTOM_VIEW);
38583858
GLUIViewpointCB(RESTORE_VIEW);
3859-
set_view_xyz[0] = xcen;
3860-
set_view_xyz[1] = ycen;
3861-
set_view_xyz[2] = zcen;
3859+
glui_xyz_fds[0] = xcen;
3860+
glui_xyz_fds[1] = ycen;
3861+
glui_xyz_fds[2] = zcen;
38623862
customview_azimuth = azimuth;
38633863
customview_elevation = elevation;
38643864
use_customview = 1;

Diff for: Source/smokeview/camera.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ void UpdateCamera(cameradata *ca){
386386
ca->ymax=clipinfo.ymax;
387387
ca->zmax=clipinfo.zmax;
388388
}
389-
GLUIUpdateSetViewXYZ(ca->eye);
389+
GLUISetPosXYZSMV(ca->eye);
390390
ca->dirty=0;
391391
}
392392

Diff for: Source/smokeview/drawGeometry.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ void DrawCAD2Geom(const cadgeomdata *cd, int trans_flag){
18891889

18901890
/* ------------------ ObstOrVent2Faces ------------------------ */
18911891

1892-
void ObstOrVent2Faces(const meshdata *meshi,blockagedata *bc,
1892+
void ObstOrVent2Faces(const meshdata *meshi, blockagedata *bc,
18931893
ventdata *vi, facedata *faceptr, int facetype){
18941894
/*
18951895
@@ -2243,11 +2243,11 @@ void ObstOrVent2Faces(const meshdata *meshi,blockagedata *bc,
22432243
faceptr->approx_center_coord[2]+=zvert;
22442244

22452245

2246-
faceptr->exact_vertex_coords[3*k]=xx2[jjj]+offset[XXX];
2246+
faceptr->exact_vertex_coords[3*k] =xx2[jjj]+offset[XXX];
22472247
faceptr->exact_vertex_coords[3*k+1]=yy2[jjj]+offset[YYY];
22482248
faceptr->exact_vertex_coords[3*k+2]=zz2[jjj]+offset[ZZZ];
2249-
if(faceptr->exact_vertex_coords[3*k]<faceptr->xmin)faceptr->xmin=faceptr->exact_vertex_coords[3*k];
2250-
if(faceptr->exact_vertex_coords[3*k]>faceptr->xmax)faceptr->xmax=faceptr->exact_vertex_coords[3*k];
2249+
if(faceptr->exact_vertex_coords[3*k] <faceptr->xmin)faceptr->xmin=faceptr->exact_vertex_coords[3*k];
2250+
if(faceptr->exact_vertex_coords[3*k] >faceptr->xmax)faceptr->xmax=faceptr->exact_vertex_coords[3*k];
22512251
if(faceptr->exact_vertex_coords[3*k+1]<faceptr->ymin)faceptr->ymin=faceptr->exact_vertex_coords[3*k+1];
22522252
if(faceptr->exact_vertex_coords[3*k+1]>faceptr->ymax)faceptr->ymax=faceptr->exact_vertex_coords[3*k+1];
22532253
if(faceptr->exact_vertex_coords[3*k+2]<faceptr->zmin)faceptr->zmin=faceptr->exact_vertex_coords[3*k+2];
@@ -2850,15 +2850,15 @@ void UpdateFaceListsWorker(void){
28502850
nface_transparent_double += n_transparent_double;
28512851
nface_outlines += n_outlines;
28522852

2853-
if(blockage_draw_option!=1)continue;
2853+
if(blockage_draw_option != 1)continue;
28542854

28552855
meshi->nface_normals_single_DOWN_X=0;
28562856
meshi->nface_normals_single_UP_X=0;
28572857
meshi->nface_normals_single_DOWN_Y=0;
28582858
meshi->nface_normals_single_UP_Y=0;
28592859
meshi->nface_normals_single_DOWN_Z=0;
28602860
meshi->nface_normals_single_UP_Z=0;
2861-
if(n_normals_single>1){
2861+
if(n_normals_single>0){
28622862
int iface;
28632863
int istartD=-1,istartU=-1;
28642864
int jstartD=-1,jstartU=-1;

Diff for: Source/smokeview/glui_display.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ GLUI_Button *BUTTON_label_4=NULL;
225225

226226
#ifdef pp_SKY
227227
#define SKY_DIAM 0
228+
#define SKY_VIS 1
228229
#endif
229230

230231
#define LABELS_label 0
@@ -741,6 +742,10 @@ void GLUISkyCB(int var){
741742
sky_diam = 1.0;
742743
if(SPINNER_sky_diam!=NULL)SPINNER_sky_diam->set_float_val(sky_diam);
743744
}
745+
GetBoxSkyCorners();
746+
break;
747+
case SKY_VIS:
748+
GetBoxSkyCorners();
744749
break;
745750
default:
746751
assert(0);
@@ -785,7 +790,7 @@ extern "C" void GLUIDisplaySetup(int main_window){
785790
CHECKBOX_labels_availmemory = glui_labels->add_checkbox_to_panel(PANEL_gen1, _("Memory load"), &visAvailmemory, LABELS_label, GLUILabelsCB);
786791
#endif
787792
#ifdef pp_SKY
788-
glui_labels->add_checkbox_to_panel(PANEL_gen1, _("show sky"), &visSky);
793+
glui_labels->add_checkbox_to_panel(PANEL_gen1, _("show sky"), &visSky, SKY_VIS, GLUISkyCB);
789794
SPINNER_sky_diam = glui_labels->add_spinner_to_panel(PANEL_gen1, _("sky diameter"), GLUI_SPINNER_FLOAT, &sky_diam, SKY_DIAM, GLUISkyCB);
790795
#endif
791796

@@ -915,7 +920,7 @@ extern "C" void GLUIDisplaySetup(int main_window){
915920
glui_labels->add_radiobutton_to_group(RADIO_timebar_overlap,_("Never"));
916921
glui_labels->add_radiobutton_to_group(RADIO_timebar_overlap,_("Only if timebar hidden"));
917922

918-
PANEL_blockage_drawing = glui_labels->add_panel_to_panel(PANEL_gen3,_("Blockage drawing"));
923+
PANEL_blockage_drawing = glui_labels->add_panel_to_panel(PANEL_gen3,_("Surface/blockage drawing"));
919924
RADIOBUTTON_label_1 = glui_labels->add_radiogroup_to_panel(PANEL_blockage_drawing, &blockage_draw_option, LABELS_drawface, GLUILabelsCB);
920925
glui_labels->add_radiobutton_to_group(RADIOBUTTON_label_1, _("original"));
921926
glui_labels->add_radiobutton_to_group(RADIOBUTTON_label_1, _("default"));

Diff for: Source/smokeview/glui_geometry.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,7 @@ extern "C" void GLUIGeometrySetup(int main_window){
608608
if(showedit_dialog==0)glui_geometry->hide();
609609

610610
if(hvaccoll.nhvacinfo > 0){
611+
have_geometry_dialog = 1;
611612
NewMemory(( void ** )&glui_hvac, sizeof(hvacdata));
612613
memcpy(glui_hvac, hvaccoll.hvacinfo, sizeof(hvacdata));
613614
ROLLOUT_hvac = glui_geometry->add_rollout("HVAC", false, HVAC_ROLLOUT, GeomRolloutCB);
@@ -735,6 +736,7 @@ extern "C" void GLUIGeometrySetup(int main_window){
735736
}
736737

737738
if(have_obsts == 1){
739+
have_geometry_dialog = 1;
738740
ROLLOUT_structured = glui_geometry->add_rollout("Structured", false, STRUCTURED_ROLLOUT, GeomRolloutCB);
739741
INSERT_ROLLOUT(ROLLOUT_structured, glui_geometry);
740742
ADDPROCINFO(geomprocinfo, ngeomprocinfo, ROLLOUT_structured, STRUCTURED_ROLLOUT, glui_geometry);
@@ -881,6 +883,7 @@ extern "C" void GLUIGeometrySetup(int main_window){
881883
}
882884

883885
if(ngeominfo>0){
886+
have_geometry_dialog = 1;
884887
ROLLOUT_unstructured = glui_geometry->add_rollout("Immersed", false, UNSTRUCTURED_ROLLOUT, GeomRolloutCB);
885888
INSERT_ROLLOUT(ROLLOUT_unstructured, glui_geometry);
886889
ADDPROCINFO(geomprocinfo, ngeomprocinfo, ROLLOUT_unstructured, UNSTRUCTURED_ROLLOUT, glui_geometry);
@@ -1105,6 +1108,7 @@ extern "C" void GLUIGeometrySetup(int main_window){
11051108
}
11061109

11071110
if(nterraininfo>0&&ngeominfo==0){
1111+
have_geometry_dialog = 1;
11081112
ROLLOUT_terrain = glui_geometry->add_rollout("Terrain", false, TERRAIN_ROLLOUT, GeomRolloutCB);
11091113
INSERT_ROLLOUT(ROLLOUT_terrain, glui_geometry);
11101114
ADDPROCINFO(geomprocinfo, ngeomprocinfo, ROLLOUT_terrain, TERRAIN_ROLLOUT, glui_geometry);

0 commit comments

Comments
 (0)