GRASS GIS 8 Programmer's Manual 8.2.1RC1(2022)-exported
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 (C) 2008, 2010 by the GRASS Development Team
9 This program is free software under the GNU General Public License
10 (>=v2). Read the file COPYING that comes with GRASS for details.
11
12 \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 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
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] =
36 0.0;
37 data->cp_on[id] = 0;
38
39 return 1;
40}
41
42/*!
43 \brief Turn on (make current) the given clip plane.
44
45 \param data nviz data
46 \param cplane id
47 */
48int Nviz_on_cplane(nv_data * data, int id)
49{
50 data->cur_cplane = id;
51 data->cp_on[id] = 1;
52 GS_set_cplane(id);
53
54 return 1;
55}
56
57/*!
58 \brief Turn off (make inactive) the given clip plane
59
60 \param data nviz data
61 \param cplane id
62 */
63int Nviz_off_cplane(nv_data * data, int id)
64{
65 data->cp_on[id] = 0;
67
68 return 1;
69}
70
71/*!
72 \brief Draw the clip plane
73
74 \param data nviz data
75 \param bound1
76 \param bound2
77 */
78int Nviz_draw_cplane(nv_data * data, int bound1, int bound2)
79{
80 cp_draw(data, data->cur_cplane, bound1, bound2);
81
82 return 1;
83}
84
85/*!
86 \brief Draw current clip plane
87
88 \param data nviz data
89 \param current id of current clip plane
90 \param surf1 first surface id
91 \param surf2 second surface id
92 */
93void cp_draw(nv_data * data, int current, int surf1, int surf2)
94{
95 int i, nsurfs;
96 int surf_min = 0, surf_max = 0, temp;
97 int *surf_list;
98
99 GS_set_draw(GSD_BACK);
100 GS_clear(data->bgcolor);
102
103 /* If surf boundaries present then find them */
104 surf_list = GS_get_surf_list(&nsurfs);
105 if ((surf1 != -1) && (surf2 != -1)) {
106 for (i = 0; i < nsurfs; i++) {
107 if (surf_list[i] == surf1)
108 surf_min = i;
109 if (surf_list[i] == surf2)
110 surf_max = i;
111 }
112
113 if (surf_max < surf_min) {
114 temp = surf_min;
115 surf_min = surf_max;
116 surf_max = temp;
117 }
118
119 surf_max++;
120 }
121 else {
122 surf_min = 0;
123 surf_max = nsurfs;
124 }
125
126 if (nsurfs > 1) {
127 for (i = 0; i < MAX_CPLANES; i++) {
128 if (data->cp_on[i])
129 GS_draw_cplane_fence(surf_list[0], surf_list[1], i);
130 }
131 }
132
133 for (i = surf_min; i < surf_max; i++) {
134 GS_draw_wire(surf_list[i]);
135 }
136
137 GS_done_draw();
138
139 return;
140}
141/*!
142 \brief Return the number of clip planes objects currently allocated.
143
144 \param data nviz data
145 */
146int Nviz_num_cplanes(nv_data * data)
147{
148 return data->num_cplanes;
149}
150
151/*!
152 \brief Get the current active cutplane.
153
154 \param data nviz data
155 */
156int Nviz_get_current_cplane(nv_data * data)
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, float dz)
172{
173 data->cp_rot[id][X] = dx;
174 data->cp_rot[id][Y] = dy;
175 data->cp_rot[id][Z] = dz;
176 GS_set_cplane_rot(id, data->cp_rot[id][X], data->cp_rot[id][Y],
177 data->cp_rot[id][Z]);
178
179 cp_draw(data, data->cur_cplane, -1, -1);
180
181 return 1;
182}
183/*!
184 \brief Get the rotation values for the current clip plane.
185
186 \param data nviz data
187 \param id id of current clip plane
188 \param dx,dy,dz rotation parameters
189
190 \return 1
191
192 */
193int Nviz_get_cplane_rotation(nv_data * data, int id, float *dx, float *dy, float *dz)
194{
195 *dx = data->cp_rot[id][X];
196 *dy = data->cp_rot[id][Y];
197 *dz = data->cp_rot[id][Z];
198
199 return 1;
200}
201
202/*!
203 \brief Set the translation for the current clip plane.
204
205 \param data nviz data
206 \param id id of current clip plane
207 \param dx,dy,dz values for setting translation
208
209 \return 1
210 */
211int Nviz_set_cplane_translation(nv_data * data, int id, float dx, float dy, float dz)
212{
213 data->cp_trans[id][X] = dx;
214 data->cp_trans[id][Y] = dy;
215 data->cp_trans[id][Z] = dz;
216 GS_set_cplane_trans(id, data->cp_trans[id][X], data->cp_trans[id][Y],
217 data->cp_trans[id][Z]);
218
219 cp_draw(data, data->cur_cplane, -1, -1);
220
221 return 1;
222}
223/*!
224 \brief Get the translation values for the current clip plane.
225
226 \param data nviz data
227 \param id id of current clip plane
228 \param dx,dy,dz translation parameters
229 */
230int Nviz_get_cplane_translation(nv_data * data, int id, float *dx, float *dy, float *dz)
231{
232 *dx = data->cp_trans[id][X];
233 *dy = data->cp_trans[id][Y];
234 *dz = data->cp_trans[id][Z];
235
236 return 1;
237}
238/*!
239 \brief Set appropriate fence color
240
241 \param type type of fence (FC_ABOVE, FC_BELOW, FC_BLEND, FC_GREY, FC_OFF)
242 */
243int Nviz_set_fence_color(nv_data * data, int type)
244{
245 GS_set_fencecolor(type);
246
247 return 1;
248
249}
250int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
251{
252 float x, y, z, len, los[2][3];
253 float dx, dy, dz;
254 float n, s, w, e;
255 Point3 realto, dir;
256 int id;
257 geosurf *gs;
258
259 if (GS_get_selected_point_on_surface(sx, sy, &id, &x, &y, &z)) {
260 gs = gs_get_surf(id);
261 if (gs) {
262 realto[X] = x - gs->ox + gs->x_trans;
263 realto[Y] = y - gs->oy + gs->y_trans;
264 realto[Z] = z + gs->z_trans;
265 }
266 else
267 return 0;
268 }
269 else {
270 if (gsd_get_los(los, (short)sx, (short)sy)) {
271 len = GS_distance(Gv.from_to[FROM], Gv.real_to);
272 GS_v3dir(los[FROM], los[TO], dir);
273 GS_v3mult(dir, len);
274 realto[X] = Gv.from_to[FROM][X] + dir[X];
275 realto[Y] = Gv.from_to[FROM][Y] + dir[Y];
276 realto[Z] = Gv.from_to[FROM][Z] + dir[Z];
277 }
278 else
279 return 0;
280 }
281 Nviz_get_cplane_translation(data, cplane, &dx, &dy, &dz);
282
283 GS_get_region(&n, &s, &w, &e);
284 dx = realto[X] - (e - w) / 2.;
285 dy = realto[Y] - (n - s) / 2.;
286
287 Nviz_set_cplane_translation(data, cplane, dx, dy, dz);
288
289 return 1;
290}
int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
Definition: cplanes_obj.c:250
int Nviz_get_current_cplane(nv_data *data)
Get the current active cutplane.
Definition: cplanes_obj.c:156
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.
Definition: cplanes_obj.c:230
int Nviz_draw_cplane(nv_data *data, int bound1, int bound2)
Draw the clip plane.
Definition: cplanes_obj.c:78
int Nviz_set_cplane_rotation(nv_data *data, int id, float dx, float dy, float dz)
Set the rotation for the current clip plane.
Definition: cplanes_obj.c:171
int Nviz_off_cplane(nv_data *data, int id)
Turn off (make inactive) the given clip plane.
Definition: cplanes_obj.c:63
int Nviz_num_cplanes(nv_data *data)
Return the number of clip planes objects currently allocated.
Definition: cplanes_obj.c:146
int Nviz_set_fence_color(nv_data *data, int type)
Set appropriate fence color.
Definition: cplanes_obj.c:243
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.
Definition: cplanes_obj.c:211
int Nviz_on_cplane(nv_data *data, int id)
Turn on (make current) the given clip plane.
Definition: cplanes_obj.c:48
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.
Definition: cplanes_obj.c:193
void GS_unset_cplane(int num)
Unset clip place (turn off)
Definition: gs2.c:3227
void GS_set_cplane_rot(int num, float dx, float dy, float dz)
Set cplace rotation.
Definition: gs2.c:3122
void GS_set_cplane_trans(int num, float dx, float dy, float dz)
Set cplace trans.
Definition: gs2.c:3135
void GS_clear(int col)
Clear view.
Definition: gs2.c:3418
void GS_set_cplane(int num)
Set cplace.
Definition: gs2.c:3215
int * GS_get_surf_list(int *numsurfs)
Get surface list.
Definition: gs2.c:1539
int GS_get_selected_point_on_surface(int sx, int sy, int *id, float *x, float *y, float *z)
Get selected point of surface.
Definition: gs2.c:3054
int GS_get_region(float *n, float *s, float *w, float *e)
Get 2D region extent.
Definition: gs2.c:156
void GS_set_fencecolor(int mode)
Set fence color.
Definition: gs2.c:3256
void GS_ready_draw(void)
Definition: gs2.c:2488
int GS_draw_cplane_fence(int hs1, int hs2, int num)
Draw cplace fence ?
Definition: gs2.c:3175
void GS_set_draw(int where)
Sets which buffer to draw to.
Definition: gs2.c:2462
void GS_done_draw(void)
Draw done, swap buffers.
Definition: gs2.c:2501
void GS_draw_wire(int id)
Draw surface wire.
Definition: gs2.c:1899
geosurf * gs_get_surf(int id)
Get geosurf struct.
Definition: gs.c:62
void GS_v3mult(float *v1, float k)
Multiple vectors.
Definition: gs_util.c:229
float GS_distance(float *from, float *to)
Calculate distance.
Definition: gs_util.c:141
int GS_v3dir(float *v1, float *v2, float *v3)
Get a normalized direction from v1 to v2, store in v3.
Definition: gs_util.c:353
int gsd_get_los(float(*vect)[3], short sx, short sy)
ADD.
Definition: gsd_views.c:40
#define X(j)
#define x
#define Y(j)