wxnviz.py 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. """!
  2. @package wxnviz.py
  3. @brief wxGUI 3D view mode
  4. This module implements 3D visualization mode for map display (ctypes
  5. required).
  6. List of classes:
  7. - Nviz
  8. (C) 2008-2011 by the GRASS Development Team
  9. This program is free software under the GNU General Public
  10. License (>=v2). Read the file COPYING that comes with GRASS
  11. for details.
  12. @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  13. @author Pythonized by Glynn Clements
  14. @author Anna Kratochvilova <KratochAnna seznam.cz> (Google SoC 2011)
  15. """
  16. import sys
  17. from threading import Thread
  18. from ctypes import *
  19. from grass.lib.gis import *
  20. from grass.lib.g3d import *
  21. from grass.lib.ogsf import *
  22. from grass.lib.nviz import *
  23. from debug import Debug
  24. log = None
  25. progress = None
  26. def print_error(msg, type):
  27. """!Redirect stderr"""
  28. global log
  29. if log:
  30. log.write(msg)
  31. else:
  32. print msg
  33. return 0
  34. def print_progress(value):
  35. """!Redirect progress info"""
  36. global progress
  37. if progress:
  38. progress.SetValue(value)
  39. else:
  40. print value
  41. return 0
  42. errtype = CFUNCTYPE(UNCHECKED(c_int), String, c_int)
  43. errfunc = errtype(print_error)
  44. pertype = CFUNCTYPE(UNCHECKED(c_int), c_int)
  45. perfunc = pertype(print_progress)
  46. class Nviz(object):
  47. def __init__(self, glog, gprogress):
  48. """!Initialize Nviz class instance
  49. @param log logging area
  50. @param gprogress progressbar
  51. """
  52. global errfunc, perfunc, log, progress
  53. log = glog
  54. progress = gprogress
  55. G_gisinit("")
  56. G_set_error_routine(errfunc)
  57. G_set_percent_routine(perfunc)
  58. G_unset_window()
  59. GS_libinit()
  60. GVL_libinit()
  61. self.data_obj = nv_data()
  62. self.data = pointer(self.data_obj)
  63. self.width = self.height = -1
  64. self.showLight = False
  65. Debug.msg(1, "Nviz::Nviz()")
  66. def __del__(self):
  67. """!Destroy Nviz class instance"""
  68. G_unset_error_routine()
  69. G_unset_percent_routine()
  70. del self.data
  71. del self.data_obj
  72. self.log = None
  73. def ResizeWindow(self, width, height):
  74. """!GL canvas resized
  75. @param width window width
  76. @param height window height
  77. @return 1 on success
  78. @return 0 on failure (window resized by default to 20x20 px)
  79. """
  80. self.width = width
  81. self.height = height
  82. Debug.msg(3, "Nviz::ResizeWindow(): width=%d height=%d",
  83. width, height)
  84. return Nviz_resize_window(width, height)
  85. def GetLongDim(self):
  86. """!Get longest dimension, used for initial size of north arrow"""
  87. return Nviz_get_longdim(self.data)
  88. def SetViewDefault(self):
  89. """!Set default view (based on loaded data)
  90. @return z-exag value, default, min and max height
  91. """
  92. # determine z-exag
  93. z_exag = Nviz_get_exag()
  94. Nviz_change_exag(self.data, z_exag)
  95. # determine height
  96. hdef = c_double()
  97. hmin = c_double()
  98. hmax = c_double()
  99. Nviz_get_exag_height(byref(hdef), byref(hmin), byref(hmax))
  100. Debug.msg(1, "Nviz::SetViewDefault(): hdef=%f, hmin=%f, hmax=%f",
  101. hdef.value, hmin.value, hmax.value)
  102. return (z_exag, hdef.value, hmin.value, hmax.value)
  103. def SetView(self, x, y, height, persp, twist):
  104. """!Change view settings
  105. @param x,y position
  106. @param height
  107. @param persp perpective
  108. @param twist
  109. """
  110. Nviz_set_viewpoint_height(height)
  111. Nviz_set_viewpoint_position(x, y)
  112. Nviz_set_viewpoint_twist(twist)
  113. Nviz_set_viewpoint_persp(persp)
  114. Debug.msg(3, "Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
  115. x, y, height, persp, twist)
  116. def LookHere(self, x, y):
  117. """!Look here feature
  118. @param x,y screen coordinates
  119. """
  120. Nviz_look_here(x, y)
  121. Debug.msg(3, "Nviz::LookHere(): x=%f, y=%f", x, y)
  122. def LookAtCenter(self):
  123. """!Center view at center of displayed surface"""
  124. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
  125. Debug.msg(3, "Nviz::LookAtCenter()")
  126. def GetFocus(self):
  127. """!Get focus"""
  128. Debug.msg(3, "Nviz::GetFocus()")
  129. if Nviz_has_focus(self.data):
  130. x = c_float()
  131. y = c_float()
  132. z = c_float()
  133. Nviz_get_focus(self.data, byref(x), byref(y), byref(z))
  134. return x.value, y.value, z.value
  135. else:
  136. return -1, -1, -1
  137. def SetFocus(self, x, y, z):
  138. """!Set focus"""
  139. Debug.msg(3, "Nviz::SetFocus()")
  140. Nviz_set_focus(self.data, x, y, z)
  141. def SetZExag(self, z_exag):
  142. """!Set z-exag value
  143. @param z_exag value
  144. @return 1
  145. """
  146. Debug.msg(3, "Nviz::SetZExag(): z_exag=%f", z_exag)
  147. return Nviz_change_exag(self.data, z_exag)
  148. def Draw(self, quick, quick_mode):
  149. """!Draw canvas
  150. Draw quick mode:
  151. - DRAW_QUICK_SURFACE
  152. - DRAW_QUICK_VLINES
  153. - DRAW_QUICK_VPOINTS
  154. - DRAW_QUICK_VOLUME
  155. @param quick if true draw in wiremode
  156. @param quick_mode quick mode
  157. """
  158. Debug.msg(3, "Nviz::Draw(): quick=%d", quick)
  159. Nviz_draw_cplane(self.data, -1, -1) # ?
  160. if quick:
  161. Nviz_draw_quick(self.data, quick_mode)
  162. else:
  163. Nviz_draw_all(self.data)
  164. def EraseMap(self):
  165. """!Erase map display (with background color)
  166. """
  167. Debug.msg(1, "Nviz::EraseMap()")
  168. GS_clear(Nviz_get_bgcolor(self.data))
  169. def InitView(self):
  170. """!Initialize view"""
  171. # initialize nviz data
  172. Nviz_init_data(self.data)
  173. # define default attributes for map objects
  174. Nviz_set_surface_attr_default()
  175. # set background color
  176. Nviz_set_bgcolor(self.data, Nviz_color_from_str("white"))
  177. GS_clear(Nviz_get_bgcolor(self.data))
  178. # initialize view, lights
  179. Nviz_init_view(self.data)
  180. Debug.msg(1, "Nviz::InitView()")
  181. def SetBgColor(self, color_str):
  182. """!Set background color
  183. @param color_str color string
  184. """
  185. Nviz_set_bgcolor(self.data, Nviz_color_from_str(color_str))
  186. def SetLight(self, x, y, z, color, bright, ambient, w = 0, lid = 1):
  187. """!Change lighting settings
  188. @param x,y,z position
  189. @param color light color (as string)
  190. @param bright light brightness
  191. @param ambient light ambient
  192. @param w local coordinate (default to 0)
  193. """
  194. Nviz_set_light_position(self.data, lid, x, y, z, w)
  195. Nviz_set_light_bright(self.data, lid, bright)
  196. Nviz_set_light_color(self.data, lid, int(color[0]), int(color[1]), int(color[2]))
  197. Nviz_set_light_ambient(self.data, lid, ambient)
  198. def LoadSurface(self, name, color_name, color_value):
  199. """!Load raster map (surface)
  200. @param name raster map name
  201. @param color_name raster map for color (None for color_value)
  202. @param color_value color string (named color or RGB triptet)
  203. @return object id
  204. @return -1 on failure
  205. """
  206. mapset = G_find_raster2(name, "")
  207. if mapset is None:
  208. G_warning(_("Raster map <%s> not found"), name)
  209. return -1
  210. # topography
  211. id = Nviz_new_map_obj(MAP_OBJ_SURF,
  212. G_fully_qualified_name(name, mapset), 0.0,
  213. self.data)
  214. if color_name: # check for color map
  215. mapset = G_find_raster2(color_name, "")
  216. if mapset is None:
  217. G_warning(_("Raster map <%s> not found"), color_name)
  218. GS_delete_surface(id)
  219. return -1
  220. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  221. G_fully_qualified_name(color_name, mapset), -1.0,
  222. self.data)
  223. elif color_value: # check for color value
  224. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
  225. None, Nviz_color_from_str(color_value),
  226. self.data)
  227. else: # use by default elevation map for coloring
  228. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
  229. G_fully_qualified_name(name, mapset), -1.0,
  230. self.data)
  231. # if (i > 1)
  232. # set_default_wirecolors(self.data, i)
  233. # focus on loaded self.data
  234. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
  235. Debug.msg(1, "Nviz::LoadRaster(): name=%s -> id=%d", name, id)
  236. return id
  237. def AddConstant(self, value, color):
  238. """!Add new constant surface"""
  239. id = Nviz_new_map_obj(MAP_OBJ_SURF, None, value, self.data)
  240. Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
  241. None, Nviz_color_from_str(color),
  242. self.data)
  243. Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
  244. Debug.msg(1, "Nviz::AddConstant(): id=%d", id)
  245. return id
  246. def UnloadSurface(self, id):
  247. """!Unload surface
  248. @param id surface id
  249. @return 1 on success
  250. @return 0 on failure
  251. """
  252. if not GS_surf_exists(id):
  253. return 0
  254. Debug.msg(1, "Nviz::UnloadSurface(): id=%d", id)
  255. if GS_delete_surface(id) < 0:
  256. return 0
  257. return 1
  258. def LoadVector(self, name, points):
  259. """!Load vector map overlay
  260. @param name vector map name
  261. @param points if true load 2d points rather then 2d lines
  262. @return object id
  263. @return -1 on failure
  264. """
  265. if GS_num_surfs() == 0: # load base surface if no loaded
  266. Nviz_new_map_obj(MAP_OBJ_SURF, None, 0.0, self.data)
  267. nsurf = c_int()
  268. surf_list = GS_get_surf_list(byref(nsurf))
  269. GS_set_att_const(surf_list[0], ATT_TRANSP, 255)
  270. mapset = G_find_vector2 (name, "")
  271. if mapset is None:
  272. G_warning(_("Vector map <%s> not found"),
  273. name)
  274. if points:
  275. id = Nviz_new_map_obj(MAP_OBJ_SITE,
  276. G_fully_qualified_name(name, mapset), 0.0,
  277. self.data)
  278. else:
  279. id = Nviz_new_map_obj(MAP_OBJ_VECT,
  280. G_fully_qualified_name(name, mapset), 0.0,
  281. self.data)
  282. Debug.msg(1, "Nviz::LoadVector(): name=%s -> id=%d", name, id)
  283. return id
  284. def UnloadVector(self, id, points):
  285. """!Unload vector set
  286. @param id vector set id
  287. @param points vector points or lines set
  288. @return 1 on success
  289. @return 0 on failure
  290. """
  291. Debug.msg(1, "Nviz::UnloadVector(): id=%d", id)
  292. if points:
  293. if not GP_site_exists(id):
  294. return 0
  295. if GP_delete_site(id) < 0:
  296. return 0
  297. else:
  298. if not GV_vect_exists(id):
  299. return 0
  300. if GV_delete_vector(id) < 0:
  301. return 0
  302. return 1
  303. def VectorSurfaceSelected(self, vid, sid):
  304. """!Check if surface is selected (currently unused)
  305. @param vid vector id
  306. @param sid surface id
  307. @return True if selected
  308. @return False if not selected
  309. """
  310. selected = GV_surf_is_selected(vid, sid)
  311. Debug.msg(1, "Nviz::VectorSurfaceSelected(): vid=%s, sid=%d -> selected=%d", vid, sid, selected)
  312. return selected
  313. def LoadVolume(self, name, color_name, color_value):
  314. """!Load 3d raster map (volume)
  315. @param name 3d raster map name
  316. @param color_name 3d raster map for color (None for color_value)
  317. @param color_value color string (named color or RGB triptet)
  318. @return object id
  319. @return -1 on failure
  320. """
  321. mapset = G_find_grid3(name, "")
  322. if mapset is None:
  323. G_warning(_("3d raster map <%s> not found"),
  324. name)
  325. return -1
  326. # topography
  327. id = Nviz_new_map_obj(MAP_OBJ_VOL,
  328. G_fully_qualified_name(name, mapset), 0.0,
  329. self.data)
  330. if color_name: # check for color map
  331. mapset = G_find_grid3(color_name, "")
  332. if mapset is None:
  333. G_warning(_("3d raster map <%s> not found"),
  334. color_name)
  335. GVL_delete_vol(id)
  336. return -1
  337. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
  338. G_fully_qualified_name(color_name, mapset), -1.0,
  339. self.data)
  340. elif color_value: # check for color value
  341. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, CONST_ATT,
  342. None, Nviz_color_from_str(color_value),
  343. self.data)
  344. else: # use by default elevation map for coloring
  345. Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
  346. G_fully_qualified_name(name, mapset), -1.0,
  347. self.data)
  348. Debug.msg(1, "Nviz::LoadVolume(): name=%s -> id=%d", name, id)
  349. return id
  350. def UnloadVolume(self, id):
  351. """!Unload volume
  352. @param id volume id
  353. @return 1 on success
  354. @return 0 on failure
  355. """
  356. if not GVL_vol_exists(id):
  357. return 0
  358. Debug.msg(1, "Nviz::UnloadVolume(): id=%d", id)
  359. if GVL_delete_vol(id) < 0:
  360. return 0
  361. return 1
  362. def SetSurfaceTopo(self, id, map, value):
  363. """!Set surface topography
  364. @param id surface id
  365. @param map if true use map otherwise constant
  366. @param value map name of value
  367. @return 1 on success
  368. @return -1 surface not found
  369. @return -2 setting attributes failed
  370. """
  371. return self.SetSurfaceAttr(id, ATT_TOPO, map, value)
  372. def SetSurfaceColor(self, id, map, value):
  373. """!Set surface color
  374. @param id surface id
  375. @param map if true use map otherwise constant
  376. @param value map name or value
  377. @return 1 on success
  378. @return -1 surface not found
  379. @return -2 setting attributes failed
  380. """
  381. return self.SetSurfaceAttr(id, ATT_COLOR, map, value)
  382. def SetSurfaceMask(self, id, invert, value):
  383. """!Set surface mask
  384. @todo invert
  385. @param id surface id
  386. @param invert if true invert mask
  387. @param value map name of value
  388. @return 1 on success
  389. @return -1 surface not found
  390. @return -2 setting attributes failed
  391. """
  392. return self.SetSurfaceAttr(id, ATT_MASK, True, value)
  393. def SetSurfaceTransp(self, id, map, value):
  394. """!Set surface mask
  395. @todo invert
  396. @param id surface id
  397. @param map if true use map otherwise constant
  398. @param value map name of value
  399. @return 1 on success
  400. @return -1 surface not found
  401. @return -2 setting attributes failed
  402. """
  403. return self.SetSurfaceAttr(id, ATT_TRANSP, map, value)
  404. def SetSurfaceShine(self, id, map, value):
  405. """!Set surface shininess
  406. @param id surface id
  407. @param map if true use map otherwise constant
  408. @param value map name of value
  409. @return 1 on success
  410. @return -1 surface not found
  411. @return -2 setting attributes failed
  412. """
  413. return self.SetSurfaceAttr(id, ATT_SHINE, map, value)
  414. def SetSurfaceEmit(self, id, map, value):
  415. """!Set surface emission (currently unused)
  416. @param id surface id
  417. @param map if true use map otherwise constant
  418. @param value map name of value
  419. @return 1 on success
  420. @return -1 surface not found
  421. @return -2 setting attributes failed
  422. """
  423. return self.SetSurfaceAttr(id, ATT_EMIT, map, value)
  424. def SetSurfaceAttr(self, id, attr, map, value):
  425. """!Set surface attribute
  426. @param id surface id
  427. @param attr attribute desc
  428. @param map if true use map otherwise constant
  429. @param value map name of value
  430. @return 1 on success
  431. @return -1 surface not found
  432. @return -2 setting attributes failed
  433. """
  434. if not GS_surf_exists(id):
  435. return -1
  436. if map:
  437. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
  438. value, -1.0, self.data)
  439. else:
  440. if attr == ATT_COLOR:
  441. val = Nviz_color_from_str(value)
  442. else:
  443. val = float(value)
  444. ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, CONST_ATT,
  445. None, val, self.data)
  446. Debug.msg(3, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
  447. id, attr, map, value)
  448. if ret < 0:
  449. return -2
  450. return 1
  451. def UnsetSurfaceMask(self, id):
  452. """!Unset surface mask
  453. @param id surface id
  454. @return 1 on success
  455. @return -1 surface not found
  456. @return -2 setting attributes failed
  457. @return -1 on failure
  458. """
  459. return self.UnsetSurfaceAttr(id, ATT_MASK)
  460. def UnsetSurfaceTransp(self, id):
  461. """!Unset surface transparency
  462. @param id surface id
  463. @return 1 on success
  464. @return -1 surface not found
  465. @return -2 setting attributes failed
  466. """
  467. return self.UnsetSurfaceAttr(id, ATT_TRANSP)
  468. def UnsetSurfaceEmit(self, id):
  469. """!Unset surface emission (currently unused)
  470. @param id surface id
  471. @return 1 on success
  472. @return -1 surface not found
  473. @return -2 setting attributes failed
  474. """
  475. return self.UnsetSurfaceAttr(id, ATT_EMIT)
  476. def UnsetSurfaceAttr(self, id, attr):
  477. """!Unset surface attribute
  478. @param id surface id
  479. @param attr attribute descriptor
  480. @return 1 on success
  481. @return -1 surface not found
  482. @return -2 setting attributes failed
  483. """
  484. if not GS_surf_exists(id):
  485. return -1
  486. Debug.msg(3, "Nviz::UnsetSurfaceAttr(): id=%d, attr=%d",
  487. id, attr)
  488. ret = Nviz_unset_attr(id, MAP_OBJ_SURF, attr)
  489. if ret < 0:
  490. return -2
  491. return 1
  492. def SetSurfaceRes(self, id, fine, coarse):
  493. """!Set surface resolution
  494. @param id surface id
  495. @param fine x/y fine resolution
  496. @param coarse x/y coarse resolution
  497. @return 1 on success
  498. @return -1 surface not found
  499. @return -2 setting attributes failed
  500. """
  501. Debug.msg(3, "Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%d",
  502. id, fine, coarse)
  503. if id > 0:
  504. if not GS_surf_exists(id):
  505. return -1
  506. if GS_set_drawres(id, fine, fine, coarse, coarse) < 0:
  507. return -2
  508. else:
  509. GS_setall_drawres(fine, fine, coarse, coarse)
  510. return 1
  511. def SetSurfaceStyle(self, id, style):
  512. """!Set draw style
  513. Draw styles:
  514. - DM_GOURAUD
  515. - DM_FLAT
  516. - DM_FRINGE
  517. - DM_WIRE
  518. - DM_COL_WIRE
  519. - DM_POLY
  520. - DM_WIRE_POLY
  521. - DM_GRID_WIRE
  522. - DM_GRID_SURF
  523. @param id surface id (<= 0 for all)
  524. @param style draw style
  525. @return 1 on success
  526. @return -1 surface not found
  527. @return -2 setting attributes failed
  528. """
  529. Debug.msg(3, "Nviz::SetSurfaceStyle(): id=%d, style=%d",
  530. id, style)
  531. if id > 0:
  532. if not GS_surf_exists(id):
  533. return -1
  534. if GS_set_drawmode(id, style) < 0:
  535. return -2
  536. return 1
  537. if GS_setall_drawmode(style) < 0:
  538. return -2
  539. return 1
  540. def SetWireColor(self, id, color_str):
  541. """!Set color of wire
  542. @todo all
  543. @param surface id (< 0 for all)
  544. @param color color string (R:G:B)
  545. @return 1 on success
  546. @return -1 surface not found
  547. @return -2 setting attributes failed
  548. @return 1 on success
  549. @return 0 on failure
  550. """
  551. Debug.msg(3, "Nviz::SetWireColor(): id=%d, color=%s",
  552. id, color_str)
  553. color = Nviz_color_from_str(color_str)
  554. if id > 0:
  555. if not GS_surf_exists(id):
  556. return -1
  557. GS_set_wire_color(id, color)
  558. else:
  559. nsurfs = c_int()
  560. surf_list = GS_get_surf_list(byref(nsurfs))
  561. for i in xrange(nsurfs.value):
  562. id = surf_list[i]
  563. GS_set_wire_color(id, color)
  564. G_free(surf_list)
  565. surf_list = None
  566. return 1
  567. def GetSurfacePosition(self, id):
  568. """!Get surface position
  569. @param id surface id
  570. @return x,y,z
  571. @return zero-length vector on error
  572. """
  573. if not GS_surf_exists(id):
  574. return []
  575. x, y, z = c_float(), c_float(), c_float()
  576. GS_get_trans(id, byref(x), byref(y), byref(z))
  577. Debug.msg(3, "Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
  578. id, x.value, y.value, z.value)
  579. return [x.value, y.value, z.value]
  580. def SetSurfacePosition(self, id, x, y, z):
  581. """!Set surface position
  582. @param id surface id
  583. @param x,y,z translation values
  584. @return 1 on success
  585. @return -1 surface not found
  586. @return -2 setting position failed
  587. """
  588. if not GS_surf_exists(id):
  589. return -1
  590. Debug.msg(3, "Nviz::SetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
  591. id, x, y, z)
  592. GS_set_trans(id, x, y, z)
  593. return 1
  594. def SetVectorLineMode(self, id, color_str, width, flat):
  595. """!Set mode of vector line overlay
  596. @param id vector id
  597. @param color_str color string
  598. @param width line width
  599. @param flat display flat or on surface
  600. @return -1 vector set not found
  601. @return -2 on failure
  602. @return 1 on success
  603. """
  604. if not GV_vect_exists(id):
  605. return -1
  606. Debug.msg(3, "Nviz::SetVectorMode(): id=%d, color=%s, width=%d, flat=%d",
  607. id, color_str, width, flat)
  608. color = Nviz_color_from_str(color_str)
  609. # use memory by default
  610. if GV_set_vectmode(id, 1, color, width, flat) < 0:
  611. return -2
  612. return 1
  613. def SetVectorLineHeight(self, id, height):
  614. """!Set vector height above surface (lines)
  615. @param id vector set id
  616. @param height
  617. @return -1 vector set not found
  618. @return 1 on success
  619. """
  620. if not GV_vect_exists(id):
  621. return -1
  622. Debug.msg(3, "Nviz::SetVectorLineHeight(): id=%d, height=%f",
  623. id, height)
  624. GV_set_trans(id, 0.0, 0.0, height)
  625. return 1
  626. def SetVectorLineSurface(self, id, surf_id):
  627. """!Set reference surface of vector set (lines)
  628. @param id vector set id
  629. @param surf_id surface id
  630. @return 1 on success
  631. @return -1 vector set not found
  632. @return -2 surface not found
  633. @return -3 on failure
  634. """
  635. if not GV_vect_exists(id):
  636. return -1
  637. if not GS_surf_exists(surf_id):
  638. return -2
  639. if GV_select_surf(id, surf_id) < 0:
  640. return -3
  641. return 1
  642. def UnsetVectorLineSurface(self, id, surf_id):
  643. """!Unset reference surface of vector set (lines)
  644. @param id vector set id
  645. @param surf_id surface id
  646. @return 1 on success
  647. @return -1 vector set not found
  648. @return -2 surface not found
  649. @return -3 on failure
  650. """
  651. if not GV_vect_exists(id):
  652. return -1
  653. if not GS_surf_exists(surf_id):
  654. return -2
  655. if GV_unselect_surf(id, surf_id) < 0:
  656. return -3
  657. return 1
  658. def SetVectorPointMode(self, id, color_str, width, size, marker):
  659. """!Set mode of vector point overlay
  660. @param id vector id
  661. @param color_str color string
  662. @param width line width
  663. @param flat
  664. @return -1 vector set not found
  665. """
  666. if not GP_site_exists(id):
  667. return -1
  668. Debug.msg(3, "Nviz::SetVectorPointMode(): id=%d, color=%s, "
  669. "width=%d, size=%f, marker=%d",
  670. id, color_str, width, size, marker)
  671. color = Nviz_color_from_str(color_str)
  672. if GP_set_style(id, color, width, size, marker) < 0:
  673. return -2
  674. return 1
  675. def SetVectorPointHeight(self, id, height):
  676. """!Set vector height above surface (points)
  677. @param id vector set id
  678. @param height
  679. @return -1 vector set not found
  680. @return 1 on success
  681. """
  682. if not GP_site_exists(id):
  683. return -1
  684. Debug.msg(3, "Nviz::SetVectorPointHeight(): id=%d, height=%f",
  685. id, height)
  686. GP_set_trans(id, 0.0, 0.0, height)
  687. return 1
  688. def SetVectorPointSurface(self, id, surf_id):
  689. """!Set reference surface of vector set (points)
  690. @param id vector set id
  691. @param surf_id surface id
  692. @return 1 on success
  693. @return -1 vector set not found
  694. @return -2 surface not found
  695. @return -3 on failure
  696. """
  697. if not GP_site_exists(id):
  698. return -1
  699. if not GS_surf_exists(surf_id):
  700. return -2
  701. if GP_select_surf(id, surf_id) < 0:
  702. return -3
  703. return 1
  704. def UnsetVectorPointSurface(self, id, surf_id):
  705. """!Unset reference surface of vector set (points)
  706. @param id vector set id
  707. @param surf_id surface id
  708. @return 1 on success
  709. @return -1 vector set not found
  710. @return -2 surface not found
  711. @return -3 on failure
  712. """
  713. if not GP_site_exists(id):
  714. return -1
  715. if not GS_surf_exists(surf_id):
  716. return -2
  717. if GP_unselect_surf(id, surf_id) < 0:
  718. return -3
  719. return 1
  720. def AddIsosurface(self, id, level, isosurf_id = None):
  721. """!Add new isosurface
  722. @param id volume id
  723. @param level isosurface level (topography)
  724. @return -1 on failure
  725. @return 1 on success
  726. """
  727. if not GVL_vol_exists(id):
  728. return -1
  729. if isosurf_id is not None:
  730. num = GVL_isosurf_num_isosurfs(id)
  731. if num < 0 or isosurf_id != num:
  732. return -1
  733. if GVL_isosurf_add(id) < 0:
  734. return -1
  735. # set topography level
  736. nisosurfs = GVL_isosurf_num_isosurfs(id)
  737. return GVL_isosurf_set_att_const(id, nisosurfs - 1, ATT_TOPO, level)
  738. def AddSlice(self, id, slice_id = None):
  739. """!Add new slice
  740. @param id volume id
  741. @return -1 on failure
  742. @return number of slices
  743. """
  744. if not GVL_vol_exists(id):
  745. return -1
  746. if slice_id is not None:
  747. num = GVL_slice_num_slices(id)
  748. if num < 0 or slice_id != num:
  749. return -1
  750. if GVL_slice_add(id) < 0:
  751. return -1
  752. return GVL_slice_num_slices(id)
  753. def DeleteIsosurface(self, id, isosurf_id):
  754. """!Delete isosurface
  755. @param id volume id
  756. @param isosurf_id isosurface id
  757. @return 1 on success
  758. @return -1 volume not found
  759. @return -2 isosurface not found
  760. @return -3 on failure
  761. """
  762. if not GVL_vol_exists(id):
  763. return -1
  764. if isosurf_id > GVL_isosurf_num_isosurfs(id):
  765. return -2
  766. ret = GVL_isosurf_del(id, isosurf_id)
  767. if ret < 0:
  768. return -3
  769. return 1
  770. def DeleteSlice(self, id, slice_id):
  771. """!Delete slice
  772. @param id volume id
  773. @param slice_id slice id
  774. @return 1 on success
  775. @return -1 volume not found
  776. @return -2 slice not found
  777. @return -3 on failure
  778. """
  779. if not GVL_vol_exists(id):
  780. return -1
  781. if slice_id > GVL_slice_num_slices(id):
  782. return -2
  783. ret = GVL_slice_del(id, slice_id)
  784. if ret < 0:
  785. return -3
  786. return 1
  787. def MoveIsosurface(self, id, isosurf_id, up):
  788. """!Move isosurface up/down in the list
  789. @param id volume id
  790. @param isosurf_id isosurface id
  791. @param up if true move up otherwise down
  792. @return 1 on success
  793. @return -1 volume not found
  794. @return -2 isosurface not found
  795. @return -3 on failure
  796. """
  797. if not GVL_vol_exists(id):
  798. return -1
  799. if isosurf_id > GVL_isosurf_num_isosurfs(id):
  800. return -2
  801. if up:
  802. ret = GVL_isosurf_move_up(id, isosurf_id)
  803. else:
  804. ret = GVL_isosurf_move_down(id, isosurf_id)
  805. if ret < 0:
  806. return -3
  807. return 1
  808. def MoveSlice(self, id, slice_id, up):
  809. """!Move slice up/down in the list
  810. @param id volume id
  811. @param slice_id slice id
  812. @param up if true move up otherwise down
  813. @return 1 on success
  814. @return -1 volume not found
  815. @return -2 slice not found
  816. @return -3 on failure
  817. """
  818. if not GVL_vol_exists(id):
  819. return -1
  820. if slice_id > GVL_slice_num_slices(id):
  821. return -2
  822. if up:
  823. ret = GVL_slice_move_up(id, slice_id)
  824. else:
  825. ret = GVL_slice_move_down(id, slice_id)
  826. if ret < 0:
  827. return -3
  828. return 1
  829. def SetIsosurfaceTopo(self, id, isosurf_id, map, value):
  830. """!Set isosurface level
  831. @param id volume id
  832. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  833. @param map if true use map otherwise constant
  834. @param value map name of value
  835. @return 1 on success
  836. @return -1 volume not found
  837. @return -2 isosurface not found
  838. @return -3 on failure
  839. """
  840. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_TOPO, map, value)
  841. def SetIsosurfaceColor(self, id, isosurf_id, map, value):
  842. """!Set isosurface color
  843. @param id volume id
  844. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  845. @param map if true use map otherwise constant
  846. @param value map name of value
  847. @return 1 on success
  848. @return -1 volume not found
  849. @return -2 isosurface not found
  850. @return -3 on failure
  851. """
  852. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_COLOR, map, value)
  853. def SetIsosurfaceMask(self, id, isosurf_id, invert, value):
  854. """!Set isosurface mask
  855. @todo invert
  856. @param id volume id
  857. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  858. @param invert true for invert mask
  859. @param value map name to be used for mask
  860. @return 1 on success
  861. @return -1 volume not found
  862. @return -2 isosurface not found
  863. @return -3 on failure
  864. """
  865. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_MASK, True, value)
  866. def SetIsosurfaceTransp(self, id, isosurf_id, map, value):
  867. """!Set isosurface transparency
  868. @param id volume id
  869. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  870. @param map if true use map otherwise constant
  871. @param value map name of value
  872. @return 1 on success
  873. @return -1 volume not found
  874. @return -2 isosurface not found
  875. @return -3 on failure
  876. """
  877. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP, map, value)
  878. def SetIsosurfaceShine(self, id, isosurf_id, map, value):
  879. """!Set isosurface shininess
  880. @param id volume id
  881. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  882. @param map if true use map otherwise constant
  883. @param value map name of value
  884. @return 1 on success
  885. @return -1 volume not found
  886. @return -2 isosurface not found
  887. @return -3 on failure
  888. """
  889. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_SHINE, map, value)
  890. def SetIsosurfaceEmit(self, id, isosurf_id, map, value):
  891. """!Set isosurface emission (currently unused)
  892. @param id volume id
  893. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  894. @param map if true use map otherwise constant
  895. @param value map name of value
  896. @return 1 on success
  897. @return -1 volume not found
  898. @return -2 isosurface not found
  899. @return -3 on failure
  900. """
  901. return self.SetIsosurfaceAttr(id, isosurf_id, ATT_EMIT, map, value)
  902. def SetIsosurfaceAttr(self, id, isosurf_id, attr, map, value):
  903. """!Set isosurface attribute
  904. @param id volume id
  905. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  906. @param attr attribute desc
  907. @param map if true use map otherwise constant
  908. @param value map name of value
  909. @return 1 on success
  910. @return -1 volume not found
  911. @return -2 isosurface not found
  912. @return -3 setting attributes failed
  913. """
  914. if not GVL_vol_exists(id):
  915. return -1
  916. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  917. return -2
  918. if map:
  919. ret = GVL_isosurf_set_att_map(id, isosurf_id, attr, value)
  920. else:
  921. if attr == ATT_COLOR:
  922. val = Nviz_color_from_str(value)
  923. else:
  924. val = float(value)
  925. ret = GVL_isosurf_set_att_const(id, isosurf_id, attr, val)
  926. Debug.msg(3, "Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
  927. "attr=%d, map=%s, value=%s",
  928. id, isosurf_id, attr, map, value)
  929. if ret < 0:
  930. return -2
  931. return 1
  932. def UnsetIsosurfaceMask(self, id, isosurf_id):
  933. """!Unset isosurface mask
  934. @param id volume id
  935. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  936. @return 1 on success
  937. @return -1 volume not found
  938. @return -2 isosurface not found
  939. @return -3 setting attributes failed
  940. """
  941. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_MASK)
  942. def UnsetIsosurfaceTransp(self, id, isosurf_id):
  943. """!Unset isosurface transparency
  944. @param id volume id
  945. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  946. @return 1 on success
  947. @return -1 volume not found
  948. @return -2 isosurface not found
  949. @return -3 setting attributes failed
  950. """
  951. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP)
  952. def UnsetIsosurfaceEmit(self, id, isosurf_id):
  953. """!Unset isosurface emission (currently unused)
  954. @param id volume id
  955. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  956. @return 1 on success
  957. @return -1 volume not found
  958. @return -2 isosurface not found
  959. @return -3 setting attributes failed
  960. """
  961. return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_EMIT)
  962. def UnsetIsosurfaceAttr(self, id, isosurf_id, attr):
  963. """!Unset surface attribute
  964. @param id surface id
  965. @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
  966. @param attr attribute descriptor
  967. @return 1 on success
  968. @return -1 volume not found
  969. @return -2 isosurface not found
  970. @return -2 on failure
  971. """
  972. if not GVL_vol_exists(id):
  973. return -1
  974. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  975. return -2
  976. Debug.msg(3, "Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%d",
  977. id, isosurf_id, attr)
  978. ret = GVL_isosurf_unset_att(id, isosurf_id, attr)
  979. if ret < 0:
  980. return -2
  981. return 1
  982. def SetIsosurfaceMode(self, id, mode):
  983. """!Set draw mode for isosurfaces
  984. @param mode
  985. @return 1 on success
  986. @return -1 volume set not found
  987. @return -2 on failure
  988. """
  989. if not GVL_vol_exists(id):
  990. return -1
  991. ret = GVL_isosurf_set_drawmode(id, mode)
  992. if ret < 0:
  993. return -2
  994. return 1
  995. def SetSliceMode(self, id, mode):
  996. """!Set draw mode for slices
  997. @param mode
  998. @return 1 on success
  999. @return -1 volume set not found
  1000. @return -2 on failure
  1001. """
  1002. if not GVL_vol_exists(id):
  1003. return -1
  1004. ret = GVL_slice_set_drawmode(id, mode)
  1005. if ret < 0:
  1006. return -2
  1007. return 1
  1008. def SetIsosurfaceRes(self, id, res):
  1009. """!Set draw resolution for isosurfaces
  1010. @param res resolution value
  1011. @return 1 on success
  1012. @return -1 volume set not found
  1013. @return -2 on failure
  1014. """
  1015. if not GVL_vol_exists(id):
  1016. return -1
  1017. ret = GVL_isosurf_set_drawres(id, res, res, res)
  1018. if ret < 0:
  1019. return -2
  1020. return 1
  1021. def SetSliceRes(self, id, res):
  1022. """!Set draw resolution for slices
  1023. @param res resolution value
  1024. @return 1 on success
  1025. @return -1 volume set not found
  1026. @return -2 on failure
  1027. """
  1028. if not GVL_vol_exists(id):
  1029. return -1
  1030. ret = GVL_slice_set_drawres(id, res, res, res)
  1031. if ret < 0:
  1032. return -2
  1033. return 1
  1034. def SetSlicePosition(self, id, slice_id, x1, x2, y1, y2, z1, z2, dir):
  1035. """!Set slice position
  1036. @param id volume id
  1037. @param slice_id slice id
  1038. @param x1,x2,y1,y2,z1,z2 slice coordinates
  1039. @param dir axis
  1040. @return 1 on success
  1041. @return -1 volume not found
  1042. @return -2 slice not found
  1043. @return -3 on failure
  1044. """
  1045. if not GVL_vol_exists(id):
  1046. return -1
  1047. if slice_id > GVL_slice_num_slices(id):
  1048. return -2
  1049. ret = GVL_slice_set_pos(id, slice_id, x1, x2, y1, y2, z1, z2, dir)
  1050. if ret < 0:
  1051. return -2
  1052. return 1
  1053. def SetSliceTransp(self, id, slice_id, value):
  1054. """!Set slice transparency
  1055. @param id volume id
  1056. @param slice_id slice id
  1057. @param x1,x2,y1,y2,z1,z2 slice coordinates
  1058. @param value transparency value (0 - 255)
  1059. @return 1 on success
  1060. @return -1 volume not found
  1061. @return -2 slice not found
  1062. @return -3 on failure
  1063. """
  1064. if not GVL_vol_exists(id):
  1065. return -1
  1066. if slice_id > GVL_slice_num_slices(id):
  1067. return -2
  1068. ret = GVL_slice_set_transp(id, slice_id, value)
  1069. if ret < 0:
  1070. return -2
  1071. return 1
  1072. def SetIsosurfaceInOut(self, id, isosurf_id, inout):
  1073. """!Set inout mode
  1074. @param inout mode true/false
  1075. @return 1 on success
  1076. @return -1 volume set not found
  1077. @return -2 isosurface not found
  1078. @return -3 on failure
  1079. """
  1080. if not GVL_vol_exists(id):
  1081. return -1
  1082. if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
  1083. return -2
  1084. ret = GVL_isosurf_set_flags(id, isosurf_id, inout)
  1085. if ret < 0:
  1086. return -3
  1087. return 1
  1088. def GetVolumePosition(self, id):
  1089. """!Get volume position
  1090. @param id volume id
  1091. @return x,y,z
  1092. @return zero-length vector on error
  1093. """
  1094. if not GVL_vol_exists(id):
  1095. return []
  1096. x, y, z = c_float(), c_float(), c_float()
  1097. GVL_get_trans(id, byref(x), byref(y), byref(z))
  1098. Debug.msg(3, "Nviz::GetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
  1099. id, x.value, y.value, z.value)
  1100. return [x.value, y.value, z.value]
  1101. def SetVolumePosition(self, id, x, y, z):
  1102. """!Set volume position
  1103. @param id volume id
  1104. @param x,y,z translation values
  1105. @return 1 on success
  1106. @return -1 volume not found
  1107. @return -2 setting position failed
  1108. """
  1109. if not GVL_vol_exists(id):
  1110. return -1
  1111. Debug.msg(3, "Nviz::SetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
  1112. id, x, y, z)
  1113. GVL_set_trans(id, x, y, z)
  1114. return 1
  1115. def GetCPlaneCurrent(self):
  1116. return Nviz_get_current_cplane(self.data)
  1117. def GetCPlanesCount(self):
  1118. """!Returns number of cutting planes"""
  1119. return Nviz_num_cplanes(self.data)
  1120. def GetCPlaneRotation(self):
  1121. """!Returns rotation parameters of current cutting plane"""
  1122. x, y, z = c_float(), c_float(), c_float()
  1123. current = Nviz_get_current_cplane(self.data)
  1124. Nviz_get_cplane_rotation(self.data, current, byref(x), byref(y), byref(z))
  1125. return x.value, y.value, z.value
  1126. def GetCPlaneTranslation(self):
  1127. """!Returns translation parameters of current cutting plane"""
  1128. x, y, z = c_float(), c_float(), c_float()
  1129. current = Nviz_get_current_cplane(self.data)
  1130. Nviz_get_cplane_translation(self.data, current, byref(x), byref(y), byref(z))
  1131. return x.value, y.value, z.value
  1132. def SetCPlaneRotation(self, x, y, z):
  1133. """!Set current clip plane rotation
  1134. @param x,y,z rotation parameters
  1135. """
  1136. current = Nviz_get_current_cplane(self.data)
  1137. Nviz_set_cplane_rotation(self.data, current, x, y, z)
  1138. Nviz_draw_cplane(self.data, -1, -1)
  1139. def SetCPlaneTranslation(self, x, y, z):
  1140. """!Set current clip plane translation
  1141. @param x,y,z translation parameters
  1142. """
  1143. current = Nviz_get_current_cplane(self.data)
  1144. Nviz_set_cplane_translation(self.data, current, x, y, z)
  1145. Nviz_draw_cplane(self.data, -1, -1)
  1146. Debug.msg(3, "Nviz::SetCPlaneTranslation(): id=%d, x=%f, y=%f, z=%f",
  1147. current, x, y, z)
  1148. def SetCPlaneInteractively(self, x, y):
  1149. current = Nviz_get_current_cplane(self.data)
  1150. ret = Nviz_set_cplane_here(self.data, current, x, y)
  1151. if ret:
  1152. Nviz_draw_cplane(self.data, -1, -1)
  1153. x, y, z = self.GetCPlaneTranslation()
  1154. return x, y, z
  1155. else:
  1156. return None, None, None
  1157. def SelectCPlane(self, index):
  1158. """!Select cutting plane
  1159. @param index index of cutting plane
  1160. """
  1161. Nviz_on_cplane(self.data, index)
  1162. def UnselectCPlane(self, index):
  1163. """!Unselect cutting plane
  1164. @param index index of cutting plane
  1165. """
  1166. Nviz_off_cplane(self.data, index)
  1167. def SetFenceColor(self, index):
  1168. """!Select current cutting plane
  1169. @param index type of fence - from 0 (off) to 4
  1170. """
  1171. Nviz_set_fence_color(self.data, index)
  1172. def GetXYRange(self):
  1173. """!Get xy range"""
  1174. return Nviz_get_xyrange(self.data)
  1175. def GetZRange(self):
  1176. """!Get z range"""
  1177. min, max = c_float(), c_float()
  1178. Nviz_get_zrange(self.data, byref(min), byref(max))
  1179. return min.value, max.value
  1180. def SaveToFile(self, filename, width = 20, height = 20, itype = 'ppm'):
  1181. """!Save current GL screen to ppm/tif file
  1182. @param filename file name
  1183. @param width image width
  1184. @param height image height
  1185. @param itype image type ('ppm' or 'tif')
  1186. """
  1187. widthOrig = self.width
  1188. heightOrig = self.height
  1189. self.ResizeWindow(width, height)
  1190. GS_clear(Nviz_get_bgcolor(self.data))
  1191. self.Draw(False, -1)
  1192. if itype == 'ppm':
  1193. GS_write_ppm(filename)
  1194. else:
  1195. GS_write_tif(filename)
  1196. self.ResizeWindow(widthOrig, heightOrig)
  1197. def DrawLightingModel(self):
  1198. """!Draw lighting model"""
  1199. if self.showLight:
  1200. Nviz_draw_model(self.data)
  1201. def DrawFringe(self):
  1202. """!Draw fringe"""
  1203. Nviz_draw_fringe(self.data)
  1204. def SetFringe(self, sid, color, elev, nw = False, ne = False, sw = False, se = False):
  1205. """!Set fringe
  1206. @param sid surface id
  1207. @param color color
  1208. @param elev elevation (height)
  1209. @param nw,ne,sw,se fringe edges (turn on/off)
  1210. """
  1211. scolor = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
  1212. Nviz_set_fringe(self.data,
  1213. sid, Nviz_color_from_str(scolor),
  1214. elev, int(nw), int(ne), int(sw), int(se))
  1215. def DrawArrow(self):
  1216. """!Draw north arrow
  1217. """
  1218. return Nviz_draw_arrow(self.data)
  1219. def SetArrow(self, sx, sy, size, color):
  1220. """!Set north arrow from canvas coordinates
  1221. @param sx,sy canvas coordinates
  1222. @param size arrow length
  1223. @param color arrow color
  1224. """
  1225. return Nviz_set_arrow(self.data, sx, sy, size, Nviz_color_from_str(color))
  1226. def DeleteArrow(self):
  1227. """!Delete north arrow
  1228. """
  1229. Nviz_delete_arrow(self.data)
  1230. def SetScalebar(self, id, sx, sy, size, color):
  1231. """!Set scale bar from canvas coordinates
  1232. @param sx,sy canvas coordinates
  1233. @param id scale bar id
  1234. @param size scale bar length
  1235. @param color scale bar color
  1236. """
  1237. return Nviz_set_scalebar(self.data, id, sx, sy, size, Nviz_color_from_str(color))
  1238. ## def DrawScalebar(self):
  1239. ## """!Draw scale bar
  1240. ## """
  1241. ## return Nviz_draw_scalebar(self.data)
  1242. def DeleteScalebar(self, id):
  1243. """!Delete scalebar
  1244. """
  1245. Nviz_delete_scalebar(self.data, id)
  1246. def GetPointOnSurface(self, sx, sy):
  1247. """!Get point on surface
  1248. @param sx,sy canvas coordinates (LL)
  1249. """
  1250. sid = c_int()
  1251. x = c_float()
  1252. y = c_float()
  1253. z = c_float()
  1254. Debug.msg(5, "Nviz::GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
  1255. num = GS_get_selected_point_on_surface(sx, sy, byref(sid), byref(x), byref(y), byref(z))
  1256. if num == 0:
  1257. return (None, None, None, None)
  1258. return (sid.value, x.value, y.value, z.value)
  1259. def QueryMap(self, sx, sy):
  1260. """!Query surface map
  1261. @param sx,sy canvas coordinates (LL)
  1262. """
  1263. sid, x, y, z = self.GetPointOnSurface(sx, sy)
  1264. if not sid:
  1265. return None
  1266. catstr = create_string_buffer(256)
  1267. valstr = create_string_buffer(256)
  1268. GS_get_cat_at_xy(sid, ATT_TOPO, catstr, x, y)
  1269. GS_get_val_at_xy(sid, ATT_COLOR, valstr, x, y)
  1270. return { 'id' : sid,
  1271. 'x' : x,
  1272. 'y' : y,
  1273. 'z' : z,
  1274. 'elevation' : catstr.value.replace('(', '').replace(')', ''),
  1275. 'color' : valstr.value }
  1276. def GetDistanceAlongSurface(self, sid, p1, p2, useExag = True):
  1277. """!Get distance measured along surface"""
  1278. d = c_float()
  1279. GS_get_distance_alongsurf(sid, p1[0], p1[1], p2[0], p2[1],
  1280. byref(d), int(useExag))
  1281. return d.value