GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
wxnviz.py
Go to the documentation of this file.
1 """!
2 @package nviz.wxnviz
3 
4 @brief wxGUI 3D view mode (ctypes-based classes)
5 
6 This module implements 3D visualization mode for map display (ctypes
7 required).
8 
9 List of classes:
10  - wxnviz::Nviz
11  - wxnviz::Texture
12  - wxnviz::ImageTexture
13  - wxnviz::TextTexture
14 
15 (C) 2008-2011 by the GRASS Development Team
16 
17 This program is free software under the GNU General Public License
18 (>=v2). Read the file COPYING that comes with GRASS for details.
19 
20 @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
21 @author Pythonized by Glynn Clements
22 @author Anna Kratochvilova <KratochAnna seznam.cz> (Google SoC 2011)
23 """
24 
25 import sys
26 import locale
27 import struct
28 from math import sqrt
29 try:
30  from numpy import matrix
31 except ImportError:
32  msg = _("This module requires the NumPy module, which could not be "
33  "imported. It probably is not installed (it's not part of the "
34  "standard Python distribution). See the Numeric Python site "
35  "(http://numpy.scipy.org) for information on downloading source or "
36  "binaries.")
37  print >> sys.stderr, "wxnviz.py: " + msg
38 
39 import wx
40 
41 from ctypes import *
42 try:
43  from grass.lib.gis import *
44  from grass.lib.g3d import *
45  from grass.lib.vector import *
46  from grass.lib.ogsf import *
47  from grass.lib.nviz import *
48 except ImportError, e:
49  sys.stderr.write(_("3D view mode: %s\n") % e)
50 
51 from core.debug import Debug
52 import grass.script as grass
53 
54 log = None
55 progress = None
56 
57 def print_error(msg, type):
58  """!Redirect stderr"""
59  global log
60  if log:
61  log.write(msg)
62  else:
63  print msg
64 
65  return 0
66 
67 def print_progress(value):
68  """!Redirect progress info"""
69  global progress
70  if progress:
71  progress.SetValue(value)
72  else:
73  print value
74 
75  return 0
76 
77 errtype = CFUNCTYPE(UNCHECKED(c_int), String, c_int)
78 errfunc = errtype(print_error)
79 pertype = CFUNCTYPE(UNCHECKED(c_int), c_int)
80 perfunc = pertype(print_progress)
81 
82 class Nviz(object):
83  def __init__(self, glog, gprogress):
84  """!Initialize Nviz class instance
85 
86  @param log logging area
87  @param gprogress progressbar
88  """
89  global errfunc, perfunc, log, progress
90  log = glog
91  progress = gprogress
92 
93  G_gisinit("wxnviz")
94  # gislib is already initialized (where?)
95  G_set_error_routine(errfunc)
96  G_set_percent_routine(perfunc)
97 
98  self.Init()
99 
100  self.data_obj = nv_data()
101  self.data = pointer(self.data_obj)
102  self.color_obj = Colors()
103  self.color = pointer(self.color_obj)
104 
105  self.width = self.height = -1
106  self.showLight = False
107 
108  Debug.msg(1, "Nviz::Nviz()")
109 
110  def __del__(self):
111  """!Destroy Nviz class instance"""
114  del self.data
115  del self.data_obj
116  self.log = None
117 
118  def Init(self):
119  """!Initialize window"""
120  locale.setlocale(locale.LC_NUMERIC, 'C')
121  #G_unset_window()
122  #Rast_unset_window()
123  #Rast__init_window()
124  GS_libinit()
125  GVL_libinit()
126 
127  def ResizeWindow(self, width, height):
128  """!GL canvas resized
129 
130  @param width window width
131  @param height window height
132 
133  @return 1 on success
134  @return 0 on failure (window resized by default to 20x20 px)
135  """
136  self.width = width
137  self.height = height
138  Debug.msg(3, "Nviz::ResizeWindow(): width=%d height=%d",
139  width, height)
140  return Nviz_resize_window(width, height)
141 
142  def GetLongDim(self):
143  """!Get longest dimension, used for initial size of north arrow"""
144  return Nviz_get_longdim(self.data)
145 
146  def SetViewDefault(self):
147  """!Set default view (based on loaded data)
148 
149  @return z-exag value, default, min and max height
150  """
151  # determine z-exag
152  z_exag = Nviz_get_exag()
153  Nviz_change_exag(self.data, z_exag)
154 
155  # determine height
156  hdef = c_double()
157  hmin = c_double()
158  hmax = c_double()
159  Nviz_get_exag_height(byref(hdef), byref(hmin), byref(hmax))
160 
161  Debug.msg(1, "Nviz::SetViewDefault(): hdef=%f, hmin=%f, hmax=%f",
162  hdef.value, hmin.value, hmax.value)
163 
164  return (z_exag, hdef.value, hmin.value, hmax.value)
165 
166  def SetView(self, x, y, height, persp, twist):
167  """!Change view settings
168  @param x,y position
169  @param height
170  @param persp perpective
171  @param twist
172  """
177 
178  Debug.msg(3, "Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
179  x, y, height, persp, twist)
180 
182  x = c_double()
183  y = c_double()
184  h = c_double()
185  Nviz_get_viewpoint_height(byref(h))
186  Nviz_get_viewpoint_position(byref(x), byref(y))
187 
188  return (x.value, y.value, h.value)
189 
190  def LookHere(self, x, y):
191  """!Look here feature
192  @param x,y screen coordinates
193  """
194 
195  Nviz_look_here(x, y)
196  Debug.msg(3, "Nviz::LookHere(): x=%f, y=%f", x, y)
197 
198  def LookAtCenter(self):
199  """!Center view at center of displayed surface"""
200  Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
201  Debug.msg(3, "Nviz::LookAtCenter()")
202 
203  def GetFocus(self):
204  """!Get focus"""
205  Debug.msg(3, "Nviz::GetFocus()")
206  if Nviz_has_focus(self.data):
207  x = c_float()
208  y = c_float()
209  z = c_float()
210  Nviz_get_focus(self.data, byref(x), byref(y), byref(z))
211  return x.value, y.value, z.value
212  else:
213  return -1, -1, -1
214 
215  def SetFocus(self, x, y, z):
216  """!Set focus"""
217  Debug.msg(3, "Nviz::SetFocus()")
218  Nviz_set_focus(self.data, x, y, z)
219 
220  def GetViewdir(self):
221  """!Get viewdir"""
222  Debug.msg(3, "Nviz::GetViewdir()")
223  dir = (c_float * 3)()
224  GS_get_viewdir(byref(dir))
225 
226  return dir[0], dir[1], dir[2]
227 
228  def SetViewdir(self, x, y, z):
229  """!Set viewdir"""
230  Debug.msg(3, "Nviz::SetViewdir(): x=%f, y=%f, z=%f" % (x, y, z))
231  dir = (c_float * 3)()
232  for i, coord in enumerate((x, y, z)):
233  dir[i] = coord
234  GS_set_viewdir(byref(dir))
235 
236  def SetZExag(self, z_exag):
237  """!Set z-exag value
238 
239  @param z_exag value
240 
241  @return 1
242  """
243  Debug.msg(3, "Nviz::SetZExag(): z_exag=%f", z_exag)
244  return Nviz_change_exag(self.data, z_exag)
245 
246  def Draw(self, quick, quick_mode):
247  """!Draw canvas
248 
249  Draw quick mode:
250  - DRAW_QUICK_SURFACE
251  - DRAW_QUICK_VLINES
252  - DRAW_QUICK_VPOINTS
253  - DRAW_QUICK_VOLUME
254 
255  @param quick if true draw in wiremode
256  @param quick_mode quick mode
257  """
258  Debug.msg(3, "Nviz::Draw(): quick=%d", quick)
259 
260  Nviz_draw_cplane(self.data, -1, -1) # ?
261 
262  if quick:
263  Nviz_draw_quick(self.data, quick_mode)
264  else:
265  Nviz_draw_all(self.data)
266 
267  def EraseMap(self):
268  """!Erase map display (with background color)
269  """
270  Debug.msg(1, "Nviz::EraseMap()")
272 
273  def InitView(self):
274  """!Initialize view"""
275  # initialize nviz data
276  Nviz_init_data(self.data)
277 
278  # define default attributes for map objects
280  # set background color
282 
284  # initialize view, lights
285  Nviz_init_view(self.data)
286 
287  Debug.msg(1, "Nviz::InitView()")
288 
289  def SetBgColor(self, color_str):
290  """!Set background color
291 
292  @param color_str color string
293  """
294  Nviz_set_bgcolor(self.data, Nviz_color_from_str(color_str))
295 
296  def SetLight(self, x, y, z, color, bright, ambient, w = 0, lid = 1):
297  """!Change lighting settings
298  @param x,y,z position
299  @param color light color (as string)
300  @param bright light brightness
301  @param ambient light ambient
302  @param w local coordinate (default to 0)
303  """
304  Nviz_set_light_position(self.data, lid, x, y, z, w)
305  Nviz_set_light_bright(self.data, lid, bright)
306  Nviz_set_light_color(self.data, lid, int(color[0]), int(color[1]), int(color[2]))
307  Nviz_set_light_ambient(self.data, lid, ambient)
308 
309  def LoadSurface(self, name, color_name, color_value):
310  """!Load raster map (surface)
311 
312  @param name raster map name
313  @param color_name raster map for color (None for color_value)
314  @param color_value color string (named color or RGB triptet)
315 
316  @return object id
317  @return -1 on failure
318  """
319  mapset = G_find_cell2(name, "")
320  if mapset is None:
321  G_warning(_("Raster map <%s> not found"), name)
322  return -1
323 
324  # topography
325  id = Nviz_new_map_obj(MAP_OBJ_SURF,
326  G_fully_qualified_name(name, mapset), 0.0,
327  self.data)
328 
329  if color_name: # check for color map
330  mapset = G_find_cell2(color_name, "")
331  if mapset is None:
332  G_warning(_("Raster map <%s> not found"), color_name)
334  return -1
335 
336  Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
337  G_fully_qualified_name(color_name, mapset), -1.0,
338  self.data)
339 
340  elif color_value: # check for color value
341  Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
342  None, Nviz_color_from_str(color_value),
343  self.data)
344 
345  else: # use by default elevation map for coloring
346  Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
347  G_fully_qualified_name(name, mapset), -1.0,
348  self.data)
349 
350  # if (i > 1)
351  # set_default_wirecolors(self.data, i)
352 
353  # focus on loaded self.data
354  Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
355 
356  Debug.msg(1, "Nviz::LoadRaster(): name=%s -> id=%d", name, id)
357 
358  return id
359 
360  def AddConstant(self, value, color):
361  """!Add new constant surface"""
362  id = Nviz_new_map_obj(MAP_OBJ_SURF, None, value, self.data)
363 
364  Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
365  None, Nviz_color_from_str(color),
366  self.data)
367  Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
368 
369  Debug.msg(1, "Nviz::AddConstant(): id=%d", id)
370  return id
371 
372  def UnloadSurface(self, id):
373  """!Unload surface
374 
375  @param id surface id
376 
377  @return 1 on success
378  @return 0 on failure
379  """
380  if not GS_surf_exists(id):
381  return 0
382 
383  Debug.msg(1, "Nviz::UnloadSurface(): id=%d", id)
384 
385  if GS_delete_surface(id) < 0:
386  return 0
387 
388  return 1
389 
390  def LoadVector(self, name, points):
391  """!Load vector map overlay
392 
393  @param name vector map name
394  @param points if true load 2d points rather then 2d lines
395 
396  @return object id, id of base surface (or -1 if it is not loaded)
397  @return -1 on failure
398  """
399  baseId = -1
400  if GS_num_surfs() == 0: # load base surface if no loaded
401  baseId = Nviz_new_map_obj(MAP_OBJ_SURF, None, 0.0, self.data)
402 
403  nsurf = c_int()
404  surf_list = GS_get_surf_list(byref(nsurf))
405  GS_set_att_const(surf_list[0], ATT_TRANSP, 255)
406 
407  mapset = G_find_vector2 (name, "")
408  if mapset is None:
409  G_warning(_("Vector map <%s> not found"),
410  name)
411 
412  if points:
413  id = Nviz_new_map_obj(MAP_OBJ_SITE,
414  G_fully_qualified_name(name, mapset), 0.0,
415  self.data)
416  else:
417  id = Nviz_new_map_obj(MAP_OBJ_VECT,
418  G_fully_qualified_name(name, mapset), 0.0,
419  self.data)
420 
421  Debug.msg(1, "Nviz::LoadVector(): name=%s -> id=%d", name, id)
422 
423  return id, baseId
424 
425  def UnloadVector(self, id, points):
426  """!Unload vector set
427 
428  @param id vector set id
429  @param points vector points or lines set
430 
431  @return 1 on success
432  @return 0 on failure
433  """
434  Debug.msg(1, "Nviz::UnloadVector(): id=%d", id)
435 
436  if points:
437  if not GP_site_exists(id):
438  return 0
439  if GP_delete_site(id) < 0:
440  return 0
441  else:
442  if not GV_vect_exists(id):
443  return 0
444  if GV_delete_vector(id) < 0:
445  return 0
446 
447  return 1
448 
449  def VectorSurfaceSelected(self, vid, sid):
450  """!Check if surface is selected (currently unused)
451 
452  @param vid vector id
453  @param sid surface id
454 
455  @return True if selected
456  @return False if not selected
457  """
458  selected = GV_surf_is_selected(vid, sid)
459  Debug.msg(1, "Nviz::VectorSurfaceSelected(): vid=%s, sid=%d -> selected=%d", vid, sid, selected)
460  return selected
461 
462  def LoadVolume(self, name, color_name, color_value):
463  """!Load 3d raster map (volume)
464 
465  @param name 3d raster map name
466  @param color_name 3d raster map for color (None for color_value)
467  @param color_value color string (named color or RGB triptet)
468 
469  @return object id
470  @return -1 on failure
471  """
472  mapset = G_find_grid3(name, "")
473  if mapset is None:
474  G_warning(_("3d raster map <%s> not found"),
475  name)
476  return -1
477 
478  # topography
479  id = Nviz_new_map_obj(MAP_OBJ_VOL,
480  G_fully_qualified_name(name, mapset), 0.0,
481  self.data)
482 
483  if color_name: # check for color map
484  mapset = G_find_grid3(color_name, "")
485  if mapset is None:
486  G_warning(_("3d raster map <%s> not found"),
487  color_name)
488  GVL_delete_vol(id)
489  return -1
490 
491  Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
492  G_fully_qualified_name(color_name, mapset), -1.0,
493  self.data)
494  elif color_value: # check for color value
495  Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, CONST_ATT,
496  None, Nviz_color_from_str(color_value),
497  self.data)
498  else: # use by default elevation map for coloring
499  Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
500  G_fully_qualified_name(name, mapset), -1.0,
501  self.data)
502 
503  Debug.msg(1, "Nviz::LoadVolume(): name=%s -> id=%d", name, id)
504 
505  return id
506 
507  def UnloadVolume(self, id):
508  """!Unload volume
509 
510  @param id volume id
511 
512  @return 1 on success
513  @return 0 on failure
514  """
515  if not GVL_vol_exists(id):
516  return 0
517 
518  Debug.msg(1, "Nviz::UnloadVolume(): id=%d", id)
519 
520  if GVL_delete_vol(id) < 0:
521  return 0
522 
523  return 1
524 
525  def SetSurfaceTopo(self, id, map, value):
526  """!Set surface topography
527 
528  @param id surface id
529  @param map if true use map otherwise constant
530  @param value map name of value
531 
532  @return 1 on success
533  @return -1 surface not found
534  @return -2 setting attributes failed
535  """
536  return self.SetSurfaceAttr(id, ATT_TOPO, map, value)
537 
538  def SetSurfaceColor(self, id, map, value):
539  """!Set surface color
540 
541  @param id surface id
542  @param map if true use map otherwise constant
543  @param value map name or value
544 
545  @return 1 on success
546  @return -1 surface not found
547  @return -2 setting attributes failed
548  """
549  return self.SetSurfaceAttr(id, ATT_COLOR, map, value)
550 
551  def SetSurfaceMask(self, id, invert, value):
552  """!Set surface mask
553 
554  @todo invert
555 
556  @param id surface id
557  @param invert if true invert mask
558  @param value map name of value
559 
560  @return 1 on success
561  @return -1 surface not found
562  @return -2 setting attributes failed
563  """
564  return self.SetSurfaceAttr(id, ATT_MASK, True, value)
565 
566  def SetSurfaceTransp(self, id, map, value):
567  """!Set surface mask
568 
569  @todo invert
570 
571  @param id surface id
572  @param map if true use map otherwise constant
573  @param value map name of value
574 
575  @return 1 on success
576  @return -1 surface not found
577  @return -2 setting attributes failed
578  """
579  return self.SetSurfaceAttr(id, ATT_TRANSP, map, value)
580 
581  def SetSurfaceShine(self, id, map, value):
582  """!Set surface shininess
583 
584  @param id surface id
585  @param map if true use map otherwise constant
586  @param value map name of value
587 
588  @return 1 on success
589  @return -1 surface not found
590  @return -2 setting attributes failed
591  """
592  return self.SetSurfaceAttr(id, ATT_SHINE, map, value)
593 
594  def SetSurfaceEmit(self, id, map, value):
595  """!Set surface emission (currently unused)
596 
597  @param id surface id
598  @param map if true use map otherwise constant
599  @param value map name of value
600 
601  @return 1 on success
602  @return -1 surface not found
603  @return -2 setting attributes failed
604  """
605  return self.SetSurfaceAttr(id, ATT_EMIT, map, value)
606 
607  def SetSurfaceAttr(self, id, attr, map, value):
608  """!Set surface attribute
609 
610  @param id surface id
611  @param attr attribute desc
612  @param map if true use map otherwise constant
613  @param value map name of value
614 
615  @return 1 on success
616  @return -1 surface not found
617  @return -2 setting attributes failed
618  """
619  if not GS_surf_exists(id):
620  return -1
621 
622  if map:
623  ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
624  value, -1.0, self.data)
625  else:
626  if attr == ATT_COLOR:
627  val = Nviz_color_from_str(value)
628  else:
629  val = float(value)
630 
631  ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, CONST_ATT,
632  None, val, self.data)
633 
634  Debug.msg(3, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
635  id, attr, map, value)
636 
637  if ret < 0:
638  return -2
639 
640  return 1
641 
642  def UnsetSurfaceMask(self, id):
643  """!Unset surface mask
644 
645  @param id surface id
646 
647  @return 1 on success
648  @return -1 surface not found
649  @return -2 setting attributes failed
650  @return -1 on failure
651  """
652  return self.UnsetSurfaceAttr(id, ATT_MASK)
653 
654  def UnsetSurfaceTransp(self, id):
655  """!Unset surface transparency
656 
657  @param id surface id
658 
659  @return 1 on success
660  @return -1 surface not found
661  @return -2 setting attributes failed
662  """
663  return self.UnsetSurfaceAttr(id, ATT_TRANSP)
664 
665  def UnsetSurfaceEmit(self, id):
666  """!Unset surface emission (currently unused)
667 
668  @param id surface id
669 
670  @return 1 on success
671  @return -1 surface not found
672  @return -2 setting attributes failed
673  """
674  return self.UnsetSurfaceAttr(id, ATT_EMIT)
675 
676  def UnsetSurfaceAttr(self, id, attr):
677  """!Unset surface attribute
678 
679  @param id surface id
680  @param attr attribute descriptor
681 
682  @return 1 on success
683  @return -1 surface not found
684  @return -2 setting attributes failed
685  """
686  if not GS_surf_exists(id):
687  return -1
688 
689  Debug.msg(3, "Nviz::UnsetSurfaceAttr(): id=%d, attr=%d",
690  id, attr)
691 
692  ret = Nviz_unset_attr(id, MAP_OBJ_SURF, attr)
693 
694  if ret < 0:
695  return -2
696 
697  return 1
698 
699  def SetSurfaceRes(self, id, fine, coarse):
700  """!Set surface resolution
701 
702  @param id surface id
703  @param fine x/y fine resolution
704  @param coarse x/y coarse resolution
705 
706  @return 1 on success
707  @return -1 surface not found
708  @return -2 setting attributes failed
709  """
710  Debug.msg(3, "Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%d",
711  id, fine, coarse)
712 
713  if id > 0:
714  if not GS_surf_exists(id):
715  return -1
716 
717  if GS_set_drawres(id, fine, fine, coarse, coarse) < 0:
718  return -2
719  else:
720  GS_setall_drawres(fine, fine, coarse, coarse)
721 
722  return 1
723 
724  def SetSurfaceStyle(self, id, style):
725  """!Set draw style
726 
727  Draw styles:
728  - DM_GOURAUD
729  - DM_FLAT
730  - DM_FRINGE
731  - DM_WIRE
732  - DM_COL_WIRE
733  - DM_POLY
734  - DM_WIRE_POLY
735  - DM_GRID_WIRE
736  - DM_GRID_SURF
737 
738  @param id surface id (<= 0 for all)
739  @param style draw style
740 
741  @return 1 on success
742  @return -1 surface not found
743  @return -2 setting attributes failed
744  """
745  Debug.msg(3, "Nviz::SetSurfaceStyle(): id=%d, style=%d",
746  id, style)
747 
748  if id > 0:
749  if not GS_surf_exists(id):
750  return -1
751 
752  if GS_set_drawmode(id, style) < 0:
753  return -2
754 
755  return 1
756 
757  if GS_setall_drawmode(style) < 0:
758  return -2
759 
760  return 1
761 
762  def SetWireColor(self, id, color_str):
763  """!Set color of wire
764 
765  @todo all
766 
767  @param surface id (< 0 for all)
768  @param color color string (R:G:B)
769 
770  @return 1 on success
771  @return -1 surface not found
772  @return -2 setting attributes failed
773  @return 1 on success
774  @return 0 on failure
775  """
776  Debug.msg(3, "Nviz::SetWireColor(): id=%d, color=%s",
777  id, color_str)
778 
779  color = Nviz_color_from_str(color_str)
780 
781  if id > 0:
782  if not GS_surf_exists(id):
783  return -1
784 
785  GS_set_wire_color(id, color)
786  else:
787  nsurfs = c_int()
788  surf_list = GS_get_surf_list(byref(nsurfs))
789  for i in xrange(nsurfs.value):
790  id = surf_list[i]
791  GS_set_wire_color(id, color)
792 
793  G_free(surf_list)
794  surf_list = None
795 
796  return 1
797 
798  def GetSurfacePosition(self, id):
799  """!Get surface position
800 
801  @param id surface id
802 
803  @return x,y,z
804  @return zero-length vector on error
805  """
806  if not GS_surf_exists(id):
807  return []
808 
809  x, y, z = c_float(), c_float(), c_float()
810  GS_get_trans(id, byref(x), byref(y), byref(z))
811 
812  Debug.msg(3, "Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
813  id, x.value, y.value, z.value)
814 
815  return [x.value, y.value, z.value]
816 
817  def SetSurfacePosition(self, id, x, y, z):
818  """!Set surface position
819 
820  @param id surface id
821  @param x,y,z translation values
822 
823  @return 1 on success
824  @return -1 surface not found
825  @return -2 setting position failed
826  """
827  if not GS_surf_exists(id):
828  return -1
829 
830  Debug.msg(3, "Nviz::SetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
831  id, x, y, z)
832 
833  GS_set_trans(id, x, y, z)
834 
835  return 1
836 
837  def SetVectorLineMode(self, id, color_str, width, flat):
838  """!Set mode of vector line overlay
839 
840  @param id vector id
841  @param color_str color string
842  @param width line width
843  @param flat display flat or on surface
844 
845  @return -1 vector set not found
846  @return -2 on failure
847  @return 1 on success
848  """
849  if not GV_vect_exists(id):
850  return -1
851 
852  Debug.msg(3, "Nviz::SetVectorMode(): id=%d, color=%s, width=%d, flat=%d",
853  id, color_str, width, flat)
854 
855  color = Nviz_color_from_str(color_str)
856 
857  # use memory by default
858  if GV_set_vectmode(id, 1, color, width, flat) < 0:
859  return -2
860 
861  return 1
862 
863  def SetVectorLineHeight(self, id, height):
864  """!Set vector height above surface (lines)
865 
866  @param id vector set id
867  @param height
868 
869  @return -1 vector set not found
870  @return 1 on success
871  """
872  if not GV_vect_exists(id):
873  return -1
874 
875  Debug.msg(3, "Nviz::SetVectorLineHeight(): id=%d, height=%f",
876  id, height)
877 
878  GV_set_trans(id, 0.0, 0.0, height)
879 
880  return 1
881 
882  def SetVectorLineSurface(self, id, surf_id):
883  """!Set reference surface of vector set (lines)
884 
885  @param id vector set id
886  @param surf_id surface id
887 
888  @return 1 on success
889  @return -1 vector set not found
890  @return -2 surface not found
891  @return -3 on failure
892  """
893  if not GV_vect_exists(id):
894  return -1
895 
896  if not GS_surf_exists(surf_id):
897  return -2
898 
899  if GV_select_surf(id, surf_id) < 0:
900  return -3
901 
902  return 1
903 
904  def UnsetVectorLineSurface(self, id, surf_id):
905  """!Unset reference surface of vector set (lines)
906 
907  @param id vector set id
908  @param surf_id surface id
909 
910  @return 1 on success
911  @return -1 vector set not found
912  @return -2 surface not found
913  @return -3 on failure
914  """
915  if not GV_vect_exists(id):
916  return -1
917 
918  if not GS_surf_exists(surf_id):
919  return -2
920 
921  if GV_unselect_surf(id, surf_id) < 0:
922  return -3
923 
924  return 1
925 
926  def SetVectorPointMode(self, id, color_str, width, size, marker):
927  """!Set mode of vector point overlay
928 
929  @param id vector id
930  @param color_str color string
931  @param width line width
932  @param flat
933 
934  @return -1 vector set not found
935  """
936  if not GP_site_exists(id):
937  return -1
938 
939  # dtree and ctree defined but not used
940  if marker > 5:
941  marker += 2
942 
943  Debug.msg(3, "Nviz::SetVectorPointMode(): id=%d, color=%s, "
944  "width=%d, size=%f, marker=%d",
945  id, color_str, width, size, marker)
946 
947  color = Nviz_color_from_str(color_str)
948 
949  if GP_set_sitemode(id, ST_ATT_NONE, color, width, size, marker) < 0:
950  return -2
951 
952  return 1
953 
954  def SetVectorPointHeight(self, id, height):
955  """!Set vector height above surface (points)
956 
957  @param id vector set id
958  @param height
959 
960  @return -1 vector set not found
961  @return 1 on success
962  """
963  if not GP_site_exists(id):
964  return -1
965 
966  Debug.msg(3, "Nviz::SetVectorPointHeight(): id=%d, height=%f",
967  id, height)
968 
969  GP_set_trans(id, 0.0, 0.0, height)
970 
971  return 1
972 
973  def SetVectorPointSurface(self, id, surf_id):
974  """!Set reference surface of vector set (points)
975 
976  @param id vector set id
977  @param surf_id surface id
978 
979  @return 1 on success
980  @return -1 vector set not found
981  @return -2 surface not found
982  @return -3 on failure
983  """
984  if not GP_site_exists(id):
985  return -1
986 
987  if not GS_surf_exists(surf_id):
988  return -2
989 
990  if GP_select_surf(id, surf_id) < 0:
991  return -3
992 
993  return 1
994 
995  def ReadVectorColors(self, name, mapset):
996  """!Read vector colors
997 
998  @param name vector map name
999  @mapset mapset name ("" for search path)
1000 
1001  @return -1 on error
1002  @return 0 if color table missing
1003  @return 1 on success (color table found)
1004  """
1005  return Vect_read_colors(name, mapset, self.color)
1006 
1007  def CheckColorTable(self, id, type):
1008  """!Check if color table exists.
1009 
1010  @param id vector set id
1011  @param type vector set type (lines/points)
1012 
1013  @return 1 color table exists
1014  @return 0 no color table found
1015  @return -1 on error
1016  @return -2 vector set not found
1017  """
1018  file = c_char_p()
1019 
1020  if type == 'points':
1021  ret = GP_get_sitename(id, byref(file))
1022  elif type == 'lines':
1023  ret = GV_get_vectname(id, byref(file))
1024 
1025  if ret < 0:
1026  return -2
1027 
1028  return self.ReadVectorColors(file, "")
1029 
1030  def UnsetVectorPointSurface(self, id, surf_id):
1031  """!Unset reference surface of vector set (points)
1032 
1033  @param id vector set id
1034  @param surf_id surface id
1035 
1036  @return 1 on success
1037  @return -1 vector set not found
1038  @return -2 surface not found
1039  @return -3 on failure
1040  """
1041  if not GP_site_exists(id):
1042  return -1
1043 
1044  if not GS_surf_exists(surf_id):
1045  return -2
1046 
1047  if GP_unselect_surf(id, surf_id) < 0:
1048  return -3
1049 
1050  return 1
1051 
1052  def SetVectorPointZMode(self, id, zMode):
1053  """!Set z mode (use z coordinate or not)
1054 
1055  @param id volume id
1056  @param zMode bool
1057 
1058  @return -1 on failure
1059  @return 0 when no 3d
1060  @return 1 on success
1061  """
1062  if not GP_site_exists(id):
1063  return -1
1064 
1065  return GP_set_zmode(id, int(zMode))
1066 
1067  def AddIsosurface(self, id, level, isosurf_id = None):
1068  """!Add new isosurface
1069 
1070  @param id volume id
1071  @param level isosurface level (topography)
1072 
1073  @return -1 on failure
1074  @return 1 on success
1075  """
1076  if not GVL_vol_exists(id):
1077  return -1
1078 
1079  if isosurf_id is not None:
1080  num = GVL_isosurf_num_isosurfs(id)
1081  if num < 0 or isosurf_id != num:
1082  return -1
1083 
1084  if GVL_isosurf_add(id) < 0:
1085  return -1
1086 
1087  # set topography level
1088  nisosurfs = GVL_isosurf_num_isosurfs(id)
1089 
1090  return GVL_isosurf_set_att_const(id, nisosurfs - 1, ATT_TOPO, level)
1091 
1092  def AddSlice(self, id, slice_id = None):
1093  """!Add new slice
1094 
1095  @param id volume id
1096 
1097  @return -1 on failure
1098  @return number of slices
1099  """
1100  if not GVL_vol_exists(id):
1101  return -1
1102 
1103  if slice_id is not None:
1104  num = GVL_slice_num_slices(id)
1105  if num < 0 or slice_id != num:
1106  return -1
1107 
1108  if GVL_slice_add(id) < 0:
1109  return -1
1110 
1111  return GVL_slice_num_slices(id)
1112 
1113  def DeleteIsosurface(self, id, isosurf_id):
1114  """!Delete isosurface
1115 
1116  @param id volume id
1117  @param isosurf_id isosurface id
1118 
1119  @return 1 on success
1120  @return -1 volume not found
1121  @return -2 isosurface not found
1122  @return -3 on failure
1123  """
1124  if not GVL_vol_exists(id):
1125  return -1
1126 
1127  if isosurf_id > GVL_isosurf_num_isosurfs(id):
1128  return -2
1129 
1130  ret = GVL_isosurf_del(id, isosurf_id)
1131 
1132  if ret < 0:
1133  return -3
1134 
1135  return 1
1136 
1137  def DeleteSlice(self, id, slice_id):
1138  """!Delete slice
1139 
1140  @param id volume id
1141  @param slice_id slice id
1142 
1143  @return 1 on success
1144  @return -1 volume not found
1145  @return -2 slice not found
1146  @return -3 on failure
1147  """
1148  if not GVL_vol_exists(id):
1149  return -1
1150 
1151  if slice_id > GVL_slice_num_slices(id):
1152  return -2
1153 
1154  ret = GVL_slice_del(id, slice_id)
1155 
1156  if ret < 0:
1157  return -3
1158 
1159  return 1
1160 
1161  def MoveIsosurface(self, id, isosurf_id, up):
1162  """!Move isosurface up/down in the list
1163 
1164  @param id volume id
1165  @param isosurf_id isosurface id
1166  @param up if true move up otherwise down
1167 
1168  @return 1 on success
1169  @return -1 volume not found
1170  @return -2 isosurface not found
1171  @return -3 on failure
1172  """
1173  if not GVL_vol_exists(id):
1174  return -1
1175 
1176  if isosurf_id > GVL_isosurf_num_isosurfs(id):
1177  return -2
1178 
1179  if up:
1180  ret = GVL_isosurf_move_up(id, isosurf_id)
1181  else:
1182  ret = GVL_isosurf_move_down(id, isosurf_id)
1183 
1184  if ret < 0:
1185  return -3
1186 
1187  return 1
1188 
1189  def MoveSlice(self, id, slice_id, up):
1190  """!Move slice up/down in the list
1191 
1192  @param id volume id
1193  @param slice_id slice id
1194  @param up if true move up otherwise down
1195 
1196  @return 1 on success
1197  @return -1 volume not found
1198  @return -2 slice not found
1199  @return -3 on failure
1200  """
1201  if not GVL_vol_exists(id):
1202  return -1
1203 
1204  if slice_id > GVL_slice_num_slices(id):
1205  return -2
1206 
1207  if up:
1208  ret = GVL_slice_move_up(id, slice_id)
1209  else:
1210  ret = GVL_slice_move_down(id, slice_id)
1211 
1212  if ret < 0:
1213  return -3
1214 
1215  return 1
1216 
1217  def SetIsosurfaceTopo(self, id, isosurf_id, map, value):
1218  """!Set isosurface level
1219 
1220  @param id volume id
1221  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1222  @param map if true use map otherwise constant
1223  @param value map name of value
1224 
1225  @return 1 on success
1226  @return -1 volume not found
1227  @return -2 isosurface not found
1228  @return -3 on failure
1229  """
1230  return self.SetIsosurfaceAttr(id, isosurf_id, ATT_TOPO, map, value)
1231 
1232  def SetIsosurfaceColor(self, id, isosurf_id, map, value):
1233  """!Set isosurface color
1234 
1235  @param id volume id
1236  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1237  @param map if true use map otherwise constant
1238  @param value map name of value
1239 
1240  @return 1 on success
1241  @return -1 volume not found
1242  @return -2 isosurface not found
1243  @return -3 on failure
1244  """
1245  return self.SetIsosurfaceAttr(id, isosurf_id, ATT_COLOR, map, value)
1246 
1247  def SetIsosurfaceMask(self, id, isosurf_id, invert, value):
1248  """!Set isosurface mask
1249 
1250  @todo invert
1251 
1252  @param id volume id
1253  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1254  @param invert true for invert mask
1255  @param value map name to be used for mask
1256 
1257  @return 1 on success
1258  @return -1 volume not found
1259  @return -2 isosurface not found
1260  @return -3 on failure
1261  """
1262  return self.SetIsosurfaceAttr(id, isosurf_id, ATT_MASK, True, value)
1263 
1264  def SetIsosurfaceTransp(self, id, isosurf_id, map, value):
1265  """!Set isosurface transparency
1266 
1267  @param id volume id
1268  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1269  @param map if true use map otherwise constant
1270  @param value map name of value
1271 
1272  @return 1 on success
1273  @return -1 volume not found
1274  @return -2 isosurface not found
1275  @return -3 on failure
1276  """
1277  return self.SetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP, map, value)
1278 
1279  def SetIsosurfaceShine(self, id, isosurf_id, map, value):
1280  """!Set isosurface shininess
1281 
1282  @param id volume id
1283  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1284  @param map if true use map otherwise constant
1285  @param value map name of value
1286 
1287  @return 1 on success
1288  @return -1 volume not found
1289  @return -2 isosurface not found
1290  @return -3 on failure
1291  """
1292  return self.SetIsosurfaceAttr(id, isosurf_id, ATT_SHINE, map, value)
1293 
1294  def SetIsosurfaceEmit(self, id, isosurf_id, map, value):
1295  """!Set isosurface emission (currently unused)
1296 
1297  @param id volume id
1298  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1299  @param map if true use map otherwise constant
1300  @param value map name of value
1301 
1302  @return 1 on success
1303  @return -1 volume not found
1304  @return -2 isosurface not found
1305  @return -3 on failure
1306  """
1307  return self.SetIsosurfaceAttr(id, isosurf_id, ATT_EMIT, map, value)
1308 
1309  def SetIsosurfaceAttr(self, id, isosurf_id, attr, map, value):
1310  """!Set isosurface attribute
1311 
1312  @param id volume id
1313  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1314  @param attr attribute desc
1315  @param map if true use map otherwise constant
1316  @param value map name of value
1317 
1318  @return 1 on success
1319  @return -1 volume not found
1320  @return -2 isosurface not found
1321  @return -3 setting attributes failed
1322  """
1323  if not GVL_vol_exists(id):
1324  return -1
1325 
1326  if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
1327  return -2
1328 
1329  if map:
1330  ret = GVL_isosurf_set_att_map(id, isosurf_id, attr, value)
1331  else:
1332  if attr == ATT_COLOR:
1333  val = Nviz_color_from_str(value)
1334  else:
1335  val = float(value)
1336 
1337  ret = GVL_isosurf_set_att_const(id, isosurf_id, attr, val)
1338 
1339  Debug.msg(3, "Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
1340  "attr=%d, map=%s, value=%s",
1341  id, isosurf_id, attr, map, value)
1342 
1343  if ret < 0:
1344  return -2
1345 
1346  return 1
1347 
1348  def UnsetIsosurfaceMask(self, id, isosurf_id):
1349  """!Unset isosurface mask
1350 
1351  @param id volume id
1352  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1353 
1354  @return 1 on success
1355  @return -1 volume not found
1356  @return -2 isosurface not found
1357  @return -3 setting attributes failed
1358  """
1359  return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_MASK)
1360 
1361  def UnsetIsosurfaceTransp(self, id, isosurf_id):
1362  """!Unset isosurface transparency
1363 
1364  @param id volume id
1365  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1366 
1367  @return 1 on success
1368  @return -1 volume not found
1369  @return -2 isosurface not found
1370  @return -3 setting attributes failed
1371  """
1372  return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_TRANSP)
1373 
1374  def UnsetIsosurfaceEmit(self, id, isosurf_id):
1375  """!Unset isosurface emission (currently unused)
1376 
1377  @param id volume id
1378  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1379 
1380  @return 1 on success
1381  @return -1 volume not found
1382  @return -2 isosurface not found
1383  @return -3 setting attributes failed
1384  """
1385  return self.UnsetIsosurfaceAttr(id, isosurf_id, ATT_EMIT)
1386 
1387  def UnsetIsosurfaceAttr(self, id, isosurf_id, attr):
1388  """!Unset surface attribute
1389 
1390  @param id surface id
1391  @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1392  @param attr attribute descriptor
1393 
1394  @return 1 on success
1395  @return -1 volume not found
1396  @return -2 isosurface not found
1397  @return -2 on failure
1398  """
1399  if not GVL_vol_exists(id):
1400  return -1
1401 
1402  if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
1403  return -2
1404 
1405  Debug.msg(3, "Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%d",
1406  id, isosurf_id, attr)
1407 
1408  ret = GVL_isosurf_unset_att(id, isosurf_id, attr)
1409 
1410  if ret < 0:
1411  return -2
1412 
1413  return 1
1414 
1415  def SetIsosurfaceMode(self, id, mode):
1416  """!Set draw mode for isosurfaces
1417 
1418  @param mode
1419 
1420  @return 1 on success
1421  @return -1 volume set not found
1422  @return -2 on failure
1423  """
1424  if not GVL_vol_exists(id):
1425  return -1
1426 
1427  ret = GVL_isosurf_set_drawmode(id, mode)
1428 
1429  if ret < 0:
1430  return -2
1431 
1432  return 1
1433 
1434  def SetSliceMode(self, id, mode):
1435  """!Set draw mode for slices
1436 
1437  @param mode
1438 
1439  @return 1 on success
1440  @return -1 volume set not found
1441  @return -2 on failure
1442  """
1443  if not GVL_vol_exists(id):
1444  return -1
1445 
1446  ret = GVL_slice_set_drawmode(id, mode)
1447 
1448  if ret < 0:
1449  return -2
1450 
1451  return 1
1452 
1453  def SetIsosurfaceRes(self, id, res):
1454  """!Set draw resolution for isosurfaces
1455 
1456  @param res resolution value
1457 
1458  @return 1 on success
1459  @return -1 volume set not found
1460  @return -2 on failure
1461  """
1462  if not GVL_vol_exists(id):
1463  return -1
1464 
1465  ret = GVL_isosurf_set_drawres(id, res, res, res)
1466 
1467  if ret < 0:
1468  return -2
1469 
1470  return 1
1471 
1472  def SetSliceRes(self, id, res):
1473  """!Set draw resolution for slices
1474 
1475  @param res resolution value
1476 
1477  @return 1 on success
1478  @return -1 volume set not found
1479  @return -2 on failure
1480  """
1481  if not GVL_vol_exists(id):
1482  return -1
1483 
1484  ret = GVL_slice_set_drawres(id, res, res, res)
1485 
1486  if ret < 0:
1487  return -2
1488 
1489  return 1
1490 
1491  def SetSlicePosition(self, id, slice_id, x1, x2, y1, y2, z1, z2, dir):
1492  """!Set slice position
1493 
1494  @param id volume id
1495  @param slice_id slice id
1496  @param x1,x2,y1,y2,z1,z2 slice coordinates
1497  @param dir axis
1498 
1499  @return 1 on success
1500  @return -1 volume not found
1501  @return -2 slice not found
1502  @return -3 on failure
1503  """
1504  if not GVL_vol_exists(id):
1505  return -1
1506 
1507  if slice_id > GVL_slice_num_slices(id):
1508  return -2
1509 
1510  ret = GVL_slice_set_pos(id, slice_id, x1, x2, y1, y2, z1, z2, dir)
1511 
1512  if ret < 0:
1513  return -2
1514 
1515  return 1
1516 
1517  def SetSliceTransp(self, id, slice_id, value):
1518  """!Set slice transparency
1519 
1520  @param id volume id
1521  @param slice_id slice id
1522  @param x1,x2,y1,y2,z1,z2 slice coordinates
1523  @param value transparency value (0 - 255)
1524 
1525  @return 1 on success
1526  @return -1 volume not found
1527  @return -2 slice not found
1528  @return -3 on failure
1529  """
1530 
1531  if not GVL_vol_exists(id):
1532  return -1
1533 
1534  if slice_id > GVL_slice_num_slices(id):
1535  return -2
1536 
1537  ret = GVL_slice_set_transp(id, slice_id, value)
1538 
1539  if ret < 0:
1540  return -2
1541 
1542  return 1
1543 
1544  def SetIsosurfaceInOut(self, id, isosurf_id, inout):
1545  """!Set inout mode
1546 
1547  @param inout mode true/false
1548 
1549  @return 1 on success
1550  @return -1 volume set not found
1551  @return -2 isosurface not found
1552  @return -3 on failure
1553  """
1554  if not GVL_vol_exists(id):
1555  return -1
1556 
1557  if isosurf_id > GVL_isosurf_num_isosurfs(id) - 1:
1558  return -2
1559 
1560  ret = GVL_isosurf_set_flags(id, isosurf_id, inout)
1561 
1562  if ret < 0:
1563  return -3
1564 
1565  return 1
1566 
1567  def GetVolumePosition(self, id):
1568  """!Get volume position
1569 
1570  @param id volume id
1571 
1572  @return x,y,z
1573  @return zero-length vector on error
1574  """
1575  if not GVL_vol_exists(id):
1576  return []
1577 
1578  x, y, z = c_float(), c_float(), c_float()
1579  GVL_get_trans(id, byref(x), byref(y), byref(z))
1580 
1581  Debug.msg(3, "Nviz::GetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
1582  id, x.value, y.value, z.value)
1583 
1584  return [x.value, y.value, z.value]
1585 
1586  def SetVolumePosition(self, id, x, y, z):
1587  """!Set volume position
1588 
1589  @param id volume id
1590  @param x,y,z translation values
1591 
1592  @return 1 on success
1593  @return -1 volume not found
1594  @return -2 setting position failed
1595  """
1596  if not GVL_vol_exists(id):
1597  return -1
1598 
1599  Debug.msg(3, "Nviz::SetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
1600  id, x, y, z)
1601 
1602  GVL_set_trans(id, x, y, z)
1603 
1604  return 1
1605 
1606  def GetCPlaneCurrent(self):
1607  return Nviz_get_current_cplane(self.data)
1608 
1609  def GetCPlanesCount(self):
1610  """!Returns number of cutting planes"""
1611  return Nviz_num_cplanes(self.data)
1612 
1614  """!Returns rotation parameters of current cutting plane"""
1615  x, y, z = c_float(), c_float(), c_float()
1616 
1617  current = Nviz_get_current_cplane(self.data)
1618  Nviz_get_cplane_rotation(self.data, current, byref(x), byref(y), byref(z))
1619 
1620  return x.value, y.value, z.value
1621 
1623  """!Returns translation parameters of current cutting plane"""
1624  x, y, z = c_float(), c_float(), c_float()
1625 
1626  current = Nviz_get_current_cplane(self.data)
1627  Nviz_get_cplane_translation(self.data, current, byref(x), byref(y), byref(z))
1628 
1629  return x.value, y.value, z.value
1630 
1631  def SetCPlaneRotation(self, x, y, z):
1632  """!Set current clip plane rotation
1633 
1634  @param x,y,z rotation parameters
1635  """
1636  current = Nviz_get_current_cplane(self.data)
1637  Nviz_set_cplane_rotation(self.data, current, x, y, z)
1638  Nviz_draw_cplane(self.data, -1, -1)
1639 
1640  def SetCPlaneTranslation(self, x, y, z):
1641  """!Set current clip plane translation
1642 
1643  @param x,y,z translation parameters
1644  """
1645  current = Nviz_get_current_cplane(self.data)
1646  Nviz_set_cplane_translation(self.data, current, x, y, z)
1647  Nviz_draw_cplane(self.data, -1, -1)
1648  Debug.msg(3, "Nviz::SetCPlaneTranslation(): id=%d, x=%f, y=%f, z=%f",
1649  current, x, y, z)
1650 
1651  def SetCPlaneInteractively(self, x, y):
1652  current = Nviz_get_current_cplane(self.data)
1653  ret = Nviz_set_cplane_here(self.data, current, x, y)
1654  if ret:
1655  Nviz_draw_cplane(self.data, -1, -1)
1656  x, y, z = self.GetCPlaneTranslation()
1657  return x, y, z
1658  else:
1659  return None, None, None
1660 
1661 
1662  def SelectCPlane(self, index):
1663  """!Select cutting plane
1664 
1665  @param index index of cutting plane
1666  """
1667  Nviz_on_cplane(self.data, index)
1668 
1669  def UnselectCPlane(self, index):
1670  """!Unselect cutting plane
1671 
1672  @param index index of cutting plane
1673  """
1674  Nviz_off_cplane(self.data, index)
1675 
1676  def SetFenceColor(self, index):
1677  """!Select current cutting plane
1678 
1679  @param index type of fence - from 0 (off) to 4
1680  """
1681  Nviz_set_fence_color(self.data, index)
1682 
1683  def GetXYRange(self):
1684  """!Get xy range"""
1685  return Nviz_get_xyrange(self.data)
1686 
1687  def GetZRange(self):
1688  """!Get z range"""
1689  min, max = c_float(), c_float()
1690  Nviz_get_zrange(self.data, byref(min), byref(max))
1691  return min.value, max.value
1692 
1693  def SaveToFile(self, filename, width = 20, height = 20, itype = 'ppm'):
1694  """!Save current GL screen to ppm/tif file
1695 
1696  @param filename file name
1697  @param width image width
1698  @param height image height
1699  @param itype image type ('ppm' or 'tif')
1700  """
1701  widthOrig = self.width
1702  heightOrig = self.height
1703 
1704  self.ResizeWindow(width, height)
1706  self.Draw(False, -1)
1707  if itype == 'ppm':
1708  GS_write_ppm(filename)
1709  else:
1710  GS_write_tif(filename)
1711 
1712  self.ResizeWindow(widthOrig, heightOrig)
1713 
1715  """!Draw lighting model"""
1716  if self.showLight:
1717  Nviz_draw_model(self.data)
1718 
1719  def DrawFringe(self):
1720  """!Draw fringe"""
1721  Nviz_draw_fringe(self.data)
1722 
1723  def SetFringe(self, sid, color, elev, nw = False, ne = False, sw = False, se = False):
1724  """!Set fringe
1725 
1726  @param sid surface id
1727  @param color color
1728  @param elev elevation (height)
1729  @param nw,ne,sw,se fringe edges (turn on/off)
1730  """
1731  scolor = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
1732  Nviz_set_fringe(self.data,
1733  sid, Nviz_color_from_str(scolor),
1734  elev, int(nw), int(ne), int(sw), int(se))
1735 
1736  def DrawArrow(self):
1737  """!Draw north arrow
1738  """
1739  return Nviz_draw_arrow(self.data)
1740 
1741  def SetArrow(self, sx, sy, size, color):
1742  """!Set north arrow from canvas coordinates
1743 
1744  @param sx,sy canvas coordinates
1745  @param size arrow length
1746  @param color arrow color
1747  """
1748  return Nviz_set_arrow(self.data, sx, sy, size, Nviz_color_from_str(color))
1749 
1750  def DeleteArrow(self):
1751  """!Delete north arrow
1752  """
1753  Nviz_delete_arrow(self.data)
1754 
1755  def SetScalebar(self, id, sx, sy, size, color):
1756  """!Set scale bar from canvas coordinates
1757 
1758  @param sx,sy canvas coordinates
1759  @param id scale bar id
1760  @param size scale bar length
1761  @param color scale bar color
1762  """
1763  return Nviz_set_scalebar(self.data, id, sx, sy, size, Nviz_color_from_str(color))
1764 
1765  def DrawScalebar(self):
1766  """!Draw scale bar
1767  """
1768  return Nviz_draw_scalebar(self.data)
1769 
1770  def DeleteScalebar(self, id):
1771  """!Delete scalebar
1772  """
1773  Nviz_delete_scalebar(self.data, id)
1774 
1775  def GetPointOnSurface(self, sx, sy):
1776  """!Get point on surface
1777 
1778  @param sx,sy canvas coordinates (LL)
1779  """
1780  sid = c_int()
1781  x = c_float()
1782  y = c_float()
1783  z = c_float()
1784  Debug.msg(5, "Nviz::GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
1785  num = GS_get_selected_point_on_surface(sx, sy, byref(sid), byref(x), byref(y), byref(z))
1786  if num == 0:
1787  return (None, None, None, None)
1788 
1789  return (sid.value, x.value, y.value, z.value)
1790 
1791  def QueryMap(self, sx, sy):
1792  """!Query surface map
1793 
1794  @param sx,sy canvas coordinates (LL)
1795  """
1796  sid, x, y, z = self.GetPointOnSurface(sx, sy)
1797  if not sid:
1798  return None
1799 
1800  catstr = create_string_buffer(256)
1801  valstr = create_string_buffer(256)
1802  GS_get_cat_at_xy(sid, ATT_TOPO, catstr, x, y)
1803  GS_get_val_at_xy(sid, ATT_COLOR, valstr, x, y)
1804 
1805  return { 'id' : sid,
1806  'x' : x,
1807  'y' : y,
1808  'z' : z,
1809  'elevation' : catstr.value.replace('(', '').replace(')', ''),
1810  'color' : valstr.value }
1811 
1812  def GetDistanceAlongSurface(self, sid, p1, p2, useExag = True):
1813  """!Get distance measured along surface"""
1814  d = c_float()
1815 
1816  GS_get_distance_alongsurf(sid, p1[0], p1[1], p2[0], p2[1],
1817  byref(d), int(useExag))
1818 
1819  return d.value
1820 
1821  def GetRotationParameters(self, dx, dy):
1822  """!Get rotation parameters (angle, x, y, z axes)
1823 
1824  @param dx,dy difference from previous mouse drag event
1825  """
1826  modelview = (c_double * 16)()
1827  Nviz_get_modelview(byref(modelview))
1828 
1829  angle = sqrt(dx*dx+dy*dy)/float(self.width+1)*180.0
1830  m = []
1831  row = []
1832  for i, item in enumerate(modelview):
1833  row.append(item)
1834  if (i+1) % 4 == 0:
1835  m.append(row)
1836  row = []
1837  inv = matrix(m).I
1838  ax, ay, az = dy, dx, 0.
1839  x = inv[0,0]*ax + inv[1,0]*ay + inv[2,0]*az
1840  y = inv[0,1]*ax + inv[1,1]*ay + inv[2,1]*az
1841  z = inv[0,2]*ax + inv[1,2]*ay + inv[2,2]*az
1842 
1843  return angle, x, y, z
1844 
1845  def Rotate(self, angle, x, y, z):
1846  """!Set rotation parameters
1847  Rotate scene (difference from current state).
1848 
1849  @param angle angle
1850  @param x,y,z axis coordinate
1851  """
1852  Nviz_set_rotation(angle, x, y, z)
1853 
1854  def UnsetRotation(self):
1855  """!Stop rotating the scene"""
1857 
1858  def ResetRotation(self):
1859  """!Reset scene rotation"""
1861 
1863  """!Get rotation matrix"""
1864  matrix = (c_double * 16)()
1865  GS_get_rotation_matrix(byref(matrix))
1866  returnMatrix = []
1867  for item in matrix:
1868  returnMatrix.append(item)
1869  return returnMatrix
1870 
1871  def SetRotationMatrix(self, matrix):
1872  """!Set rotation matrix"""
1873  mtrx = (c_double * 16)()
1874  for i in range(len(matrix)):
1875  mtrx[i] = matrix[i]
1876  GS_set_rotation_matrix(byref(mtrx))
1877 
1878  def Start2D(self):
1879  Nviz_set_2D(self.width, self.height)
1880 
1881  def FlyThrough(self, flyInfo, mode, exagInfo):
1882  """!Fly through the scene
1883 
1884  @param flyInfo fly parameters
1885  @param mode 0 or 1 for different fly behaviour
1886  @param exagInfo parameters changing fly speed
1887  """
1888  fly = (c_float * 3)()
1889  for i, item in enumerate(flyInfo):
1890  fly[i] = item
1891  exag = (c_int * 2)()
1892  exag[0] = int(exagInfo['move'])
1893  exag[1] = int(exagInfo['turn'])
1894  Nviz_flythrough(self.data, fly, exag, mode)
1895 
1896 class Texture(object):
1897  """!Class representing OpenGL texture"""
1898  def __init__(self, filepath, overlayId, coords):
1899  """!Load image to texture
1900 
1901  @param filepath path to image file
1902  @param overlayId id of overlay (1 for legend, 101 and more for text)
1903  @param coords image coordinates
1904  """
1905  self.path = filepath
1906  self.image = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
1907  self.width = self.image.GetWidth()
1908  self.height = self.image.GetHeight()
1909  self.id = overlayId
1910  self.coords = list(coords)
1911  self.bounds = wx.Rect()
1912  self.active = True
1913 
1914  # alpha needs to be initialized
1915  if not self.image.HasAlpha():
1916  self.image.InitAlpha()
1917 
1918  # resize image to match 2^n
1919  self.Resize()
1920 
1921  # check max texture size
1922  maxSize = c_int()
1923  Nviz_get_max_texture(byref(maxSize))
1924  self.maxSize = maxSize.value
1925  if self.maxSize < self.width or self.maxSize < self.height:
1926  # TODO: split up image
1927  self.textureId = None
1928  else:
1929  self.textureId = self.Load()
1930 
1931  def __del__(self):
1932  """!Delete texture"""
1933  if self.textureId:
1935  grass.try_remove(self.path)
1936 
1937  def Resize(self):
1938  """!Resize image to match 2^n"""
1939  n = m = 1
1940  while self.width > pow(2,n):
1941  n += 1
1942  while self.height > pow(2,m):
1943  m += 1
1944  self.image.Resize(size = (pow(2,n), pow(2,m)), pos = (0, 0))
1945  self.width = self.image.GetWidth()
1946  self.height = self.image.GetHeight()
1947 
1948  def Load(self):
1949  """!Load image to texture"""
1950  if self.image.HasAlpha():
1951  bytesPerPixel = 4
1952  else:
1953  bytesPerPixel = 3
1954  bytes = bytesPerPixel * self.width * self.height
1955  rev_val = self.height - 1
1956  im = (c_ubyte * bytes)()
1957  bytes3 = 3 * self.width * self.height
1958  bytes1 = self.width * self.height
1959  imageData = struct.unpack(str(bytes3) + 'B', self.image.GetData())
1960  if self.image.HasAlpha():
1961  alphaData = struct.unpack(str(bytes1) + 'B', self.image.GetAlphaData())
1962 
1963  # this takes too much time
1964  wx.BeginBusyCursor()
1965  for i in range(self.height):
1966  for j in range(self.width):
1967  im[(j + i * self.width) * bytesPerPixel + 0] = imageData[( j + (rev_val - i) * self.width) * 3 + 0]
1968  im[(j + i * self.width) * bytesPerPixel + 1] = imageData[( j + (rev_val - i) * self.width) * 3 + 1]
1969  im[(j + i * self.width) * bytesPerPixel + 2] = imageData[( j + (rev_val - i) * self.width) * 3 + 2]
1970  if self.image.HasAlpha():
1971  im[(j + i * self.width) * bytesPerPixel + 3] = alphaData[( j + (rev_val - i) * self.width)]
1972  wx.EndBusyCursor()
1973 
1974  id = Nviz_load_image(im, self.width, self.height, self.image.HasAlpha())
1975 
1976  return id
1977 
1978  def Draw(self):
1979  """!Draw texture as an image"""
1980  Nviz_draw_image(self.coords[0], self.coords[1], self.width, self.height, self.textureId)
1981 
1982 
1983  def SetBounds(self, rect):
1984  """!Set Bounding Rectangle"""
1985  self.bounds = rect
1986 
1987  def HitTest(self, x, y, radius):
1988  copy = wx.Rect(*self.bounds)
1989  copy.Inflate(radius, radius)
1990  return copy.ContainsXY(x, y)
1991 
1992  def MoveTexture(self, dx, dy):
1993  """!Move texture on the screen"""
1994  self.coords[0] += dx
1995  self.coords[1] += dy
1996  self.bounds.OffsetXY(dx, dy)
1997 
1998  def SetCoords(self, coords):
1999  """!Set coordinates"""
2000  dx = coords[0] - self.coords[0]
2001  dy = coords[1] - self.coords[1]
2002  self.MoveTexture(dx, dy)
2003 
2004  def GetId(self):
2005  """!Returns image id."""
2006  return self.id
2007 
2008  def SetActive(self, active = True):
2009  self.active = active
2010 
2011  def IsActive(self):
2012  return self.active
2013 
2015  """!Class representing OpenGL texture as an overlay image"""
2016  def __init__(self, filepath, overlayId, coords, cmd):
2017  """!Load image to texture
2018 
2019  @param filepath path to image file
2020  @param overlayId id of overlay (1 for legend)
2021  @param coords image coordinates
2022  @param cmd d.legend command
2023  """
2024  Texture.__init__(self, filepath = filepath, overlayId = overlayId, coords = coords)
2025 
2026  self.cmd = cmd
2027 
2028  def GetCmd(self):
2029  """!Returns overlay command."""
2030  return self.cmd
2031 
2032  def Corresponds(self, item):
2033  return sorted(self.GetCmd()) == sorted(item.GetCmd())
2034 
2036  """!Class representing OpenGL texture as a text label"""
2037  def __init__(self, filepath, overlayId, coords, textDict):
2038  """!Load image to texture
2039 
2040  @param filepath path to image file
2041  @param overlayId id of overlay (101 and more for text)
2042  @param coords text coordinates
2043  @param textDict text properties
2044  """
2045  Texture.__init__(self, filepath = filepath, overlayId = overlayId, coords = coords)
2046 
2047  self.textDict = textDict
2048 
2049  def GetTextDict(self):
2050  """!Returns text properties."""
2051  return self.textDict
2052 
2053 
2054  def Corresponds(self, item):
2055  t = self.GetTextDict()
2056  for prop in t.keys():
2057  if prop in ('coords','bbox'): continue
2058  if t[prop] != item[prop]:
2059  return False
2060 
2061  return True
int Nviz_get_focus(nv_data *data, float *x, float *y, float *z)
Get focus.
Definition: position.c:119
def EraseMap
Erase map display (with background color)
Definition: wxnviz.py:267
void GS_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition: GS2.c:2388
void Nviz_draw_model(nv_data *data)
Draw lighting model.
Definition: lights.c:185
int GVL_slice_move_down(int id, int slice_id)
Move down slice.
Definition: GVL2.c:1256
def ResizeWindow
GL canvas resized.
Definition: wxnviz.py:127
int GVL_isosurf_move_up(int id, int isosurf_id)
Move up isosurface in list.
Definition: GVL2.c:694
void Nviz_init_view(nv_data *data)
Definition: position.c:23
def ResetRotation
Reset scene rotation.
Definition: wxnviz.py:1858
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
def UnsetSurfaceTransp
Unset surface transparency.
Definition: wxnviz.py:654
int Nviz_color_from_str(const char *color_str)
Get color value from color string (name or RGB triplet)
Definition: nviz.c:121
def SaveToFile
Save current GL screen to ppm/tif file.
Definition: wxnviz.py:1693
int GVL_delete_vol(int id)
Delete volume set from list.
Definition: GVL2.c:190
def SetIsosurfaceTopo
Set isosurface level.
Definition: wxnviz.py:1217
int GS_get_distance_alongsurf(int hs, float x1, float y1, float x2, float y2, float *dist, int use_exag)
Measure distance &quot;as the ball rolls&quot; between two points on surface.
Definition: GS2.c:3283
int Nviz_set_viewpoint_height(double height)
Change viewpoint height.
Definition: change_view.c:157
def Resize
Resize image to match 2^n.
Definition: wxnviz.py:1937
int G_unset_error_routine(void)
After this call subsequent error messages will be handled in the default method.
int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
Definition: GVL2.c:340
def SetIsosurfaceShine
Set isosurface shininess.
Definition: wxnviz.py:1279
def SetIsosurfaceColor
Set isosurface color.
Definition: wxnviz.py:1232
def SetRotationMatrix
Set rotation matrix.
Definition: wxnviz.py:1871
int GVL_slice_move_up(int id, int slice_id)
Move up slice.
Definition: GVL2.c:1222
def SetBgColor
Set background color.
Definition: wxnviz.py:289
void Nviz_set_2D(int width, int height)
Set ortho view for drawing images.
Definition: nviz/draw.c:354
def SetSurfacePosition
Set surface position.
Definition: wxnviz.py:817
int GP_unselect_surf(int hp, int hs)
Unselect surface.
Definition: GP2.c:461
int GS_setall_drawmode(int mode)
Set all draw-modes.
Definition: GS2.c:2058
def SetFringe
Set fringe.
Definition: wxnviz.py:1723
int GS_get_selected_point_on_surface(int sx, int sy, int *id, float *x, float *y, float *z)
Get selected point of surface.
Definition: GS2.c:3052
def SetView
Change view settings.
Definition: wxnviz.py:166
int Nviz_draw_all(nv_data *data)
Draw all map objects (in full resolution) and decorations.
Definition: nviz/draw.c:204
def LookAtCenter
Center view at center of displayed surface.
Definition: wxnviz.py:198
Class representing OpenGL texture.
Definition: wxnviz.py:1896
def UnloadSurface
Unload surface.
Definition: wxnviz.py:372
def SetVectorPointZMode
Set z mode (use z coordinate or not)
Definition: wxnviz.py:1052
def GetLongDim
Get longest dimension, used for initial size of north arrow.
Definition: wxnviz.py:142
int GP_site_exists(int id)
Check if point set exists.
Definition: GP2.c:38
def UnsetRotation
Stop rotating the scene.
Definition: wxnviz.py:1854
int GS_get_val_at_xy(int id, int att, char *valstr, float x, float y)
Get RGB color at given point.
Definition: GS2.c:1307
wxGUI debugging
int GVL_slice_del(int id, int slice_id)
Delete slice.
Definition: GVL2.c:1183
void Nviz_get_viewpoint_position(double *x_pos, double *y_pos)
Definition: change_view.c:130
def SetViewdir
Set viewdir.
Definition: wxnviz.py:228
tuple pertype
Definition: wxnviz.py:79
void Nviz_delete_arrow(nv_data *data)
Deletes the North Arrow.
Definition: nviz.c:313
int Nviz_draw_cplane(nv_data *data, int bound1, int bound2)
Draw the clip plane.
Definition: cplanes_obj.c:74
def SetIsosurfaceEmit
Set isosurface emission (currently unused)
Definition: wxnviz.py:1294
int GS_surf_exists(int id)
Definition: GS2.c:194
int Nviz_get_exag_height(double *val, double *min, double *max)
Get view height.
Definition: exag.c:28
def print_error
Redirect stderr.
Definition: wxnviz.py:57
int GVL_isosurf_unset_att(int id, int isosurf_id, int att)
Unset isosurface attributes.
Definition: GVL2.c:806
int G_set_error_routine(int(*error_routine)(const char *, int))
Establishes error_routine as the routine that will handle the printing of subsequent error messages...
int Nviz_set_fence_color(nv_data *data, int type)
Set appropriate fence color.
Definition: cplanes_obj.c:239
Class representing OpenGL texture as an overlay image.
Definition: wxnviz.py:2014
int GVL_isosurf_num_isosurfs(int id)
Get number of available isosurfaces.
Definition: GVL2.c:955
Class representing OpenGL texture as a text label.
Definition: wxnviz.py:2035
int GV_vect_exists(int id)
Check if vector set exists.
Definition: GV2.c:38
int Nviz_resize_window(int width, int height)
GL canvas resized.
Definition: change_view.c:29
void Nviz_draw_image(int x, int y, int width, int height, int texture_id)
Draw image as texture.
Definition: nviz/draw.c:378
def GetSurfacePosition
Get surface position.
Definition: wxnviz.py:798
def UnselectCPlane
Unselect cutting plane.
Definition: wxnviz.py:1669
void Nviz_init_rotation(void)
Stop scene rotation.
Definition: change_view.c:305
def SetScalebar
Set scale bar from canvas coordinates.
Definition: wxnviz.py:1755
def UnsetSurfaceMask
Unset surface mask.
Definition: wxnviz.py:642
def UnsetIsosurfaceEmit
Unset isosurface emission (currently unused)
Definition: wxnviz.py:1374
def GetXYRange
Get xy range.
Definition: wxnviz.py:1683
def DeleteArrow
Delete north arrow.
Definition: wxnviz.py:1750
def SetCPlaneInteractively
Definition: wxnviz.py:1651
void G_set_percent_routine(int(*percent_routine)(int))
Establishes percent_routine as the routine that will handle the printing of percentage progress messa...
Definition: percent.c:166
int Nviz_set_attr(int id, int type, int desc, int src, const char *str_value, double num_value, nv_data *data)
Definition: map_obj.c:180
int GS_get_cat_at_xy(int id, int att, char *catstr, float x, float y)
Get surface category on given position.
Definition: GS2.c:1180
def GetCPlanesCount
Returns number of cutting planes.
Definition: wxnviz.py:1609
def SetWireColor
Set color of wire.
Definition: wxnviz.py:762
int Nviz_set_cplane_rotation(nv_data *data, int id, float dx, float dy, float dz)
Set the rotation for the current clip plane.
Definition: cplanes_obj.c:167
def SetVectorLineMode
Set mode of vector line overlay.
Definition: wxnviz.py:837
int Nviz_set_viewpoint_persp(int persp)
Change viewpoint perspective (field of view)
Definition: change_view.c:199
void Nviz_flythrough(nv_data *data, float *fly_info, int *scale, int lateral)
Fly through the scene.
Definition: change_view.c:322
def SetSlicePosition
Set slice position.
Definition: wxnviz.py:1491
def GetViewdir
Get viewdir.
Definition: wxnviz.py:220
void GS_get_rotation_matrix(double *matrix)
Get rotation matrix.
Definition: GS2.c:2927
int Nviz_set_focus_map(int type, int id)
Set focus based on loaded map.
Definition: position.c:75
void GS_clear(int col)
Clear view.
Definition: GS2.c:3416
int GS_write_tif(const char *name)
Write data to tif file.
Definition: gsd_img_tif.c:51
def UnsetVectorPointSurface
Unset reference surface of vector set (points)
Definition: wxnviz.py:1030
def Load
Load image to texture.
Definition: wxnviz.py:1948
int Nviz_get_cplane_rotation(nv_data *data, int id, float *dx, float *dy, float *dz)
Get the rotation values for the current clip plane.
Definition: cplanes_obj.c:189
def SelectCPlane
Select cutting plane.
Definition: wxnviz.py:1662
int GS_set_drawmode(int id, int mode)
Set draw mode.
Definition: GS2.c:2080
def SetVectorPointHeight
Set vector height above surface (points)
Definition: wxnviz.py:954
def DrawFringe
Draw fringe.
Definition: wxnviz.py:1719
int GP_set_sitemode(int id, int atmod, int color, int width, float size, int marker)
Set point set mode.
Definition: GP2.c:254
int GS_setall_drawres(int xres, int yres, int xwire, int ywire)
Set all draw resolutions.
Definition: GS2.c:2195
int Nviz_set_light_color(nv_data *data, int num, int red, int green, int blue)
Set light color.
Definition: lights.c:87
def SetCoords
Set coordinates.
Definition: wxnviz.py:1998
void GP_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition: GP2.c:383
void Nviz_init_data(nv_data *data)
Initialize Nviz data.
Definition: nviz.c:23
def SetSurfaceMask
Set surface mask.
Definition: wxnviz.py:551
def LookHere
Look here feature.
Definition: wxnviz.py:190
def UnsetIsosurfaceMask
Unset isosurface mask.
Definition: wxnviz.py:1348
float Nviz_get_xyrange(nv_data *data)
Get xy range.
Definition: position.c:176
def UnsetSurfaceEmit
Unset surface emission (currently unused)
Definition: wxnviz.py:665
def LoadVolume
Load 3d raster map (volume)
Definition: wxnviz.py:462
def GetCPlaneTranslation
Returns translation parameters of current cutting plane.
Definition: wxnviz.py:1622
def __init__
Load image to texture.
Definition: wxnviz.py:2037
int Nviz_get_bgcolor(nv_data *data)
Get background color.
Definition: nviz.c:109
void GS_set_wire_color(int id, int colr)
Set wire color.
Definition: GS2.c:2011
void GVL_libinit(void)
Library intialization for volumes.
Definition: GVL2.c:36
int Nviz_change_exag(nv_data *data, double exag)
Change z-exag value.
Definition: change_view.c:239
def UnloadVector
Unload vector set.
Definition: wxnviz.py:425
int Nviz_set_light_bright(nv_data *data, int num, double value)
Set light brightness.
Definition: lights.c:63
def LoadVector
Load vector map overlay.
Definition: wxnviz.py:390
int Nviz_set_light_ambient(nv_data *data, int num, double value)
Set light ambient.
Definition: lights.c:114
def DrawScalebar
Draw scale bar.
Definition: wxnviz.py:1765
def DrawArrow
Draw north arrow.
Definition: wxnviz.py:1736
void Nviz_set_rotation(double angle, double x, double y, double z)
Set rotation parameters.
Definition: change_view.c:288
float Nviz_get_longdim(nv_data *data)
Get largest dimension.
Definition: position.c:198
def __init__
Load image to texture.
Definition: wxnviz.py:1898
def SetSurfaceRes
Set surface resolution.
Definition: wxnviz.py:699
int GVL_isosurf_set_drawmode(int id, int mode)
Set isosurface draw mode.
Definition: GVL2.c:593
void Nviz_del_texture(int texture_id)
Delete texture.
Definition: nviz/draw.c:407
def __init__
Load image to texture.
Definition: wxnviz.py:2016
def SetViewDefault
Set default view (based on loaded data)
Definition: wxnviz.py:146
int Nviz_off_cplane(nv_data *data, int id)
Turn off (make inactive) the given clip plane.
Definition: cplanes_obj.c:60
char * G_find_cell2(const char *name, const char *mapset)
find a raster map (look but don&#39;t touch)
Definition: find_cell.c:83
def GetId
Returns image id.
Definition: wxnviz.py:2004
int GV_surf_is_selected(int hv, int hs)
Check if surface is selected.
Definition: GV2.c:397
def SetLight
Change lighting settings.
Definition: wxnviz.py:296
def GetCmd
Returns overlay command.
Definition: wxnviz.py:2028
void Nviz_get_modelview(double *modelMatrix)
Get current modelview matrix.
Definition: change_view.c:272
def SetVectorLineSurface
Set reference surface of vector set (lines)
Definition: wxnviz.py:882
def SetBounds
Set Bounding Rectangle.
Definition: wxnviz.py:1983
int GV_delete_vector(int id)
Delete vector set from list.
Definition: GV2.c:131
def UnsetSurfaceAttr
Unset surface attribute.
Definition: wxnviz.py:676
def GetCPlaneRotation
Returns rotation parameters of current cutting plane.
Definition: wxnviz.py:1613
int GP_get_sitename(int id, char **filename)
Get point set filename.
Definition: GP2.c:208
void GS_set_viewdir(float *dir)
Set viewdir.
Definition: GS2.c:2821
def SetSliceMode
Set draw mode for slices.
Definition: wxnviz.py:1434
int GVL_slice_add(int id)
Add slice.
Definition: GVL2.c:1147
int GVL_slice_set_drawmode(int id, int mode)
Set slice draw mode.
Definition: GVL2.c:1122
int GS_set_att_const(int id, int att, float constant)
Set attribute constant.
Definition: GS2.c:1409
def SetVectorPointSurface
Set reference surface of vector set (points)
Definition: wxnviz.py:973
def SetVectorLineHeight
Set vector height above surface (lines)
Definition: wxnviz.py:863
void Nviz_draw_scalebar(nv_data *data)
Draws the Scale bar.
Definition: nviz.c:409
int Nviz_get_zrange(nv_data *data, float *min, float *max)
Get z range.
Definition: position.c:187
int Nviz_unset_attr(int id, int type, int desc)
Definition: map_obj.c:362
int GP_set_zmode(int id, int use_z)
Set z-mode.
Definition: GP2.c:335
def GetRotationMatrix
Get rotation matrix.
Definition: wxnviz.py:1862
void G_unset_percent_routine(void)
After this call subsequent percentage progress messages will be handled in the default method...
Definition: percent.c:177
int Nviz_set_cplane_translation(nv_data *data, int id, float dx, float dy, float dz)
Set the translation for the current clip plane.
Definition: cplanes_obj.c:207
int Nviz_get_current_cplane(nv_data *data)
Get the current active cutplane.
Definition: cplanes_obj.c:152
def GetVolumePosition
Get volume position.
Definition: wxnviz.py:1567
def Draw
Draw texture as an image.
Definition: wxnviz.py:1978
void Nviz_get_viewpoint_height(double *height)
Definition: change_view.c:181
int GS_set_drawres(int id, int xres, int yres, int xwire, int ywire)
Set draw resolution for surface.
Definition: GS2.c:2218
def SetSliceTransp
Set slice transparency.
Definition: wxnviz.py:1517
def UnloadVolume
Unload volume.
Definition: wxnviz.py:507
def SetCPlaneTranslation
Set current clip plane translation.
Definition: wxnviz.py:1640
void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition: GVL2.c:314
void GS_set_rotation_matrix(double *matrix)
Set rotation matrix.
Definition: GS2.c:2939
def SetVectorPointMode
Set mode of vector point overlay.
Definition: wxnviz.py:926
def SetZExag
Set z-exag value.
Definition: wxnviz.py:236
def LoadSurface
Load raster map (surface)
Definition: wxnviz.py:309
def DeleteScalebar
Delete scalebar.
Definition: wxnviz.py:1770
def Draw
Draw canvas.
Definition: wxnviz.py:246
def GetZRange
Get z range.
Definition: wxnviz.py:1687
int GV_get_vectname(int id, char **filename)
Get vector map name.
Definition: GV2.c:206
int Nviz_set_viewpoint_twist(int twist)
Change viewpoint twist.
Definition: change_view.c:221
void GS_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
Definition: GS2.c:2411
def AddConstant
Add new constant surface.
Definition: wxnviz.py:360
int GV_unselect_surf(int hv, int hs)
Unselect surface.
Definition: GV2.c:360
int Nviz_on_cplane(nv_data *data, int id)
Turn on (make current) the given clip plane.
Definition: cplanes_obj.c:45
def GetPointOnSurface
Get point on surface.
Definition: wxnviz.py:1775
int Nviz_num_cplanes(nv_data *data)
Return the number of clip planes objects currently allocated.
Definition: cplanes_obj.c:142
def ReadVectorColors
Read vector colors.
Definition: wxnviz.py:995
def SetIsosurfaceMode
Set draw mode for isosurfaces.
Definition: wxnviz.py:1415
int GVL_slice_num_slices(int id)
Get number or slices.
Definition: GVL2.c:1289
int Nviz_look_here(double sx, double sy)
Change focused point.
Definition: change_view.c:262
def FlyThrough
Fly through the scene.
Definition: wxnviz.py:1881
def CheckColorTable
Check if color table exists.
Definition: wxnviz.py:1007
int GS_num_surfs(void)
Get number of surfaces.
Definition: GS2.c:1521
int Nviz_set_viewpoint_position(double x_pos, double y_pos)
Change position of view.
Definition: change_view.c:96
int GVL_slice_set_transp(int id, int slice_id, int transp)
Set slice trans ?
Definition: GVL2.c:1464
def SetIsosurfaceTransp
Set isosurface transparency.
Definition: wxnviz.py:1264
def SetSurfaceEmit
Set surface emission (currently unused)
Definition: wxnviz.py:594
def Start2D
Definition: wxnviz.py:1878
def GetDistanceAlongSurface
Get distance measured along surface.
Definition: wxnviz.py:1812
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
def SetIsosurfaceInOut
Set inout mode.
Definition: wxnviz.py:1544
def DeleteSlice
Delete slice.
Definition: wxnviz.py:1137
def SetSurfaceColor
Set surface color.
Definition: wxnviz.py:538
int Nviz_set_light_position(nv_data *data, int num, double x, double y, double z, double w)
Set light position.
Definition: lights.c:27
int Nviz_draw_quick(nv_data *data, int draw_mode)
Draw all surfaces in wireframe (quick mode)
Definition: nviz/draw.c:278
def SetIsosurfaceRes
Set draw resolution for isosurfaces.
Definition: wxnviz.py:1453
int Nviz_draw_arrow(nv_data *data)
Draws the North Arrow.
Definition: nviz.c:296
def SetSurfaceTopo
Set surface topography.
Definition: wxnviz.py:525
void GS_get_viewdir(float *dir)
Get viewdir.
Definition: GS2.c:2807
int GS_write_ppm(const char *name)
Save current GL screen to ppm file.
Definition: gsd_img_ppm.c:42
int Nviz_set_focus(nv_data *data, float x, float y, float z)
Set focus.
Definition: position.c:141
void Nviz_set_surface_attr_default()
Set default surface attributes.
Definition: map_obj.c:274
def SetCPlaneRotation
Set current clip plane rotation.
Definition: wxnviz.py:1631
int GVL_isosurf_set_att_map(int id, int isosurf_id, int att, const char *filename)
Set isosurface map attribute.
Definition: GVL2.c:877
def SetIsosurfaceMask
Set isosurface mask.
Definition: wxnviz.py:1247
int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
Definition: cplanes_obj.c:246
def DeleteIsosurface
Delete isosurface.
Definition: wxnviz.py:1113
void Nviz_get_max_texture(int *size)
Get maximum texture size.
Definition: nviz/draw.c:419
int GP_delete_site(int id)
Delete registrated point set.
Definition: GP2.c:131
def Rotate
Set rotation parameters Rotate scene (difference from current state).
Definition: wxnviz.py:1845
def AddIsosurface
Add new isosurface.
Definition: wxnviz.py:1067
def SetVolumePosition
Set volume position.
Definition: wxnviz.py:1586
char * G_fully_qualified_name(const char *name, const char *mapset)
fully qualified file name
Definition: nme_in_mps.c:118
def UnsetIsosurfaceTransp
Unset isosurface transparency.
Definition: wxnviz.py:1361
def SetSurfaceStyle
Set draw style.
Definition: wxnviz.py:724
void Nviz_unset_rotation(void)
Stop scene rotation.
Definition: change_view.c:297
struct fringe_data * Nviz_set_fringe(nv_data *data, int id, unsigned long color, double elev, int nw, int ne, int sw, int se)
Definition: nviz.c:190
def SetSurfaceTransp
Set surface mask.
Definition: wxnviz.py:566
int * GS_get_surf_list(int *numsurfs)
Get surface list.
Definition: GS2.c:1536
int Nviz_new_map_obj(int type, const char *name, double value, nv_data *data)
Create a new map object which can be one of surf, vect, vol or site.
Definition: map_obj.c:44
def DrawLightingModel
Draw lighting model.
Definition: wxnviz.py:1714
def UnsetIsosurfaceAttr
Unset surface attribute.
Definition: wxnviz.py:1387
char * G_find_grid3(const char *name, const char *mapset)
Definition: find_grid3.c:21
def GetFocus
Get focus.
Definition: wxnviz.py:203
void Nviz_set_bgcolor(nv_data *data, int color)
Set background color.
Definition: nviz.c:95
def GetRotationParameters
Get rotation parameters (angle, x, y, z axes)
Definition: wxnviz.py:1821
int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
Set isosurface draw resolution.
Definition: GVL2.c:532
def SetFocus
Set focus.
Definition: wxnviz.py:215
def AddSlice
Add new slice.
Definition: wxnviz.py:1092
void GS_libinit(void)
Initialize OGSF library.
Definition: GS2.c:96
def InitView
Initialize view.
Definition: wxnviz.py:273
def UnsetVectorLineSurface
Unset reference surface of vector set (lines)
Definition: wxnviz.py:904
def GetViewpointPosition
Definition: wxnviz.py:181
def __del__
Delete texture.
Definition: wxnviz.py:1931
void Nviz_draw_fringe(nv_data *data)
Definition: nviz.c:231
def Init
Initialize window.
Definition: wxnviz.py:118
int GVL_slice_set_pos(int id, int slice_id, float x1, float x2, float y1, float y2, float z1, float z2, int dir)
Get slice position.
Definition: GVL2.c:1377
tuple errtype
Definition: wxnviz.py:77
def GetTextDict
Returns text properties.
Definition: wxnviz.py:2049
def SetFenceColor
Select current cutting plane.
Definition: wxnviz.py:1676
tuple range
Definition: tools.py:1406
void Nviz_delete_scalebar(nv_data *data, int bar_id)
Deletes scale bar.
Definition: nviz.c:427
int GVL_isosurf_set_flags(int id, int isosurf_id, int inout)
Set isosurface flags.
Definition: GVL2.c:930
def GetCPlaneCurrent
Definition: wxnviz.py:1606
def __init__
Initialize Nviz class instance.
Definition: wxnviz.py:83
int GVL_isosurf_move_down(int id, int isosurf_id)
Move down isosurface in list.
Definition: GVL2.c:728
int GVL_vol_exists(int id)
Check if volume set exists.
Definition: GVL2.c:91
int GP_select_surf(int hp, int hs)
Select surface.
Definition: GP2.c:433
int Nviz_load_image(GLubyte *image_data, int width, int height, int alpha)
Load image into texture.
Definition: nviz/draw.c:315
int Nviz_get_cplane_translation(nv_data *data, int id, float *dx, float *dy, float *dz)
Get the translation values for the current clip plane.
Definition: cplanes_obj.c:226
int Nviz_has_focus(nv_data *data)
Test focus.
Definition: position.c:161
def MoveIsosurface
Move isosurface up/down in the list.
Definition: wxnviz.py:1161
struct scalebar_data * Nviz_set_scalebar(nv_data *data, int bar_id, int sx, int sy, float size, unsigned int color)
Sets the scale bar position and return world coords.
Definition: nviz.c:366
int GS_delete_surface(int id)
Delete surface.
Definition: GS2.c:1563
def SetSurfaceAttr
Set surface attribute.
Definition: wxnviz.py:607
int GVL_isosurf_add(int id)
Add isosurface.
Definition: GVL2.c:618
def MoveTexture
Move texture on the screen.
Definition: wxnviz.py:1992
def __del__
Destroy Nviz class instance.
Definition: wxnviz.py:110
def QueryMap
Query surface map.
Definition: wxnviz.py:1791
int Nviz_set_arrow(nv_data *data, int sx, int sy, float size, unsigned int color)
Sets the North Arrow position and return world coords.
Definition: nviz.c:249
def VectorSurfaceSelected
Check if surface is selected (currently unused)
Definition: wxnviz.py:449
def MoveSlice
Move slice up/down in the list.
Definition: wxnviz.py:1189
def SetIsosurfaceAttr
Set isosurface attribute.
Definition: wxnviz.py:1309
int GV_select_surf(int hv, int hs)
Select surface identified by hs to have vector identified by hv draped over it.
Definition: GV2.c:331
def SetSliceRes
Set draw resolution for slices.
Definition: wxnviz.py:1472
int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
Set constant isosurface attribute.
Definition: GVL2.c:841
def print_progress
Redirect progress info.
Definition: wxnviz.py:67
def SetSurfaceShine
Set surface shininess.
Definition: wxnviz.py:581
double Nviz_get_exag()
Get view z-exag value.
Definition: exag.c:76
int GVL_slice_set_drawres(int id, int xres, int yres, int zres)
Set slice draw resolution.
Definition: GVL2.c:1061
void GV_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition: GV2.c:281
int GVL_isosurf_del(int id, int isosurf_id)
Delete isosurface.
Definition: GVL2.c:655
def SetArrow
Set north arrow from canvas coordinates.
Definition: wxnviz.py:1741
int GV_set_vectmode(int id, int mem, int color, int width, int flat)
Set vector set mode.
Definition: GV2.c:231