Gvl3.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*!
  2. \file Gvl3.c
  3. \brief OGSF library - loading volumes (lower level functions)
  4. GRASS OpenGL gsurf OGSF Library
  5. (C) 1999-2008 by the GRASS Development Team
  6. This program is free software under the
  7. GNU General Public License (>=v2).
  8. Read the file COPYING that comes with GRASS
  9. for details.
  10. \author Tomas Paudits (December 2003)
  11. \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
  12. */
  13. #include <grass/gis.h>
  14. #include <grass/raster.h>
  15. #include <grass/raster3d.h>
  16. #include <grass/ogsf.h>
  17. #include <grass/glocale.h>
  18. /*!
  19. \brief Load color table
  20. \param[out] color_data color data buffer
  21. \param name 3D raster map name
  22. \return -1 on failure
  23. \return 1 on success
  24. */
  25. int Gvl_load_colors_data(void **color_data, const char *name)
  26. {
  27. const char *mapset;
  28. struct Colors *colors;
  29. if (NULL == (mapset = G_find_raster3d(name, ""))) {
  30. G_warning(_("3D raster map <%s> not found"), name);
  31. return (-1);
  32. }
  33. if (NULL == (colors = (struct Colors *)G_malloc(sizeof(struct Colors))))
  34. return (-1);
  35. if (0 > Rast3d_read_colors(name, mapset, colors)) {
  36. G_free(colors);
  37. return (-1);
  38. }
  39. *color_data = colors;
  40. return (1);
  41. }
  42. /*!
  43. \brief Unload color table
  44. \param color_data color data buffer
  45. \return -1 on failure
  46. \return 1 on success
  47. */
  48. int Gvl_unload_colors_data(void *color_data)
  49. {
  50. Rast_free_colors(color_data);
  51. G_free(color_data);
  52. return (1);
  53. }
  54. /*!
  55. \brief Get color for value
  56. \param color_data color data value
  57. \param value data value
  58. \return color value
  59. */
  60. int Gvl_get_color_for_value(void *color_data, float *value)
  61. {
  62. int r, g, b;
  63. Rast_get_f_color((FCELL *) value, &r, &g, &b, color_data);
  64. return ((r & 0xff) | ((g & 0xff) << 8) | ((b & 0xff) << 16));
  65. }