4 @brief wxGUI 3D view mode
6 This module implements 3D visualization mode for map display.
11 (C) 2008-2010 by the GRASS Development Team
13 This program is free software under the GNU General Public
14 License (>=v2). Read the file COPYING that comes with GRASS
17 @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
18 @author Pythonized by Glynn Clements
22 from threading
import Thread
30 except ImportError, e:
31 sys.stderr.write(_(
"3D view mode: %s\n") % e)
33 from debug
import Debug
39 """!Redirect stderr"""
49 """!Redirect progress info"""
52 progress.SetValue(value)
58 errtype = CFUNCTYPE(UNCHECKED(c_int), String, c_int)
60 pertype = CFUNCTYPE(UNCHECKED(c_int), c_int)
65 """!Initialize Nviz class instance
67 @param log logging area
69 global errfunc, perfunc, log, progress
85 Debug.msg(1,
"Nviz::Nviz()")
88 """!Destroy Nviz class instance"""
98 @param width window width
99 @param height window height
102 @return 0 on failure (window resized by default to 20x20 px)
106 Debug.msg(3,
"Nviz::ResizeWindow(): width=%d height=%d",
111 """!Set default view (based on loaded data)
113 @return z-exag value, default, min and max height
125 Debug.msg(1,
"Nviz::SetViewDefault(): hdef=%f, hmin=%f, hmax=%f",
126 hdef.value, hmin.value, hmax.value)
128 return (z_exag, hdef.value, hmin.value, hmax.value)
130 def SetView(self, x, y, height, persp, twist):
131 """!Change view settings
134 @param persp perpective
142 Debug.msg(3,
"Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
143 x, y, height, persp, twist)
152 Debug.msg(3,
"Nviz::SetZExag(): z_exag=%f", z_exag)
155 def Draw(self, quick, quick_mode):
164 @param quick if true draw in wiremode
165 @param quick_mode quick mode
167 Debug.msg(3,
"Nviz::Draw(): quick=%d", quick)
177 """!Erase map display (with background color)
179 Debug.msg(1,
"Nviz::EraseMap()")
183 """!Initialize view"""
196 Debug.msg(1,
"Nviz::InitView()")
199 """!Set background color
201 @param color_str color string
205 def SetLight(self, x, y, z, color, bright, ambient, w = 0, lid = 1):
206 """!Change lighting settings
207 @param x,y,z position
208 @param color light color (as string)
209 @param bright light brightness
210 @param ambient light ambient
211 @param w local coordinate (default to 0)
219 """!Load raster map (surface)
221 @param name raster map name
222 @param color_name raster map for color (None for color_value)
223 @param color_value color string (named color or RGB triptet)
226 @return -1 on failure
230 G_warning(_(
"Raster map <%s> not found"), name)
241 G_warning(_(
"Raster map <%s> not found"), color_name)
265 Debug.msg(1,
"Nviz::LoadRaster(): name=%s -> id=%d", name, id)
280 Debug.msg(1,
"Nviz::UnloadSurface(): id=%d", id)
288 """!Load vector map overlay
290 @param name vector map name
291 @param points if true load 2d points rather then 2d lines
294 @return -1 on failure
303 mapset = G_find_vector2 (name,
"")
305 G_warning(_(
"Vector map <%s> not found"),
317 Debug.msg(1,
"Nviz::LoadVector(): name=%s -> id=%d", name, id)
322 """!Unload vector set
324 @param id vector set id
325 @param points vector points or lines set
330 Debug.msg(1,
"Nviz::UnloadVector(): id=%d", id)
346 """!Load 3d raster map (volume)
348 @param name 3d raster map name
349 @param color_name 3d raster map for color (None for color_value)
350 @param color_value color string (named color or RGB triptet)
353 @return -1 on failure
357 G_warning(_(
"3d raster map <%s> not found"),
369 G_warning(_(
"3d raster map <%s> not found"),
386 Debug.msg(1,
"Nviz::LoadVolume(): name=%s -> id=%d", name, id)
401 Debug.msg(1,
"Nviz::UnloadVolume(): id=%d", id)
409 """!Set surface topography
412 @param map if true use map otherwise constant
413 @param value map name of value
416 @return -1 surface not found
417 @return -2 setting attributes failed
422 """!Set surface color
425 @param map if true use map otherwise constant
426 @param value map name of value
429 @return -1 surface not found
430 @return -2 setting attributes failed
440 @param invert if true invert mask
441 @param value map name of value
444 @return -1 surface not found
445 @return -2 setting attributes failed
455 @param map if true use map otherwise constant
456 @param value map name of value
459 @return -1 surface not found
460 @return -2 setting attributes failed
465 """!Set surface shininess
468 @param map if true use map otherwise constant
469 @param value map name of value
472 @return -1 surface not found
473 @return -2 setting attributes failed
478 """!Set surface emission
481 @param map if true use map otherwise constant
482 @param value map name of value
485 @return -1 surface not found
486 @return -2 setting attributes failed
491 """!Set surface attribute
494 @param attr attribute desc
495 @param map if true use map otherwise constant
496 @param value map name of value
499 @return -1 surface not found
500 @return -2 setting attributes failed
507 value, -1.0, self.
data)
509 if attr == ATT_COLOR:
515 None, val, self.
data)
517 Debug.msg(3,
"Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
518 id, attr, map, value)
526 """!Unset surface mask
531 @return -1 surface not found
532 @return -2 setting attributes failed
533 @return -1 on failure
538 """!Unset surface transparency
543 @return -1 surface not found
544 @return -2 setting attributes failed
549 """!Unset surface emission
554 @return -1 surface not found
555 @return -2 setting attributes failed
560 """!Unset surface attribute
563 @param attr attribute descriptor
566 @return -1 surface not found
567 @return -2 setting attributes failed
572 Debug.msg(3,
"Nviz::UnsetSurfaceAttr(): id=%d, attr=%d",
583 """!Set surface resolution
586 @param fine x/y fine resolution
587 @param coarse x/y coarse resolution
590 @return -1 surface not found
591 @return -2 setting attributes failed
593 Debug.msg(3,
"Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%d",
621 @param id surface id (<= 0 for all)
622 @param style draw style
625 @return -1 surface not found
626 @return -2 setting attributes failed
628 Debug.msg(3,
"Nviz::SetSurfaceStyle(): id=%d, style=%d",
646 """!Set color of wire
650 @param surface id (< 0 for all)
651 @param color color string (R:G:B)
654 @return -1 surface not found
655 @return -2 setting attributes failed
659 Debug.msg(3,
"Nviz::SetWireColor(): id=%d, color=%s",
672 for i
in xrange(nsurfs.value):
682 """!Get surface position
687 @return zero-length vector on error
692 x, y, z = c_float(), c_float(), c_float()
695 Debug.msg(3,
"Nviz::GetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
696 id, x.value, y.value, z.value)
698 return [x.value, y.value, z.value]
701 """!Set surface position
704 @param x,y,z translation values
707 @return -1 surface not found
708 @return -2 setting position failed
713 Debug.msg(3,
"Nviz::SetSurfacePosition(): id=%d, x=%f, y=%f, z=%f",
721 """!Set mode of vector line overlay
724 @param color_str color string
725 @param width line width
726 @param flat display flat or on surface
728 @return -1 vector set not found
729 @return -2 on failure
735 Debug.msg(3,
"Nviz::SetVectorMode(): id=%d, color=%s, width=%d, flat=%d",
736 id, color_str, width, flat)
747 """!Set vector height above surface (lines)
749 @param id vector set id
752 @return -1 vector set not found
758 Debug.msg(3,
"Nviz::SetVectorLineHeight(): id=%d, height=%f",
766 """!Set reference surface of vector set (lines)
768 @param id vector set id
769 @param surf_id surface id
772 @return -1 vector set not found
773 @return -2 surface not found
774 @return -3 on failure
788 """!Set mode of vector point overlay
791 @param color_str color string
792 @param width line width
795 @return -1 vector set not found
800 Debug.msg(3,
"Nviz::SetVectorPointMode(): id=%d, color=%s, "
801 "width=%d, size=%f, marker=%d",
802 id, color_str, width, size, marker)
813 """!Set vector height above surface (points)
815 @param id vector set id
818 @return -1 vector set not found
824 Debug.msg(3,
"Nviz::SetVectorPointHeight(): id=%d, height=%f",
832 """!Set reference surface of vector set (points)
834 @param id vector set id
835 @param surf_id surface id
838 @return -1 vector set not found
839 @return -2 surface not found
840 @return -3 on failure
854 """!Add new isosurface
857 @param level isosurface level (topography)
859 @return -1 on failure
874 """!Delete isosurface
877 @param isosurf_id isosurface id
880 @return -1 volume not found
881 @return -2 isosurface not found
882 @return -3 on failure
898 """!Move isosurface up/down in the list
901 @param isosurf_id isosurface id
902 @param up if true move up otherwise down
905 @return -1 volume not found
906 @return -2 isosurface not found
907 @return -3 on failure
926 """!Set isosurface color
929 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
930 @param map if true use map otherwise constant
931 @param value map name of value
934 @return -1 volume not found
935 @return -2 isosurface not found
936 @return -3 on failure
941 """!Set isosurface mask
946 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
947 @param invert true for invert mask
948 @param value map name to be used for mask
951 @return -1 volume not found
952 @return -2 isosurface not found
953 @return -3 on failure
958 """!Set isosurface transparency
961 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
962 @param map if true use map otherwise constant
963 @param value map name of value
966 @return -1 volume not found
967 @return -2 isosurface not found
968 @return -3 on failure
973 """!Set isosurface shininess
976 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
977 @param map if true use map otherwise constant
978 @param value map name of value
981 @return -1 volume not found
982 @return -2 isosurface not found
983 @return -3 on failure
988 """!Set isosurface emission
991 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
992 @param map if true use map otherwise constant
993 @param value map name of value
996 @return -1 volume not found
997 @return -2 isosurface not found
998 @return -3 on failure
1003 """!Set isosurface attribute
1006 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1007 @param attr attribute desc
1008 @param map if true use map otherwise constant
1009 @param value map name of value
1011 @return 1 on success
1012 @return -1 volume not found
1013 @return -2 isosurface not found
1014 @return -3 setting attributes failed
1025 if attr == ATT_COLOR:
1032 Debug.msg(3,
"Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
1033 "attr=%d, map=%d, value=%s",
1034 id, isosurf_id, attr, map, value)
1042 """!Unset isosurface mask
1045 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1047 @return 1 on success
1048 @return -1 volume not found
1049 @return -2 isosurface not found
1050 @return -3 setting attributes failed
1055 """!Unset isosurface transparency
1058 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1060 @return 1 on success
1061 @return -1 volume not found
1062 @return -2 isosurface not found
1063 @return -3 setting attributes failed
1068 """!Unset isosurface emission
1071 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1073 @return 1 on success
1074 @return -1 volume not found
1075 @return -2 isosurface not found
1076 @return -3 setting attributes failed
1081 """!Unset surface attribute
1083 @param id surface id
1084 @param isosurf_id isosurface id (0 - MAX_ISOSURFS)
1085 @param attr attribute descriptor
1087 @return 1 on success
1088 @return -1 volume not found
1089 @return -2 isosurface not found
1090 @return -2 on failure
1098 Debug.msg(3,
"Nviz::UnsetSurfaceAttr(): id=%d, isosurf_id=%d, attr=%d",
1099 id, isosurf_id, attr)
1109 """!Set draw mode for isosurfaces
1113 @return 1 on success
1114 @return -1 volume set not found
1115 @return -2 on failure
1128 """!Set draw resolution for isosurfaces
1130 @param res resolution value
1132 @return 1 on success
1133 @return -1 volume set not found
1134 @return -2 on failure
1146 def SaveToFile(self, filename, width = 20, height = 20, itype = 'ppm'):
1147 """!Save current GL screen to ppm/tif file
1149 @param filename file name
1150 @param width image width
1151 @param height image height
1152 @param itype image type ('ppm' or 'tif')
1154 widthOrig = self.
width
1159 self.
Draw(
False, -1)
1168 """!Draw lighting model"""
1172 def SetFringe(self, sid, color, elev, nw = False, ne = False, sw = False, se = False):
1175 @param sid surface id
1177 @param elev elevation (height)
1178 @param nw,ne,sw,se fringe edges (turn on/off)
1180 scolor = str(color[0]) +
':' + str(color[1]) +
':' + str(color[2])
1184 elev, int(nw), int(ne), int(sw), int(se))
1187 """!Get point on surface
1189 @param sx,sy canvas coordinates (LL)
1195 Debug.msg(5,
"GLWindow.GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
1198 return (
None,
None,
None,
None)
1200 return (sid.value, x.value, y.value, z.value)
1203 """!Query surface map
1205 @param sx,sy canvas coordinates (LL)
1211 catstr = create_string_buffer(256)
1212 valstr = create_string_buffer(256)
1216 return {
'id' : sid,
1220 'elevation' : catstr.value.replace(
'(',
'').replace(
')',
''),
1221 'color' : valstr.value }
1224 """!Get distance measured along surface"""
1228 byref(d), int(useExag))