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