GRASS 8 Programmer's Manual 8.6.0dev(2026)-0f6a7341fc
Loading...
Searching...
No Matches
gpd.c
Go to the documentation of this file.
1/*!
2 \file lib/ogsf/gpd.c
3
4 \brief OGSF library - loading and manipulating point sets (lower level)
5
6 SPDX-FileCopyrightText: 1999-2008, 2011 GRASS Development Team
7 SPDX-License-Identifier: GPL-2.0-or-later
8
9 \author Bill Brown USACERL, GMSL/University of Illinois (December 1993)
10 \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
11 */
12
13#include <stdlib.h>
14#include <math.h>
15
16#include <grass/ogsf.h>
17
18#include "rowcol.h"
19
20#define CHK_FREQ 50
21
22/* BOB -- border allowed outside of viewport */
23#define v_border 50
24
25/*!
26 \brief Check if point is in region
27
28 Check for cancel every CHK_FREQ points
29
30 \param gs surface (geosurf)
31 \param pt point (array(X,Y,Z))
32 \param region region settings (array (top,bottom,left,right))
33
34 \return 0 point outside of region
35 \return 1 point inside region
36 */
37int gs_point_in_region(geosurf *gs, float *pt, float *region)
38{
39 float top, bottom, left, right;
40
41 if (!region) {
42 top = gs->yrange;
43 bottom = VROW2Y(gs, VROWS(gs));
44 left = 0.0;
45 right = VCOL2X(gs, VCOLS(gs));
46 }
47 else {
48 top = region[0];
49 bottom = region[1];
50 left = region[2];
51 right = region[3];
52 }
53
54 return (pt[X] >= left && pt[X] <= right && pt[Y] >= bottom && pt[Y] <= top);
55}
56
57/*!
58 \brief Draw point representing object
59
60 Do normal transforms before calling
61
62 Note gs: NULL if 3d obj or const elev surface
63
64 \param gs surface (geosurf)
65 \param style object displaying style (highlighted or not)
66 \param pt 3d point (Point3)
67 */
69{
70 float sz, lpt[3];
71 float siz[3];
72
73 gsd_color_func(style->color);
74 sz = GS_global_exag();
75 GS_v3eq(lpt, pt); /* CHANGING Z OF POINT PASSED, so use copy */
76
77 switch (style->symbol) {
78 case ST_HISTOGRAM:
81
82 if (sz) {
83 lpt[Z] *= sz;
84 gsd_scale(1.0, 1.0, 1. / sz);
85 }
86
87 siz[0] = style->size; /*TODO: Fix historgam drawing */
88 siz[1] = style->size;
89 siz[2] = style->size;
90
91 gsd_box(lpt, style->color, siz);
92
95
96 break;
97 case ST_DIAMOND:
98 /*
99 gsd_colormode(CM_AD);
100 */
103
104 if (sz) {
105 lpt[Z] *= sz;
106 gsd_scale(1.0, 1.0, 1. / sz);
107 }
108
109 gsd_diamond(lpt, style->color, style->size);
112
113 break;
114 case ST_BOX:
117
118 if (sz) {
119 lpt[Z] *= sz;
120 gsd_scale(1.0, 1.0, 1. / sz);
121 }
122
123 gsd_draw_box(lpt, style->color, style->size);
125
126 break;
127 case ST_SPHERE:
128 /*
129 gsd_colormode(CM_AD);
130 */
133
134 if (sz) {
135 lpt[Z] *= sz;
136 gsd_scale(1.0, 1.0, 1. / sz);
137 }
138
139 gsd_sphere(lpt, style->size);
142
143 break;
144 case ST_GYRO:
147
148 if (sz) {
149 lpt[Z] *= sz;
150 gsd_scale(1.0, 1.0, 1. / sz);
151 }
152
153 gsd_draw_gyro(lpt, style->color, style->size);
155
156 break;
157 case ST_ASTER:
160
161 if (sz) {
162 lpt[Z] *= sz;
163 gsd_scale(1.0, 1.0, 1. / sz);
164 }
165
166 gsd_draw_asterisk(lpt, style->color, style->size);
168
169 break;
170 case ST_CUBE:
173
174 if (sz) {
175 lpt[Z] *= sz;
176 gsd_scale(1.0, 1.0, 1. / sz);
177 }
178
179 gsd_cube(lpt, style->color, style->size);
182
183 break;
184 default:
185 case ST_X:
187 gsd_x(gs, lpt, style->color, style->size);
188
189 break;
190 }
191
192 return;
193}
194
195/*!
196 \brief Draw 2D point set
197
198 Need to think about translations - If user translates surface,
199 sites should automatically go with it, but translating sites should
200 translate it relative to surface on which it's displayed
201
202 Handling mask checking here
203
204 \todo prevent scaling by 0
205
206 \param gp site (geosite)
207 \param gs surface (geosurf)
208 \param do_fast (unused)
209
210 \return 0 on failure
211 \return 1 on success
212 */
214{
215 float site[4], konst;
216 int src, check;
217 geopoint *gpt;
218 typbuff *buf;
220 GLint viewport[4];
221 GLint window[4];
222
223 if (GS_check_cancel()) {
224 return 0;
225 }
226
227 if (!gs)
228 return 1;
229
231
232 src = gs_get_att_src(gs, ATT_TOPO);
233
234 if (src == CONST_ATT) {
235 konst = gs->att[ATT_TOPO].constant;
236 }
237 else {
238 buf = gs_get_att_typbuff(gs, ATT_TOPO, 0);
239 }
240
241 /* Get viewport parameters for view check */
243
245 gsd_do_scale(1);
246 gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans);
247 gsd_linewidth(gp->style->width);
248 check = 0;
249
250 for (gpt = gp->points; gpt; gpt = gpt->next) {
251 if (!(++check % CHK_FREQ)) {
252 if (GS_check_cancel()) {
253 gsd_linewidth(1);
255
256 return 0;
257 }
258 }
259
260 site[X] = gpt->p3[X] + gp->x_trans - gs->ox;
261 site[Y] = gpt->p3[Y] + gp->y_trans - gs->oy;
262
263 if (gs_point_is_masked(gs, site)) {
264 continue;
265 }
266
267 if (src == MAP_ATT) {
268 if (viewcell_tri_interp(gs, buf, site, 1)) {
269 /* returns 0 if outside or masked */
270 site[Z] += gp->z_trans;
271
273 projMatrix))
274 continue;
275 }
276 }
277 else if (src == CONST_ATT) {
279 site[Z] = konst + gp->z_trans;
281 projMatrix))
282 continue;
283 }
284 }
285
286 if (gpt->highlighted > 0)
287 gpd_obj(gs, gp->hstyle, site);
288 else if (gp->tstyle && gp->tstyle->active)
289 gpd_obj(gs, gpt->style, site);
290 else
291 gpd_obj(gs, gp->style, site);
292 }
293
294 gsd_linewidth(1);
296
297 return 1;
298}
299
300/*!
301 \brief Draw 3D point set
302
303 \param gp site (geosite)
304 \param xo,yo
305 \param do_fast (unused)
306
307 \return 0 on success
308 \return 1 on failure
309 */
310int gpd_3dsite(geosite *gp, float xo, float yo, int do_fast G_UNUSED)
311{
312 float site[4], tz;
313 int check;
314 geopoint *gpt;
316 GLint viewport[4];
317 GLint window[4];
318
319 if (GS_check_cancel()) {
320 return 0;
321 }
322
324
326
327 gsd_do_scale(1);
328
329 tz = GS_global_exag();
330 site[Z] = 0.0;
331
332 check = 0;
333
334 gsd_linewidth(gp->style->width);
335
336 for (gpt = gp->points; gpt; gpt = gpt->next) {
337 if (!(++check % CHK_FREQ)) {
338 if (GS_check_cancel()) {
339 gsd_linewidth(1);
341
342 return (0);
343 }
344 }
345
346 site[X] = gpt->p3[X] + gp->x_trans - xo;
347 site[Y] = gpt->p3[Y] + gp->y_trans - yo;
348
349 if (tz) {
350 site[Z] = gpt->p3[Z] + gp->z_trans;
351 }
352
354 continue;
355 else
356 /* clip points outside default region? */
357 {
358 if (gpt->highlighted > 0)
359 gpd_obj(NULL, gp->hstyle, site);
360 else if (gp->tstyle && gp->tstyle->active)
361 gpd_obj(NULL, gpt->style, site);
362 else
363 gpd_obj(NULL, gp->style, site);
364 }
365 }
366
367 gsd_linewidth(1);
369
370 return 1;
371}
#define NULL
Definition ccmath.h:32
void gsd_cube(float *, unsigned long, float)
Draws a cube symbol at the specified center location.
Definition gsd_objs.c:418
int gs_point_is_masked(geosurf *, float *)
Check if point is masked.
Definition gs.c:1310
void gsd_diamond(float *, unsigned long, float)
Draws a diamond symbol at the specified center location.
Definition gsd_objs.c:312
void gsd_pushmatrix(void)
Push the current matrix stack.
Definition gsd_prim.c:507
void gsd_box(float *, int, float *)
Draws a box at the specified center location.
Definition gsd_objs.c:1471
void gsd_scale(float, float, float)
Multiply the current matrix by a general scaling matrix.
Definition gsd_prim.c:521
void gsd_getwindow(int *, int *, double *, double *)
Get viewport.
Definition gsd_prim.c:550
void gsd_do_scale(int)
Set current scale.
Definition gsd_views.c:351
void gsd_x(geosurf *, float *, int, float)
Draws a X symbol at the specified center location.
Definition gsd_objs.c:259
void gsd_draw_box(float *, unsigned long, float)
Draws a box symbol at the specified center location.
Definition gsd_objs.c:498
void gsd_sphere(float *, float)
ADD.
Definition gsd_prim.c:203
int gs_get_att_src(geosurf *, int)
Get attribute source.
Definition gs.c:652
int gsd_checkpoint(float[4], int[4], int[4], double[16], double[16])
ADD.
Definition gsd_prim.c:581
void GS_v3eq(float *, float *)
Copy vector values.
Definition gs_util.c:174
void gsd_draw_gyro(float *, unsigned long, float)
Draws a gyro symbol at the specified center location.
Definition gsd_objs.c:663
int gs_update_curmask(geosurf *)
Update current maps.
Definition gs_bm.c:224
void gsd_color_func(unsigned int)
Set current color.
Definition gsd_prim.c:694
void gsd_translate(float, float, float)
Multiply the current matrix by a translation matrix.
Definition gsd_prim.c:535
void gsd_popmatrix(void)
Pop the current matrix stack.
Definition gsd_prim.c:497
void gsd_linewidth(short)
Set width of rasterized lines.
Definition gsd_prim.c:263
int viewcell_tri_interp(geosurf *, typbuff *, Point3, int)
ADD.
Definition gsdrape.c:505
void gsd_colormode(int)
Set color mode.
Definition gsd_prim.c:94
typbuff * gs_get_att_typbuff(geosurf *, int, int)
Get attribute data buffer.
Definition gs.c:677
void gsd_draw_asterisk(float *, unsigned long, float)
Draws an asterisk symbol at the specified center location.
Definition gsd_objs.c:604
int GS_check_cancel(void)
Check for cancel.
Definition gsx.c:26
float GS_global_exag(void)
Get global z-exag value.
Definition gs2.c:1996
#define G_UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition gis.h:43
#define CHK_FREQ
Definition gpd.c:20
void gpd_obj(geosurf *gs, gvstyle *style, Point3 pt)
Draw point representing object.
Definition gpd.c:68
int gpd_3dsite(geosite *gp, float xo, float yo, int do_fast)
Draw 3D point set.
Definition gpd.c:310
int gs_point_in_region(geosurf *gs, float *pt, float *region)
Check if point is in region.
Definition gpd.c:37
int gpd_2dsite(geosite *gp, geosurf *gs, int do_fast)
Draw 2D point set.
Definition gpd.c:213
OGSF header file (structures)
#define CM_DIFFUSE
Definition ogsf.h:152
#define X
Definition ogsf.h:141
#define ST_CUBE
Definition ogsf.h:96
#define ATT_TOPO
Definition ogsf.h:76
#define ST_GYRO
Definition ogsf.h:101
float Point3[3]
Definition ogsf.h:206
#define ST_BOX
Definition ogsf.h:94
#define Z
Definition ogsf.h:143
#define ST_SPHERE
Definition ogsf.h:95
#define Y
Definition ogsf.h:142
#define MAP_ATT
Definition ogsf.h:86
#define CM_COLOR
Definition ogsf.h:149
#define ST_HISTOGRAM
Definition ogsf.h:102
#define ST_DIAMOND
Definition ogsf.h:97
#define CONST_ATT
Definition ogsf.h:87
#define ST_ASTER
Definition ogsf.h:100
#define ST_X
Definition ogsf.h:93
#define VCOL2X(gs, vcol)
Definition rowcol.h:40
#define VCOLS(gs)
Definition rowcol.h:14
#define VROWS(gs)
Definition rowcol.h:13
#define VROW2Y(gs, vrow)
Definition rowcol.h:39
Point instance.
Definition ogsf.h:401
Vector map (points)
Definition ogsf.h:416
Definition ogsf.h:267
Struct for vector feature displaying attributes.
Definition ogsf.h:308
int color
Line color.
Definition ogsf.h:310
int symbol
Point symbol/line type.
Definition ogsf.h:313
float size
Symbol size.
Definition ogsf.h:319