GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
exag.c
Go to the documentation of this file.
1 /*!
2  \file lib/nviz/exag.c
3 
4  \brief Nviz library -- Exaggeration functions
5 
6  Based on visualization/nviz/src/exag.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/nviz.h>
17 
18 /*!
19  \brief Get view height
20 
21  Call after initial data has been loaded
22 
23  \param[out] val height value
24  \param[out] min min value (or NULL)
25  \param[out] max max value (or NULL)
26 
27  \return 1
28  */
29 int Nviz_get_exag_height(double *val, double *min, double *max)
30 {
31  float longdim, exag, texag, hmin, hmax, fmin, fmax;
32  int nsurfs, i, *surf_list;
33 
34  surf_list = GS_get_surf_list(&nsurfs);
35  if (nsurfs) {
36  GS_get_longdim(&longdim);
37  GS_get_zrange_nz(&hmin, &hmax);
38 
39  exag = 0.0;
40  for (i = 0; i < nsurfs; i++) {
41  if (GS_get_exag_guess(surf_list[i], &texag) > -1)
42  if (texag)
43  exag = texag > exag ? texag : exag;
44  }
45  if (exag == 0.0)
46  exag = 1.0;
47 
48  fmin = hmin - (2. * longdim / exag);
49  fmax = hmin + (3 * longdim / exag);
50  }
51  else {
52  fmax = 10000.0;
53  fmin = 0.0;
54  }
55 
56  *val = fmin + (fmax - fmin) / 2.0;
57 
58  if (min)
59  *min = fmin;
60 
61  if (max)
62  *max = fmax;
63 
64  G_debug(1, "Nviz_get_exag_height(): value = %f min = %f max = %f", *val,
65  min ? *min : 0.0, max ? *max : 0.0);
66 
67  return 1;
68 }
69 
70 /*!
71  \brief Get view z-exag value
72 
73  Call after initial data has been loaded
74 
75  \return value
76  */
77 double Nviz_get_exag(void)
78 {
79  float exag, texag;
80  int nsurfs, i, *surf_list;
81 
82  surf_list = GS_get_surf_list(&nsurfs);
83 
84  exag = 0.0;
85  for (i = 0; i < nsurfs; i++) {
86  if (GS_get_exag_guess(surf_list[i], &texag) > -1) {
87  if (texag)
88  exag = (texag > exag) ? texag : exag;
89  }
90  }
91 
92  if (exag == 0.0)
93  exag = 1.0;
94 
95  if (nsurfs > 0)
96  G_free(surf_list);
97 
98  G_debug(1, "Nviz_get_exag(): value = %f", exag);
99  return exag;
100 }
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:150
int G_debug(int, const char *,...) __attribute__((format(printf
int * GS_get_surf_list(int *)
Get surface list.
Definition: gs2.c:1530
int GS_get_longdim(float *)
Get largest dimension.
Definition: gs2.c:140
void GS_get_zrange_nz(float *, float *)
Get Z extents for all loaded surfaces.
Definition: gs2.c:2355
int GS_get_exag_guess(int, float *)
Get exag-value guess.
Definition: gs2.c:2304
#define min(x, y)
Definition: draw2.c:29
#define max(x, y)
Definition: draw2.c:30
int Nviz_get_exag_height(double *val, double *min, double *max)
Get view height.
Definition: exag.c:29
double Nviz_get_exag(void)
Get view z-exag value.
Definition: exag.c:77