wxnviz.py 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. from ctypes import *
  2. from grass.lib.grass import *
  3. from grass.lib.ogsf import *
  4. from grass.lib.nviz import *
  5. def G_debug(level, str, *args):
  6. print str, args
  7. class Nviz(object):
  8. #!
  9. # \brief Initialize Nviz class instance
  10. def __init__(self, log):
  11. G_gisinit("") # GRASS functions
  12. # logStream = log
  13. # G_set_error_routine(&print_error)
  14. # G_set_percent_routine(&print_percent)
  15. GS_libinit()
  16. GVL_libinit()
  17. # GS_set_swap_func(swap_gl)
  18. self.data_obj = nv_data()
  19. self.data = pointer(self.data_obj)
  20. G_debug(1, "Nviz::Nviz()")
  21. #!
  22. # \brief Destroy Nviz class instance
  23. def __del__(self):
  24. # G_unset_error_routine()
  25. # G_unset_percent_routine()
  26. del self.data
  27. del self.data_obj
  28. # logStream = None
  29. #!
  30. # \brief GL canvas resized
  31. #
  32. # \param width window width
  33. # \param height window height
  34. #
  35. # \return 1 on success
  36. # \return 0 on failure (window resized by default to 20x20 px)
  37. def ResizeWindow(self, width, height):
  38. G_debug(1, "Nviz::ResizeWindow(): width=%d height=%d",
  39. width, height)
  40. return Nviz_resize_window(width, height)
  41. #!
  42. # \brief Set default view (based on loaded data)
  43. #
  44. # \return z-exag value, default, min and max height
  45. def SetViewDefault(self):
  46. # determine z-exag
  47. z_exag = Nviz_get_exag()
  48. Nviz_change_exag(self.data, z_exag)
  49. # determine height
  50. hdef = c_float()
  51. hmin = c_float()
  52. hmax = c_float()
  53. Nviz_get_exag_height(byref(hdef), byref(hmin), byref(hmax))
  54. G_debug(1, "Nviz::SetViewDefault(): hdef=%f, hmin=%f, hmax=%f",
  55. hdef, hmin, hmax)
  56. return (z_exag, hdef.value, hmin.value, hmax.value)
  57. #!
  58. # \brief Change view settings
  59. #
  60. # \param x,y position
  61. # \param height
  62. # \param persp perpective
  63. # \param twist
  64. #
  65. # \return 1 on success
  66. def SetView(self, x, y, height, persp, twist):
  67. Nviz_set_viewpoint_height(self.data, height)
  68. Nviz_set_viewpoint_position(self.data, x, y)
  69. Nviz_set_viewpoint_twist(self.data, twist)
  70. Nviz_set_viewpoint_persp(self.data, persp)
  71. G_debug(1, "Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
  72. x, y, height, persp, twist)
  73. return 1
  74. #!
  75. # \brief Set z-exag value
  76. #
  77. # \param z_exag value
  78. #
  79. # \return 1
  80. def SetZExag(self, z_exag):
  81. G_debug(1, "Nviz::SetZExag(): z_exag=%f", z_exag)
  82. return Nviz_change_exag(self.data, z_exag)
  83. #!
  84. # \brief Draw map
  85. #
  86. # Draw quick mode:
  87. # - DRAW_QUICK_SURFACE
  88. # - DRAW_QUICK_VLINES
  89. # - DRAW_QUICK_VPOINTS
  90. # - DRAW_QUICK_VOLUME
  91. #
  92. # \param quick if true draw in wiremode
  93. # \param quick_mode quick mode
  94. def Draw(self, quick, quick_mode):
  95. Nviz_draw_cplane(self.data, -1, -1) # ?
  96. if quick:
  97. Nviz_draw_quick(self.data, quick_mode)
  98. else:
  99. Nviz_draw_all(self.data)
  100. G_debug(1, "Nviz::Draw(): quick=%d", quick)
  101. #!
  102. # \brief Erase map display (with background color)
  103. def EraseMap(self):
  104. GS_clear(self.data.bgcolor)
  105. G_debug(1, "Nviz::EraseMap()")
  106. def InitView(self):
  107. # initialize nviz data
  108. Nviz_init_data(self.data)
  109. # define default attributes for map objects
  110. Nviz_set_surface_attr_default()
  111. # set background color
  112. Nviz_set_bgcolor(self.data, Nviz_color_from_str("white")) # TODO
  113. # initialize view
  114. Nviz_init_view()
  115. # set default lighting model
  116. self.SetLightsDefault()
  117. # clear window
  118. GS_clear(self.data.bgcolor)
  119. G_debug(1, "Nviz::InitView()")
  120. #!
  121. # \brief Set background color
  122. #
  123. # \param color_str color string
  124. def SetBgColor(self, color_str):
  125. self.data.bgcolor = Nviz_color_from_str(color_str)
  126. #!
  127. # \brief Set default lighting model
  128. def SetLightsDefault(self):
  129. # first
  130. Nviz_set_light_position(self.data, 0, 0.68, -0.68, 0.80, 0.0)
  131. Nviz_set_light_bright(self.data, 0, 0.8)
  132. Nviz_set_light_color(self.data, 0, 1.0, 1.0, 1.0)
  133. Nviz_set_light_ambient(self.data, 0, 0.2, 0.2, 0.2)
  134. # second
  135. Nviz_set_light_position(self.data, 1, 0.0, 0.0, 1.0, 0.0)
  136. Nviz_set_light_bright(self.data, 1, 0.5)
  137. Nviz_set_light_color(self.data, 1, 1.0, 1.0, 1.0)
  138. Nviz_set_light_ambient(self.data, 1, 0.3, 0.3, 0.3)
  139. G_debug(1, "Nviz::SetLightsDefault()")
  140. #!
  141. # \brief Load raster map (surface)
  142. #
  143. # \param name raster map name
  144. # \param color_name raster map for color (NULL for color_value)
  145. # \param color_value color string (named color or RGB triptet)
  146. #
  147. # \return object id
  148. # \return -1 on failure
  149. def LoadSurface(self, name, color_name, color_value):
  150. mapset = G_find_raster2(name, "")
  151. if mapset is None:
  152. G_warning(_("Raster map <%s> not found"), name)
  153. return -1
  154. # topography
  155. id = Nviz_new_map_obj(MAP_OBJ_SURF,
  156. G_fully_qualified_name(name, mapset), 0.0,
  157. self.data)
  158. if color_name: # check for color map
  159. mapset = G_find_raster2(color_name, "")
  160. if mapset is None:
  161. G_warning(_("Raster map <%s> not found"), color_name)
  162. GS_delete_surface(id)
  163. return -1
  164. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  165. G_fully_qualified_name(color_name, mapset), -1.0,
  166. self.data)
  167. elif color_value: # check for color value
  168. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
  169. None, Nviz_color_from_str(color_value),
  170. self.data)
  171. else: # use by default elevation map for coloring
  172. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  173. G_fully_qualified_name(name, mapset), -1.0,
  174. self.data)
  175. # if (i > 1)
  176. # set_default_wirecolors(self.data, i)
  177. # focus on loaded self.data
  178. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
  179. G_debug(1, "Nviz::LoadRaster(): name=%s -> id=%d", name, id)
  180. return id
  181. #!
  182. # \brief Unload surface
  183. #
  184. # \param id surface id
  185. #
  186. # \return 1 on success
  187. # \return 0 on failure
  188. def UnloadSurface(self, id):
  189. if not GS_surf_exists(id):
  190. return 0
  191. G_debug(1, "Nviz::UnloadSurface(): id=%d", id)
  192. if GS_delete_surface(id) < 0:
  193. return 0
  194. return 1
  195. #!
  196. # \brief Load vector map overlay
  197. #
  198. # \param name vector map name
  199. # \param points if true load 2d points rather then 2d lines
  200. #
  201. # \return object id
  202. # \return -1 on failure
  203. def LoadVector(self, name, points):
  204. if GS_num_surfs() == 0: # load base surface if no loaded
  205. Nviz_new_map_obj(MAP_OBJ_SURF, NULL, 0.0, self.data)
  206. nsurf = c_int()
  207. surf_list = GS_get_surf_list(byref(nsurf))
  208. GS_set_att_const(surf_list[0], ATT_TRANSP, 255)
  209. mapset = G_find_vector2 (name, "")
  210. if mapset is None:
  211. G_warning(_("Vector map <%s> not found"),
  212. name)
  213. if points:
  214. id = Nviz_new_map_obj(MAP_OBJ_SITE,
  215. G_fully_qualified_name(name, mapset), 0.0,
  216. self.data)
  217. else:
  218. id = Nviz_new_map_obj(MAP_OBJ_VECT,
  219. G_fully_qualified_name(name, mapset), 0.0,
  220. self.data)
  221. G_debug(1, "Nviz::LoadVector(): name=%s -> id=%d", name, id)
  222. return id
  223. #!
  224. # \brief Unload vector set
  225. #
  226. # \param id vector set id
  227. # \param points vector points or lines set
  228. #
  229. # \return 1 on success
  230. # \return 0 on failure
  231. def UnloadVector(self, id, points):
  232. G_debug(1, "Nviz::UnloadVector(): id=%d", id)
  233. if points:
  234. if not GP_site_exists(id):
  235. return 0
  236. if GP_delete_site(id) < 0:
  237. return 0
  238. else:
  239. if not GV_vect_exists(id):
  240. return 0
  241. if GV_delete_vector(id) < 0:
  242. return 0
  243. return 1
  244. #!
  245. # \brief Load 3d raster map (volume)
  246. #
  247. # \param name 3d raster map name
  248. # \param color_name 3d raster map for color (NULL for color_value)
  249. # \param color_value color string (named color or RGB triptet)
  250. #
  251. # \return object id
  252. # \return -1 on failure
  253. def LoadVolume(self, name, color_name, color_value):
  254. mapset = G_find_grid3(name, "")
  255. if mapset is None:
  256. G_warning(_("3d raster map <%s> not found"),
  257. name)
  258. return -1
  259. # topography
  260. id = Nviz_new_map_obj(MAP_OBJ_VOL,
  261. G_fully_qualified_name(name, mapset), 0.0,
  262. self.data)
  263. if color_name: # check for color map
  264. mapset = G_find_grid3(color_name, "")
  265. if mapset is None:
  266. G_warning(_("3d raster map <%s> not found"),
  267. color_name)
  268. GVL_delete_vol(id)
  269. return -1
  270. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
  271. G_fully_qualified_name(color_name, mapset), -1.0,
  272. self.data)
  273. elif color_value: # check for color value
  274. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, CONST_ATT,
  275. NULL, Nviz_color_from_str(color_value),
  276. self.data)
  277. else: # use by default elevation map for coloring
  278. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
  279. G_fully_qualified_name(name, mapset), -1.0,
  280. self.data)
  281. G_debug(1, "Nviz::LoadVolume(): name=%s -> id=%d", name, id)
  282. return id
  283. #!
  284. # \brief Unload volume
  285. #
  286. # \param id volume id
  287. #
  288. # \return 1 on success
  289. # \return 0 on failure
  290. def UnloadVolume(self, id):
  291. if not GVL_vol_exists(id):
  292. return 0
  293. G_debug(1, "Nviz::UnloadVolume(): id=%d", id)
  294. if GVL_delete_vol(id) < 0:
  295. return 0
  296. return 1
  297. #!
  298. # \brief Set surface topography
  299. #
  300. # \param id surface id
  301. # \param map if true use map otherwise constant
  302. # \param value map name of value
  303. #
  304. # \return 1 on success
  305. # \return -1 surface not found
  306. # \return -2 setting attributes failed
  307. def SetSurfaceTopo(self, id, map, value):
  308. return self.SetSurfaceAttr(id, ATT_TOPO, map, value)
  309. #!
  310. # \brief Set surface color
  311. #
  312. # \param id surface id
  313. # \param map if true use map otherwise constant
  314. # \param value map name of value
  315. #
  316. # \return 1 on success
  317. # \return -1 surface not found
  318. # \return -2 setting attributes failed
  319. def SetSurfaceColor(self, id, map, value):
  320. return self.SetSurfaceAttr(id, ATT_COLOR, map, value)
  321. #!
  322. # \brief Set surface mask
  323. #
  324. # @todo invert
  325. #
  326. # \param id surface id
  327. # \param invert if true invert mask
  328. # \param value map name of value
  329. #
  330. # \return 1 on success
  331. # \return -1 surface not found
  332. # \return -2 setting attributes failed
  333. def SetSurfaceMask(self, id, invert, value):
  334. return self.SetSurfaceAttr(id, ATT_MASK, true, value)
  335. #!
  336. # \brief Set surface mask
  337. #
  338. # @todo invert
  339. #
  340. # \param id surface id
  341. # \param map if true use map otherwise constant
  342. # \param value map name of value
  343. #
  344. # \return 1 on success
  345. # \return -1 surface not found
  346. # \return -2 setting attributes failed
  347. def SetSurfaceTransp(self, id, map, value):
  348. return self.SetSurfaceAttr(id, ATT_TRANSP, map, value)
  349. #!
  350. # \brief Set surface shininess
  351. #
  352. # \param id surface id
  353. # \param map if true use map otherwise constant
  354. # \param value map name of value
  355. #
  356. # \return 1 on success
  357. # \return -1 surface not found
  358. # \return -2 setting attributes failed
  359. def SetSurfaceShine(self, id, map, value):
  360. return self.SetSurfaceAttr(id, ATT_SHINE, map, value)
  361. #!
  362. # \brief Set surface emission
  363. #
  364. # \param id surface id
  365. # \param map if true use map otherwise constant
  366. # \param value map name of value
  367. #
  368. # \return 1 on success
  369. # \return -1 surface not found
  370. # \return -2 setting attributes failed
  371. def SetSurfaceEmit(self, id, map, value):
  372. return self.SetSurfaceAttr(id, ATT_EMIT, map, value)
  373. #!
  374. # \brief Set surface attribute
  375. #
  376. # \param id surface id
  377. # \param attr attribute desc
  378. # \param map if true use map otherwise constant
  379. # \param value map name of value
  380. #
  381. # \return 1 on success
  382. # \return -1 surface not found
  383. # \return -2 setting attributes failed
  384. def SetSurfaceAttr(self, id, attr, map, value):
  385. if not GS_surf_exists(id):
  386. return -1
  387. if map:
  388. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
  389. value, -1.0, self.data)
  390. else:
  391. if attr == ATT_COLOR:
  392. val = Nviz_color_from_str(value)
  393. else:
  394. val = atof(value)
  395. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, CONST_ATT,
  396. NULL, val, self.data)
  397. G_debug(1, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
  398. id, attr, map, value)
  399. return 1 if ret else -2
  400. #!
  401. # \brief Unset surface mask
  402. #
  403. # \param id surface id
  404. #
  405. # \return 1 on success
  406. # \return -1 surface not found
  407. # \return -2 setting attributes failed
  408. # \return -1 on failure
  409. def UnsetSurfaceMask(self, id):
  410. return self.UnsetSurfaceAttr(id, ATT_MASK)
  411. #!
  412. # \brief Unset surface transparency
  413. #
  414. # \param id surface id
  415. #
  416. # \return 1 on success
  417. # \return -1 surface not found
  418. # \return -2 setting attributes failed
  419. def UnsetSurfaceTransp(self, id):
  420. return self.UnsetSurfaceAttr(id, ATT_TRANSP)
  421. #!
  422. # \brief Unset surface emission
  423. #
  424. # \param id surface id
  425. #
  426. # \return 1 on success
  427. # \return -1 surface not found
  428. # \return -2 setting attributes failed
  429. def UnsetSurfaceEmit(self, id):
  430. return self.UnsetSurfaceAttr(id, ATT_EMIT)
  431. #!
  432. # \brief Unset surface attribute
  433. #
  434. # \param id surface id
  435. # \param attr attribute descriptor
  436. #
  437. # \return 1 on success
  438. # \return -1 surface not found
  439. # \return -2 setting attributes failed
  440. def UnsetSurfaceAttr(self, id, attr):
  441. if not GS_surf_exists(id):
  442. return -1
  443. G_debug(1, "Nviz::UnsetSurfaceAttr(): id=%d, attr=%d",
  444. id, attr)
  445. ret = Nviz_unset_attr(id, MAP_OBJ_SURF, attr)
  446. return 1 if ret else -2
  447. #!
  448. # \brief Set surface resolution
  449. #
  450. # \param id surface id
  451. # \param fine x/y fine resolution
  452. # \param coarse x/y coarse resolution
  453. #
  454. # \return 1 on success
  455. # \return -1 surface not found
  456. # \return -2 setting attributes failed
  457. def SetSurfaceRes(self, id, fine, coarse):
  458. G_debug(1, "Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%d",
  459. id, fine, coarse)
  460. if id > 0:
  461. if not GS_surf_exists(id):
  462. return -1
  463. if GS_set_drawres(id, fine, fine, coarse, coarse) < 0:
  464. return -2
  465. else:
  466. GS_setall_drawres(fine, fine, coarse, coarse)
  467. return 1
  468. #!
  469. # \brief Set draw style
  470. #
  471. # Draw styles:
  472. # - DM_GOURAUD
  473. # - DM_FLAT
  474. # - DM_FRINGE
  475. # - DM_WIRE
  476. # - DM_COL_WIRE
  477. # - DM_POLY
  478. # - DM_WIRE_POLY
  479. # - DM_GRID_WIRE
  480. # - DM_GRID_SURF
  481. #
  482. # \param id surface id (<= 0 for all)
  483. # \param style draw style
  484. #
  485. # \return 1 on success
  486. # \return -1 surface not found
  487. # \return -2 setting attributes failed
  488. def SetSurfaceStyle(self, id, style):
  489. G_debug(1, "Nviz::SetSurfaceStyle(): id=%d, style=%d",
  490. id, style)
  491. if id > 0:
  492. if not GS_surf_exists(id):
  493. return -1
  494. if GS_set_drawmode(id, style) < 0:
  495. return -2
  496. return 1
  497. if GS_setall_drawmode(style) < 0:
  498. return -2
  499. return 1
  500. #!
  501. # \brief Set color of wire
  502. #
  503. # \todo all
  504. #
  505. # \param surface id (< 0 for all)
  506. # \param color color string (R:G:B)
  507. #
  508. # \return 1 on success
  509. # \return -1 surface not found
  510. # \return -2 setting attributes failed
  511. # \return 1 on success
  512. # \return 0 on failure
  513. def SetWireColor(self, id, color_str):
  514. G_debug(1, "Nviz::SetWireColor(): id=%d, color=%s",
  515. id, color_str)
  516. color = Nviz_color_from_str(color_str)
  517. if id > 0:
  518. if not GS_surf_exists(id):
  519. return -1
  520. GS_set_wire_color(id, color)
  521. else:
  522. nsurfs = c_int()
  523. surf_list = GS_get_surf_list(byref(nsurfs))
  524. for i in xrange(nsurfs.value):
  525. id = surf_list[i]
  526. GS_set_wire_color(id, color)
  527. G_free(surf_list)
  528. surf_list = None
  529. return 1
  530. #!
  531. # \brief Get surface position
  532. #
  533. # \param id surface id
  534. #
  535. # \return x,y,z
  536. # \return zero-length vector on error
  537. def GetSurfacePosition(self, id):
  538. if not GS_surf_exists(id):
  539. return []
  540. x, y, z = c_float(), c_float(), c_float()
  541. GS_get_trans(id, byref(x), byref(y), byref(z))
  542. G_debug(1, "Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
  543. id, x, y, z)
  544. return [x.value, y.value, z.value]
  545. #!
  546. # \brief Set surface position
  547. #
  548. # \param id surface id
  549. # \param x,y,z translation values
  550. #
  551. # \return 1 on success
  552. # \return -1 surface not found
  553. # \return -2 setting position failed
  554. def SetSurfacePosition(self, id, x, y, z):
  555. if not GS_surf_exists(id):
  556. return -1
  557. G_debug(1, "Nviz::SetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
  558. id, x, y, z)
  559. GS_set_trans(id, x, y, z)
  560. return 1
  561. #!
  562. # \brief Set mode of vector line overlay
  563. #
  564. # \param id vector id
  565. # \param color_str color string
  566. # \param width line width
  567. # \param flat display flat or on surface
  568. #
  569. # \return -1 vector set not found
  570. # \return -2 on failure
  571. # \return 1 on success
  572. def SetVectorLineMode(self, id, color_str, width, flat):
  573. if not GV_vect_exists(id):
  574. return -1
  575. G_debug(1, "Nviz::SetVectorMode(): id=%d, color=%s, width=%d, flat=%d",
  576. id, color_str, width, flat)
  577. color = Nviz_color_from_str(color_str)
  578. # use memory by default
  579. if GV_set_vectmode(id, 1, color, width, flat) < 0:
  580. return -2
  581. return 1
  582. #!
  583. # \brief Set vector height above surface (lines)
  584. #
  585. # \param id vector set id
  586. # \param height
  587. #
  588. # \return -1 vector set not found
  589. # \return 1 on success
  590. def SetVectorLineHeight(self, id, height):
  591. if not GV_vect_exists(id):
  592. return -1
  593. G_debug(1, "Nviz::SetVectorLineHeight(): id=%d, height=%f",
  594. id, height)
  595. GV_set_trans(id, 0.0, 0.0, height)
  596. return 1
  597. #!
  598. # \brief Set reference surface of vector set (lines)
  599. #
  600. # \param id vector set id
  601. # \param surf_id surface id
  602. #
  603. # \return 1 on success
  604. # \return -1 vector set not found
  605. # \return -2 surface not found
  606. # \return -3 on failure
  607. def SetVectorLineSurface(self, id, surf_id):
  608. if not GV_vect_exists(id):
  609. return -1
  610. if not GS_surf_exists(surf_id):
  611. return -2
  612. if GV_select_surf(id, surf_id) < 0:
  613. return -3
  614. return 1
  615. #!
  616. # \brief Set mode of vector point overlay
  617. #
  618. # \param id vector id
  619. # \param color_str color string
  620. # \param width line width
  621. # \param flat
  622. #
  623. # \return -1 vector set not found
  624. def SetVectorPointMode(self, id, color_str, width, size, marker):
  625. if not GP_site_exists(id):
  626. return -1
  627. G_debug(1, "Nviz::SetVectorPointMode(): id=%d, color=%s, "
  628. "width=%d, size=%f, marker=%d",
  629. id, color_str, width, size, marker)
  630. color = Nviz_color_from_str(color_str)
  631. if GP_set_style(id, color, width, size, marker) < 0:
  632. return -2
  633. return 1
  634. #!
  635. # \brief Set vector height above surface (points)
  636. #
  637. # \param id vector set id
  638. # \param height
  639. #
  640. # \return -1 vector set not found
  641. # \return 1 on success
  642. def SetVectorPointHeight(self, id, height):
  643. if not GP_site_exists(id):
  644. return -1
  645. G_debug(1, "Nviz::SetVectorPointHeight(): id=%d, height=%f",
  646. id, height)
  647. GP_set_trans(id, 0.0, 0.0, height)
  648. return 1
  649. #!
  650. # \brief Set reference surface of vector set (points)
  651. #
  652. # \param id vector set id
  653. # \param surf_id surface id
  654. #
  655. # \return 1 on success
  656. # \return -1 vector set not found
  657. # \return -2 surface not found
  658. # \return -3 on failure
  659. def SetVectorPointSurface(self, id, surf_id):
  660. if not GP_site_exists(id):
  661. return -1
  662. if not GS_surf_exists(surf_id):
  663. return -2
  664. if GP_select_surf(id, surf_id) < 0:
  665. return -3
  666. return 1
  667. #!
  668. # \brief Add new isosurface
  669. #
  670. # \param id volume id
  671. # \param level isosurface level (topography)
  672. #
  673. # \return -1 on failure
  674. # \return 1 on success
  675. def AddIsosurface(self, id, level):
  676. if not GVL_vol_exists(id):
  677. return -1
  678. if GVL_isosurf_add(id) < 0:
  679. return -1
  680. # set topography level
  681. nisosurfs = GVL_isosurf_num_isosurfs(id)
  682. return GVL_isosurf_set_att_const(id, nisosurfs - 1, ATT_TOPO, level)
  683. #!
  684. # \brief Delete isosurface
  685. #
  686. # \param id volume id
  687. # \param isosurf_id isosurface id
  688. #
  689. # \return 1 on success
  690. # \return -1 volume not found
  691. # \return -2 isosurface not found
  692. # \return -3 on failure
  693. def DeleteIsosurface(self, id, isosurf_id):
  694. if not GVL_vol_exists(id):
  695. return -1
  696. if isosurf_id > GVL_isosurf_num_isosurfs(id):
  697. return -2
  698. ret = GVL_isosurf_del(id, isosurf_id)
  699. return -3 if ret < 0 else 1
  700. #!
  701. # \brief Move isosurface up/down in the list
  702. #
  703. # \param id volume id
  704. # \param isosurf_id isosurface id
  705. # \param up if true move up otherwise down
  706. #
  707. # \return 1 on success
  708. # \return -1 volume not found
  709. # \return -2 isosurface not found
  710. # \return -3 on failure
  711. def MoveIsosurface(self, id, isosurf_id, up):
  712. if not GVL_vol_exists(id):
  713. return -1
  714. if isosurf_id > GVL_isosurf_num_isosurfs(id):
  715. return -2
  716. if up:
  717. ret = GVL_isosurf_move_up(id, isosurf_id)
  718. else:
  719. ret = GVL_isosurf_move_down(id, isosurf_id)
  720. return -3 if ret < 0 else 1
  721. #!
  722. # \brief Set isosurface color
  723. #
  724. # \param id volume id
  725. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  726. # \param map if true use map otherwise constant
  727. # \param value map name of value
  728. #
  729. # \return 1 on success
  730. # \return -1 volume not found
  731. # \return -2 isosurface not found
  732. # \return -3 on failure
  733. def SetIsosurfaceColor(self, id, isosurf_id, map, value):
  734. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_COLOR, map, value)
  735. #!
  736. # \brief Set isosurface mask
  737. #
  738. # @todo invert
  739. #
  740. # \param id volume id
  741. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  742. # \param invert true for invert mask
  743. # \param value map name to be used for mask
  744. #
  745. # \return 1 on success
  746. # \return -1 volume not found
  747. # \return -2 isosurface not found
  748. # \return -3 on failure
  749. def SetIsosurfaceMask(self, id, isosurf_id, invert, value):
  750. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_MASK, true, value)
  751. #!
  752. # \brief Set isosurface transparency
  753. #
  754. # \param id volume id
  755. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  756. # \param map if true use map otherwise constant
  757. # \param value map name of value
  758. #
  759. # \return 1 on success
  760. # \return -1 volume not found
  761. # \return -2 isosurface not found
  762. # \return -3 on failure
  763. def SetIsosurfaceTransp(self, id, isosurf_id, map, value):
  764. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP, map, value)
  765. #!
  766. # \brief Set isosurface shininess
  767. #
  768. # \param id volume id
  769. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  770. # \param map if true use map otherwise constant
  771. # \param value map name of value
  772. #
  773. # \return 1 on success
  774. # \return -1 volume not found
  775. # \return -2 isosurface not found
  776. # \return -3 on failure
  777. def SetIsosurfaceShine(self, id, isosurf_id, map, value):
  778. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_SHINE, map, value)
  779. #!
  780. # \brief Set isosurface emission
  781. #
  782. # \param id volume id
  783. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  784. # \param map if true use map otherwise constant
  785. # \param value map name of value
  786. #
  787. # \return 1 on success
  788. # \return -1 volume not found
  789. # \return -2 isosurface not found
  790. # \return -3 on failure
  791. def SetIsosurfaceEmit(self, id, isosurf_id, map, value):
  792. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_EMIT, map, value)
  793. #!
  794. # \brief Set isosurface attribute
  795. #
  796. # \param id volume id
  797. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  798. # \param attr attribute desc
  799. # \param map if true use map otherwise constant
  800. # \param value map name of value
  801. #
  802. # \return 1 on success
  803. # \return -1 volume not found
  804. # \return -2 isosurface not found
  805. # \return -3 setting attributes failed
  806. def SetIsosurfaceAttr(self, id, isosurf_id, attr, map, value):
  807. if not GVL_vol_exists(id):
  808. return -1
  809. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  810. return -2
  811. if map:
  812. ret = GVL_isosurf_set_att_map(id, isosurf_id, attr, value)
  813. else:
  814. if attr == ATT_COLOR:
  815. val = Nviz_color_from_str(value)
  816. else:
  817. val = float(value)
  818. ret = GVL_isosurf_set_att_const(id, isosurf_id, attr, val)
  819. G_debug(1, "Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
  820. "attr=%d, map=%d, value=%s",
  821. id, isosurf_id, attr, map, value)
  822. return 1 if ret > 0 else -2
  823. #!
  824. # \brief Unset isosurface mask
  825. #
  826. # \param id volume id
  827. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  828. #
  829. # \return 1 on success
  830. # \return -1 volume not found
  831. # \return -2 isosurface not found
  832. # \return -3 setting attributes failed
  833. def UnsetIsosurfaceMask(self, id, isosurf_id):
  834. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_MASK)
  835. #!
  836. # \brief Unset isosurface transparency
  837. #
  838. # \param id volume id
  839. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  840. #
  841. # \return 1 on success
  842. # \return -1 volume not found
  843. # \return -2 isosurface not found
  844. # \return -3 setting attributes failed
  845. def UnsetIsosurfaceTransp(self, id, isosurf_id):
  846. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP)
  847. #!
  848. # \brief Unset isosurface emission
  849. #
  850. # \param id volume id
  851. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  852. #
  853. # \return 1 on success
  854. # \return -1 volume not found
  855. # \return -2 isosurface not found
  856. # \return -3 setting attributes failed
  857. def UnsetIsosurfaceEmit(self, id, isosurf_id):
  858. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_EMIT)
  859. #!
  860. # \brief Unset surface attribute
  861. #
  862. # \param id surface id
  863. # \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  864. # \param attr attribute descriptor
  865. #
  866. # \return 1 on success
  867. # \return -1 volume not found
  868. # \return -2 isosurface not found
  869. # \return -2 on failure
  870. def UnsetIsosurfaceAttr(self, id, isosurf_id, attr):
  871. if not GVL_vol_exists(id):
  872. return -1
  873. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  874. return -2
  875. G_debug(1, "Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%d",
  876. id, isosurf_id, attr)
  877. ret = GVL_isosurf_unset_att(id, isosurf_id, attr)
  878. return 1 if ret > 0 else -2
  879. #!
  880. # \brief Set draw mode for isosurfaces
  881. #
  882. # \param mode
  883. #
  884. # \return 1 on success
  885. # \return -1 volume set not found
  886. # \return -2 on failure
  887. def SetIsosurfaceMode(self, id, mode):
  888. if not GVL_vol_exists(id):
  889. return -1
  890. ret = GVL_isosurf_set_drawmode(id, mode)
  891. return -2 if ret < 0 else 1
  892. #!
  893. # \brief Set draw resolution for isosurfaces
  894. #
  895. # \param res resolution value
  896. #
  897. # \return 1 on success
  898. # \return -1 volume set not found
  899. # \return -2 on failure
  900. def SetIsosurfaceRes(self, id, res):
  901. if not GVL_vol_exists(id):
  902. return -1
  903. ret = GVL_isosurf_set_drawres(id, res, res, res)
  904. return -2 if ret < 0 else 1