File: gsd_fringe.c

package info (click to toggle)
grass 8.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 277,040 kB
  • sloc: ansic: 460,798; python: 227,732; cpp: 42,026; sh: 11,262; makefile: 7,007; xml: 3,637; sql: 968; lex: 520; javascript: 484; yacc: 450; asm: 387; perl: 157; sed: 25; objc: 6; ruby: 4
file content (553 lines) | stat: -rw-r--r-- 15,022 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
/*!
   \file lib/ogsf/gsd_fonts.c

   \brief OGSF library - manipulating surfaces/fridge (lower level function)

   GRASS OpenGL gsurf OGSF Library

   \todo This file needs to be re-written in OpenGL

   (C) 1999-2008 by the GRASS Development Team

   This program is free software under the
   GNU General Public License (>=v2).
   Read the file COPYING that comes with GRASS
   for details.

   \author Bill Brown USACERL, GMSL/University of Illinois
   \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
 */

#include <grass/ogsf.h>

#include "gsget.h"
#include "rowcol.h"

#define FRINGE_FORE  0x000000
#define FRINGE_WIDTH 2

/*!
   \brief Normals
 */
float Nnorth[] = {0.0, 0.8, 0.6};
float Nsouth[] = {0.0, -0.8, 0.6};
float Neast[] = {0.8, 0.0, 0.6};
float Nwest[] = {-0.8, 0.0, 0.6};
float Ntop[] = {0.0, 0.0, 1.0};
float Nbottom[] = {0.0, 0.0, -1.0};

/*!
   \brief Display fridge

   \todo add elevation for bottom
   add color option
   add ruler grid lines

   \param surf surface (geosurf)
   \param clr
   \param elev
   \param where
 */
void gsd_display_fringe(geosurf *surf, unsigned long clr, float elev,
                        int where[4])
{
    float bot /*, xres, yres */; /* world size of view cell */
    int ycnt, xcnt;              /* number of view cells across */

    /* float xmax, ymax; */

    /* xres = surf->x_mod * surf->xres; */
    /* yres = surf->y_mod * surf->yres; */

    xcnt = VCOLS(surf);
    ycnt = VROWS(surf);

    /* xmax = surf->xmax; */
    /* ymax = surf->ymax; */

    /*
       bot = surf->zmin - ((surf->zrange/4.) * surf->z_exag);
     */
    bot = elev - ((surf->zrange / 4.) * surf->z_exag);

    gsd_linewidth(FRINGE_WIDTH);
    gsd_colormode(CM_COLOR);

    /* North fringe */
    if (where[0] || where[1]) {
        glNormal3fv(Nnorth);
        gsd_color_func(clr);
        gsd_zwritemask(0x0);
        gsd_fringe_horiz_poly(bot, surf, 0, 0);
        gsd_color_func(FRINGE_FORE); /* WHITE */
        gsd_fringe_horiz_line(bot, surf, 0, 0);
        gsd_zwritemask(0xffffffff);
        /*   wmpack (0); ??? glColorMask */
        gsd_color_func(clr);
        gsd_fringe_horiz_poly(bot, surf, 0, 0);
    }

    /* South fringe */
    if (where[2] || where[3]) {
        glNormal3fv(Nsouth);
        gsd_color_func(clr);
        gsd_zwritemask(0x0);
        gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
        gsd_color_func(FRINGE_FORE); /* WHITE */
        gsd_fringe_horiz_line(bot, surf, ycnt - 2, 1);
        gsd_zwritemask(0xffffffff);
        /*   wmpack (0); ??? glColorMask */
        gsd_color_func(clr);
        gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
    }

    /* West fringe */
    if (where[0] || where[2]) {
        glNormal3fv(Nwest);
        gsd_color_func(clr);
        gsd_zwritemask(0x0);
        gsd_fringe_vert_poly(bot, surf, 0, 0);
        gsd_color_func(FRINGE_FORE);
        gsd_fringe_vert_line(bot, surf, 0, 0);
        gsd_zwritemask(0xffffffff);
        gsd_color_func(clr);
        gsd_fringe_vert_poly(bot, surf, 0, 0);
    }

    /* East fringe */
    if (where[1] || where[3]) {
        glNormal3fv(Neast);
        gsd_color_func(clr);
        gsd_zwritemask(0x0);
        gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
        gsd_color_func(FRINGE_FORE);
        gsd_fringe_vert_line(bot, surf, xcnt - 2, 1);
        gsd_zwritemask(0xffffffff);
        gsd_color_func(clr);
        gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
    }

    return;
}

/*!
   \brief Draw fringe polygon in x direction

   \param bot coordinate of fringe bottom
   \param surf surface (geosurf)
   \param row row along which is fringe drawn
   \param side
 */
void gsd_fringe_horiz_poly(float bot, geosurf *surf, int row, int side)
{
    int col;
    float pt[4];
    typbuff *buff;
    long offset;
    int xcnt;
    int row_shift, max_row_shift;

    max_row_shift = 20;

    GS_set_draw(GSD_FRONT);
    gsd_pushmatrix();
    gsd_do_scale(1);
    gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);

    buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
    xcnt = VCOLS(surf);

    gsd_bgnqstrip();

    col = 0;
    /* floor left */
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] = ((surf->rows - 1) * surf->yres) -
            ((row + side) * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);

    /* find nearest row with defined z coordinate  */
    row_shift = 0;
    while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
        row_shift++;
        if (side)
            offset = ((row - row_shift) * surf->y_mod * surf->cols) +
                     (col * surf->x_mod);
        else
            offset = ((row + row_shift) * surf->y_mod * surf->cols) +
                     (col * surf->x_mod);
    }
    pt[Z] = pt[Z] * surf->z_exag;
    gsd_vert_func(pt);

    for (col = 0; col < xcnt - 1; col++) {
        /* bottom vertex */
        pt[X] = col * (surf->x_mod * surf->xres);
        pt[Y] = ((surf->rows - 1) * surf->yres) -
                ((row + side) * (surf->y_mod * surf->yres));
        pt[Z] = bot;
        gsd_vert_func(pt);

        /* map vertex */
        offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
        row_shift = 0;
        while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
            row_shift++;
            if (side)
                offset = ((row - row_shift) * surf->y_mod * surf->cols) +
                         (col * surf->x_mod);
            else
                offset = ((row + row_shift) * surf->y_mod * surf->cols) +
                         (col * surf->x_mod);
        }
        pt[Z] = pt[Z] * surf->z_exag;
        gsd_vert_func(pt);
    }

    gsd_endqstrip();

    GS_done_draw();
    gsd_popmatrix();
    gsd_flush();

    return;
}

/*!
   \brief Draw fringe outline in x direction

   \param bot coordinate of fringe bottom
   \param surf surface (geosurf)
   \param row row along which is fringe drawn
   \param side
 */
void gsd_fringe_horiz_line(float bot, geosurf *surf, int row, int side)
{
    int col;
    float pt[4];
    typbuff *buff;
    long offset;
    int xcnt;
    int row_shift, max_row_shift;

    max_row_shift = 20;

    GS_set_draw(GSD_FRONT);
    gsd_pushmatrix();
    gsd_do_scale(1);
    gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);

    buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
    xcnt = VCOLS(surf);

    gsd_bgnline();

    col = 0;
    /* floor left */
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] = ((surf->rows - 1) * surf->yres) -
            ((row + side) * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    /* find nearest row with defined z coordinate  */
    offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
    row_shift = 0;
    while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
        row_shift++;
        if (side)
            offset = ((row - row_shift) * surf->y_mod * surf->cols) +
                     (col * surf->x_mod);
        else
            offset = ((row + row_shift) * surf->y_mod * surf->cols) +
                     (col * surf->x_mod);
    }
    pt[Z] = pt[Z] * surf->z_exag;
    gsd_vert_func(pt);

    for (col = 0; col < xcnt - 1; col++) {
        /* bottom right */
        pt[X] = col * (surf->x_mod * surf->xres);
        pt[Y] = ((surf->rows - 1) * surf->yres) -
                ((row + side) * (surf->y_mod * surf->yres));
        offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
        row_shift = 0;
        while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
            row_shift++;
            if (side)
                offset = ((row - row_shift) * surf->y_mod * surf->cols) +
                         (col * surf->x_mod);
            else
                offset = ((row + row_shift) * surf->y_mod * surf->cols) +
                         (col * surf->x_mod);
        }
        pt[Z] = pt[Z] * surf->z_exag;
        gsd_vert_func(pt);
    }

    col--;
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] = ((surf->rows - 1) * surf->yres) -
            ((row + side) * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    col = 0;
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] = ((surf->rows - 1) * surf->yres) -
            ((row + side) * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    gsd_endline();

    GS_done_draw();
    gsd_popmatrix();
    gsd_flush();

    return;
}

/*!
   \brief Draw fringe outline in y direction

   \param bot coordinate of fringe bottom
   \param surf surface (geosurf)
   \param col column along which is fringe drawn
   \param side
 */
void gsd_fringe_vert_poly(float bot, geosurf *surf, int col, int side)
{

    int row;
    float pt[4];
    typbuff *buff;
    long offset;
    int ycnt;
    int col_shift, max_col_shift;

    max_col_shift = 20;

    GS_set_draw(GSD_FRONT);
    gsd_pushmatrix();
    gsd_do_scale(1);
    gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);

    gsd_bgnqstrip();

    buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
    ycnt = VROWS(surf);

    row = 0;
    /* floor left */
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] =
        ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    /* find nearest row with defined z coordinate  */
    offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
    col_shift = 0;
    while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
        col_shift++;
        if (side)
            offset = (row * surf->y_mod * surf->cols) +
                     ((col - col_shift) * surf->x_mod);
        else
            offset = (row * surf->y_mod * surf->cols) +
                     ((col + col_shift) * surf->x_mod);
    }
    pt[Z] = pt[Z] * surf->z_exag;
    gsd_vert_func(pt);

    for (row = 0; row < ycnt - 1; row++) {
        /* floor */
        pt[X] = col * (surf->x_mod * surf->xres);
        pt[Y] = ((surf->rows - 1) * surf->yres) -
                (row * (surf->y_mod * surf->yres));
        pt[Z] = bot;
        gsd_vert_func(pt);
        /* map elevation */
        offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
        col_shift = 0;
        while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
            col_shift++;
            if (side)
                offset = (row * surf->y_mod * surf->cols) +
                         ((col - col_shift) * surf->x_mod);
            else
                offset = (row * surf->y_mod * surf->cols) +
                         ((col + col_shift) * surf->x_mod);
        }
        pt[Z] = pt[Z] * surf->z_exag;
        gsd_vert_func(pt);
    }

    gsd_endqstrip();

    GS_done_draw();
    gsd_popmatrix();
    gsd_flush();

    return;
}

/*!
   \brief Draw fringe outline in y direction

   \param bot coordinate of fringe bottom
   \param surf surface (geosurf)
   \param col column along which is fringe drawn
   \param side
 */
void gsd_fringe_vert_line(float bot, geosurf *surf, int col, int side)
{
    int row;
    float pt[4];
    typbuff *buff;
    long offset;
    int ycnt;
    int col_shift, max_col_shift;

    max_col_shift = 20;

    GS_set_draw(GSD_FRONT);
    gsd_pushmatrix();
    gsd_do_scale(1);
    gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);

    buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
    ycnt = VROWS(surf);
    gsd_bgnline();

    row = 0;
    /* floor left */
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] =
        ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    /* find nearest row with defined z coordinate  */
    offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
    col_shift = 0;
    while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
        col_shift++;
        if (side)
            offset = (row * surf->y_mod * surf->cols) +
                     ((col - col_shift) * surf->x_mod);
        else
            offset = (row * surf->y_mod * surf->cols) +
                     ((col + col_shift) * surf->x_mod);
    }
    pt[Z] = pt[Z] * surf->z_exag;
    gsd_vert_func(pt);

    for (row = 0; row < ycnt - 1; row++) {
        /* bottom right */
        pt[X] = col * (surf->x_mod * surf->xres);
        pt[Y] = ((surf->rows - 1) * surf->yres) -
                (row * (surf->y_mod * surf->yres));
        offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
        col_shift = 0;
        while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
            col_shift++;
            if (side)
                offset = (row * surf->y_mod * surf->cols) +
                         ((col - col_shift) * surf->x_mod);
            else
                offset = (row * surf->y_mod * surf->cols) +
                         ((col + col_shift) * surf->x_mod);
        }
        pt[Z] = pt[Z] * surf->z_exag;
        gsd_vert_func(pt);
    }

    row--;
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] =
        ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    row = 0;
    pt[X] = col * (surf->x_mod * surf->xres);
    pt[Y] =
        ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    gsd_endline();

    GS_done_draw();
    gsd_popmatrix();
    gsd_flush();

    return;
}

/*!
   \brief ADD

   \param bot
   \param surf surface (geosurf)
   \param row
   \param side
 */
void gsd_fringe_horiz_line2(float bot, geosurf *surf, int row, int side)
{
    int col;
    float pt[4];
    typbuff *buff;
    long offset;
    int xcnt;

    GS_set_draw(GSD_FRONT);
    gsd_pushmatrix();
    gsd_do_scale(1);
    gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);

    buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
    xcnt = VCOLS(surf);
    gsd_bgnline();

    col = 0;
    /* floor left */
    pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
    pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    offset = 0;
    GET_MAPATT(buff, offset, pt[Z]);
    pt[Z] = pt[Z] * surf->z_exag;
    gsd_vert_func(pt);

    for (col = 0; col < xcnt - 1; col++) {
        /* bottom right */
        pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
        pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
        offset = col * surf->x_mod;
        GET_MAPATT(buff, offset, pt[Z]);
        pt[Z] = pt[Z] * surf->z_exag;
        gsd_vert_func(pt);
    }

    col--;
    pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
    pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
    pt[Z] = bot;
    gsd_vert_func(pt);

    gsd_endline();

    GS_done_draw();
    gsd_popmatrix();
    gsd_flush();

    return;
}