surface.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /**
  2. \file map_obj.cpp
  3. \brief Experimental C++ wxWidgets Nviz prototype -- map object management
  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 Set surface topography
  15. \param id surface id
  16. \param map if true use map otherwise constant
  17. \param value map name of value
  18. \return 1 on success
  19. \return 0 on failure
  20. */
  21. int Nviz::SetSurfaceTopo(int id, bool map, const char *value)
  22. {
  23. return SetSurfaceAttr(id, ATT_TOPO, map, value);
  24. }
  25. /*!
  26. \brief Set surface color
  27. \param id surface id
  28. \param map if true use map otherwise constant
  29. \param value map name of value
  30. \return 1 on success
  31. \return 0 on failure
  32. */
  33. int Nviz::SetSurfaceColor(int id, bool map, const char *value)
  34. {
  35. return SetSurfaceAttr(id, ATT_COLOR, map, value);
  36. }
  37. /*!
  38. \brief Set surface mask
  39. @todo invert
  40. \param id surface id
  41. \param invert if true invert mask
  42. \param value map name of value
  43. \return 1 on success
  44. \return 0 on failure
  45. */
  46. int Nviz::SetSurfaceMask(int id, bool invert, const char *value)
  47. {
  48. return SetSurfaceAttr(id, ATT_MASK, true, value);
  49. }
  50. /*!
  51. \brief Set surface mask
  52. @todo invert
  53. \param id surface id
  54. \param map if true use map otherwise constant
  55. \param value map name of value
  56. \return 1 on success
  57. \return 0 on failure
  58. */
  59. int Nviz::SetSurfaceTransp(int id, bool map, const char *value)
  60. {
  61. return SetSurfaceAttr(id, ATT_TRANSP, map, value);
  62. }
  63. /*!
  64. \brief Set surface shininess
  65. \param id surface id
  66. \param map if true use map otherwise constant
  67. \param value map name of value
  68. \return 1 on success
  69. \return 0 on failure
  70. */
  71. int Nviz::SetSurfaceShine(int id, bool map, const char *value)
  72. {
  73. return SetSurfaceAttr(id, ATT_SHINE, map, value);
  74. }
  75. /*!
  76. \brief Set surface emission
  77. \param id surface id
  78. \param map if true use map otherwise constant
  79. \param value map name of value
  80. \return 1 on success
  81. \return 0 on failure
  82. */
  83. int Nviz::SetSurfaceEmit(int id, bool map, const char *value)
  84. {
  85. return SetSurfaceAttr(id, ATT_EMIT, map, value);
  86. }
  87. /*!
  88. \brief Set surface attribute
  89. \param id surface id
  90. \param attr attribute desc
  91. \param map if true use map otherwise constant
  92. \param value map name of value
  93. \return 1 on success
  94. \return 0 on failure
  95. */
  96. int Nviz::SetSurfaceAttr(int id, int attr, bool map, const char *value)
  97. {
  98. int ret;
  99. if (!GS_surf_exists(id)) {
  100. return 0;
  101. }
  102. if (map) {
  103. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
  104. value, -1.0,
  105. data);
  106. }
  107. else {
  108. float val;
  109. if (attr == ATT_COLOR) {
  110. val = Nviz_color_from_str(value);
  111. }
  112. else {
  113. val = atof(value);
  114. }
  115. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, CONST_ATT,
  116. NULL, val,
  117. data);
  118. }
  119. G_debug(1, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
  120. id, attr, map, value);
  121. return ret;
  122. }
  123. /*!
  124. \brief Unset surface mask
  125. \param id surface id
  126. \return 1 on success
  127. \return 0 on failure
  128. */
  129. int Nviz::UnsetSurfaceMask(int id)
  130. {
  131. return UnsetSurfaceAttr(id, ATT_MASK);
  132. }
  133. /*!
  134. \brief Unset surface transparency
  135. \param id surface id
  136. \return 1 on success
  137. \return 0 on failure
  138. */
  139. int Nviz::UnsetSurfaceTransp(int id)
  140. {
  141. return UnsetSurfaceAttr(id, ATT_TRANSP);
  142. }
  143. /*!
  144. \brief Unset surface emission
  145. \param id surface id
  146. \return 1 on success
  147. \return 0 on failure
  148. */
  149. int Nviz::UnsetSurfaceEmit(int id)
  150. {
  151. return UnsetSurfaceAttr(id, ATT_EMIT);
  152. }
  153. /*!
  154. \brief Unset surface attribute
  155. \param id surface id
  156. \param attr attribute descriptor
  157. \return 1 on success
  158. \return 0 on failure
  159. */
  160. int Nviz::UnsetSurfaceAttr(int id, int attr)
  161. {
  162. if (!GS_surf_exists(id)) {
  163. return 0;
  164. }
  165. return Nviz_unset_attr(id, MAP_OBJ_SURF, attr);
  166. }
  167. /*!
  168. \brief Set surface resolution
  169. \param id surface id
  170. \param fine x/y fine resolution
  171. \param coarse x/y coarse resolution
  172. \return 0 on error
  173. \return 1 on success
  174. */
  175. int Nviz::SetSurfaceRes(int id, int fine, int coarse)
  176. {
  177. if (id > 0) {
  178. if (!GS_surf_exists(id)) {
  179. return 0;
  180. }
  181. if (GS_set_drawres(id, fine, fine, coarse, coarse) < 0) {
  182. return 0;
  183. }
  184. }
  185. else {
  186. GS_setall_drawres(fine, fine, coarse, coarse);
  187. }
  188. return 1;
  189. }
  190. /*!
  191. \brief Set draw style
  192. Draw styles:
  193. - DM_GOURAUD
  194. - DM_FLAT
  195. - DM_FRINGE
  196. - DM_WIRE
  197. - DM_COL_WIRE
  198. - DM_POLY
  199. - DM_WIRE_POLY
  200. - DM_GRID_WIRE
  201. - DM_GRID_SURF
  202. \param id surface id (<= 0 for all)
  203. \param style draw style
  204. \return 1 on success
  205. \return 0 on error
  206. */
  207. int Nviz::SetSurfaceStyle(int id, int style)
  208. {
  209. if (id > 0) {
  210. if (!GS_surf_exists(id)) {
  211. return 0;
  212. }
  213. if (GS_set_drawmode(id, style) < 0) {
  214. return 0;
  215. }
  216. return 1;
  217. }
  218. if (GS_setall_drawmode(style) < 0) {
  219. return 0;
  220. }
  221. return 1;
  222. }
  223. /*!
  224. \brief Set color of wire
  225. \todo all
  226. \param surface id (< 0 for all)
  227. \param color color string (R:G:B)
  228. \return 1 on success
  229. \return 0 on failure
  230. */
  231. int Nviz::SetWireColor(int id, const char* color_str)
  232. {
  233. int color;
  234. color = Nviz_color_from_str(color_str);
  235. if (id > 0) {
  236. if (!GS_surf_exists(id)) {
  237. return 0;
  238. }
  239. GS_set_wire_color(id, color);
  240. }
  241. else {
  242. int *surf_list, nsurfs, id;
  243. surf_list = GS_get_surf_list(&nsurfs);
  244. for (int i = 0; i < nsurfs; i++) {
  245. id = surf_list[i];
  246. GS_set_wire_color(id, color);
  247. }
  248. G_free(surf_list);
  249. }
  250. return 1;
  251. }