load.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. \file load.cpp
  3. \brief Experimental C++ wxWidgets Nviz prototype -- load data layers
  4. Used by wxGUI Nviz extension.
  5. Copyright: (C) by the GRASS Development Team
  6. This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. \author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
  10. \date 2008
  11. */
  12. #include "nviz.h"
  13. extern "C" {
  14. #include <grass/glocale.h>
  15. }
  16. /*!
  17. \brief Load raster map (surface)
  18. \param name raster map name
  19. \param color_name raster map for color (NULL for color_value)
  20. \param color_value color string (named color or RGB triptet)
  21. \return object id
  22. \return -1 on failure
  23. */
  24. int Nviz::LoadRaster(const char* name, const char *color_name, const char *color_value)
  25. {
  26. char *mapset;
  27. int id;
  28. mapset = G_find_cell2 (name, "");
  29. if (mapset == NULL) {
  30. G_warning(_("Raster map <%s> not found"),
  31. name);
  32. return -1;
  33. }
  34. /* topography */
  35. id = Nviz_new_map_obj(MAP_OBJ_SURF,
  36. G_fully_qualified_name(name, mapset), 0.0,
  37. data);
  38. if (color_name) { /* check for color map */
  39. mapset = G_find_cell2 (color_name, "");
  40. if (mapset == NULL) {
  41. G_warning(_("Raster map <%s> not found"),
  42. color_name);
  43. GS_delete_surface(id);
  44. return -1;
  45. }
  46. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  47. G_fully_qualified_name(color_name, mapset), -1.0,
  48. data);
  49. }
  50. else if (color_value) { /* check for color value */
  51. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
  52. NULL, Nviz_color_from_str(color_value),
  53. data);
  54. }
  55. else { /* use by default elevation map for coloring */
  56. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  57. G_fully_qualified_name(name, mapset), -1.0,
  58. data);
  59. }
  60. /*
  61. if (i > 1)
  62. set_default_wirecolors(data, i);
  63. */
  64. /* focus on loaded data */
  65. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
  66. G_debug(1, "Nviz::LoadRaster(): name=%s", name);
  67. return id;
  68. }