wxnviz.py 32 KB

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