wxnviz.py 48 KB

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