gsdiff.c 1.9 KB

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