gsdiff.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*!
  2. \file 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 <stdio.h>
  22. #include <grass/gstypes.h>
  23. #include "gsget.h"
  24. static geosurf *Refsurf = NULL;
  25. static typbuff *Refbuff = NULL;
  26. static float Refscale = 1.0;
  27. /*!
  28. \brief Set scale
  29. \param scale value
  30. */
  31. void gsdiff_set_SDscale(float scale)
  32. {
  33. Refscale = scale;
  34. return;
  35. }
  36. /*!
  37. \brief Get scale
  38. \return scale value
  39. */
  40. float gsdiff_get_SDscale(void)
  41. {
  42. return (Refscale);
  43. }
  44. /*!
  45. \brief ADD
  46. \param gsref
  47. */
  48. void gsdiff_set_SDref(geosurf * gsref)
  49. {
  50. Refsurf = gsref;
  51. Refbuff = gs_get_att_typbuff(gsref, ATT_TOPO, 0);
  52. return;
  53. }
  54. /*!
  55. \brief ADD
  56. \return pointer to geosurf struct
  57. */
  58. geosurf *gsdiff_get_SDref(void)
  59. {
  60. if (Refsurf && Refbuff) {
  61. return (Refsurf);
  62. }
  63. return (NULL);
  64. }
  65. /*!
  66. \brief ADD
  67. \param val
  68. \param offset
  69. \return value
  70. */
  71. float gsdiff_do_SD(float val, int offset)
  72. {
  73. float ref;
  74. if (Refbuff) {
  75. GET_MAPATT(Refbuff, offset, ref);
  76. return (ref + (val - ref) * Refscale);
  77. }
  78. return (val);
  79. }