GRASS Programmer's Manual  6.4.2(2012)
gsd_surf.c
Go to the documentation of this file.
00001 
00019 #include <stdlib.h>
00020 
00021 #include <grass/gis.h>
00022 #include <grass/glocale.h>
00023 #include <grass/gstypes.h>
00024 
00025 #include "gsget.h"
00026 #include "rowcol.h"
00027 
00028 /*
00029    #define CALC_AREA
00030  */
00031 
00032 /*
00033    #define DO_ARROW_SOLID
00034    #define DEBUG_ARROW ((row && !(row%surf->y_modw))&&(col && !(col%surf->x_modw)))
00035  */
00036 
00037 /*
00038    #define DO_ARROW
00039  */
00040 
00041 #define DEBUG_ARROW (0)
00042 
00046 #define SET_SCOLOR(sf) \
00047             if(check_color[sf]) \
00048             { \
00049                 tx = points[sf][i][X] - gsurfs[sf]->x_trans; \
00050                 ty = points[sf][i][Y] - gsurfs[sf]->y_trans; \
00051                 offset = XY2OFF(gsurfs[sf], tx, ty); \
00052                 colors[sf] = gs_mapcolor(cobuf[sf], coloratt[sf], offset); \
00053             }
00054 
00055 static int transpoint_is_masked(geosurf *, Point3);
00056 static int get_point_below(Point3 **, geosurf **, int, int, int, int *);
00057 
00058 static int FCmode;
00059 
00060 
00061 /************************************************************************/
00062 /* Notes on exageration:
00063    vertical exageration is of two forms: 
00064    1) global exageration (from geoview struct) 
00065    2) vertical exageration for each surface (UN-IMPLEMENTED)
00066  */
00067 
00068 /************************************************************************/
00069 /* may need to add more parameters to tell it which window or off_screen
00070  * pixmap to draw into.
00071  */
00072 
00081 int gsd_surf(geosurf * surf)
00082 {
00083     int desc, ret;
00084 
00085     G_debug(5, "gsd_surf(): id=%d", surf->gsurf_id);
00086 
00087     desc = ATT_TOPO;
00088 
00089     /* won't recalculate if update not needed, but may want to check
00090        to see if lights are on */
00091     gs_calc_normals(surf);
00092 
00093     switch (gs_get_att_src(surf, desc)) {
00094     case NOTSET_ATT:
00095         ret = (-1);
00096 
00097         break;
00098 
00099     case MAP_ATT:
00100         ret = (gsd_surf_map(surf));     /* changed to use test draw routine */
00101 
00102 #ifdef DO_ARROW
00103         gsd_norm_arrows(surf);
00104 
00105         /* Not ready yet - need to recalc normals for proper res
00106            gsd_wire_arrows(surf);
00107          */
00108 #endif
00109 
00110         break;
00111 
00112     case CONST_ATT:
00113         ret = (gsd_surf_const(surf, surf->att[desc].constant));
00114 
00115         break;
00116 
00117     case FUNC_ATT:
00118         ret = (gsd_surf_func(surf, surf->att[desc].user_func));
00119 
00120         break;
00121 
00122     default:
00123         ret = (-1);
00124 
00125         break;
00126     }
00127 
00128     return (ret);
00129 }
00130 
00140 int gsd_surf_map_old(geosurf * surf)
00141 {
00142     int check_mask, check_color, check_transp;
00143     int check_material, check_emis, check_shin;
00144     typbuff *buff, *cobuff, *trbuff, *embuff, *shbuff;
00145     int xmod, ymod, row, col, cnt, xcnt, ycnt;
00146     long offset, y1off, y2off;
00147     float x1, x2, y1, y2, tx, ty, tz, ttr;
00148     float n[3], pt[4], xres, yres, ymax, zexag;
00149     int em_src, sh_src, trans_src, col_src, curcolor;
00150     gsurf_att *ematt, *shatt, *tratt, *coloratt;
00151 
00152 
00153     /* Viewport variables for accelerated drawing */
00154     GLdouble modelMatrix[16], projMatrix[16];
00155     GLint viewport[4];
00156     GLint window[4];
00157 
00158 #ifdef CALC_AREA
00159     float sz, mag, tedge1[3], tedge2[3], crossp[3], triv[3][3];
00160     double asurf = 0.0, axsurf = 0.0;
00161 #endif
00162 
00163     int zeros, dr1, dr2, dr3, dr4;
00164     int datarow1, datacol1, datarow2, datacol2;
00165 
00166     float kem, ksh, pkem, pksh;
00167     unsigned int ktrans;
00168 
00169     G_debug(3, "gsd_surf_map_old");
00170 
00171     /* avoid scaling by zero */
00172     GS_get_scale(&tx, &ty, &tz, 1);
00173 
00174     if (tz == 0.0) {
00175         return (gsd_surf_const(surf, 0.0));
00176     }
00177     /* else if (surf->z_exag  == 0.0)
00178        {
00179        return(gsd_surf_const(surf, surf->z_min));
00180        }
00181        NOT YET IMPLEMENTED */
00182 
00183     buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
00184     cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
00185 
00186     gs_update_curmask(surf);
00187     check_mask = surf->curmask ? 1 : 0;
00188 
00189     /*
00190        checks ATT_TOPO & ATT_COLOR no_zero flags, make a mask from each,
00191        combine it/them with any current mask, put in surf->curmask:
00192      */
00193     xmod = surf->x_mod;
00194     ymod = surf->y_mod;
00195     xres = xmod * surf->xres;
00196     yres = ymod * surf->yres;
00197     ymax = (surf->rows - 1) * surf->yres;
00198 
00199     xcnt = VCOLS(surf);
00200     ycnt = VROWS(surf);
00201 
00202     /* Get viewport */
00203     gsd_getwindow(window, viewport, modelMatrix, projMatrix);
00204     /* adjust window */
00205     window[0] += (int)(yres * 2);
00206     window[1] -= (int)(yres * 2);
00207     window[2] -= (int)(xres * 2);
00208     window[3] += (int)(xres * 2);
00209 
00210     gsd_colormode(CM_DIFFUSE);
00211     gsd_pushmatrix();
00212     gsd_do_scale(1);
00213     gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
00214     zexag = surf->z_exag;
00215 
00216     /* CURRENTLY ALWAYS 1.0 */
00217 #ifdef CALC_AREA
00218     sz = GS_global_exag();
00219 #endif
00220 
00221     /* TESTING */
00222     /*
00223        fprintf(stderr, "This machine has %d alpha bits\n", getgdesc(GD_BITS_NORM_DBL_ALPHA));
00224        fprintf(stderr, "GD_BLEND = %d \n", getgdesc(GD_BLEND));
00225        fprintf(stderr, "GD_CLIPPLANES = %d \n", getgdesc(GD_CLIPPLANES));
00226      */
00227 
00228     /* TODO: get rid of (define) these magic numbers scaling the attribute vals */
00229     check_transp = 0;
00230     tratt = &(surf->att[ATT_TRANSP]);
00231     ktrans = (255 << 24);
00232     trans_src = surf->att[ATT_TRANSP].att_src;
00233 
00234     if (CONST_ATT == trans_src && surf->att[ATT_TRANSP].constant != 0.0) {
00235         ktrans = (255 - (int)surf->att[ATT_TRANSP].constant) << 24;
00236         gsd_blend(1);
00237         gsd_zwritemask(0x0);
00238     }
00239     else if (MAP_ATT == trans_src) {
00240         trbuff = gs_get_att_typbuff(surf, ATT_TRANSP, 0);
00241         check_transp = trbuff ? 1 : 0;
00242         gsd_blend(1);
00243         gsd_zwritemask(0x0);
00244     }
00245 
00246     check_emis = 0;
00247     ematt = &(surf->att[ATT_EMIT]);
00248     kem = 0.0;
00249     pkem = 1.0;
00250     em_src = surf->att[ATT_EMIT].att_src;
00251 
00252     if (CONST_ATT == em_src) {
00253         kem = surf->att[ATT_EMIT].constant / 255.;
00254     }
00255     else if (MAP_ATT == em_src) {
00256         embuff = gs_get_att_typbuff(surf, ATT_EMIT, 0);
00257         check_emis = embuff ? 1 : 0;
00258     }
00259 
00260     check_shin = 0;
00261     shatt = &(surf->att[ATT_SHINE]);
00262     ksh = 0.0;
00263     pksh = 1.0;
00264     sh_src = surf->att[ATT_SHINE].att_src;
00265 
00266     if (CONST_ATT == sh_src) {
00267         ksh = surf->att[ATT_SHINE].constant / 255.;
00268         gsd_set_material(1, 0, ksh, kem, 0x0);
00269     }
00270     else if (MAP_ATT == sh_src) {
00271         shbuff = gs_get_att_typbuff(surf, ATT_SHINE, 0);
00272         check_shin = shbuff ? 1 : 0;
00273     }
00274 
00275     /* will need to check for color source of FUNC_ATT & NOTSET_ATT, 
00276        or else use more general and inefficient gets */
00277     check_color = 1;
00278     coloratt = &(surf->att[ATT_COLOR]);
00279     col_src = surf->att[ATT_COLOR].att_src;
00280 
00281     if (col_src != MAP_ATT) {
00282         if (col_src == CONST_ATT) {
00283             curcolor = (int)surf->att[ATT_COLOR].constant;
00284         }
00285         else {
00286             curcolor = surf->wire_color;
00287         }
00288 
00289         check_color = 0;
00290     }
00291 
00292     check_material = (check_shin || check_emis || (kem && check_color));
00293 
00294     /* would also be good to check if colormap == surfmap, to increase speed */
00295     /* will also need to set check_transp, check_shine, etc & fix material */
00296     cnt = 0;
00297 
00298     for (row = 0; row < ycnt; row++) {
00299         if (GS_check_cancel()) {
00300             gsd_popmatrix();
00301             gsd_blend(0);
00302             gsd_zwritemask(0xffffffff);
00303 
00304             return (-1);
00305         }
00306 
00307         datarow1 = row * ymod;
00308         datarow2 = (row + 1) * ymod;
00309 
00310         y1 = ymax - row * yres;
00311         y2 = ymax - (row + 1) * yres;
00312         y1off = row * ymod * surf->cols;
00313         y2off = (row + 1) * ymod * surf->cols;
00314 
00315         gsd_bgntmesh();
00316 
00317         zeros = 0;
00318         dr1 = dr2 = dr3 = dr4 = 1;
00319 
00320         if (check_mask) {
00321             if (BM_get(surf->curmask, 0, datarow1)) {
00322                  /*TL*/ ++zeros;
00323                 dr1 = 0;
00324             }
00325 
00326             if (BM_get(surf->curmask, 0, datarow2)) {
00327                  /*BL*/ ++zeros;
00328                 dr2 = 0;
00329             }
00330         }
00331 
00332         if (dr1 && dr2) {
00333             offset = y1off;     /* TL */
00334             FNORM(surf->norms[offset], n);
00335             pt[X] = 0;
00336             pt[Y] = y1;
00337             GET_MAPATT(buff, offset, pt[Z]);
00338             pt[Z] *= zexag;
00339 
00340             if (check_color) {
00341                 curcolor = gs_mapcolor(cobuff, coloratt, offset);
00342             }
00343 
00344             if (check_transp) {
00345                 GET_MAPATT(trbuff, offset, ttr);
00346                 ktrans = (char)SCALE_ATT(tratt, ttr, 0, 255);
00347                 ktrans = (char)(255 - ktrans) << 24;
00348             }
00349 
00350             gsd_litvert_func(n, ktrans | curcolor, pt);
00351 
00352 #ifdef CALC_AREA
00353             GS_v3eq(triv[cnt % 3], pt);
00354 #endif
00355 
00356             cnt++;
00357 
00358             offset = y2off;     /* BL */
00359             FNORM(surf->norms[offset], n);
00360             pt[X] = 0;
00361             pt[Y] = y2;
00362             GET_MAPATT(buff, offset, pt[Z]);
00363             pt[Z] *= zexag;
00364 
00365             if (check_color) {
00366                 curcolor = gs_mapcolor(cobuff, coloratt, offset);
00367             }
00368 
00369             if (check_transp) {
00370                 GET_MAPATT(trbuff, offset, ttr);
00371                 ktrans = (char)SCALE_ATT(tratt, ttr, 0, 255);
00372                 ktrans = (char)(255 - ktrans) << 24;
00373             }
00374 
00375             if (check_material) {
00376                 if (check_emis) {
00377                     GET_MAPATT(embuff, offset, kem);
00378                     kem = SCALE_ATT(ematt, kem, 0., 1.);
00379                 }
00380 
00381                 if (check_shin) {
00382                     GET_MAPATT(shbuff, offset, ksh);
00383                     ksh = SCALE_ATT(shatt, ksh, 0., 1.);
00384                 }
00385 
00386                 if (pksh != ksh || pkem != kem || (kem && check_color)) {
00387                     /* expensive */
00388                     pksh = ksh;
00389                     pkem = kem;
00390                     gsd_set_material(check_shin, check_emis, ksh, kem,
00391                                      curcolor);
00392                 }
00393             }
00394 
00395             gsd_litvert_func(n, ktrans | curcolor, pt);
00396 
00397 #ifdef CALC_AREA
00398             GS_v3eq(triv[cnt % 3], pt);
00399 #endif
00400 
00401             cnt++;
00402         }
00403 
00404         for (col = 0; col < xcnt; col++) {
00405             datacol1 = col * xmod;
00406             datacol2 = (col + 1) * xmod;
00407 
00408             x1 = col * xres;
00409             x2 = (col + 1) * xres;
00410 
00411             zeros = 0;
00412             dr1 = dr2 = dr3 = dr4 = 1;
00413 
00414             if (check_mask) {
00415                 if (BM_get(surf->curmask, datacol1, datarow1)) {
00416                      /*TL*/ ++zeros;
00417                     dr1 = 0;
00418                 }
00419 
00420                 if (BM_get(surf->curmask, datacol1, datarow2)) {
00421                      /*BL*/ ++zeros;
00422                     dr2 = 0;
00423                 }
00424 
00425                 if (BM_get(surf->curmask, datacol2, datarow2)) {
00426                      /*BR*/ ++zeros;
00427                     dr3 = 0;
00428                 }
00429 
00430                 if (BM_get(surf->curmask, datacol2, datarow1)) {
00431                      /*TR*/ ++zeros;
00432                     dr4 = 0;
00433                 }
00434 
00435                 if ((zeros > 1) && cnt) {
00436                     gsd_endtmesh();
00437                     cnt = 0;
00438                     gsd_bgntmesh();
00439                     continue;
00440                 }
00441             }
00442 
00443             if (cnt > 252) {
00444                 /* not needed! - no limit for tmesh */
00445                 cnt = 0;
00446                 gsd_endtmesh();
00447                 gsd_bgntmesh();
00448 
00449                 if (dr1) {
00450                     offset = y1off + datacol1;  /* TL */
00451                     FNORM(surf->norms[offset], n);
00452                     pt[X] = x1;
00453                     pt[Y] = y1;
00454                     GET_MAPATT(buff, offset, pt[Z]);
00455                     pt[Z] *= zexag;
00456 
00457                     if (gsd_checkpoint
00458                         (pt, window, viewport, modelMatrix, projMatrix)) {
00459                         gsd_endtmesh();
00460                         cnt = 0;
00461                         gsd_bgntmesh();
00462                         continue;
00463                     }
00464 
00465                     if (check_color) {
00466                         curcolor = gs_mapcolor(cobuff, coloratt, offset);
00467                     }
00468 
00469                     if (check_transp) {
00470                         GET_MAPATT(trbuff, offset, ttr);
00471                         ktrans = (char)SCALE_ATT(tratt, ttr, 0, 255);
00472                         ktrans = (char)(255 - ktrans) << 24;
00473                     }
00474 
00475                     if (check_material) {
00476                         if (check_emis) {
00477                             GET_MAPATT(embuff, offset, kem);
00478                             kem = SCALE_ATT(ematt, kem, 0., 1.);
00479                         }
00480 
00481                         if (check_shin) {
00482                             GET_MAPATT(shbuff, offset, ksh);
00483                             ksh = SCALE_ATT(shatt, ksh, 0., 1.);
00484                         }
00485 
00486                         if (pksh != ksh || pkem != kem
00487                             || (kem && check_color)) {
00488                             pksh = ksh;
00489                             pkem = kem;
00490                             gsd_set_material(check_shin, check_emis,
00491                                              ksh, kem, curcolor);
00492                         }
00493                     }
00494 
00495                     gsd_litvert_func(n, ktrans | curcolor, pt);
00496 
00497 #ifdef CALC_AREA
00498                     GS_v3eq(triv[cnt % 3], pt);
00499 #endif
00500 
00501                     cnt++;
00502                 }
00503 
00504                 if (dr2) {
00505                     offset = y2off + datacol1;  /* BL */
00506                     FNORM(surf->norms[offset], n);
00507                     pt[X] = x1;
00508                     pt[Y] = y2;
00509                     GET_MAPATT(buff, offset, pt[Z]);
00510                     pt[Z] *= zexag;
00511 
00512                     if (gsd_checkpoint
00513                         (pt, window, viewport, modelMatrix, projMatrix)) {
00514                         gsd_endtmesh();
00515                         cnt = 0;
00516                         gsd_bgntmesh();
00517                         continue;
00518                     }
00519 
00520                     if (check_color) {
00521                         curcolor = gs_mapcolor(cobuff, coloratt, offset);
00522                     }
00523 
00524                     if (check_transp) {
00525                         GET_MAPATT(trbuff, offset, ttr);
00526                         ktrans = (char)SCALE_ATT(tratt, ttr, 0, 255);
00527                         ktrans = (char)(255 - ktrans) << 24;
00528                     }
00529 
00530                     if (check_material) {
00531                         if (check_emis) {
00532                             GET_MAPATT(embuff, offset, kem);
00533                             kem = SCALE_ATT(ematt, kem, 0., 1.);
00534                         }
00535 
00536                         if (check_shin) {
00537                             GET_MAPATT(shbuff, offset, ksh);
00538                             ksh = SCALE_ATT(shatt, ksh, 0., 1.);
00539                         }
00540 
00541                         if (pksh != ksh || pkem != kem
00542                             || (kem && check_color)) {
00543                             pksh = ksh;
00544                             pkem = kem;
00545                             gsd_set_material(check_shin, check_emis,
00546                                              ksh, kem, curcolor);
00547                         }
00548                     }
00549 
00550                     gsd_litvert_func(n, ktrans | curcolor, pt);
00551 
00552 #ifdef CALC_AREA
00553                     GS_v3eq(triv[cnt % 3], pt);
00554 #endif
00555 
00556                     cnt++;
00557                 }
00558             }
00559 
00560             if (dr4) {
00561                 offset = y1off + datacol2;      /* TR */
00562                 FNORM(surf->norms[offset], n);
00563                 pt[X] = x2;
00564                 pt[Y] = y1;
00565                 GET_MAPATT(buff, offset, pt[Z]);
00566                 pt[Z] *= zexag;
00567 
00568                 if (gsd_checkpoint
00569                     (pt, window, viewport, modelMatrix, projMatrix)) {
00570                     gsd_endtmesh();
00571                     cnt = 0;
00572                     gsd_bgntmesh();
00573                     continue;
00574                 }
00575 
00576                 if (check_color) {
00577                     curcolor = gs_mapcolor(cobuff, coloratt, offset);
00578                 }
00579 
00580                 if (check_transp) {
00581                     GET_MAPATT(trbuff, offset, ttr);
00582                     ktrans = (char)SCALE_ATT(tratt, ttr, 0, 255);
00583                     ktrans = (char)(255 - ktrans) << 24;
00584                 }
00585 
00586                 if (check_material) {
00587                     if (check_emis) {
00588                         GET_MAPATT(embuff, offset, kem);
00589                         kem = SCALE_ATT(ematt, kem, 0., 1.);
00590                     }
00591 
00592                     if (check_shin) {
00593                         GET_MAPATT(shbuff, offset, ksh);
00594                         ksh = SCALE_ATT(shatt, ksh, 0., 1.);
00595                     }
00596 
00597                     if (pksh != ksh || pkem != kem || (kem && check_color)) {
00598                         pksh = ksh;
00599                         pkem = kem;
00600                         gsd_set_material(check_shin, check_emis,
00601                                          ksh, kem, curcolor);
00602                     }
00603                 }
00604 
00605                 gsd_litvert_func(n, ktrans | curcolor, pt);
00606 
00607 #ifdef CALC_AREA
00608                 GS_v3eq(triv[cnt % 3], pt);
00609 
00610                 if (cnt > 1) {
00611                     GS_v3eq(tedge1, triv[1]);
00612                     GS_v3eq(tedge2, triv[2]);
00613                     GS_v3sub(tedge1, triv[0]);
00614                     GS_v3sub(tedge2, triv[1]);
00615                     GS_v3cross(tedge1, tedge2, crossp);
00616                     GS_v3mag(crossp, &mag);
00617                     asurf += .5 * mag;
00618                     tedge1[Z] *= sz;
00619                     tedge2[Z] *= sz;
00620                     GS_v3cross(tedge1, tedge2, crossp);
00621                     GS_v3mag(crossp, &mag);
00622                     axsurf += .5 * mag;
00623                 }
00624 #endif
00625 
00626                 cnt++;
00627             }
00628 
00629             if (dr3) {
00630                 offset = y2off + datacol2;      /* BR */
00631                 FNORM(surf->norms[offset], n);
00632                 pt[X] = x2;
00633                 pt[Y] = y2;
00634                 GET_MAPATT(buff, offset, pt[Z]);
00635                 pt[Z] *= zexag;
00636 
00637                 if (gsd_checkpoint
00638                     (pt, window, viewport, modelMatrix, projMatrix)) {
00639                     gsd_endtmesh();
00640                     cnt = 0;
00641                     gsd_bgntmesh();
00642                     continue;
00643                 }
00644 
00645                 if (check_color) {
00646                     curcolor = gs_mapcolor(cobuff, coloratt, offset);
00647                 }
00648 
00649                 if (check_transp) {
00650                     GET_MAPATT(trbuff, offset, ttr);
00651                     ktrans = (char)SCALE_ATT(tratt, ttr, 0, 255);
00652                     ktrans = (char)(255 - ktrans) << 24;
00653                 }
00654 
00655                 if (check_material) {
00656                     if (check_emis) {
00657                         GET_MAPATT(embuff, offset, kem);
00658                         kem = SCALE_ATT(ematt, kem, 0., 1.);
00659                     }
00660 
00661                     if (check_shin) {
00662                         GET_MAPATT(shbuff, offset, ksh);
00663                         ksh = SCALE_ATT(shatt, ksh, 0., 1.);
00664                     }
00665 
00666                     if (pksh != ksh || pkem != kem || (kem && check_color)) {
00667                         pksh = ksh;
00668                         pkem = kem;
00669                         gsd_set_material(check_shin, check_emis,
00670                                          ksh, kem, curcolor);
00671                     }
00672                 }
00673 
00674                 gsd_litvert_func(n, ktrans | curcolor, pt);
00675 
00676 #ifdef CALC_AREA
00677                 GS_v3eq(triv[cnt % 3], pt);
00678 
00679                 if (cnt > 1) {
00680                     GS_v3eq(tedge1, triv[1]);
00681                     GS_v3eq(tedge2, triv[2]);
00682                     GS_v3sub(tedge1, triv[0]);
00683                     GS_v3sub(tedge2, triv[1]);
00684                     GS_v3cross(tedge1, tedge2, crossp);
00685                     GS_v3mag(crossp, &mag);
00686                     asurf += .5 * mag;
00687                     tedge1[Z] *= sz;
00688                     tedge2[Z] *= sz;
00689                     GS_v3cross(tedge1, tedge2, crossp);
00690                     GS_v3mag(crossp, &mag);
00691                     axsurf += .5 * mag;
00692                 }
00693 #endif
00694 
00695                 cnt++;
00696             }
00697         }                       /* ea col */
00698 
00699         gsd_endtmesh();
00700     }                           /* ea row */
00701 
00702     gsd_popmatrix();
00703     gsd_blend(0);
00704     gsd_zwritemask(0xffffffff);
00705 
00706     show_colormode();
00707 
00708 #ifdef CALC_AREA
00709     G_debug(5, "  Surface Area: %.12lf", asurf);
00710     G_debug(5, "  Exaggerated Surface Area: %.12lf", axsurf);
00711 #endif
00712 
00713     return (0);
00714 }
00715 
00729 int gsd_surf_const(geosurf * surf, float k)
00730 {
00731     int do_diff, check_mask, check_color;
00732     typbuff *cobuff;
00733     int xmod, ymod, row, col, cnt, xcnt, ycnt;
00734     long offset, y1off, y2off;
00735     float x1, x2, y1, y2, tx, ty, tz;
00736     float n[3], pt[4], xres, yres, ymax, zexag;
00737     int col_src, curcolor;
00738     gsurf_att *coloratt;
00739 
00740     /* Viewport variables */
00741     GLdouble modelMatrix[16], projMatrix[16];
00742     GLint viewport[4];
00743     GLint window[4];
00744 
00745     int zeros, dr1, dr2, dr3, dr4;
00746     int datarow1, datacol1, datarow2, datacol2;
00747 
00748     unsigned int ktrans = 255;
00749 
00750     G_debug(5, "gsd_surf_const(): id=%d", surf->gsurf_id);
00751 
00752     if (GS_check_cancel()) {
00753         return (-1);
00754     }
00755 
00756     cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
00757 
00758     gs_update_curmask(surf);
00759     check_mask = surf->curmask ? 1 : 0;
00760 
00761     /*
00762        checks ATT_TOPO & ATT_COLOR no_zero flags, make a mask from each,
00763        combine it/them with any current mask, put in surf->curmask:
00764      */
00765     do_diff = (NULL != gsdiff_get_SDref());
00766     xmod = surf->x_mod;
00767     ymod = surf->y_mod;
00768     xres = xmod * surf->xres;
00769     yres = ymod * surf->yres;
00770 
00771     xcnt = VCOLS(surf);
00772     ycnt = VROWS(surf);
00773     ymax = (surf->rows - 1) * surf->yres;
00774 
00775     /* Get Viewport */
00776     gsd_getwindow(window, viewport, modelMatrix, projMatrix);
00777     /* adjust window */
00778     window[0] += (int)(yres * 2);
00779     window[1] -= (int)(yres * 2);
00780     window[2] -= (int)(xres * 2);
00781     window[3] += (int)(xres * 2);
00782 
00783 
00784     gsd_colormode(CM_DIFFUSE);
00785     gsd_pushmatrix();
00786 
00787     /* avoid scaling by zero */
00788     GS_get_scale(&tx, &ty, &tz, 1);
00789 
00790     if (tz == 0.0) {
00791         k = 0.0;
00792         gsd_do_scale(0);
00793     }
00794     else {
00795         gsd_do_scale(1);
00796     }
00797 
00798     gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
00799     zexag = surf->z_exag;
00800 
00801     if (CONST_ATT == surf->att[ATT_TRANSP].att_src) {
00802         gsd_blend(1);
00803         ktrans = 255 - (int)surf->att[ATT_TRANSP].constant;
00804         gsd_zwritemask(0x0);
00805     }
00806 
00807     ktrans = (ktrans << 24);
00808 
00809     /* will need to check for color source of FUNC_ATT & NOTSET_ATT, 
00810        or else use more general and inefficient gets */
00811 
00812     check_color = 1;
00813     coloratt = &(surf->att[ATT_COLOR]);
00814     col_src = surf->att[ATT_COLOR].att_src;
00815 
00816     if (col_src != MAP_ATT) {
00817         if (col_src == CONST_ATT) {
00818             curcolor = (int)surf->att[ATT_COLOR].constant;
00819         }
00820         else {
00821             curcolor = surf->wire_color;
00822         }
00823 
00824         check_color = 0;
00825     }
00826 
00827     /* CONSTANTS */
00828     pt[Z] = k * zexag;
00829     n[X] = n[Y] = 0.0;
00830     n[Z] = 1.0;
00831 
00832     /* just draw one polygon if no color mapped */
00833     /* fast, but specular reflection will prob. be poor */
00834     if (!check_color && !check_mask && !do_diff) {
00835         gsd_bgnpolygon();
00836 
00837         pt[X] = pt[Y] = 0;
00838         gsd_litvert_func(n, ktrans | curcolor, pt);
00839 
00840         pt[X] = xcnt * xres;
00841         gsd_litvert_func(n, ktrans | curcolor, pt);
00842 
00843         pt[Y] = ycnt * yres;
00844         gsd_litvert_func(n, ktrans | curcolor, pt);
00845 
00846         pt[X] = 0;
00847         gsd_litvert_func(n, ktrans | curcolor, pt);
00848 
00849         gsd_endpolygon();
00850         gsd_popmatrix();
00851         gsd_blend(0);
00852         gsd_zwritemask(0xffffffff);
00853 
00854         return (0);
00855     }
00856 
00857     cnt = 0;
00858 
00859     for (row = 0; row < ycnt; row++) {
00860         if (GS_check_cancel()) {
00861             gsd_popmatrix();
00862             gsd_blend(0);
00863             gsd_zwritemask(0xffffffff);
00864 
00865             return (-1);
00866         }
00867 
00868         datarow1 = row * ymod;
00869         datarow2 = (row + 1) * ymod;
00870 
00871         y1 = ymax - row * yres;
00872         y2 = ymax - (row + 1) * yres;
00873         y1off = row * ymod * surf->cols;
00874         y2off = (row + 1) * ymod * surf->cols;
00875 
00876         gsd_bgntmesh();
00877 
00878         zeros = 0;
00879         dr1 = dr2 = dr3 = dr4 = 1;
00880 
00881         if (check_mask) {
00882             if (BM_get(surf->curmask, 0, datarow1)) {
00883                  /*TL*/ ++zeros;
00884                 dr1 = 0;
00885             }
00886 
00887             if (BM_get(surf->curmask, 0, datarow2)) {
00888                  /*BL*/ ++zeros;
00889                 dr2 = 0;
00890             }
00891         }
00892 
00893         if (dr1 && dr2) {
00894             offset = y1off;     /* TL */
00895             pt[X] = 0;
00896             pt[Y] = y1;
00897 
00898             if (check_color) {
00899                 curcolor = gs_mapcolor(cobuff, coloratt, offset);
00900             }
00901 
00902             if (do_diff) {
00903                 pt[Z] = gsdiff_do_SD(k * zexag, offset);
00904             }
00905 
00906             gsd_litvert_func(n, ktrans | curcolor, pt);
00907             cnt++;
00908 
00909             offset = y2off;     /* BL */
00910             pt[X] = 0;
00911             pt[Y] = y2;
00912 
00913             if (check_color) {
00914                 curcolor = gs_mapcolor(cobuff, coloratt, offset);
00915             }
00916 
00917             if (do_diff) {
00918                 pt[Z] = gsdiff_do_SD(k * zexag, offset);
00919             }
00920 
00921             gsd_litvert_func(n, ktrans | curcolor, pt);
00922             cnt++;
00923         }
00924 
00925         for (col = 0; col < xcnt; col++) {
00926             datacol1 = col * xmod;
00927             datacol2 = (col + 1) * xmod;
00928 
00929             x1 = col * xres;
00930             x2 = (col + 1) * xres;
00931 
00932             zeros = 0;
00933             dr1 = dr2 = dr3 = dr4 = 1;
00934 
00935             if (check_mask) {
00936                 if (BM_get(surf->curmask, datacol1, datarow1)) {
00937                      /*TL*/ ++zeros;
00938                     dr1 = 0;
00939                 }
00940 
00941                 if (BM_get(surf->curmask, datacol1, datarow2)) {
00942                      /*BL*/ ++zeros;
00943                     dr2 = 0;
00944                 }
00945 
00946                 if (BM_get(surf->curmask, datacol2, datarow2)) {
00947                      /*BR*/ ++zeros;
00948                     dr3 = 0;
00949                 }
00950 
00951                 if (BM_get(surf->curmask, datacol2, datarow1)) {
00952                      /*TR*/ ++zeros;
00953                     dr4 = 0;
00954                 }
00955 
00956                 if ((zeros > 1) && cnt) {
00957                     gsd_endtmesh();
00958                     cnt = 0;
00959                     gsd_bgntmesh();
00960                     continue;
00961                 }
00962 
00963             }
00964 
00965             if (cnt > 250) {
00966                 cnt = 0;
00967                 gsd_endtmesh();
00968                 gsd_bgntmesh();
00969 
00970                 if (dr1) {
00971                     offset = y1off + datacol1;  /* TL */
00972                     pt[X] = x1;
00973                     pt[Y] = y1;
00974 
00975                     if (gsd_checkpoint
00976                         (pt, window, viewport, modelMatrix, projMatrix)) {
00977                         gsd_endtmesh();
00978                         cnt = 0;
00979                         gsd_bgntmesh();
00980                         continue;
00981                     }
00982 
00983                     if (check_color) {
00984                         curcolor = gs_mapcolor(cobuff, coloratt, offset);
00985                     }
00986 
00987                     if (do_diff) {
00988                         pt[Z] = gsdiff_do_SD(k * zexag, offset);
00989                     }
00990 
00991                     gsd_litvert_func(n, ktrans | curcolor, pt);
00992                     cnt++;
00993                 }
00994 
00995                 if (dr2) {
00996                     offset = y2off + datacol1;  /* BL */
00997                     pt[X] = x1;
00998                     pt[Y] = y2;
00999 
01000                     if (gsd_checkpoint
01001                         (pt, window, viewport, modelMatrix, projMatrix)) {
01002                         gsd_endtmesh();
01003                         cnt = 0;
01004                         gsd_bgntmesh();
01005                         continue;
01006                     }
01007 
01008                     if (check_color) {
01009                         curcolor = gs_mapcolor(cobuff, coloratt, offset);
01010                     }
01011 
01012                     if (do_diff) {
01013                         pt[Z] = gsdiff_do_SD(k * zexag, offset);
01014                     }
01015 
01016                     gsd_litvert_func(n, ktrans | curcolor, pt);
01017                     cnt++;
01018                 }
01019             }
01020 
01021             if (dr4) {
01022                 offset = y1off + datacol2;      /* TR */
01023                 pt[X] = x2;
01024                 pt[Y] = y1;
01025 
01026                 if (gsd_checkpoint
01027                     (pt, window, viewport, modelMatrix, projMatrix)) {
01028                     gsd_endtmesh();
01029                     cnt = 0;
01030                     gsd_bgntmesh();
01031                     continue;
01032                 }
01033 
01034                 if (check_color) {
01035                     curcolor = gs_mapcolor(cobuff, coloratt, offset);
01036                 }
01037 
01038                 if (do_diff) {
01039                     pt[Z] = gsdiff_do_SD(k * zexag, offset);
01040                 }
01041 
01042                 gsd_litvert_func(n, ktrans | curcolor, pt);
01043                 cnt++;
01044             }
01045 
01046             if (dr3) {
01047                 offset = y2off + datacol2;      /* BR */
01048                 pt[X] = x2;
01049                 pt[Y] = y2;
01050 
01051                 if (gsd_checkpoint
01052                     (pt, window, viewport, modelMatrix, projMatrix)) {
01053                     gsd_endtmesh();
01054                     cnt = 0;
01055                     gsd_bgntmesh();
01056                     continue;
01057                 }
01058 
01059                 if (check_color) {
01060                     curcolor = gs_mapcolor(cobuff, coloratt, offset);
01061                 }
01062 
01063                 if (do_diff) {
01064                     pt[Z] = gsdiff_do_SD(k * zexag, offset);
01065                 }
01066 
01067                 gsd_litvert_func(n, ktrans | curcolor, pt);
01068                 cnt++;
01069             }
01070         }                       /* ea col */
01071 
01072         gsd_endtmesh();
01073     }                           /* ea row */
01074 
01075     gsd_popmatrix();
01076     gsd_blend(0);
01077     gsd_zwritemask(0xffffffff);
01078 
01079     return (0);
01080 }
01081 
01092 int gsd_surf_func(geosurf * gs, int (*user_func) ())
01093 {
01094 
01095     return (1);
01096 }
01097 
01111 int gsd_triangulated_wall(int npts1, int npts2, geosurf * surf1,
01112                           geosurf * surf2, Point3 * points1, Point3 * points2,
01113                           float *norm)
01114 {
01115     int i, i1, i2, nlong, offset, col_src;
01116     int check_color1, check_color2, color1, color2;
01117     typbuff *cobuf1, *cobuf2;
01118     gsurf_att *coloratt1, *coloratt2;
01119 
01120     check_color1 = check_color2 = 1;
01121 
01122     col_src = surf1->att[ATT_COLOR].att_src;
01123 
01124     if (col_src != MAP_ATT) {
01125         if (col_src == CONST_ATT) {
01126             color1 = (int)surf1->att[ATT_COLOR].constant;
01127         }
01128         else {
01129             color1 = surf1->wire_color;
01130         }
01131 
01132         check_color1 = 0;
01133     }
01134 
01135     coloratt1 = &(surf1->att[ATT_COLOR]);
01136     cobuf1 = gs_get_att_typbuff(surf1, ATT_COLOR, 0);
01137 
01138     col_src = surf2->att[ATT_COLOR].att_src;
01139     if (col_src != MAP_ATT) {
01140         if (col_src == CONST_ATT) {
01141             color2 = (int)surf2->att[ATT_COLOR].constant;
01142         }
01143         else {
01144             color2 = surf2->wire_color;
01145         }
01146 
01147         check_color2 = 0;
01148     }
01149 
01150     coloratt2 = &(surf2->att[ATT_COLOR]);
01151     cobuf2 = gs_get_att_typbuff(surf2, ATT_COLOR, 0);
01152 
01153     gsd_colormode(CM_DIFFUSE);
01154     gsd_pushmatrix();
01155     gsd_do_scale(1);
01156 
01157     gsd_bgntmesh();
01158 
01159     for (nlong = (npts1 > npts2 ? npts1 : npts2), i = 0; i < nlong; i++) {
01160         i1 = i * npts1 / nlong;
01161         i2 = i * npts2 / nlong;
01162         offset = XY2OFF(surf1, points1[i1][X], points1[i1][Y]);
01163 
01164         if (check_color1) {
01165             color1 = gs_mapcolor(cobuf1, coloratt1, offset);
01166         }
01167 
01168         offset = XY2OFF(surf1, points2[i2][X], points2[i2][Y]);
01169 
01170         if (check_color2) {
01171             color2 = gs_mapcolor(cobuf2, coloratt2, offset);
01172         }
01173 
01174         /* start with long line to ensure triangle */
01175         if (npts1 > npts2) {
01176             points1[i1][X] += surf1->x_trans;
01177             points1[i1][Y] += surf1->y_trans;
01178             points1[i1][Z] += surf1->z_trans;
01179             gsd_litvert_func(norm, color1, points1[i1]);
01180             points2[i2][X] += surf2->x_trans;
01181             points2[i2][Y] += surf2->y_trans;
01182             points2[i2][Z] += surf2->z_trans;
01183             gsd_litvert_func(norm, color2, points2[i2]);
01184         }
01185         else {
01186             points2[i2][X] += surf2->x_trans;
01187             points2[i2][Y] += surf2->y_trans;
01188             points2[i2][Z] += surf2->z_trans;
01189             gsd_litvert_func(norm, color2, points2[i2]);
01190             points1[i1][X] += surf1->x_trans;
01191             points1[i1][Y] += surf1->y_trans;
01192             points1[i1][Z] += surf1->z_trans;
01193             gsd_litvert_func(norm, color1, points1[i1]);
01194         }
01195     }
01196 
01197     gsd_endtmesh();
01198     gsd_popmatrix();
01199 
01200     return (1);
01201 }
01202 
01208 void gsd_setfc(int mode)
01209 {
01210     FCmode = mode;
01211 
01212     return;
01213 }
01214 
01220 int gsd_getfc(void)
01221 {
01222     return (FCmode);
01223 }
01224 
01233 static int transpoint_is_masked(geosurf * surf, Point3 point)
01234 {
01235     Point3 tp;
01236 
01237     tp[X] = point[X] - surf->x_trans;
01238     tp[Y] = point[Y] - surf->y_trans;
01239 
01240     return (gs_point_is_masked(surf, tp));
01241 }
01242 
01258 static int get_point_below(Point3 ** points, geosurf ** gsurfs, int ptn,
01259                            int cursurf, int numsurfs, int *belowsurf)
01260 {
01261     int n, found = -1;
01262     float nearz = 0.0, diff;
01263 
01264     if (gsurfs[cursurf]->curmask) {
01265         if (transpoint_is_masked(gsurfs[cursurf], points[cursurf][ptn])) {
01266             return (-1);
01267         }
01268     }
01269 
01270     for (n = 0; n < numsurfs; ++n) {
01271         diff = points[cursurf][ptn][Z] - points[n][ptn][Z];
01272 
01273         if (diff > 0) {
01274             if (!nearz || diff < nearz) {
01275                 if (gsurfs[n]->curmask) {
01276                     if (transpoint_is_masked(gsurfs[n], points[n][ptn])) {
01277                         continue;
01278                     }
01279                 }
01280 
01281                 nearz = diff;
01282                 found = n;
01283             }
01284         }
01285         /* else if (diff == 0.0 && n != cursurf)
01286            {
01287            if (gsurfs[n]->curmask)
01288            {
01289            if (transpoint_is_masked(gsurfs[n], points[n][ptn]))
01290            {
01291            continue;
01292            }
01293            }
01294 
01295            nearz=diff;
01296            found = n;
01297            break;
01298            }
01299          */
01300     }
01301 
01302     if (found != -1) {
01303         *belowsurf = found;
01304 
01305         return (1);
01306     }
01307 
01308     return (0);
01309 }
01310 
01311 
01312 /*
01313    #define CPDEBUG
01314  */
01315 
01327 int gsd_ortho_wall(int np, int ns, geosurf ** gsurfs, Point3 ** points,
01328                    float *norm)
01329 {
01330     int n, i, offset, col_src, check_color[MAX_SURFS];
01331     int color, colors[MAX_SURFS], nocolor;
01332     typbuff *cobuf[MAX_SURFS];
01333     gsurf_att *coloratt[MAX_SURFS];
01334 
01335     nocolor = FCmode == FC_GREY ? 1 : 0;
01336 
01337     if (!nocolor) {
01338         for (n = 0; n < ns; ++n) {
01339             check_color[n] = 1;
01340 
01341             col_src = gsurfs[n]->att[ATT_COLOR].att_src;
01342 
01343             if (col_src != MAP_ATT) {
01344                 if (col_src == CONST_ATT) {
01345                     colors[n] = (int)gsurfs[n]->att[ATT_COLOR].constant;
01346                 }
01347                 else {
01348                     colors[n] = gsurfs[n]->wire_color;
01349                 }
01350 
01351                 check_color[n] = 0;
01352             }
01353 
01354             coloratt[n] = &(gsurfs[n]->att[ATT_COLOR]);
01355             cobuf[n] = gs_get_att_typbuff(gsurfs[n], ATT_COLOR, 0);
01356         }
01357     }
01358 
01359 #ifdef CPDEBUG
01360     {
01361         GS_set_draw(GSD_BOTH);
01362     }
01363 #endif
01364 
01365     /* changed from CM_DIFFUSE - July 25, 2005
01366      * should display proper color for cut planes
01367      */
01368     gsd_colormode(CM_COLOR);
01369 
01370     /* actually ought to write a GS_set_fencetransp() */
01371     if (nocolor) {
01372         color = 0x80808080;
01373         gsd_blend(1);
01374         gsd_zwritemask(0x0);
01375     }
01376 
01377     gsd_pushmatrix();
01378     gsd_do_scale(1);
01379 
01380     /* using segs_intersect here with segments projected to 
01381        the 2d clipping plane */
01382     {
01383         float tx, ty;
01384         int bn, bnl, ctop, cbot, ctopl, cbotl, bsret;
01385         Point3 xing;
01386 
01387         if (nocolor) {
01388             ctop = cbot = ctopl = cbotl = color;
01389         }
01390 
01391         for (n = 0; n < ns; ++n) {
01392             for (i = 0; i < np; i++) {
01393                 if (0 <
01394                     (bsret =
01395                      get_point_below(points, gsurfs, i, n, ns, &bn))) {
01396                     gsd_bgntmesh();
01397 
01398                     if (!nocolor) {
01399                         SET_SCOLOR(n);
01400                         SET_SCOLOR(bn);
01401 
01402                         if (FCmode == FC_ABOVE) {
01403                             ctop = cbot = colors[n];
01404                         }
01405                         else if (FCmode == FC_BELOW) {
01406                             ctop = cbot = colors[bn];
01407                         }
01408                         else {
01409                             cbot = colors[bn];
01410                             ctop = colors[n];
01411                         }
01412                     }
01413 
01414                     if (i) {
01415                         /* need to find crossing? */
01416                         if (!transpoint_is_masked(gsurfs[n], points[n][i - 1])
01417                             && !transpoint_is_masked(gsurfs[bn],
01418                                                      points[bn][i - 1])) {
01419                             if (1 ==
01420                                 segs_intersect(0.0, points[n][i - 1][Z], 1.0,
01421                                                points[n][i][Z], 0.0,
01422                                                points[bn][i - 1][Z], 1.0,
01423                                                points[bn][i][Z], &tx, &ty)) {
01424                                 xing[Z] = ty;
01425                                 xing[Y] = points[n][i - 1][Y] + tx *
01426                                     (points[n][i][Y] - points[n][i - 1][Y]);
01427                                 xing[X] = points[n][i - 1][X] + tx *
01428                                     (points[n][i][X] - points[n][i - 1][X]);
01429                                 gsd_litvert_func(norm, ctop, xing);
01430                                 xing[Z] = points[bn][i - 1][Z] + tx *
01431                                     (points[bn][i][Z] - points[bn][i - 1][Z]);
01432                                 gsd_litvert_func(norm, cbot, xing);
01433                             }
01434                         }
01435                     }
01436 
01437                     gsd_litvert_func(norm, ctop, points[n][i]);
01438                     gsd_litvert_func(norm, cbot, points[bn][i]);
01439                     i++;
01440 
01441                     bnl = -1;
01442 
01443                     while (i < np && 0 < (bsret =
01444                                           get_point_below(points, gsurfs, i,
01445                                                           n, ns, &bn))) {
01446 #ifdef CPDEBUG
01447                         {
01448                             int lower = 0;
01449 
01450                             if (GS_check_cancel()) {
01451                                 break;
01452                             }
01453                         }
01454 #endif
01455 
01456                         if (!nocolor) {
01457                             ctopl = ctop;
01458                             cbotl = cbot;
01459                             SET_SCOLOR(n);
01460                             SET_SCOLOR(bn);
01461 
01462                             if (FCmode == FC_ABOVE) {
01463                                 ctop = cbot = colors[n];
01464                             }
01465                             else if (FCmode == FC_BELOW) {
01466                                 ctop = cbot = colors[bn];
01467                             }
01468                             else {
01469                                 cbot = colors[bn];
01470                                 ctop = colors[n];
01471                             }
01472                         }
01473 
01474                         /* 
01475                            IF UPPER crossing :
01476                            (crossing is between current & new lower surf) 
01477                            IF XING going DOWN:
01478                            - plot crossing point (color previous upper) 
01479                            - endtmesh/bgntmesh
01480                            - plot crossing point (color current upper) 
01481                            - plot "equivalent" point below (color current lower) 
01482                            IF XING going UP:
01483                            - plot crossing point (color previous upper) 
01484                            - plot "equivalent" point below (color previous lower) 
01485                            - endtmesh/bgntmesh
01486                            - plot crossing point (color current upper) 
01487                            ELSE IF LOWER crossing: 
01488                            (crossing between new & previous lower surfs):
01489                            - plot "equivalent" point above (color previous upper) 
01490                            - plot crossing below (color previous lower)
01491                            - endtmesh/bgntmesh
01492                            - plot "equivalent" point above (color current upper) 
01493                            - plot crossing below (color current lower)
01494                          */
01495                         if (bnl >= 0 && bnl != bn) {
01496                             /* crossing */
01497                             float z1, z2;
01498                             int upper = 0;
01499 
01500                             if (!transpoint_is_masked(gsurfs[n],
01501                                                       points[n][i - 1]) &&
01502                                 !transpoint_is_masked(gsurfs[bnl],
01503                                                       points[bnl][i - 1]) &&
01504                                 !transpoint_is_masked(gsurfs[bn],
01505                                                       points[bn][i - 1])) {
01506 
01507                                 if (1 == segs_intersect(0.0,
01508                                                         points[n][i - 1][Z],
01509                                                         1.0, points[n][i][Z],
01510                                                         0.0,
01511                                                         points[bn][i - 1][Z],
01512                                                         1.0, points[bn][i][Z],
01513                                                         &tx, &ty)) {
01514                                     /* crossing going up */
01515 
01516                                     G_debug(5,
01517                                             "crossing going up at surf %d no. %d",
01518                                             n, i);
01519 
01520                                     upper = 1;
01521                                     xing[Z] = ty;
01522                                     xing[Y] = points[n][i - 1][Y] + tx *
01523                                         (points[n][i][Y] -
01524                                          points[n][i - 1][Y]);
01525                                     xing[X] =
01526                                         points[n][i - 1][X] +
01527                                         tx * (points[n][i][X] -
01528                                               points[n][i - 1][X]);
01529                                     gsd_litvert_func(norm, ctopl, xing);
01530                                     z1 = xing[Z];
01531                                     xing[Z] = points[bnl][i - 1][Z] + tx *
01532                                         (points[bnl][i][Z] -
01533                                          points[bnl][i - 1][Z]);
01534                                     gsd_litvert_func(norm, cbotl, xing);
01535                                     xing[Z] = z1;
01536                                     gsd_endtmesh();
01537                                     gsd_bgntmesh();
01538                                     gsd_litvert_func(norm, ctop, xing);
01539                                 }
01540                                 else if (1 == segs_intersect(0.0,
01541                                                              points[n][i -
01542                                                                        1][Z],
01543                                                              1.0,
01544                                                              points[n][i][Z],
01545                                                              0.0,
01546                                                              points[bnl][i -
01547                                                                          1]
01548                                                              [Z], 1.0,
01549                                                              points[bnl][i]
01550                                                              [Z], &tx, &ty)) {
01551                                     /* crossing going down */
01552 
01553                                     G_debug(5,
01554                                             "crossing going down at surf %d no. %d",
01555                                             n, i);
01556 
01557                                     upper = 1;
01558                                     xing[Z] = ty;
01559                                     xing[Y] = points[n][i - 1][Y] + tx *
01560                                         (points[n][i][Y] -
01561                                          points[n][i - 1][Y]);
01562                                     xing[X] =
01563                                         points[n][i - 1][X] +
01564                                         tx * (points[n][i][X] -
01565                                               points[n][i - 1][X]);
01566                                     gsd_litvert_func(norm, ctopl, xing);
01567                                     z1 = xing[Z];
01568                                     xing[Z] = points[bnl][i - 1][Z] + tx *
01569                                         (points[bnl][i][Z] -
01570                                          points[bnl][i - 1][Z]);
01571                                     gsd_litvert_func(norm, cbotl, xing);
01572                                     xing[Z] = z1;
01573                                     gsd_endtmesh();
01574                                     gsd_bgntmesh();
01575                                     gsd_litvert_func(norm, ctop, xing);
01576                                     xing[Z] = points[bn][i - 1][Z] + tx *
01577                                         (points[bn][i][Z] -
01578                                          points[bn][i - 1][Z]);
01579                                     gsd_litvert_func(norm, cbot, xing);
01580                                 }
01581                             }
01582 
01583                             if (!upper &&
01584                                 !transpoint_is_masked(gsurfs[bn],
01585                                                       points[bn][i - 1]) &&
01586                                 !transpoint_is_masked(gsurfs[bnl],
01587                                                       points[bnl][i - 1])) {
01588 
01589                                 if (1 == segs_intersect(0.0,
01590                                                         points[bn][i - 1][Z],
01591                                                         1.0, points[bn][i][Z],
01592                                                         0.0,
01593                                                         points[bnl][i - 1][Z],
01594                                                         1.0,
01595                                                         points[bnl][i][Z],
01596                                                         &tx, &ty)) {
01597 #ifdef CPDEBUG
01598                                     {
01599                                         lower = 1;
01600                                     }
01601 #endif
01602                                     G_debug(5,
01603                                             "lower crossing at surf %d no. %d between surfs %d & %d",
01604                                             n, i, bn, bnl);
01605 
01606                                     xing[Z] = ty;
01607                                     xing[Y] = points[bn][i - 1][Y] + tx *
01608                                         (points[bn][i][Y] -
01609                                          points[bn][i - 1][Y]);
01610                                     xing[X] = points[bn][i - 1][X] + tx *
01611                                         (points[bn][i][X] -
01612                                          points[bn][i - 1][X]);
01613                                     z2 = xing[Z];
01614                                     z1 = xing[Z] = points[n][i - 1][Z] + tx *
01615                                         (points[n][i][Z] -
01616                                          points[n][i - 1][Z]);
01617                                     gsd_litvert_func(norm, ctopl, xing);
01618                                     xing[Z] = z2;
01619                                     gsd_litvert_func(norm, cbotl, xing);
01620                                     gsd_endtmesh();
01621                                     gsd_bgntmesh();
01622                                     xing[Z] = z1;
01623                                     gsd_litvert_func(norm, ctop, xing);
01624                                     xing[Z] = z2;
01625                                     gsd_litvert_func(norm, cbot, xing);
01626                                 }
01627                             }
01628 
01629 #ifdef CPDEBUG
01630                             {
01631                                 if (!upper && !lower) {
01632                                     G_debug(5,
01633                                             "Crossing NOT found or masked:");
01634                                     G_debug(5,
01635                                             "  current surf: %d [ %.2f %.2f %.2f -> %.2f %.2f %f",
01636                                             n, points[n][i - 1][X],
01637                                             points[n][i - 1][Y],
01638                                             points[n][i - 1][Z],
01639                                             points[n][i][X], points[n][i][Y],
01640                                             points[n][i][Z]);
01641                                     G_debug(5,
01642                                             "  below surf: %d [ %.2f %.2f %.2f -> %.2f %.2f %f\n",
01643                                             bn, points[bn][i - 1][X],
01644                                             points[bn][i - 1][Y],
01645                                             points[bn][i - 1][Z],
01646                                             points[bn][i][X],
01647                                             points[bn][i][Y],
01648                                             points[bn][i][Z]);
01649                                     G_debug(5, gs
01650                                             "  last below surf: %d [ %.2f %.2f %.2f -> %.2f %.2f %f\n",
01651                                             bnl, points[bnl][i - 1][X],
01652                                             points[bnl][i - 1][Y],
01653                                             points[bnl][i - 1][Z],
01654                                             points[bnl][i][X],
01655                                             points[bnl][i][Y],
01656                                             points[bnl][i][Z]);
01657                                 }
01658                             }
01659 #endif
01660                         }
01661 
01662                         gsd_litvert_func(norm, ctop, points[n][i]);
01663                         gsd_litvert_func(norm, cbot, points[bn][i]);
01664                         bnl = bn;
01665                         i++;
01666                     }
01667 
01668                     if (i < np) {
01669                         /* need to find crossing? */
01670                         if (!transpoint_is_masked(gsurfs[n], points[n][i - 1])
01671                             && !transpoint_is_masked(gsurfs[bn],
01672                                                      points[bn][i - 1])) {
01673                             if (1 ==
01674                                 segs_intersect(0.0, points[n][i - 1][Z], 1.0,
01675                                                points[n][i][Z], 0.0,
01676                                                points[bn][i - 1][Z], 1.0,
01677                                                points[bn][i][Z], &tx, &ty)) {
01678                                 xing[Z] = ty;
01679                                 xing[Y] = points[n][i - 1][Y] + tx *
01680                                     (points[n][i][Y] - points[n][i - 1][Y]);
01681                                 xing[X] = points[n][i - 1][X] + tx *
01682                                     (points[n][i][X] - points[n][i - 1][X]);
01683                                 gsd_litvert_func(norm, ctop, xing);
01684                             }
01685 
01686                             i--;
01687                         }
01688                     }
01689 
01690                     gsd_endtmesh();
01691                 }
01692             }
01693         }
01694     }
01695 
01696     gsd_colormode(CM_DIFFUSE);  /* set colormode back to DIFFUSE */
01697     gsd_popmatrix();
01698     gsd_blend(0);
01699     gsd_zwritemask(0xffffffff);
01700 
01701     return (1);
01702 }
01703 
01715 int gsd_wall(float *bgn, float *end, float *norm)
01716 {
01717     geosurf *gsurfs[MAX_SURFS];
01718     Point3 *points[MAX_SURFS], *tmp;
01719     int nsurfs, ret, npts, npts1, n, i, err = 0;
01720     float bgn1[2], end1[2];
01721 
01722     if (norm[Z] > 0.0001 || norm[Z] < -.0001) {
01723         return (0);             /* can't do tilted wall yet */
01724     }
01725 
01726     if (FCmode == FC_OFF) {
01727         return (0);
01728     }
01729 
01730     nsurfs = gs_getall_surfaces(gsurfs);
01731 
01732     for (n = 0; n < nsurfs; n++) {
01733         /* get drape points for surf */
01734         bgn1[X] = bgn[X] - gsurfs[n]->x_trans;
01735         bgn1[Y] = bgn[Y] - gsurfs[n]->y_trans;
01736         end1[X] = end[X] - gsurfs[n]->x_trans;
01737         end1[Y] = end[Y] - gsurfs[n]->y_trans;
01738         tmp = gsdrape_get_allsegments(gsurfs[n], bgn1, end1, &npts1);
01739 
01740         if (n) {
01741             if (npts != npts1) {
01742                 G_warning(_("Cut-plane points mis-match between surfaces. "
01743                             "Check resolution(s)."));
01744                 err = 1;
01745                 nsurfs = n;
01746 
01747                 break;
01748             }
01749         }
01750 
01751         npts = npts1;
01752 
01753         if (n == nsurfs - 1) {
01754             /* last surf - don't need to copy */
01755             points[n] = tmp;
01756 
01757             for (i = 0; i < npts1; i++) {
01758                 /* DOING translation here! */
01759                 points[n][i][X] += gsurfs[n]->x_trans;
01760                 points[n][i][Y] += gsurfs[n]->y_trans;
01761                 points[n][i][Z] += gsurfs[n]->z_trans;
01762             }
01763 
01764             break;
01765         }
01766 
01767         /* allocate space in points and copy tmp to points */
01768         points[n] = (Point3 *) G_calloc(npts1, sizeof(Point3)); /* G_fatal_error */
01769 
01770         for (i = 0; i < npts1; i++) {
01771             GS_v3eq(points[n][i], tmp[i]);
01772 
01773             /* DOING translation here! */
01774             points[n][i][X] += gsurfs[n]->x_trans;
01775             points[n][i][Y] += gsurfs[n]->y_trans;
01776             points[n][i][Z] += gsurfs[n]->z_trans;
01777         }
01778     }                           /* done for */
01779 
01780     if (err) {
01781         for (n = 0; n < nsurfs; n++) {
01782             if (points[n]) {
01783                 G_free(points[n]);
01784             }
01785         }
01786         return (0);
01787     }
01788 
01789 
01790     ret = gsd_ortho_wall(npts, nsurfs, gsurfs, points, norm);
01791 
01792     for (n = 0; n < nsurfs - 1; n++) {
01793         /* don't free last - it's constant */
01794         G_free(points[n]);
01795     }
01796 
01797     return (ret);
01798 }
01799 
01810 int gsd_norm_arrows(geosurf * surf)
01811 {
01812     typbuff *buff, *cobuff;
01813     int check_mask, check_color;
01814     int xmod, ymod, row, col, cnt, xcnt, ycnt;
01815     long offset, y1off, y2off;
01816     float x1, x2, y1, y2, tx, ty, tz, sz;
01817     float n[3], pt[4], xres, yres, ymax, zexag;
01818     int col_src, curcolor;
01819     gsurf_att *coloratt;
01820 
01821     int zeros, dr1, dr2, dr3, dr4;
01822     int datarow1, datacol1, datarow2, datacol2;
01823 
01824     G_debug(3, "gsd_norm_arrows");
01825 
01826     /* avoid scaling by zero */
01827     GS_get_scale(&tx, &ty, &tz, 1);
01828 
01829     if (tz == 0.0) {
01830         return (0);
01831     }
01832 
01833     sz = GS_global_exag();
01834 
01835     /*
01836        checks ATT_TOPO & ATT_COLOR no_zero flags, make a mask from each,
01837        combine it/them with any current mask, put in surf->curmask:
01838      */
01839     gs_update_curmask(surf);
01840     check_mask = surf->curmask ? 1 : 0;
01841 
01842     check_color = 1;
01843     coloratt = &(surf->att[ATT_COLOR]);
01844     col_src = surf->att[ATT_COLOR].att_src;
01845 
01846     if (col_src != MAP_ATT) {
01847         if (col_src == CONST_ATT) {
01848             curcolor = (int)surf->att[ATT_COLOR].constant;
01849         }
01850         else {
01851             curcolor = surf->wire_color;
01852         }
01853 
01854         check_color = 0;
01855     }
01856 
01857     buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
01858     cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
01859 
01860     xmod = surf->x_mod;
01861     ymod = surf->y_mod;
01862     xres = xmod * surf->xres;
01863     yres = ymod * surf->yres;
01864     ymax = (surf->rows - 1) * surf->yres;
01865 
01866     xcnt = VCOLS(surf);
01867     ycnt = VROWS(surf);
01868 
01869     gsd_pushmatrix();
01870     gsd_do_scale(1);
01871     gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
01872 
01873     zexag = surf->z_exag;
01874     /* CURRENTLY ALWAYS 1.0 */
01875 
01876 #ifdef DO_ARROW_SOLID
01877     gsd_colormode(CM_DIFFUSE);
01878 #else
01879     gsd_colormode(CM_COLOR);
01880 #endif
01881 
01882     cnt = 0;
01883 
01884     for (row = 0; row < ycnt; row++) {
01885         if (GS_check_cancel()) {
01886             gsd_popmatrix();
01887 
01888             return (-1);
01889         }
01890 
01891         datarow1 = row * ymod;
01892         datarow2 = (row + 1) * ymod;
01893 
01894         y1 = ymax - row * yres;
01895         y2 = ymax - (row + 1) * yres;
01896         y1off = row * ymod * surf->cols;
01897         y2off = (row + 1) * ymod * surf->cols;
01898 
01899         zeros = 0;
01900         dr1 = dr2 = dr3 = dr4 = 1;
01901 
01902         if (check_mask) {
01903             if (BM_get(surf->curmask, 0, datarow1)) {
01904                  /*TL*/ ++zeros;
01905                 dr1 = 0;
01906             }
01907 
01908             if (BM_get(surf->curmask, 0, datarow2)) {
01909                  /*BL*/ ++zeros;
01910                 dr2 = 0;
01911             }
01912         }
01913 
01914         if (dr1 && dr2) {
01915             offset = y1off;     /* TL */
01916             FNORM(surf->norms[offset], n);
01917             pt[X] = 0;
01918             pt[Y] = y2;
01919             GET_MAPATT(buff, offset, pt[Z]);
01920             pt[Z] *= zexag;
01921 
01922             if (check_color) {
01923                 curcolor = gs_mapcolor(cobuff, coloratt, offset);
01924             }
01925 
01926 #ifdef DO_ARROW_SOLID
01927             gsd_3darrow(pt, curcolor, xres * 2, xres / 2, n, sz);
01928 #else
01929             if (DEBUG_ARROW) {
01930                 gsd_arrow(pt, 0x000000, xres * 2, n, sz, surf);
01931             }
01932 #endif
01933 
01934             cnt++;
01935 
01936             offset = y2off;     /* BL */
01937             FNORM(surf->norms[offset], n);
01938             pt[X] = 0;
01939             pt[Y] = y2;
01940             GET_MAPATT(buff, offset, pt[Z]);
01941             pt[Z] *= zexag;
01942 
01943             if (check_color) {
01944                 curcolor = gs_mapcolor(cobuff, coloratt, offset);
01945             }
01946 
01947 #ifdef DO_ARROW_SOLID
01948             gsd_3darrow(pt, curcolor, xres * 2, xres / 2, n, sz);
01949 #else
01950             if (DEBUG_ARROW) {
01951                 gsd_arrow(pt, 0x000000, xres * 2, n, sz, surf);
01952             }
01953 #endif
01954 
01955             cnt++;
01956         }
01957 
01958         for (col = 0; col < xcnt; col++) {
01959             datacol1 = col * xmod;
01960             datacol2 = (col + 1) * xmod;
01961 
01962             x1 = col * xres;
01963             x2 = (col + 1) * xres;
01964 
01965             zeros = 0;
01966             dr1 = dr2 = dr3 = dr4 = 1;
01967 
01968             if (check_mask) {
01969                 if (BM_get(surf->curmask, datacol1, datarow1)) {
01970                      /*TL*/ ++zeros;
01971                     dr1 = 0;
01972                 }
01973 
01974                 if (BM_get(surf->curmask, datacol1, datarow2)) {
01975                      /*BL*/ ++zeros;
01976                     dr2 = 0;
01977                 }
01978 
01979                 if (BM_get(surf->curmask, datacol2, datarow2)) {
01980                      /*BR*/ ++zeros;
01981                     dr3 = 0;
01982                 }
01983 
01984                 if (BM_get(surf->curmask, datacol2, datarow1)) {
01985                      /*TR*/ ++zeros;
01986                     dr4 = 0;
01987                 }
01988 
01989                 if ((zeros > 1) && cnt) {
01990                     cnt = 0;
01991                     continue;
01992                 }
01993 
01994             }
01995 
01996             if (dr4) {
01997                 offset = y1off + datacol2;      /* TR */
01998                 FNORM(surf->norms[offset], n);
01999                 pt[X] = x2;
02000                 pt[Y] = y1;
02001                 GET_MAPATT(buff, offset, pt[Z]);
02002                 pt[Z] *= zexag;
02003 
02004                 if (check_color) {
02005                     curcolor = gs_mapcolor(cobuff, coloratt, offset);
02006                 }
02007 
02008 #ifdef DO_ARROW_SOLID
02009                 gsd_3darrow(pt, curcolor, xres * 2, xres / 2, n, sz);
02010 #else
02011                 if (DEBUG_ARROW) {
02012                     gsd_arrow(pt, 0x000000, xres * 2, n, sz, surf);
02013                 }
02014 #endif
02015 
02016                 cnt++;
02017             }
02018 
02019             if (dr3) {
02020                 offset = y2off + datacol2;      /* BR */
02021                 FNORM(surf->norms[offset], n);
02022                 pt[X] = x2;
02023                 pt[Y] = y2;
02024                 GET_MAPATT(buff, offset, pt[Z]);
02025                 pt[Z] *= zexag;
02026 
02027                 if (check_color) {
02028                     curcolor = gs_mapcolor(cobuff, coloratt, offset);
02029                 }
02030 
02031 #ifdef DO_ARROW_SOLID
02032                 gsd_3darrow(pt, curcolor, xres * 2, xres / 2, n, sz);
02033 #else
02034                 if (DEBUG_ARROW) {
02035                     gsd_arrow(pt, 0x000000, xres * 2, n, sz, surf);
02036                 }
02037 #endif
02038 
02039                 cnt++;
02040             }
02041         }                       /* ea col */
02042     }                           /* ea row */
02043     gsd_popmatrix();
02044 
02045     return (1);
02046 }
02047 
02048 
02062 int gsd_surf_map(geosurf * surf)
02063 {
02064     int check_mask, check_color, check_transp;
02065     int check_material, check_emis, check_shin;
02066     typbuff *buff, *cobuff, *trbuff, *embuff, *shbuff;
02067     int xmod, ymod;
02068     int row, col, cnt, xcnt, ycnt;
02069     long y1off, y2off, y3off;
02070     long offset2[10];
02071     float pt2[10][2];
02072     int ii;
02073     float x1, x2, x3, y1, y2, y3, tx, ty, tz, ttr;
02074     float n[3], pt[4], xres, yres, ymax, zexag;
02075     int em_src, sh_src, trans_src, col_src, curcolor;
02076     gsurf_att *ematt, *shatt, *tratt, *coloratt;
02077 
02078 
02079     /* Viewport variables for accelerated drawing */
02080     GLdouble modelMatrix[16], projMatrix[16];
02081     GLint viewport[4];
02082     GLint window[4];
02083     int cnt1 = 0, cnt2 = 0;
02084 
02085     int datarow1, datacol1, datarow2, datacol2, datarow3, datacol3;
02086 
02087     float kem, ksh, pkem, pksh;
02088     unsigned int ktrans;
02089 
02090     int step_val = 2;           /* should always be factor of 2 for fan */
02091     int start_val = 1;          /* one half of step_val */
02092 
02093     /* avoid scaling by zero */
02094     GS_get_scale(&tx, &ty, &tz, 1);
02095 
02096     if (tz == 0.0) {
02097         return (gsd_surf_const(surf, 0.0));
02098     }
02099     /* else if (surf->z_exag  == 0.0)
02100        {
02101        return(gsd_surf_const(surf, surf->z_min));
02102        }
02103        NOT YET IMPLEMENTED */
02104 
02105     buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
02106     cobuff = gs_get_att_typbuff(surf, ATT_COLOR, 0);
02107 
02108     gs_update_curmask(surf);
02109     check_mask = surf->curmask ? 1 : 0;
02110 
02111     /*
02112        checks ATT_TOPO & ATT_COLOR no_zero flags, make a mask from each,
02113        combine it/them with any current mask, put in surf->curmask:
02114      */
02115     xmod = surf->x_mod;
02116     ymod = surf->y_mod;
02117     xres = xmod * surf->xres;
02118     yres = ymod * surf->yres;
02119     ymax = (surf->rows - 1) * surf->yres;
02120 
02121     xcnt = VCOLS(surf);
02122     ycnt = VROWS(surf);
02123 
02124     /* Get viewport */
02125     gsd_getwindow(window, viewport, modelMatrix, projMatrix);
02126 
02127 
02128     gsd_colormode(CM_DIFFUSE);
02129     gsd_pushmatrix();
02130     gsd_do_scale(1);
02131     gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
02132     zexag = surf->z_exag;
02133 
02134     /* adjust window */
02135     window[0] += (int)(yres * 4 * zexag);
02136     window[1] -= (int)(yres * 4 * zexag);
02137     window[2] -= (int)(xres * 4 * zexag);
02138     window[3] += (int)(xres * 4 * zexag);
02139 
02140     /* CURRENTLY ALWAYS 1.0 */
02141 #ifdef CALC_AREA
02142     sz = GS_global_exag();
02143 #endif
02144 
02145     /* TODO: get rid of (define) these magic numbers scaling the attribute vals */
02146     check_transp = 0;
02147     tratt = &(surf->att[ATT_TRANSP]);
02148     ktrans = (255 << 24);
02149     trans_src = surf->att[ATT_TRANSP].att_src;
02150 
02151     if (CONST_ATT == trans_src && surf->att[ATT_TRANSP].constant != 0.0) {
02152         ktrans = (255 - (int)surf->att[ATT_TRANSP].constant) << 24;
02153         gsd_blend(1);
02154         gsd_zwritemask(0x0);
02155     }
02156     else if (MAP_ATT == trans_src) {
02157         trbuff = gs_get_att_typbuff(surf, ATT_TRANSP, 0);
02158         check_transp = trbuff ? 1 : 0;
02159         gsd_blend(1);
02160         gsd_zwritemask(0x0);
02161     }
02162 
02163     check_emis = 0;
02164     ematt = &(surf->att[ATT_EMIT]);
02165     kem = 0.0;
02166     pkem = 1.0;
02167     em_src = surf->att[ATT_EMIT].att_src;
02168 
02169     if (CONST_ATT == em_src) {
02170         kem = surf->att[ATT_EMIT].constant / 255.;
02171     }
02172     else if (MAP_ATT == em_src) {
02173         embuff = gs_get_att_typbuff(surf, ATT_EMIT, 0);
02174         check_emis = embuff ? 1 : 0;
02175     }
02176 
02177     check_shin = 0;
02178     shatt = &(surf->att[ATT_SHINE]);
02179     ksh = 0.0;
02180     pksh = 1.0;
02181     sh_src = surf->att[ATT_SHINE].att_src;
02182 
02183     if (CONST_ATT == sh_src) {
02184         ksh = surf->att[ATT_SHINE].constant / 255.;
02185         gsd_set_material(1, 0, ksh, kem, 0x0);
02186     }
02187     else if (MAP_ATT == sh_src) {
02188         shbuff = gs_get_att_typbuff(surf, ATT_SHINE, 0);
02189         check_shin = shbuff ? 1 : 0;
02190     }
02191 
02192     /* will need to check for color source of FUNC_ATT & NOTSET_ATT, 
02193        or else use more general and inefficient gets */
02194     check_color = 1;
02195     coloratt = &(surf->att[ATT_COLOR]);
02196     col_src = surf->att[ATT_COLOR].att_src;
02197 
02198     if (col_src != MAP_ATT) {
02199         if (col_src == CONST_ATT) {
02200             curcolor = (int)surf->att[ATT_COLOR].constant;
02201         }
02202         else {
02203             curcolor = surf->wire_color;
02204         }
02205 
02206         check_color = 0;
02207     }
02208 
02209     check_material = (check_shin || check_emis || (kem && check_color));
02210 
02211     /* would also be good to check if colormap == surfmap, to increase speed */
02212     /* will also need to set check_transp, check_shine, etc & fix material */
02213     cnt = 0;
02214 
02215     for (row = start_val; row < ycnt; row += step_val) {
02216         if (GS_check_cancel()) {
02217             gsd_popmatrix();
02218             gsd_blend(0);
02219             gsd_zwritemask(0xffffffff);
02220 
02221             return (-1);
02222         }
02223 
02224         /*
02225            if (row == 201 && new_fan == 0) {
02226            xmod *= 2;
02227            ymod *= 2;
02228            xres = xmod * surf->xres;
02229            yres = ymod * surf->yres;
02230            step_val *= 2;
02231            new_fan = 1;
02232            row -= 1;
02233            row /= 2;
02234            }
02235          */
02236         datarow1 = row * ymod;
02237         datarow2 = (row - (step_val / 2)) * ymod;
02238         datarow3 = (row + (step_val / 2)) * ymod;
02239 
02240 
02241         y1 = ymax - row * yres;
02242         y2 = ymax - (row - (step_val / 2)) * yres;
02243         y3 = ymax - (row + (step_val / 2)) * yres;
02244 
02245         y1off = row * ymod * surf->cols;
02246         y2off = (row - (step_val / 2)) * ymod * surf->cols;
02247         y3off = (row + (step_val / 2)) * ymod * surf->cols;
02248 
02249 
02250         for (col = start_val; col < xcnt; col += step_val) {
02251             datacol1 = col * xmod;
02252             datacol2 = (col - (step_val / 2)) * xmod;
02253             datacol3 = (col + (step_val / 2)) * xmod;
02254 
02255             x1 = col * xres;
02256             x2 = (col - (step_val / 2)) * xres;
02257             x3 = (col + (step_val / 2)) * xres;
02258 
02259 
02260             /* 0 */
02261             /*
02262                if (check_mask) {
02263                if (BM_get(surf->curmask, datacol1, datarow1))
02264                continue;
02265                }
02266              */
02267 
02268             cnt1++;
02269 
02270             /* Do not need BM_get because GET_MAPATT calls
02271              * same and returns zero if masked
02272              */
02273             offset2[0] = y1off + datacol1;      /* fan center */
02274             pt2[0][X] = x1;
02275             pt2[0][Y] = y1;     /* fan center */
02276             pt[X] = pt2[0][X];
02277             pt[Y] = pt2[0][Y];
02278             if (!GET_MAPATT(buff, offset2[0], pt[Z]))
02279                 continue;       /* masked */
02280             else {
02281                 pt[Z] *= zexag;
02282                 if (gsd_checkpoint
02283                     (pt, window, viewport, modelMatrix, projMatrix))
02284                     continue;
02285             }
02286 
02287 
02288             offset2[1] = y2off + datacol2;
02289             offset2[2] = y2off + datacol1;
02290             offset2[3] = y2off + datacol3;
02291             offset2[4] = y1off + datacol3;
02292             offset2[5] = y3off + datacol3;
02293             offset2[6] = y3off + datacol1;
02294             offset2[7] = y3off + datacol2;
02295             offset2[8] = y1off + datacol2;
02296             offset2[9] = y2off + datacol2;      /* repeat 1st corner to close */
02297 
02298             pt2[1][X] = x2;
02299             pt2[1][Y] = y2;
02300             pt2[2][X] = x1;
02301             pt2[2][Y] = y2;
02302             pt2[3][X] = x3;
02303             pt2[3][Y] = y2;
02304             pt2[4][X] = x3;
02305             pt2[4][Y] = y1;
02306             pt2[5][X] = x3;
02307             pt2[5][Y] = y3;
02308             pt2[6][X] = x1;
02309             pt2[6][Y] = y3;
02310             pt2[7][X] = x2;
02311             pt2[7][Y] = y3;
02312             pt2[8][X] = x2;
02313             pt2[8][Y] = y1;
02314             pt2[9][X] = x2;
02315             pt2[9][Y] = y2;     /* repeat 1st corner to close */
02316 
02317 
02318             /* Run through triangle fan */
02319             gsd_bgntfan();
02320             for (ii = 0; ii < 10; ii++) {
02321 
02322                 if (ii > 0) {
02323                     pt[X] = pt2[ii][X];
02324                     pt[Y] = pt2[ii][Y];
02325                     if (!GET_MAPATT(buff, offset2[ii], pt[Z]))
02326                         continue;
02327                     pt[Z] *= zexag;
02328                 }
02329 
02330                 FNORM(surf->norms[offset2[ii]], n);
02331 
02332                 if (check_color)
02333                     curcolor = gs_mapcolor(cobuff, coloratt, offset2[ii]);
02334 
02335                 if (check_transp) {
02336                     GET_MAPATT(trbuff, offset2[ii], ttr);
02337                     ktrans = (char)SCALE_ATT(tratt, ttr, 0, 255);
02338                     ktrans = (char)(255 - ktrans) << 24;
02339                 }
02340 
02341                 if (check_material) {
02342                     if (check_emis) {
02343                         GET_MAPATT(embuff, offset2[ii], kem);
02344                         kem = SCALE_ATT(ematt, kem, 0., 1.);
02345                     }
02346 
02347                     if (check_shin) {
02348                         GET_MAPATT(shbuff, offset2[ii], ksh);
02349                         ksh = SCALE_ATT(shatt, ksh, 0., 1.);
02350                     }
02351 
02352                     if (pksh != ksh || pkem != kem || (kem && check_color)) {
02353                         pksh = ksh;
02354                         pkem = kem;
02355                         gsd_set_material(check_shin, check_emis,
02356                                          ksh, kem, curcolor);
02357                     }
02358                 }
02359 
02360                 gsd_litvert_func(n, ktrans | curcolor, pt);
02361 
02362 
02363             }                   /* close ii loop */
02364             gsd_endtfan();
02365             cnt2++;
02366         }                       /* end col */
02367     }                           /* end row */
02368 
02369 
02370     gsd_popmatrix();
02371     gsd_blend(0);
02372     gsd_zwritemask(0xffffffff);
02373 
02374     return (0);
02375 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines