surface.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 (map) {
  100. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
  101. value, -1.0,
  102. data);
  103. }
  104. else {
  105. float val;
  106. if (attr == ATT_COLOR) {
  107. val = Nviz_color_from_str(value);
  108. }
  109. else {
  110. val = atof(value);
  111. }
  112. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, CONST_ATT,
  113. NULL, val,
  114. data);
  115. }
  116. G_debug(1, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
  117. id, attr, map, value);
  118. return ret;
  119. }
  120. /*!
  121. \brief Unset surface mask
  122. \param id surface id
  123. \return 1 on success
  124. \return 0 on failure
  125. */
  126. int Nviz::UnsetSurfaceMask(int id)
  127. {
  128. return UnsetSurfaceAttr(id, ATT_MASK);
  129. }
  130. /*!
  131. \brief Unset surface transparency
  132. \param id surface id
  133. \return 1 on success
  134. \return 0 on failure
  135. */
  136. int Nviz::UnsetSurfaceTransp(int id)
  137. {
  138. return UnsetSurfaceAttr(id, ATT_TRANSP);
  139. }
  140. /*!
  141. \brief Unset surface emission
  142. \param id surface id
  143. \return 1 on success
  144. \return 0 on failure
  145. */
  146. int Nviz::UnsetSurfaceEmit(int id)
  147. {
  148. return UnsetSurfaceAttr(id, ATT_EMIT);
  149. }
  150. /*!
  151. \brief Unset surface attribute
  152. \param id surface id
  153. \param attr attribute descriptor
  154. \return 1 on success
  155. \return 0 on failure
  156. */
  157. int Nviz::UnsetSurfaceAttr(int id, int attr)
  158. {
  159. return Nviz_unset_attr(id, MAP_OBJ_SURF, attr);
  160. }
  161. /*!
  162. \brief Set surface resolution
  163. \param id surface id
  164. \param fine x/y fine resolution
  165. \param coarse x/y coarse resolution
  166. \return -1 on error
  167. \return 0 on success
  168. */
  169. int Nviz::SetSurfaceRes(int id, int fine, int coarse)
  170. {
  171. return GS_set_drawres(id, fine, fine, coarse, coarse);
  172. }
  173. /*!
  174. \brief Set draw style
  175. Draw styles:
  176. - DM_GOURAUD
  177. - DM_FLAT
  178. - DM_FRINGE
  179. - DM_WIRE
  180. - DM_COL_WIRE
  181. - DM_POLY
  182. - DM_WIRE_POLY
  183. - DM_GRID_WIRE
  184. - DM_GRID_SURF
  185. \param id surface id (<= 0 for all)
  186. \param style draw style
  187. \return 0 on success
  188. \return -1 on error
  189. */
  190. int Nviz::SetSurfaceStyle(int id, int style)
  191. {
  192. if (id > 0) {
  193. return GS_set_drawmode(id, style);
  194. }
  195. return GS_setall_drawmode(style);
  196. }
  197. /*!
  198. \brief Set color of wire
  199. \todo all
  200. \param surface id
  201. \param color color string (R:G:B)
  202. \return 1
  203. */
  204. int Nviz::SetWireColor(int id, const char* color)
  205. {
  206. GS_set_wire_color(id, Nviz_color_from_str(color));
  207. return 1;
  208. }