GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
position.c
Go to the documentation of this file.
1 /*!
2  \file lib/nviz/position.c
3 
4  \brief Nviz library -- Position, focus settings
5 
6  Based on visualization/nviz/src/position.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/glocale.h>
16 #include <grass/nviz.h>
17 
18 /*!
19  Initialize view, position, lighting settings (focus)
20 
21  Set position to center of view
22  */
23 void Nviz_init_view(nv_data * data)
24 {
25  GS_init_view();
26  Nviz_set_focus_state(1); /* center of view */
27 
28  /* set default lights (1 & 2) */
29  Nviz_set_light_position(data, 1, 0.68, -0.68, 0.80, 0.0);
30  Nviz_set_light_bright(data, 1, 0.8);
31  Nviz_set_light_color(data, 1, 255, 255, 255);
32  Nviz_set_light_ambient(data, 1, 0.2);
33  Nviz_set_light_position(data, 2, 0.0, 0.0, 1.0, 0.0);
34  Nviz_set_light_bright(data, 2, 0.5);
35  Nviz_set_light_color(data, 2, 255, 255, 255);
36  Nviz_set_light_ambient(data, 2, 0.3);
37 
38  return;
39 }
40 
41 /*!
42  \brief Set focus state
43 
44  \param state_flag 1 for center view, 0 use viewdir
45 
46  \return 1 on success
47  \return 0 on failure
48  */
49 int Nviz_set_focus_state(int state_flag)
50 {
51  if (state_flag == 1)
52  GS_set_infocus(); /* return center of view */
53  else if (state_flag == 0)
54  GS_set_nofocus(); /* no center of view -- use viewdir */
55  else {
56  G_warning(_("Unable to set focus"));
57  return 0;
58  }
59 
60  return 1;
61 }
62 
63 /*!
64  \brief Set focus based on loaded map
65 
66  If <i>map</i> is MAP_OBJ_UNDEFINED, set focus from first
67  surface/volume in the list.
68 
69  \param type map object type
70  \param id map object id
71 
72  \return 0 on no focus
73  \return id id of map object used for setting focus
74  */
75 int Nviz_set_focus_map(int type, int id)
76 {
77  if (GS_num_surfs() < 0 && GVL_num_vols() < 0) {
79  return 0;
80  }
81 
82  if (type == MAP_OBJ_UNDEFINED) {
83  int *surf_list, num_surfs, *vol_list;
84 
85  if (GS_num_surfs() > 0) {
86  surf_list = GS_get_surf_list(&num_surfs);
87  id = surf_list[0];
88  G_free(surf_list);
89 
91  }
92 
93  if (GVL_num_vols() > 0) {
94  vol_list = GVL_get_vol_list(&num_surfs);
95  id = vol_list[0];
96  G_free(vol_list);
97 
99  }
100  return id;
101  }
102 
103  if (type == MAP_OBJ_SURF) {
105  }
106  else if (type == MAP_OBJ_VOL) {
108  }
109 
110  return id;
111 }
112 
113 /*!
114  \brief Get focus
115 
116  \param data nviz data
117  \param x,y,z focus coordinates
118  */
119 int Nviz_get_focus(nv_data * data, float *x, float *y, float *z)
120 {
121  float realto[3];
122 
123  /* Get current center */
124  GS_get_focus(realto);
125  *x = realto[0];
126  *y = realto[1];
127  *z = realto[2];
128  /* old nviz code is more complicated and it doesn't work properly, */
129  /* no idea why */
130 
131  return 1;
132 
133 }
134 
135 /*!
136  \brief Set focus
137 
138  \param data nviz data
139  \param x, y, z focus coordinates
140  */
141 int Nviz_set_focus(nv_data * data, float x, float y, float z)
142 {
143  float realto[3];
144 
145  realto[0] = x;
146  realto[1] = y;
147  realto[2] = z;
148  GS_set_focus(realto);
149  /* old nviz code is more complicated and it doesn't work properly, */
150  /* no idea why */
151 
152  return 1;
153 
154 }
155 
156 /*!
157  \brief Test focus
158 
159  \param data nviz data
160  */
162 {
163  float realto[3];
164 
165  if (GS_get_focus(realto))
166  return 1;
167  else
168  return 0;
169 }
170 
171 /*!
172  \brief Get xy range
173 
174  \param data nviz data
175  */
177 {
178  return data->xyrange;
179 }
180 
181 /*!
182  \brief Get z range
183 
184  \param data nviz data
185  \param min,max z range
186  */
187 int Nviz_get_zrange(nv_data * data, float *min, float *max)
188 {
189  GS_get_zrange_nz(min, max);
190  return 1;
191 }
192 
193 /*!
194  \brief Get largest dimension
195 
196  \param data nviz data
197  */
199 {
200  float dim;
201 
202  GS_get_longdim(&dim);
203 
204  return dim;
205 }
int Nviz_get_focus(nv_data *data, float *x, float *y, float *z)
Get focus.
Definition: position.c:119
void Nviz_init_view(nv_data *data)
Definition: position.c:23
int Nviz_set_light_ambient(nv_data *, int, double)
Set light ambient.
Definition: lights.c:114
int Nviz_set_focus_state(int state_flag)
Set focus state.
Definition: position.c:49
void GS_set_focus(float *)
Set focus.
Definition: gs2.c:2520
int GVL_num_vols(void)
Get number of loaded volume sets.
Definition: gvl2.c:166
#define min(x, y)
Definition: draw2.c:31
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
#define x
#define max(x, y)
Definition: draw2.c:32
int Nviz_set_focus_map(int type, int id)
Set focus based on loaded map.
Definition: position.c:75
float Nviz_get_xyrange(nv_data *data)
Get xy range.
Definition: position.c:176
float Nviz_get_longdim(nv_data *data)
Get largest dimension.
Definition: position.c:198
void GS_set_focus_center_map(int)
Set focus to map center.
Definition: gs2.c:2582
void GS_get_zrange_nz(float *, float *)
Get Z extents for all loaded surfaces.
Definition: gs2.c:2357
int Nviz_set_light_position(nv_data *, int, double, double, double, double)
Set light position.
Definition: lights.c:27
float xyrange
Definition: nviz.h:104
int Nviz_set_light_bright(nv_data *, int, double)
Set light brightness.
Definition: lights.c:63
int Nviz_get_zrange(nv_data *data, float *min, float *max)
Get z range.
Definition: position.c:187
void GVL_set_focus_center_map(int)
Set focus on map center.
Definition: gvl2.c:516
#define MAP_OBJ_VOL
Definition: nviz.h:44
int * GS_get_surf_list(int *)
Get surface list.
Definition: gs2.c:1539
void GS_set_infocus(void)
Set focus.
Definition: gs2.c:2967
#define MAP_OBJ_SURF
Definition: nviz.h:43
#define MAP_OBJ_UNDEFINED
Definition: nviz.h:42
void GS_init_view(void)
Init viewpoint.
Definition: gs2.c:3347
Definition: nviz.h:101
void G_warning(const char *,...) __attribute__((format(printf
int Nviz_set_focus(nv_data *data, float x, float y, float z)
Set focus.
Definition: position.c:141
int GS_get_focus(float *)
Get focus.
Definition: gs2.c:2563
#define _(str)
Definition: glocale.h:10
int Nviz_set_light_color(nv_data *, int, int, int, int)
Set light color.
Definition: lights.c:87
int GS_get_longdim(float *)
Get largest dimension.
Definition: gs2.c:140
int Nviz_has_focus(nv_data *data)
Test focus.
Definition: position.c:161
void GS_set_nofocus(void)
Unset focus.
Definition: gs2.c:2953
int * GVL_get_vol_list(int *)
Get list of loaded volume sets.
Definition: gvl2.c:181
int GS_num_surfs(void)
Get number of surfaces.
Definition: gs2.c:1524