volume.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /**
  2. \file volume.cpp
  3. \brief Experimental C++ wxWidgets Nviz prototype -- volume attributes
  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. /**
  14. \brief Add new isosurface
  15. \param id volume id
  16. \param level isosurface level (topography)
  17. \return -1 on failure
  18. \return 1 on success
  19. */
  20. int Nviz::AddIsosurface(int id, int level)
  21. {
  22. int nisosurfs;
  23. if (!GVL_vol_exists(id))
  24. return -1;
  25. if (GVL_isosurf_add(id) < 0)
  26. return -1;
  27. /* set topography level */
  28. nisosurfs = GVL_isosurf_num_isosurfs(id);
  29. return GVL_isosurf_set_att_const(id, nisosurfs - 1,
  30. ATT_TOPO, level);
  31. }
  32. /**
  33. \brief Delete isosurface
  34. \param id volume id
  35. \param isosurf_id isosurface id
  36. \return 1 on success
  37. \return -1 volume not found
  38. \return -2 isosurface not found
  39. \return -3 on failure
  40. */
  41. int Nviz::DeleteIsosurface(int id, int isosurf_id)
  42. {
  43. int ret;
  44. if (!GVL_vol_exists(id))
  45. return -1;
  46. if (isosurf_id > GVL_isosurf_num_isosurfs(id))
  47. return -2;
  48. ret = GVL_isosurf_del(id, isosurf_id);
  49. return ret < 0 ? -3 : 1;
  50. }
  51. /*!
  52. \brief Move isosurface up/down in the list
  53. \param id volume id
  54. \param isosurf_id isosurface id
  55. \param up if true move up otherwise down
  56. \return 1 on success
  57. \return -1 volume not found
  58. \return -2 isosurface not found
  59. \return -3 on failure
  60. */
  61. int Nviz::MoveIsosurface(int id, int isosurf_id, bool up)
  62. {
  63. int ret;
  64. if (!GVL_vol_exists(id))
  65. return -1;
  66. if (isosurf_id > GVL_isosurf_num_isosurfs(id))
  67. return -2;
  68. if (up)
  69. ret = GVL_isosurf_move_up(id, isosurf_id);
  70. else
  71. ret = GVL_isosurf_move_down(id, isosurf_id);
  72. return ret < 0 ? -3 : 1;
  73. }
  74. /*!
  75. \brief Set surface color
  76. \param id surface id
  77. \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  78. \param map if true use map otherwise constant
  79. \param value map name of value
  80. \return 1 on success
  81. \return -1 volume not found
  82. \return -2 isosurface not found
  83. \return -3 setting attributes failed
  84. */
  85. int Nviz::SetIsosurfaceColor(int id, int isosurf_id,
  86. bool map, const char *value)
  87. {
  88. return SetIsosurfaceAttr(id, isosurf_id, ATT_COLOR, map, value);
  89. }
  90. /*!
  91. \brief Set isosurface attribute
  92. \param id volume id
  93. \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  94. \param attr attribute desc
  95. \param map if true use map otherwise constant
  96. \param value map name of value
  97. \return 1 on success
  98. \return -1 volume not found
  99. \return -2 isosurface not found
  100. \return -3 setting attributes failed
  101. */
  102. int Nviz::SetIsosurfaceAttr(int id, int isosurf_id,
  103. int attr, bool map, const char *value)
  104. {
  105. int ret;
  106. if (!GVL_vol_exists(id)) {
  107. return -1;
  108. }
  109. if (isosurf_id > GVL_isosurf_num_isosurfs(id) - 1)
  110. return -2;
  111. if (map) {
  112. ret = GVL_isosurf_set_att_map(id, isosurf_id, attr,
  113. value);
  114. }
  115. else {
  116. float val;
  117. if (attr == ATT_COLOR) {
  118. val = Nviz_color_from_str(value);
  119. }
  120. else {
  121. val = atof(value);
  122. }
  123. ret = GVL_isosurf_set_att_const(id, isosurf_id, attr,
  124. val);
  125. }
  126. G_debug(1, "Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
  127. "attr=%d, map=%d, value=%s",
  128. id, isosurf_id, attr, map, value);
  129. return ret > 0 ? 1 : -2;
  130. }
  131. /*!
  132. \brief Unset surface attribute
  133. \param id surface id
  134. \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  135. \param attr attribute descriptor
  136. \return 1 on success
  137. \return -1 volume not found
  138. \return -2 isosurface not found
  139. \return -2 on failure
  140. */
  141. int Nviz::UnsetIsosurfaceAttr(int id, int isosurf_id,
  142. int attr)
  143. {
  144. int ret;
  145. if (!GVL_vol_exists(id)) {
  146. return -1;
  147. }
  148. if (isosurf_id > GVL_isosurf_num_isosurfs(id) - 1)
  149. return -2;
  150. G_debug(1, "Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%d",
  151. id, isosurf_id, attr);
  152. ret = GVL_isosurf_unset_att(id, isosurf_id, attr);
  153. return ret > 0 ? 1 : -2;
  154. }
  155. /*!
  156. \brief Set draw mode for isosurfaces
  157. \param mode
  158. \return 1 on success
  159. \return -1 volume set not found
  160. \return -2 on failure
  161. */
  162. int Nviz::SetIsosurfaceMode(int id, int mode)
  163. {
  164. int ret;
  165. if (!GVL_vol_exists(id)) {
  166. return -1;
  167. }
  168. ret = GVL_isosurf_set_drawmode(id, mode);
  169. return ret < 0 ? -2 : 1;
  170. }
  171. /*!
  172. \brief Set draw resolution for isosurfaces
  173. \param res resolution value
  174. \return 1 on success
  175. \return -1 volume set not found
  176. \return -2 on failure
  177. */
  178. int Nviz::SetIsosurfaceRes(int id, int res)
  179. {
  180. int ret;
  181. if (!GVL_vol_exists(id)) {
  182. return -1;
  183. }
  184. ret = GVL_isosurf_set_drawres(id, res, res, res);
  185. return ret < 0 ? -2 : 1;
  186. }