GRASS 8 Programmer's Manual 8.6.0dev(2026)-985dd2421b
Loading...
Searching...
No Matches
cplanes_obj.c
Go to the documentation of this file.
1/*!
2 \file lib/nviz/cplanes_obj.c
3
4 \brief Nviz library -- Clip planes manipulation
5
6 Based on visualization/nviz/src/cutplanes_obj.c
7
8 SPDX-FileCopyrightText: 2008, 2010 GRASS Development Team
9 SPDX-License-Identifier: GPL-2.0-or-later
10
11 \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC
12 2008/2010)
13 */
14
15#include <grass/nviz.h>
16
17static void cp_draw(nv_data *, int, int, int);
18static geoview Gv;
19
20/*!
21 \brief Creates a clip plane object
22
23 The number of clip planes is fixed (MAX_CPLANES) and
24 we'll create them all ahead of time anyway we just let
25 the user decide on the id for each.
26
27 \param data nviz data
28 \param id cplane id
29 */
30int Nviz_new_cplane(nv_data *data, int id)
31{
32 data->num_cplanes++;
33 /* Initialize internal attributes for this cutplane */
34 data->cp_rot[id][X] = data->cp_rot[id][Y] = data->cp_rot[id][Z] = 0.0;
35 data->cp_trans[id][X] = data->cp_trans[id][Y] = data->cp_trans[id][Z] = 0.0;
36 data->cp_on[id] = 0;
37
38 return 1;
39}
40
41/*!
42 \brief Turn on (make current) the given clip plane.
43
44 \param data nviz data
45 \param id cplane id
46 */
47int Nviz_on_cplane(nv_data *data, int id)
48{
49 data->cur_cplane = id;
50 data->cp_on[id] = 1;
51 GS_set_cplane(id);
52
53 return 1;
54}
55
56/*!
57 \brief Turn off (make inactive) the given clip plane
58
59 \param data nviz data
60 \param id cplane id
61 */
62int Nviz_off_cplane(nv_data *data, int id)
63{
64 data->cp_on[id] = 0;
66
67 return 1;
68}
69
70/*!
71 \brief Draw the clip plane
72
73 \param data nviz data
74 \param bound1
75 \param bound2
76 */
78{
79 cp_draw(data, data->cur_cplane, bound1, bound2);
80
81 return 1;
82}
83
84/*!
85 \brief Draw current clip plane
86
87 \param data nviz data
88 \param current id of current clip plane [unused]
89 \param surf1 first surface id
90 \param surf2 second surface id
91 */
92void cp_draw(nv_data *data, int current G_UNUSED, int surf1, int surf2)
93{
94 int i, nsurfs;
95 int surf_min = 0, surf_max = 0, temp;
96 int *surf_list;
97
99 GS_clear(data->bgcolor);
101
102 /* If surf boundaries present then find them */
104 if ((surf1 != -1) && (surf2 != -1)) {
105 for (i = 0; i < nsurfs; i++) {
106 if (surf_list[i] == surf1)
107 surf_min = i;
108 if (surf_list[i] == surf2)
109 surf_max = i;
110 }
111
112 if (surf_max < surf_min) {
113 temp = surf_min;
115 surf_max = temp;
116 }
117
118 surf_max++;
119 }
120 else {
121 surf_min = 0;
123 }
124
125 if (nsurfs > 1) {
126 for (i = 0; i < MAX_CPLANES; i++) {
127 if (data->cp_on[i])
129 }
130 }
131
132 for (i = surf_min; i < surf_max; i++) {
134 }
135
136 GS_done_draw();
137
138 return;
139}
140
141/*!
142 \brief Return the number of clip planes objects currently allocated.
143
144 \param data nviz data
145 */
147{
148 return data->num_cplanes;
149}
150
151/*!
152 \brief Get the current active cutplane.
153
154 \param data nviz data
155 */
157{
158 return data->cur_cplane;
159}
160
161/*!
162 \brief Set the rotation for the current clip plane.
163
164 \param data nviz data
165 \param id id of current clip plane
166 \param dx,dy,dz rotation parameters
167
168 \return 1
169
170 */
171int Nviz_set_cplane_rotation(nv_data *data, int id, float dx, float dy,
172 float dz)
173{
174 data->cp_rot[id][X] = dx;
175 data->cp_rot[id][Y] = dy;
176 data->cp_rot[id][Z] = dz;
177 GS_set_cplane_rot(id, data->cp_rot[id][X], data->cp_rot[id][Y],
178 data->cp_rot[id][Z]);
179
180 cp_draw(data, data->cur_cplane, -1, -1);
181
182 return 1;
183}
184
185/*!
186 \brief Get the rotation values for the current clip plane.
187
188 \param data nviz data
189 \param id id of current clip plane
190 \param dx,dy,dz rotation parameters
191
192 \return 1
193
194 */
195int Nviz_get_cplane_rotation(nv_data *data, int id, float *dx, float *dy,
196 float *dz)
197{
198 *dx = data->cp_rot[id][X];
199 *dy = data->cp_rot[id][Y];
200 *dz = data->cp_rot[id][Z];
201
202 return 1;
203}
204
205/*!
206 \brief Set the translation for the current clip plane.
207
208 \param data nviz data
209 \param id id of current clip plane
210 \param dx,dy,dz values for setting translation
211
212 \return 1
213 */
214int Nviz_set_cplane_translation(nv_data *data, int id, float dx, float dy,
215 float dz)
216{
217 data->cp_trans[id][X] = dx;
218 data->cp_trans[id][Y] = dy;
219 data->cp_trans[id][Z] = dz;
220 GS_set_cplane_trans(id, data->cp_trans[id][X], data->cp_trans[id][Y],
221 data->cp_trans[id][Z]);
222
223 cp_draw(data, data->cur_cplane, -1, -1);
224
225 return 1;
226}
227
228/*!
229 \brief Get the translation values for the current clip plane.
230
231 \param data nviz data
232 \param id id of current clip plane
233 \param dx,dy,dz translation parameters
234 */
235int Nviz_get_cplane_translation(nv_data *data, int id, float *dx, float *dy,
236 float *dz)
237{
238 *dx = data->cp_trans[id][X];
239 *dy = data->cp_trans[id][Y];
240 *dz = data->cp_trans[id][Z];
241
242 return 1;
243}
244
245/*!
246 \brief Set appropriate fence color
247
248 \param type type of fence (FC_ABOVE, FC_BELOW, FC_BLEND, FC_GREY, FC_OFF)
249 */
251{
252 GS_set_fencecolor(type);
253
254 return 1;
255}
256
257int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
258{
259 float x, y, z, len, los[2][3];
260 float dx, dy, dz;
261 float n, s, w, e;
262 Point3 realto, dir;
263 int id;
264 geosurf *gs;
265
266 if (GS_get_selected_point_on_surface(sx, sy, &id, &x, &y, &z)) {
267 gs = gs_get_surf(id);
268 if (gs) {
269 realto[X] = x - gs->ox + gs->x_trans;
270 realto[Y] = y - gs->oy + gs->y_trans;
271 realto[Z] = z + gs->z_trans;
272 }
273 else
274 return 0;
275 }
276 else {
277 if (gsd_get_los(los, (short)sx, (short)sy)) {
278 len = GS_distance(Gv.from_to[FROM], Gv.real_to);
279 GS_v3dir(los[FROM], los[TO], dir);
280 GS_v3mult(dir, len);
281 realto[X] = Gv.from_to[FROM][X] + dir[X];
282 realto[Y] = Gv.from_to[FROM][Y] + dir[Y];
283 realto[Z] = Gv.from_to[FROM][Z] + dir[Z];
284 }
285 else
286 return 0;
287 }
288 Nviz_get_cplane_translation(data, cplane, &dx, &dy, &dz);
289
290 GS_get_region(&n, &s, &w, &e);
291 dx = realto[X] - (e - w) / 2.;
292 dy = realto[Y] - (n - s) / 2.;
293
294 Nviz_set_cplane_translation(data, cplane, dx, dy, dz);
295
296 return 1;
297}
int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
int Nviz_get_current_cplane(nv_data *data)
Get the current active cutplane.
int Nviz_get_cplane_translation(nv_data *data, int id, float *dx, float *dy, float *dz)
Get the translation values for the current clip plane.
int Nviz_draw_cplane(nv_data *data, int bound1, int bound2)
Draw the clip plane.
Definition cplanes_obj.c:77
int Nviz_set_cplane_rotation(nv_data *data, int id, float dx, float dy, float dz)
Set the rotation for the current clip plane.
int Nviz_off_cplane(nv_data *data, int id)
Turn off (make inactive) the given clip plane.
Definition cplanes_obj.c:62
int Nviz_num_cplanes(nv_data *data)
Return the number of clip planes objects currently allocated.
int Nviz_set_fence_color(nv_data *data, int type)
Set appropriate fence color.
int Nviz_new_cplane(nv_data *data, int id)
Creates a clip plane object.
Definition cplanes_obj.c:30
int Nviz_set_cplane_translation(nv_data *data, int id, float dx, float dy, float dz)
Set the translation for the current clip plane.
int Nviz_on_cplane(nv_data *data, int id)
Turn on (make current) the given clip plane.
Definition cplanes_obj.c:47
int Nviz_get_cplane_rotation(nv_data *data, int id, float *dx, float *dy, float *dz)
Get the rotation values for the current clip plane.
void GS_v3mult(float *, float)
Multiple vectors.
Definition gs_util.c:225
int GS_get_region(float *, float *, float *, float *)
Get 2D region extent.
Definition gs2.c:152
void GS_set_draw(int)
Sets which buffer to draw to.
Definition gs2.c:2458
int GS_get_selected_point_on_surface(int, int, int *, float *, float *, float *)
Get selected point of surface.
Definition gs2.c:3050
geosurf * gs_get_surf(int)
Get geosurf struct.
Definition gs.c:59
void GS_unset_cplane(int)
Unset clip place (turn off)
Definition gs2.c:3222
int GS_draw_cplane_fence(int, int, int)
Draw cplace fence ?
Definition gs2.c:3170
int * GS_get_surf_list(int *)
Get surface list.
Definition gs2.c:1528
void GS_set_cplane(int)
Set cplace.
Definition gs2.c:3210
void GS_ready_draw(void)
Definition gs2.c:2484
void GS_set_cplane_rot(int, float, float, float)
Set cplace rotation.
Definition gs2.c:3118
void GS_draw_wire(int)
Draw surface wire.
Definition gs2.c:1896
void GS_clear(int)
Clear view.
Definition gs2.c:3413
int GS_v3dir(float *, float *, float *)
Get a normalized direction from v1 to v2, store in v3.
Definition gs_util.c:347
int gsd_get_los(float(*)[3], short, short)
ADD.
Definition gsd_views.c:36
void GS_done_draw(void)
Draw done, swap buffers.
Definition gs2.c:2497
void GS_set_fencecolor(int)
Set fence color.
Definition gs2.c:3251
float GS_distance(float *, float *)
Calculate distance.
Definition gs_util.c:137
void GS_set_cplane_trans(int, float, float, float)
Set cplace trans.
Definition gs2.c:3131
#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 MAX_CPLANES
Definition ogsf.h:48
#define X
Definition ogsf.h:141
float Point3[3]
Definition ogsf.h:206
#define Z
Definition ogsf.h:143
#define Y
Definition ogsf.h:142
#define GSD_BACK
Definition ogsf.h:106
#define FROM
Definition ogsf.h:145
#define TO
Definition ogsf.h:146
Definition ogsf.h:267
Definition nviz.h:96
int cp_on[6]
Definition nviz.h:102
int cur_cplane
Definition nviz.h:102
int num_cplanes
Definition nviz.h:101
float cp_rot[6][3]
Definition nviz.h:104
float cp_trans[6][3]
Definition nviz.h:103
int bgcolor
Definition nviz.h:122
#define x