gsdiff.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*!
  2. \file gsdiff.c
  3. \brief OGSF library - loading and manipulating surfaces
  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. */
  20. #include <stdio.h>
  21. #include <grass/gstypes.h>
  22. #include "gsget.h"
  23. static geosurf *Refsurf = NULL;
  24. static typbuff *Refbuff = NULL;
  25. static float Refscale = 1.0;
  26. /***********************************************************************/
  27. void gsdiff_set_SDscale(float scale)
  28. {
  29. Refscale = scale;
  30. return;
  31. }
  32. /***********************************************************************/
  33. float gsdiff_get_SDscale(void)
  34. {
  35. return (Refscale);
  36. }
  37. /***********************************************************************/
  38. void gsdiff_set_SDref(geosurf * gsref)
  39. {
  40. Refsurf = gsref;
  41. Refbuff = gs_get_att_typbuff(gsref, ATT_TOPO, 0);
  42. return;
  43. }
  44. /***********************************************************************/
  45. geosurf *gsdiff_get_SDref(void)
  46. {
  47. if (Refsurf && Refbuff) {
  48. return (Refsurf);
  49. }
  50. return (NULL);
  51. }
  52. /***********************************************************************/
  53. float gsdiff_do_SD(float val, int offset)
  54. {
  55. float ref;
  56. if (Refbuff) {
  57. GET_MAPATT(Refbuff, offset, ref);
  58. return (ref + (val - ref) * Refscale);
  59. }
  60. return (val);
  61. }