GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gsd_fringe.c
Go to the documentation of this file.
1 
21 #include <grass/gstypes.h>
22 
23 #include "gsget.h"
24 #include "rowcol.h"
25 
26 #define FRINGE_FORE 0x000000
27 #define FRINGE_WIDTH 2
28 
32 float Nnorth[] = { 0.0, 0.8, 0.6 };
33 float Nsouth[] = { 0.0, -0.8, 0.6 };
34 float Neast[] = { 0.8, 0.0, 0.6 };
35 float Nwest[] = { -0.8, 0.0, 0.6 };
36 float Ntop[] = { 0.0, 0.0, 1.0 };
37 float Nbottom[] = { 0.0, 0.0, -1.0 };
38 
51 void gsd_display_fringe(geosurf * surf, unsigned long clr, float elev,
52  int where[4])
53 {
54  float bot, xres, yres; /* world size of view cell */
55  int ycnt, xcnt; /* number of view cells across */
56  float xmax, ymax;
57 
58  xres = surf->x_mod * surf->xres;
59  yres = surf->y_mod * surf->yres;
60 
61  xcnt = VCOLS(surf);
62  ycnt = VROWS(surf);
63 
64  xmax = surf->xmax;
65  ymax = surf->ymax;
66 
67  /*
68  bot = surf->zmin - ((surf->zrange/4.) * surf->z_exag);
69  */
70  bot = elev - ((surf->zrange / 4.) * surf->z_exag);
71 
72 
74  gsd_colormode(CM_COLOR);
75 
76  /* North fringe */
77  if (where[0] || where[1]) {
78  glNormal3fv(Nnorth);
79  gsd_color_func(clr);
80  gsd_zwritemask(0x0);
81  gsd_fringe_horiz_poly(bot, surf, 0, 0);
82  gsd_color_func(FRINGE_FORE); /* WHITE */
83  gsd_fringe_horiz_line(bot, surf, 0, 0);
84  gsd_zwritemask(0xffffffff);
85  /* wmpack (0); ??? glColorMask */
86  gsd_color_func(clr);
87  gsd_fringe_horiz_poly(bot, surf, 0, 0);
88  }
89 
90  /* South fringe */
91  if (where[2] || where[3]) {
92  glNormal3fv(Nsouth);
93  gsd_color_func(clr);
94  gsd_zwritemask(0x0);
95  gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
96  gsd_color_func(FRINGE_FORE); /* WHITE */
97  gsd_fringe_horiz_line(bot, surf, ycnt - 2, 1);
98  gsd_zwritemask(0xffffffff);
99  /* wmpack (0); ??? glColorMask */
100  gsd_color_func(clr);
101  gsd_fringe_horiz_poly(bot, surf, ycnt - 2, 1);
102  }
103 
104  /* West fringe */
105  if (where[0] || where[2]) {
106  glNormal3fv(Nwest);
107  gsd_color_func(clr);
108  gsd_zwritemask(0x0);
109  gsd_fringe_vert_poly(bot, surf, 0, 0);
111  gsd_fringe_vert_line(bot, surf, 0, 0);
112  gsd_zwritemask(0xffffffff);
113  gsd_color_func(clr);
114  gsd_fringe_vert_poly(bot, surf, 0, 0);
115  }
116 
117  /* East fringe */
118  if (where[1] || where[3]) {
119  glNormal3fv(Neast);
120  gsd_color_func(clr);
121  gsd_zwritemask(0x0);
122  gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
124  gsd_fringe_vert_line(bot, surf, xcnt - 2, 1);
125  gsd_zwritemask(0xffffffff);
126  gsd_color_func(clr);
127  gsd_fringe_vert_poly(bot, surf, xcnt - 2, 1);
128  }
129 
130  return;
131 }
132 
141 void gsd_fringe_horiz_poly(float bot, geosurf * surf, int row, int side)
142 {
143  int col;
144  int cnt;
145  float pt[4];
146  typbuff *buff;
147  long offset;
148  int xcnt;
149 
150  GS_set_draw(GSD_FRONT);
151  gsd_pushmatrix();
152  gsd_do_scale(1);
153  gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
154 
155  buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
156  xcnt = VCOLS(surf);
157 
158  gsd_bgnpolygon();
159 
160  col = 0;
161  /* floor left */
162  pt[X] = col * (surf->x_mod * surf->xres);
163  pt[Y] =
164  ((surf->rows - 1) * surf->yres) -
165  ((row + side) * (surf->y_mod * surf->yres));
166  pt[Z] = bot;
167  gsd_vert_func(pt);
168 
169  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
170  GET_MAPATT(buff, offset, pt[Z]);
171  pt[Z] = pt[Z] * surf->z_exag;
172  gsd_vert_func(pt);
173 
174  cnt = 1;
175  for (col = 0; col < xcnt - 1; col++) {
176  /* bottom right */
177  pt[X] = col * (surf->x_mod * surf->xres);
178  pt[Y] =
179  ((surf->rows - 1) * surf->yres) -
180  ((row + side) * (surf->y_mod * surf->yres));
181  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
182  GET_MAPATT(buff, offset, pt[Z]);
183  pt[Z] = pt[Z] * surf->z_exag;
184  gsd_vert_func(pt);
185  cnt++;
186  }
187 
188  col--;
189  pt[X] = col * (surf->x_mod * surf->xres);
190  pt[Y] =
191  ((surf->rows - 1) * surf->yres) -
192  ((row + side) * (surf->y_mod * surf->yres));
193  pt[Z] = bot;
194  gsd_vert_func(pt);
195 
196  gsd_endpolygon();
197 
198  GS_done_draw();
199  gsd_popmatrix();
200  gsd_flush();
201 
202  return;
203 }
204 
213 void gsd_fringe_horiz_line(float bot, geosurf * surf, int row, int side)
214 {
215  int col;
216  int cnt;
217  float pt[4];
218  typbuff *buff;
219  long offset;
220  int xcnt;
221 
222  GS_set_draw(GSD_FRONT);
223  gsd_pushmatrix();
224  gsd_do_scale(1);
225  gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
226 
227 
228  buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
229  xcnt = VCOLS(surf);
230 
231  gsd_bgnline();
232 
233  col = 0;
234  /* floor left */
235  pt[X] = col * (surf->x_mod * surf->xres);
236  pt[Y] =
237  ((surf->rows - 1) * surf->yres) -
238  ((row + side) * (surf->y_mod * surf->yres));
239  pt[Z] = bot;
240  gsd_vert_func(pt);
241 
242  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
243  GET_MAPATT(buff, offset, pt[Z]);
244  pt[Z] = pt[Z] * surf->z_exag;
245  gsd_vert_func(pt);
246 
247  cnt = 1;
248  for (col = 0; col < xcnt - 1; col++) {
249  /* bottom right */
250  pt[X] = col * (surf->x_mod * surf->xres);
251  pt[Y] =
252  ((surf->rows - 1) * surf->yres) -
253  ((row + side) * (surf->y_mod * surf->yres));
254  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
255  GET_MAPATT(buff, offset, pt[Z]);
256  pt[Z] = pt[Z] * surf->z_exag;
257  gsd_vert_func(pt);
258  cnt++;
259  }
260 
261  col--;
262  pt[X] = col * (surf->x_mod * surf->xres);
263  pt[Y] =
264  ((surf->rows - 1) * surf->yres) -
265  ((row + side) * (surf->y_mod * surf->yres));
266  pt[Z] = bot;
267  gsd_vert_func(pt);
268 
269  col = 0;
270  pt[X] = col * (surf->x_mod * surf->xres);
271  pt[Y] =
272  ((surf->rows - 1) * surf->yres) -
273  ((row + side) * (surf->y_mod * surf->yres));
274  pt[Z] = bot;
275  gsd_vert_func(pt);
276 
277  gsd_endline();
278 
279  GS_done_draw();
280  gsd_popmatrix();
281  gsd_flush();
282 
283  return;
284 }
285 
294 void gsd_fringe_vert_poly(float bot, geosurf * surf, int col, int side)
295 {
296 
297  int row;
298  int cnt;
299  float pt[4];
300  typbuff *buff;
301  long offset;
302  int ycnt;
303 
304  GS_set_draw(GSD_FRONT);
305  gsd_pushmatrix();
306  gsd_do_scale(1);
307  gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
308 
309  gsd_bgnpolygon();
310 
311  buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
312  ycnt = VROWS(surf);
313 
314  row = 0;
315  /* floor left */
316  pt[X] = col * (surf->x_mod * surf->xres);
317  pt[Y] =
318  ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
319  pt[Z] = bot;
320  gsd_vert_func(pt);
321 
322  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
323  GET_MAPATT(buff, offset, pt[Z]);
324  pt[Z] = pt[Z] * surf->z_exag;
325  gsd_vert_func(pt);
326 
327  cnt = 1;
328  for (row = 0; row < ycnt - 1; row++) {
329  /* bottom right */
330  pt[X] = col * (surf->x_mod * surf->xres);
331  pt[Y] =
332  ((surf->rows - 1) * surf->yres) -
333  (row * (surf->y_mod * surf->yres));
334  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
335  GET_MAPATT(buff, offset, pt[Z]);
336  pt[Z] = pt[Z] * surf->z_exag;
337  gsd_vert_func(pt);
338  cnt++;
339  }
340 
341  row--;
342  pt[X] = col * (surf->x_mod * surf->xres);
343  pt[Y] =
344  ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
345  pt[Z] = bot;
346  gsd_vert_func(pt);
347 
348  gsd_endpolygon();
349 
350  GS_done_draw();
351  gsd_popmatrix();
352  gsd_flush();
353 
354  return;
355 }
356 
365 void gsd_fringe_vert_line(float bot, geosurf * surf, int col, int side)
366 {
367  int row;
368  int cnt;
369  float pt[4];
370  typbuff *buff;
371  long offset;
372  int ycnt;
373 
374  GS_set_draw(GSD_FRONT);
375  gsd_pushmatrix();
376  gsd_do_scale(1);
377  gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
378 
379 
380  buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
381  ycnt = VROWS(surf);
382  gsd_bgnline();
383 
384  row = 0;
385  /* floor left */
386  pt[X] = col * (surf->x_mod * surf->xres);
387  pt[Y] =
388  ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
389  pt[Z] = bot;
390  gsd_vert_func(pt);
391 
392  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
393  GET_MAPATT(buff, offset, pt[Z]);
394  pt[Z] = pt[Z] * surf->z_exag;
395  gsd_vert_func(pt);
396 
397  cnt = 1;
398  for (row = 0; row < ycnt - 1; row++) {
399  /* bottom right */
400  pt[X] = col * (surf->x_mod * surf->xres);
401  pt[Y] =
402  ((surf->rows - 1) * surf->yres) -
403  (row * (surf->y_mod * surf->yres));
404  offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
405  GET_MAPATT(buff, offset, pt[Z]);
406  pt[Z] = pt[Z] * surf->z_exag;
407  gsd_vert_func(pt);
408  cnt++;
409  }
410 
411  row--;
412  pt[X] = col * (surf->x_mod * surf->xres);
413  pt[Y] =
414  ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
415  pt[Z] = bot;
416  gsd_vert_func(pt);
417 
418  row = 0;
419  pt[X] = col * (surf->x_mod * surf->xres);
420  pt[Y] =
421  ((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
422  pt[Z] = bot;
423  gsd_vert_func(pt);
424 
425  gsd_endline();
426 
427  GS_done_draw();
428  gsd_popmatrix();
429  gsd_flush();
430 
431  return;
432 }
433 
442 void gsd_fringe_horiz_line2(float bot, geosurf * surf, int row, int side)
443 {
444  int col;
445  int cnt;
446  float pt[4];
447  typbuff *buff;
448  long offset;
449  int xcnt;
450 
451  GS_set_draw(GSD_FRONT);
452  gsd_pushmatrix();
453  gsd_do_scale(1);
454  gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
455 
456  buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
457  xcnt = VCOLS(surf);
458  gsd_bgnline();
459 
460  col = 0;
461  /* floor left */
462  pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
463  pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
464  pt[Z] = bot;
465  gsd_vert_func(pt);
466 
467  offset = 0;
468  GET_MAPATT(buff, offset, pt[Z]);
469  pt[Z] = pt[Z] * surf->z_exag;
470  gsd_vert_func(pt);
471 
472  cnt = 1;
473  for (col = 0; col < xcnt - 1; col++) {
474  /* bottom right */
475  pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
476  pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
477  offset = col * surf->x_mod;
478  GET_MAPATT(buff, offset, pt[Z]);
479  pt[Z] = pt[Z] * surf->z_exag;
480  gsd_vert_func(pt);
481  cnt++;
482  }
483 
484  col--;
485  pt[X] = surf->xmin + (col * (surf->x_mod * surf->xres));
486  pt[Y] = surf->ymax - ((row + side) * (surf->y_mod * surf->yres));
487  pt[Z] = bot;
488  gsd_vert_func(pt);
489 
490  gsd_endline();
491 
492  GS_done_draw();
493  gsd_popmatrix();
494  gsd_flush();
495 
496  return;
497 }
void gsd_zwritemask(unsigned long n)
Write out z-mask.
Definition: gsd_prim.c:231
double xmax
Definition: dataquad.c:293
void gsd_do_scale(int doexag)
Set current scale.
Definition: gsd_views.c:355
#define VROWS(gs)
Definition: rowcol.h:11
#define VCOLS(gs)
Definition: rowcol.h:12
float Nwest[]
Definition: gsd_fringe.c:35
void GS_done_draw(void)
Draw done, swap buffers.
Definition: GS2.c:2499
void gsd_bgnpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
Definition: gsd_prim.c:362
#define Y(x)
Definition: display/draw.c:246
float Neast[]
Definition: gsd_fringe.c:34
#define FRINGE_FORE
Definition: gsd_fringe.c:26
void gsd_colormode(int cm)
Set color mode.
Definition: gsd_prim.c:88
#define X(y)
Definition: display/draw.c:248
void gsd_color_func(unsigned int col)
Set current color.
Definition: gsd_prim.c:689
#define FRINGE_WIDTH
Definition: gsd_fringe.c:27
float Nnorth[]
Normals.
Definition: gsd_fringe.c:32
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
Definition: gsd_prim.c:526
char buff[1024]
Definition: g3dcats.c:89
void gsd_pushmatrix(void)
Push the current matrix stack.
Definition: gsd_prim.c:498
void gsd_fringe_vert_poly(float bot, geosurf *surf, int col, int side)
ADD.
Definition: gsd_fringe.c:294
typbuff * gs_get_att_typbuff(geosurf *gs, int desc, int to_write)
Get attribute data buffer.
Definition: gs.c:681
void gsd_endline(void)
End line.
Definition: gsd_prim.c:397
void gsd_fringe_horiz_poly(float bot, geosurf *surf, int row, int side)
ADD.
Definition: gsd_fringe.c:141
void gsd_fringe_horiz_line(float bot, geosurf *surf, int row, int side)
ADD.
Definition: gsd_fringe.c:213
double ymax
Definition: dataquad.c:293
void gsd_vert_func(float *pt)
ADD.
Definition: gsd_prim.c:677
void gsd_endpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
Definition: gsd_prim.c:377
float Nsouth[]
Definition: gsd_fringe.c:33
void gsd_linewidth(short n)
Set width of rasterized lines.
Definition: gsd_prim.c:257
float Nbottom[]
Definition: gsd_fringe.c:37
void gsd_flush(void)
Mostly for flushing drawing commands accross a network.
Definition: gsd_prim.c:74
void gsd_popmatrix(void)
Pop the current matrix stack.
Definition: gsd_prim.c:488
void gsd_display_fringe(geosurf *surf, unsigned long clr, float elev, int where[4])
Display fridge.
Definition: gsd_fringe.c:51
void gsd_fringe_vert_line(float bot, geosurf *surf, int col, int side)
ADD.
Definition: gsd_fringe.c:365
void gsd_bgnline(void)
Begin line.
Definition: gsd_prim.c:387
void GS_set_draw(int where)
Sets which buffer to draw to.
Definition: GS2.c:2457
void gsd_fringe_horiz_line2(float bot, geosurf *surf, int row, int side)
ADD.
Definition: gsd_fringe.c:442
float Ntop[]
Definition: gsd_fringe.c:36
#define GET_MAPATT(buff, offset, att)
Definition: gsget.h:27