GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
gsdiff.c
Go to the documentation of this file.
1 /*!
2  \file lib/ogsf/gsdiff.c
3 
4  \brief OGSF library - manipulating surfaces (lower level functions)
5 
6  GRASS OpenGL gsurf OGSF Library
7 
8  Routines to set up automatic on-the-fly recalculation
9  of surface elevations, doing a "scaled difference" using another
10  surface for reference
11 
12  Note that we're using a true difference here, between data set values,
13  no translations, etc.
14 
15  \todo generalize this concept to allow transform functions which are
16  dependent on surfaces that are dependent on other surfaces, etc., as long
17  as the dependency doesn't loop back.
18 
19  (C) 1999-2008 by the GRASS Development Team
20 
21  This program is free software under the
22  GNU General Public License (>=v2).
23  Read the file COPYING that comes with GRASS
24  for details.
25 
26  \author Bill Brown USACERL, GMSL/University of Illinois (November 1994)
27  \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
28  */
29 
30 #include <grass/ogsf.h>
31 #include "gsget.h"
32 
33 static geosurf *Refsurf = NULL;
34 static typbuff *Refbuff = NULL;
35 static float Refscale = 1.0;
36 
37 /*!
38  \brief Set scale
39 
40  \param scale value
41  */
42 void gsdiff_set_SDscale(float scale)
43 {
44  Refscale = scale;
45 
46  return;
47 }
48 
49 /*!
50  \brief Get scale
51 
52  \return scale value
53  */
54 float gsdiff_get_SDscale(void)
55 {
56  return (Refscale);
57 }
58 
59 /*!
60  \brief ADD
61 
62  \param gsref
63  */
65 {
66  Refsurf = gsref;
67  Refbuff = gs_get_att_typbuff(gsref, ATT_TOPO, 0);
68 
69  return;
70 }
71 
72 /*!
73  \brief ADD
74 
75  \return pointer to geosurf struct
76  */
78 {
79  if (Refsurf && Refbuff) {
80  return (Refsurf);
81  }
82 
83  return (NULL);
84 }
85 
86 /*!
87  \brief ADD
88 
89  \param val
90  \param offset
91 
92  \return value
93  */
94 float gsdiff_do_SD(float val, int offset)
95 {
96  float ref;
97 
98  if (Refbuff) {
99  GET_MAPATT(Refbuff, offset, ref);
100  return (ref + (val - ref) * Refscale);
101  }
102 
103  return (val);
104 }
void gsdiff_set_SDscale(float scale)
Set scale.
Definition: gsdiff.c:42
float gsdiff_get_SDscale(void)
Get scale.
Definition: gsdiff.c:54
#define ATT_TOPO
Definition: ogsf.h:73
#define NULL
Definition: ccmath.h:32
geosurf * gsdiff_get_SDref(void)
ADD.
Definition: gsdiff.c:77
void gsdiff_set_SDref(geosurf *gsref)
ADD.
Definition: gsdiff.c:64
typbuff * gs_get_att_typbuff(geosurf *, int, int)
Get attribute data buffer.
Definition: gs.c:681
Definition: ogsf.h:204
float gsdiff_do_SD(float val, int offset)
ADD.
Definition: gsdiff.c:94
Definition: ogsf.h:257
#define GET_MAPATT(buff, offset, att)
Definition: gsget.h:27