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