4 @brief wxGUI 3D view mode (ctypes-based classes)
6 This module implements 3D visualization mode for map display (ctypes
12 - wxnviz::ImageTexture
15 (C) 2008-2011 by the GRASS Development Team
17 This program is free software under the GNU General Public License
18 (>=v2). Read the file COPYING that comes with GRASS for details.
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)
30 from numpy
import matrix
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 "
37 print >> sys.stderr,
"wxnviz.py: " + msg
48 except ImportError, e:
49 sys.stderr.write(_(
"3D view mode: %s\n") % e)
58 """!Redirect stderr"""
68 """!Redirect progress info"""
71 progress.SetValue(value)
77 errtype = CFUNCTYPE(UNCHECKED(c_int), String, c_int)
79 pertype = CFUNCTYPE(UNCHECKED(c_int), c_int)
84 """!Initialize Nviz class instance
86 @param log logging area
87 @param gprogress progressbar
89 global errfunc, perfunc, log, progress
108 Debug.msg(1,
"Nviz::Nviz()")
111 """!Destroy Nviz class instance"""
119 """!Initialize window"""
120 locale.setlocale(locale.LC_NUMERIC,
'C')
128 """!GL canvas resized
130 @param width window width
131 @param height window height
134 @return 0 on failure (window resized by default to 20x20 px)
138 Debug.msg(3,
"Nviz::ResizeWindow(): width=%d height=%d",
143 """!Get longest dimension, used for initial size of north arrow"""
147 """!Set default view (based on loaded data)
149 @return z-exag value, default, min and max height
161 Debug.msg(1,
"Nviz::SetViewDefault(): hdef=%f, hmin=%f, hmax=%f",
162 hdef.value, hmin.value, hmax.value)
164 return (z_exag, hdef.value, hmin.value, hmax.value)
166 def SetView(self, x, y, height, persp, twist):
167 """!Change view settings
170 @param persp perpective
178 Debug.msg(3,
"Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
179 x, y, height, persp, twist)
188 return (x.value, y.value, h.value)
191 """!Look here feature
192 @param x,y screen coordinates
196 Debug.msg(3,
"Nviz::LookHere(): x=%f, y=%f", x, y)
199 """!Center view at center of displayed surface"""
201 Debug.msg(3,
"Nviz::LookAtCenter()")
205 Debug.msg(3,
"Nviz::GetFocus()")
211 return x.value, y.value, z.value
217 Debug.msg(3,
"Nviz::SetFocus()")
222 Debug.msg(3,
"Nviz::GetViewdir()")
223 dir = (c_float * 3)()
226 return dir[0], dir[1], dir[2]
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)):
243 Debug.msg(3,
"Nviz::SetZExag(): z_exag=%f", z_exag)
246 def Draw(self, quick, quick_mode):
255 @param quick if true draw in wiremode
256 @param quick_mode quick mode
258 Debug.msg(3,
"Nviz::Draw(): quick=%d", quick)
268 """!Erase map display (with background color)
270 Debug.msg(1,
"Nviz::EraseMap()")
274 """!Initialize view"""
287 Debug.msg(1,
"Nviz::InitView()")
290 """!Set background color
292 @param color_str color string
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)
310 """!Load raster map (surface)
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)
317 @return -1 on failure
321 G_warning(_(
"Raster map <%s> not found"), name)
332 G_warning(_(
"Raster map <%s> not found"), color_name)
356 Debug.msg(1,
"Nviz::LoadRaster(): name=%s -> id=%d", name, id)
361 """!Add new constant surface"""
369 Debug.msg(1,
"Nviz::AddConstant(): id=%d", id)
383 Debug.msg(1,
"Nviz::UnloadSurface(): id=%d", id)
391 """!Load vector map overlay
393 @param name vector map name
394 @param points if true load 2d points rather then 2d lines
396 @return object id, id of base surface (or -1 if it is not loaded)
397 @return -1 on failure
407 mapset = G_find_vector2 (name,
"")
409 G_warning(_(
"Vector map <%s> not found"),
421 Debug.msg(1,
"Nviz::LoadVector(): name=%s -> id=%d", name, id)
426 """!Unload vector set
428 @param id vector set id
429 @param points vector points or lines set
434 Debug.msg(1,
"Nviz::UnloadVector(): id=%d", id)
450 """!Check if surface is selected (currently unused)
453 @param sid surface id
455 @return True if selected
456 @return False if not selected
459 Debug.msg(1,
"Nviz::VectorSurfaceSelected(): vid=%s, sid=%d -> selected=%d", vid, sid, selected)
463 """!Load 3d raster map (volume)
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)
470 @return -1 on failure
474 G_warning(_(
"3d raster map <%s> not found"),
486 G_warning(_(
"3d raster map <%s> not found"),
503 Debug.msg(1,
"Nviz::LoadVolume(): name=%s -> id=%d", name, id)
518 Debug.msg(1,
"Nviz::UnloadVolume(): id=%d", id)
526 """!Set surface topography
529 @param map if true use map otherwise constant
530 @param value map name of value
533 @return -1 surface not found
534 @return -2 setting attributes failed
539 """!Set surface color
542 @param map if true use map otherwise constant
543 @param value map name or value
546 @return -1 surface not found
547 @return -2 setting attributes failed
557 @param invert if true invert mask
558 @param value map name of value
561 @return -1 surface not found
562 @return -2 setting attributes failed
572 @param map if true use map otherwise constant
573 @param value map name of value
576 @return -1 surface not found
577 @return -2 setting attributes failed
582 """!Set surface shininess
585 @param map if true use map otherwise constant
586 @param value map name of value
589 @return -1 surface not found
590 @return -2 setting attributes failed
595 """!Set surface emission (currently unused)
598 @param map if true use map otherwise constant
599 @param value map name of value
602 @return -1 surface not found
603 @return -2 setting attributes failed
608 """!Set surface attribute
611 @param attr attribute desc
612 @param map if true use map otherwise constant
613 @param value map name of value
616 @return -1 surface not found
617 @return -2 setting attributes failed
624 value, -1.0, self.
data)
626 if attr == ATT_COLOR:
632 None, val, self.
data)
634 Debug.msg(3,
"Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
635 id, attr, map, value)
643 """!Unset surface mask
648 @return -1 surface not found
649 @return -2 setting attributes failed
650 @return -1 on failure
655 """!Unset surface transparency
660 @return -1 surface not found
661 @return -2 setting attributes failed
666 """!Unset surface emission (currently unused)
671 @return -1 surface not found
672 @return -2 setting attributes failed
677 """!Unset surface attribute
680 @param attr attribute descriptor
683 @return -1 surface not found
684 @return -2 setting attributes failed
689 Debug.msg(3,
"Nviz::UnsetSurfaceAttr(): id=%d, attr=%d",
700 """!Set surface resolution
703 @param fine x/y fine resolution
704 @param coarse x/y coarse resolution
707 @return -1 surface not found
708 @return -2 setting attributes failed
710 Debug.msg(3,
"Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%d",
738 @param id surface id (<= 0 for all)
739 @param style draw style
742 @return -1 surface not found
743 @return -2 setting attributes failed
745 Debug.msg(3,
"Nviz::SetSurfaceStyle(): id=%d, style=%d",
763 """!Set color of wire
767 @param surface id (< 0 for all)
768 @param color color string (R:G:B)
771 @return -1 surface not found
772 @return -2 setting attributes failed
776 Debug.msg(3,
"Nviz::SetWireColor(): id=%d, color=%s",
789 for i
in xrange(nsurfs.value):
799 """!Get surface position
804 @return zero-length vector on error
809 x, y, z = c_float(), c_float(), c_float()
812 Debug.msg(3,
"Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
813 id, x.value, y.value, z.value)
815 return [x.value, y.value, z.value]
818 """!Set surface position
821 @param x,y,z translation values
824 @return -1 surface not found
825 @return -2 setting position failed
830 Debug.msg(3,
"Nviz::SetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
838 """!Set mode of vector line overlay
841 @param color_str color string
842 @param width line width
843 @param flat display flat or on surface
845 @return -1 vector set not found
846 @return -2 on failure
852 Debug.msg(3,
"Nviz::SetVectorMode(): id=%d, color=%s, width=%d, flat=%d",
853 id, color_str, width, flat)
864 """!Set vector height above surface (lines)
866 @param id vector set id
869 @return -1 vector set not found
875 Debug.msg(3,
"Nviz::SetVectorLineHeight(): id=%d, height=%f",
883 """!Set reference surface of vector set (lines)
885 @param id vector set id
886 @param surf_id surface id
889 @return -1 vector set not found
890 @return -2 surface not found
891 @return -3 on failure
905 """!Unset reference surface of vector set (lines)
907 @param id vector set id
908 @param surf_id surface id
911 @return -1 vector set not found
912 @return -2 surface not found
913 @return -3 on failure
927 """!Set mode of vector point overlay
930 @param color_str color string
931 @param width line width
934 @return -1 vector set not found
943 Debug.msg(3,
"Nviz::SetVectorPointMode(): id=%d, color=%s, "
944 "width=%d, size=%f, marker=%d",
945 id, color_str, width, size, marker)
955 """!Set vector height above surface (points)
957 @param id vector set id
960 @return -1 vector set not found
966 Debug.msg(3,
"Nviz::SetVectorPointHeight(): id=%d, height=%f",
974 """!Set reference surface of vector set (points)
976 @param id vector set id
977 @param surf_id surface id
980 @return -1 vector set not found
981 @return -2 surface not found
982 @return -3 on failure
996 """!Read vector colors
998 @param name vector map name
999 @mapset mapset name ("" for search path)
1002 @return 0 if color table missing
1003 @return 1 on success (color table found)
1005 return Vect_read_colors(name, mapset, self.
color)
1008 """!Check if color table exists.
1010 @param id vector set id
1011 @param type vector set type (lines/points)
1013 @return 1 color table exists
1014 @return 0 no color table found
1016 @return -2 vector set not found
1020 if type ==
'points':
1022 elif type ==
'lines':
1031 """!Unset reference surface of vector set (points)
1033 @param id vector set id
1034 @param surf_id surface id
1036 @return 1 on success
1037 @return -1 vector set not found
1038 @return -2 surface not found
1039 @return -3 on failure
1053 """!Set z mode (use z coordinate or not)
1058 @return -1 on failure
1059 @return 0 when no 3d
1060 @return 1 on success
1068 """!Add new isosurface
1071 @param level isosurface level (topography)
1073 @return -1 on failure
1074 @return 1 on success
1079 if isosurf_id
is not None:
1081 if num < 0
or isosurf_id != num:
1097 @return -1 on failure
1098 @return number of slices
1103 if slice_id
is not None:
1105 if num < 0
or slice_id != num:
1114 """!Delete isosurface
1117 @param isosurf_id isosurface id
1119 @return 1 on success
1120 @return -1 volume not found
1121 @return -2 isosurface not found
1122 @return -3 on failure
1141 @param slice_id slice id
1143 @return 1 on success
1144 @return -1 volume not found
1145 @return -2 slice not found
1146 @return -3 on failure
1162 """!Move isosurface up/down in the list
1165 @param isosurf_id isosurface id
1166 @param up if true move up otherwise down
1168 @return 1 on success
1169 @return -1 volume not found
1170 @return -2 isosurface not found
1171 @return -3 on failure
1190 """!Move slice up/down in the list
1193 @param slice_id slice id
1194 @param up if true move up otherwise down
1196 @return 1 on success
1197 @return -1 volume not found
1198 @return -2 slice not found
1199 @return -3 on failure
1218 """!Set isosurface level
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
1225 @return 1 on success
1226 @return -1 volume not found
1227 @return -2 isosurface not found
1228 @return -3 on failure
1233 """!Set isosurface color
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
1240 @return 1 on success
1241 @return -1 volume not found
1242 @return -2 isosurface not found
1243 @return -3 on failure
1248 """!Set isosurface mask
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
1257 @return 1 on success
1258 @return -1 volume not found
1259 @return -2 isosurface not found
1260 @return -3 on failure
1265 """!Set isosurface transparency
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
1272 @return 1 on success
1273 @return -1 volume not found
1274 @return -2 isosurface not found
1275 @return -3 on failure
1280 """!Set isosurface shininess
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
1287 @return 1 on success
1288 @return -1 volume not found
1289 @return -2 isosurface not found
1290 @return -3 on failure
1295 """!Set isosurface emission (currently unused)
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
1302 @return 1 on success
1303 @return -1 volume not found
1304 @return -2 isosurface not found
1305 @return -3 on failure
1310 """!Set isosurface attribute
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
1318 @return 1 on success
1319 @return -1 volume not found
1320 @return -2 isosurface not found
1321 @return -3 setting attributes failed
1332 if attr == ATT_COLOR:
1339 Debug.msg(3,
"Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
1340 "attr=%d, map=%s, value=%s",
1341 id, isosurf_id, attr, map, value)
1349 """!Unset isosurface mask
1352 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1354 @return 1 on success
1355 @return -1 volume not found
1356 @return -2 isosurface not found
1357 @return -3 setting attributes failed
1362 """!Unset isosurface transparency
1365 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1367 @return 1 on success
1368 @return -1 volume not found
1369 @return -2 isosurface not found
1370 @return -3 setting attributes failed
1375 """!Unset isosurface emission (currently unused)
1378 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1380 @return 1 on success
1381 @return -1 volume not found
1382 @return -2 isosurface not found
1383 @return -3 setting attributes failed
1388 """!Unset surface attribute
1390 @param id surface id
1391 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1392 @param attr attribute descriptor
1394 @return 1 on success
1395 @return -1 volume not found
1396 @return -2 isosurface not found
1397 @return -2 on failure
1405 Debug.msg(3,
"Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%d",
1406 id, isosurf_id, attr)
1416 """!Set draw mode for isosurfaces
1420 @return 1 on success
1421 @return -1 volume set not found
1422 @return -2 on failure
1435 """!Set draw mode for slices
1439 @return 1 on success
1440 @return -1 volume set not found
1441 @return -2 on failure
1454 """!Set draw resolution for isosurfaces
1456 @param res resolution value
1458 @return 1 on success
1459 @return -1 volume set not found
1460 @return -2 on failure
1473 """!Set draw resolution for slices
1475 @param res resolution value
1477 @return 1 on success
1478 @return -1 volume set not found
1479 @return -2 on failure
1492 """!Set slice position
1495 @param slice_id slice id
1496 @param x1,x2,y1,y2,z1,z2 slice coordinates
1499 @return 1 on success
1500 @return -1 volume not found
1501 @return -2 slice not found
1502 @return -3 on failure
1518 """!Set slice transparency
1521 @param slice_id slice id
1522 @param x1,x2,y1,y2,z1,z2 slice coordinates
1523 @param value transparency value (0 - 255)
1525 @return 1 on success
1526 @return -1 volume not found
1527 @return -2 slice not found
1528 @return -3 on failure
1547 @param inout mode true/false
1549 @return 1 on success
1550 @return -1 volume set not found
1551 @return -2 isosurface not found
1552 @return -3 on failure
1568 """!Get volume position
1573 @return zero-length vector on error
1578 x, y, z = c_float(), c_float(), c_float()
1581 Debug.msg(3,
"Nviz::GetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
1582 id, x.value, y.value, z.value)
1584 return [x.value, y.value, z.value]
1587 """!Set volume position
1590 @param x,y,z translation values
1592 @return 1 on success
1593 @return -1 volume not found
1594 @return -2 setting position failed
1599 Debug.msg(3,
"Nviz::SetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
1610 """!Returns number of cutting planes"""
1614 """!Returns rotation parameters of current cutting plane"""
1615 x, y, z = c_float(), c_float(), c_float()
1620 return x.value, y.value, z.value
1623 """!Returns translation parameters of current cutting plane"""
1624 x, y, z = c_float(), c_float(), c_float()
1629 return x.value, y.value, z.value
1632 """!Set current clip plane rotation
1634 @param x,y,z rotation parameters
1641 """!Set current clip plane translation
1643 @param x,y,z translation parameters
1648 Debug.msg(3,
"Nviz::SetCPlaneTranslation(): id=%d, x=%f, y=%f, z=%f",
1659 return None,
None,
None
1663 """!Select cutting plane
1665 @param index index of cutting plane
1670 """!Unselect cutting plane
1672 @param index index of cutting plane
1677 """!Select current cutting plane
1679 @param index type of fence - from 0 (off) to 4
1689 min, max = c_float(), c_float()
1691 return min.value, max.value
1693 def SaveToFile(self, filename, width = 20, height = 20, itype = 'ppm'):
1694 """!Save current GL screen to ppm/tif file
1696 @param filename file name
1697 @param width image width
1698 @param height image height
1699 @param itype image type ('ppm' or 'tif')
1701 widthOrig = self.
width
1706 self.
Draw(
False, -1)
1715 """!Draw lighting model"""
1723 def SetFringe(self, sid, color, elev, nw = False, ne = False, sw = False, se = False):
1726 @param sid surface id
1728 @param elev elevation (height)
1729 @param nw,ne,sw,se fringe edges (turn on/off)
1731 scolor = str(color[0]) +
':' + str(color[1]) +
':' + str(color[2])
1734 elev, int(nw), int(ne), int(sw), int(se))
1737 """!Draw north arrow
1742 """!Set north arrow from canvas coordinates
1744 @param sx,sy canvas coordinates
1745 @param size arrow length
1746 @param color arrow color
1751 """!Delete north arrow
1756 """!Set scale bar from canvas coordinates
1758 @param sx,sy canvas coordinates
1759 @param id scale bar id
1760 @param size scale bar length
1761 @param color scale bar color
1776 """!Get point on surface
1778 @param sx,sy canvas coordinates (LL)
1784 Debug.msg(5,
"Nviz::GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
1787 return (
None,
None,
None,
None)
1789 return (sid.value, x.value, y.value, z.value)
1792 """!Query surface map
1794 @param sx,sy canvas coordinates (LL)
1800 catstr = create_string_buffer(256)
1801 valstr = create_string_buffer(256)
1805 return {
'id' : sid,
1809 'elevation' : catstr.value.replace(
'(',
'').replace(
')',
''),
1810 'color' : valstr.value }
1813 """!Get distance measured along surface"""
1817 byref(d), int(useExag))
1822 """!Get rotation parameters (angle, x, y, z axes)
1824 @param dx,dy difference from previous mouse drag event
1826 modelview = (c_double * 16)()
1829 angle = sqrt(dx*dx+dy*dy)/float(self.
width+1)*180.0
1832 for i, item
in enumerate(modelview):
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
1843 return angle, x, y, z
1846 """!Set rotation parameters
1847 Rotate scene (difference from current state).
1850 @param x,y,z axis coordinate
1855 """!Stop rotating the scene"""
1859 """!Reset scene rotation"""
1863 """!Get rotation matrix"""
1864 matrix = (c_double * 16)()
1868 returnMatrix.append(item)
1872 """!Set rotation matrix"""
1873 mtrx = (c_double * 16)()
1874 for i
in range(len(matrix)):
1882 """!Fly through the scene
1884 @param flyInfo fly parameters
1885 @param mode 0 or 1 for different fly behaviour
1886 @param exagInfo parameters changing fly speed
1888 fly = (c_float * 3)()
1889 for i, item
in enumerate(flyInfo):
1891 exag = (c_int * 2)()
1892 exag[0] = int(exagInfo[
'move'])
1893 exag[1] = int(exagInfo[
'turn'])
1897 """!Class representing OpenGL texture"""
1899 """!Load image to texture
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
1906 self.
image = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
1915 if not self.image.HasAlpha():
1916 self.image.InitAlpha()
1932 """!Delete texture"""
1935 grass.try_remove(self.
path)
1938 """!Resize image to match 2^n"""
1940 while self.
width > pow(2,n):
1942 while self.
height > pow(2,m):
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()
1949 """!Load image to texture"""
1950 if self.image.HasAlpha():
1955 rev_val = self.
height - 1
1956 im = (c_ubyte * bytes)()
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())
1964 wx.BeginBusyCursor()
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)]
1979 """!Draw texture as an image"""
1984 """!Set Bounding Rectangle"""
1988 copy = wx.Rect(*self.
bounds)
1989 copy.Inflate(radius, radius)
1990 return copy.ContainsXY(x, y)
1993 """!Move texture on the screen"""
1996 self.bounds.OffsetXY(dx, dy)
1999 """!Set coordinates"""
2000 dx = coords[0] - self.
coords[0]
2001 dy = coords[1] - self.
coords[1]
2005 """!Returns image id."""
2015 """!Class representing OpenGL texture as an overlay image"""
2017 """!Load image to texture
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
2024 Texture.__init__(self, filepath = filepath, overlayId = overlayId, coords = coords)
2029 """!Returns overlay command."""
2033 return sorted(self.
GetCmd()) == sorted(item.GetCmd())
2036 """!Class representing OpenGL texture as a text label"""
2037 def __init__(self, filepath, overlayId, coords, textDict):
2038 """!Load image to texture
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
2045 Texture.__init__(self, filepath = filepath, overlayId = overlayId, coords = coords)
2050 """!Returns text properties."""
2056 for prop
in t.keys():
2057 if prop
in (
'coords',
'bbox'):
continue
2058 if t[prop] != item[prop]:
int Nviz_get_focus(nv_data *data, float *x, float *y, float *z)
Get focus.
def EraseMap
Erase map display (with background color)
void GS_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
void Nviz_draw_model(nv_data *data)
Draw lighting model.
int GVL_slice_move_down(int id, int slice_id)
Move down slice.
def ResizeWindow
GL canvas resized.
int GVL_isosurf_move_up(int id, int isosurf_id)
Move up isosurface in list.
void Nviz_init_view(nv_data *data)
def ResetRotation
Reset scene rotation.
void G_free(void *buf)
Free allocated memory.
def UnsetSurfaceTransp
Unset surface transparency.
int Nviz_color_from_str(const char *color_str)
Get color value from color string (name or RGB triplet)
def SaveToFile
Save current GL screen to ppm/tif file.
int GVL_delete_vol(int id)
Delete volume set from list.
def SetIsosurfaceTopo
Set isosurface level.
int GS_get_distance_alongsurf(int hs, float x1, float y1, float x2, float y2, float *dist, int use_exag)
Measure distance "as the ball rolls" between two points on surface.
int Nviz_set_viewpoint_height(double height)
Change viewpoint height.
def Resize
Resize image to match 2^n.
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 ?
def SetIsosurfaceShine
Set isosurface shininess.
def SetIsosurfaceColor
Set isosurface color.
def SetRotationMatrix
Set rotation matrix.
int GVL_slice_move_up(int id, int slice_id)
Move up slice.
def SetBgColor
Set background color.
void Nviz_set_2D(int width, int height)
Set ortho view for drawing images.
def SetSurfacePosition
Set surface position.
int GP_unselect_surf(int hp, int hs)
Unselect surface.
int GS_setall_drawmode(int mode)
Set all draw-modes.
int GS_get_selected_point_on_surface(int sx, int sy, int *id, float *x, float *y, float *z)
Get selected point of surface.
def SetView
Change view settings.
int Nviz_draw_all(nv_data *data)
Draw all map objects (in full resolution) and decorations.
def LookAtCenter
Center view at center of displayed surface.
Class representing OpenGL texture.
def UnloadSurface
Unload surface.
def SetVectorPointZMode
Set z mode (use z coordinate or not)
def GetLongDim
Get longest dimension, used for initial size of north arrow.
int GP_site_exists(int id)
Check if point set exists.
def UnsetRotation
Stop rotating the scene.
int GS_get_val_at_xy(int id, int att, char *valstr, float x, float y)
Get RGB color at given point.
int GVL_slice_del(int id, int slice_id)
Delete slice.
void Nviz_get_viewpoint_position(double *x_pos, double *y_pos)
def SetViewdir
Set viewdir.
void Nviz_delete_arrow(nv_data *data)
Deletes the North Arrow.
int Nviz_draw_cplane(nv_data *data, int bound1, int bound2)
Draw the clip plane.
def SetIsosurfaceEmit
Set isosurface emission (currently unused)
int GS_surf_exists(int id)
int Nviz_get_exag_height(double *val, double *min, double *max)
Get view height.
def print_error
Redirect stderr.
int GVL_isosurf_unset_att(int id, int isosurf_id, int att)
Unset isosurface attributes.
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.
Class representing OpenGL texture as an overlay image.
int GVL_isosurf_num_isosurfs(int id)
Get number of available isosurfaces.
Class representing OpenGL texture as a text label.
int GV_vect_exists(int id)
Check if vector set exists.
int Nviz_resize_window(int width, int height)
GL canvas resized.
void Nviz_draw_image(int x, int y, int width, int height, int texture_id)
Draw image as texture.
def GetSurfacePosition
Get surface position.
def UnselectCPlane
Unselect cutting plane.
void Nviz_init_rotation(void)
Stop scene rotation.
def SetScalebar
Set scale bar from canvas coordinates.
def UnsetSurfaceMask
Unset surface mask.
def UnsetIsosurfaceEmit
Unset isosurface emission (currently unused)
def GetXYRange
Get xy range.
def DeleteArrow
Delete north arrow.
def SetCPlaneInteractively
void G_set_percent_routine(int(*percent_routine)(int))
Establishes percent_routine as the routine that will handle the printing of percentage progress messa...
int Nviz_set_attr(int id, int type, int desc, int src, const char *str_value, double num_value, nv_data *data)
int GS_get_cat_at_xy(int id, int att, char *catstr, float x, float y)
Get surface category on given position.
def GetCPlanesCount
Returns number of cutting planes.
def SetWireColor
Set color of wire.
int Nviz_set_cplane_rotation(nv_data *data, int id, float dx, float dy, float dz)
Set the rotation for the current clip plane.
def SetVectorLineMode
Set mode of vector line overlay.
int Nviz_set_viewpoint_persp(int persp)
Change viewpoint perspective (field of view)
void Nviz_flythrough(nv_data *data, float *fly_info, int *scale, int lateral)
Fly through the scene.
def SetSlicePosition
Set slice position.
def GetViewdir
Get viewdir.
void GS_get_rotation_matrix(double *matrix)
Get rotation matrix.
int Nviz_set_focus_map(int type, int id)
Set focus based on loaded map.
void GS_clear(int col)
Clear view.
int GS_write_tif(const char *name)
Write data to tif file.
def UnsetVectorPointSurface
Unset reference surface of vector set (points)
def Load
Load image to texture.
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.
def SelectCPlane
Select cutting plane.
int GS_set_drawmode(int id, int mode)
Set draw mode.
def SetVectorPointHeight
Set vector height above surface (points)
def DrawFringe
Draw fringe.
int GP_set_sitemode(int id, int atmod, int color, int width, float size, int marker)
Set point set mode.
int GS_setall_drawres(int xres, int yres, int xwire, int ywire)
Set all draw resolutions.
int Nviz_set_light_color(nv_data *data, int num, int red, int green, int blue)
Set light color.
def SetCoords
Set coordinates.
void GP_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
void Nviz_init_data(nv_data *data)
Initialize Nviz data.
def SetSurfaceMask
Set surface mask.
def LookHere
Look here feature.
def UnsetIsosurfaceMask
Unset isosurface mask.
float Nviz_get_xyrange(nv_data *data)
Get xy range.
def UnsetSurfaceEmit
Unset surface emission (currently unused)
def LoadVolume
Load 3d raster map (volume)
def GetCPlaneTranslation
Returns translation parameters of current cutting plane.
def __init__
Load image to texture.
int Nviz_get_bgcolor(nv_data *data)
Get background color.
void GS_set_wire_color(int id, int colr)
Set wire color.
void GVL_libinit(void)
Library intialization for volumes.
int Nviz_change_exag(nv_data *data, double exag)
Change z-exag value.
def UnloadVector
Unload vector set.
int Nviz_set_light_bright(nv_data *data, int num, double value)
Set light brightness.
def LoadVector
Load vector map overlay.
int Nviz_set_light_ambient(nv_data *data, int num, double value)
Set light ambient.
def DrawScalebar
Draw scale bar.
def DrawArrow
Draw north arrow.
void Nviz_set_rotation(double angle, double x, double y, double z)
Set rotation parameters.
float Nviz_get_longdim(nv_data *data)
Get largest dimension.
def __init__
Load image to texture.
def SetSurfaceRes
Set surface resolution.
int GVL_isosurf_set_drawmode(int id, int mode)
Set isosurface draw mode.
void Nviz_del_texture(int texture_id)
Delete texture.
def __init__
Load image to texture.
def SetViewDefault
Set default view (based on loaded data)
int Nviz_off_cplane(nv_data *data, int id)
Turn off (make inactive) the given clip plane.
char * G_find_cell2(const char *name, const char *mapset)
find a raster map (look but don't touch)
def GetId
Returns image id.
int GV_surf_is_selected(int hv, int hs)
Check if surface is selected.
def SetLight
Change lighting settings.
def GetCmd
Returns overlay command.
void Nviz_get_modelview(double *modelMatrix)
Get current modelview matrix.
def SetVectorLineSurface
Set reference surface of vector set (lines)
def SetBounds
Set Bounding Rectangle.
int GV_delete_vector(int id)
Delete vector set from list.
def UnsetSurfaceAttr
Unset surface attribute.
def GetCPlaneRotation
Returns rotation parameters of current cutting plane.
int GP_get_sitename(int id, char **filename)
Get point set filename.
void GS_set_viewdir(float *dir)
Set viewdir.
def SetSliceMode
Set draw mode for slices.
int GVL_slice_add(int id)
Add slice.
int GVL_slice_set_drawmode(int id, int mode)
Set slice draw mode.
int GS_set_att_const(int id, int att, float constant)
Set attribute constant.
def SetVectorPointSurface
Set reference surface of vector set (points)
def SetVectorLineHeight
Set vector height above surface (lines)
void Nviz_draw_scalebar(nv_data *data)
Draws the Scale bar.
int Nviz_get_zrange(nv_data *data, float *min, float *max)
Get z range.
int Nviz_unset_attr(int id, int type, int desc)
int GP_set_zmode(int id, int use_z)
Set z-mode.
def GetRotationMatrix
Get rotation matrix.
void G_unset_percent_routine(void)
After this call subsequent percentage progress messages will be handled in the default method...
int Nviz_set_cplane_translation(nv_data *data, int id, float dx, float dy, float dz)
Set the translation for the current clip plane.
int Nviz_get_current_cplane(nv_data *data)
Get the current active cutplane.
def GetVolumePosition
Get volume position.
def Draw
Draw texture as an image.
void Nviz_get_viewpoint_height(double *height)
int GS_set_drawres(int id, int xres, int yres, int xwire, int ywire)
Set draw resolution for surface.
def SetSliceTransp
Set slice transparency.
def UnloadVolume
Unload volume.
def SetCPlaneTranslation
Set current clip plane translation.
void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
void GS_set_rotation_matrix(double *matrix)
Set rotation matrix.
def SetVectorPointMode
Set mode of vector point overlay.
def SetZExag
Set z-exag value.
def LoadSurface
Load raster map (surface)
def DeleteScalebar
Delete scalebar.
def GetZRange
Get z range.
int GV_get_vectname(int id, char **filename)
Get vector map name.
int Nviz_set_viewpoint_twist(int twist)
Change viewpoint twist.
void GS_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
def AddConstant
Add new constant surface.
int GV_unselect_surf(int hv, int hs)
Unselect surface.
int Nviz_on_cplane(nv_data *data, int id)
Turn on (make current) the given clip plane.
def GetPointOnSurface
Get point on surface.
int Nviz_num_cplanes(nv_data *data)
Return the number of clip planes objects currently allocated.
def ReadVectorColors
Read vector colors.
def SetIsosurfaceMode
Set draw mode for isosurfaces.
int GVL_slice_num_slices(int id)
Get number or slices.
int Nviz_look_here(double sx, double sy)
Change focused point.
def FlyThrough
Fly through the scene.
def CheckColorTable
Check if color table exists.
int GS_num_surfs(void)
Get number of surfaces.
int Nviz_set_viewpoint_position(double x_pos, double y_pos)
Change position of view.
int GVL_slice_set_transp(int id, int slice_id, int transp)
Set slice trans ?
def SetIsosurfaceTransp
Set isosurface transparency.
def SetSurfaceEmit
Set surface emission (currently unused)
def GetDistanceAlongSurface
Get distance measured along surface.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
def SetIsosurfaceInOut
Set inout mode.
def DeleteSlice
Delete slice.
def SetSurfaceColor
Set surface color.
int Nviz_set_light_position(nv_data *data, int num, double x, double y, double z, double w)
Set light position.
int Nviz_draw_quick(nv_data *data, int draw_mode)
Draw all surfaces in wireframe (quick mode)
def SetIsosurfaceRes
Set draw resolution for isosurfaces.
int Nviz_draw_arrow(nv_data *data)
Draws the North Arrow.
def SetSurfaceTopo
Set surface topography.
void GS_get_viewdir(float *dir)
Get viewdir.
int GS_write_ppm(const char *name)
Save current GL screen to ppm file.
int Nviz_set_focus(nv_data *data, float x, float y, float z)
Set focus.
void Nviz_set_surface_attr_default()
Set default surface attributes.
def SetCPlaneRotation
Set current clip plane rotation.
int GVL_isosurf_set_att_map(int id, int isosurf_id, int att, const char *filename)
Set isosurface map attribute.
def SetIsosurfaceMask
Set isosurface mask.
int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
def DeleteIsosurface
Delete isosurface.
void Nviz_get_max_texture(int *size)
Get maximum texture size.
int GP_delete_site(int id)
Delete registrated point set.
def Rotate
Set rotation parameters Rotate scene (difference from current state).
def AddIsosurface
Add new isosurface.
def SetVolumePosition
Set volume position.
char * G_fully_qualified_name(const char *name, const char *mapset)
fully qualified file name
def UnsetIsosurfaceTransp
Unset isosurface transparency.
def SetSurfaceStyle
Set draw style.
void Nviz_unset_rotation(void)
Stop scene rotation.
struct fringe_data * Nviz_set_fringe(nv_data *data, int id, unsigned long color, double elev, int nw, int ne, int sw, int se)
def SetSurfaceTransp
Set surface mask.
int * GS_get_surf_list(int *numsurfs)
Get surface list.
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.
def DrawLightingModel
Draw lighting model.
def UnsetIsosurfaceAttr
Unset surface attribute.
char * G_find_grid3(const char *name, const char *mapset)
void Nviz_set_bgcolor(nv_data *data, int color)
Set background color.
def GetRotationParameters
Get rotation parameters (angle, x, y, z axes)
int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
Set isosurface draw resolution.
def AddSlice
Add new slice.
void GS_libinit(void)
Initialize OGSF library.
def InitView
Initialize view.
def UnsetVectorLineSurface
Unset reference surface of vector set (lines)
def __del__
Delete texture.
void Nviz_draw_fringe(nv_data *data)
def Init
Initialize window.
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.
def GetTextDict
Returns text properties.
def SetFenceColor
Select current cutting plane.
void Nviz_delete_scalebar(nv_data *data, int bar_id)
Deletes scale bar.
int GVL_isosurf_set_flags(int id, int isosurf_id, int inout)
Set isosurface flags.
def __init__
Initialize Nviz class instance.
int GVL_isosurf_move_down(int id, int isosurf_id)
Move down isosurface in list.
int GVL_vol_exists(int id)
Check if volume set exists.
int GP_select_surf(int hp, int hs)
Select surface.
int Nviz_load_image(GLubyte *image_data, int width, int height, int alpha)
Load image into texture.
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.
int Nviz_has_focus(nv_data *data)
Test focus.
def MoveIsosurface
Move isosurface up/down in the list.
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.
int GS_delete_surface(int id)
Delete surface.
def SetSurfaceAttr
Set surface attribute.
int GVL_isosurf_add(int id)
Add isosurface.
def MoveTexture
Move texture on the screen.
def __del__
Destroy Nviz class instance.
def QueryMap
Query surface map.
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.
def VectorSurfaceSelected
Check if surface is selected (currently unused)
def MoveSlice
Move slice up/down in the list.
def SetIsosurfaceAttr
Set isosurface attribute.
int GV_select_surf(int hv, int hs)
Select surface identified by hs to have vector identified by hv draped over it.
def SetSliceRes
Set draw resolution for slices.
int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
Set constant isosurface attribute.
def print_progress
Redirect progress info.
def SetSurfaceShine
Set surface shininess.
double Nviz_get_exag()
Get view z-exag value.
int GVL_slice_set_drawres(int id, int xres, int yres, int zres)
Set slice draw resolution.
void GV_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
int GVL_isosurf_del(int id, int isosurf_id)
Delete isosurface.
def SetArrow
Set north arrow from canvas coordinates.
int GV_set_vectmode(int id, int mem, int color, int width, int flat)
Set vector set mode.