[GRASS-SVN] r42502 - in grass/branches/develbranch_6:
gui/wxpython/gui_modules visualization/nviz/src
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jun 7 19:10:53 EDT 2010
Author: martinl
Date: 2010-06-07 19:10:53 -0400 (Mon, 07 Jun 2010)
New Revision: 42502
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py
grass/branches/develbranch_6/visualization/nviz/src/lights.c
Log:
wxGUI/nviz: lighting in progress
(merge r42500 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py 2010-06-07 23:10:13 UTC (rev 42501)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py 2010-06-07 23:10:53 UTC (rev 42502)
@@ -45,6 +45,7 @@
wxUpdateProperties, EVT_UPDATE_PROP = NewEvent()
wxUpdateView, EVT_UPDATE_VIEW = NewEvent()
+wxUpdateLight, EVT_UPDATE_LIGHT = NewEvent()
class NvizThread(Thread):
def __init__(self, log, progressbar, window):
@@ -126,7 +127,8 @@
self.view = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'view')) # copy
self.iview = UserSettings.Get(group = 'nviz', key = 'view', internal = True)
self.nvizDefault = NvizDefault()
-
+ self.lighting = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'lighting')) # copy
+
self.size = None
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
self.Bind(wx.EVT_SIZE, self.OnSize)
@@ -136,8 +138,9 @@
self.Bind(wx.EVT_MOTION, self.OnMouseAction)
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseAction)
- self.Bind(EVT_UPDATE_PROP, self.UpdateMapObjProperties)
- self.Bind(EVT_UPDATE_VIEW, self.UpdateView)
+ self.Bind(EVT_UPDATE_PROP, self.UpdateMapObjProperties)
+ self.Bind(EVT_UPDATE_VIEW, self.UpdateView)
+ self.Bind(EVT_UPDATE_LIGHT, self.UpdateLight)
self.Bind(wx.EVT_CLOSE, self.OnClose)
@@ -243,16 +246,27 @@
def UpdateView(self, event):
"""!Change view settings"""
- self._display.SetView(self.view['pos']['x'], self.view['pos']['y'],
+ data = self.view
+ self._display.SetView(data['pos']['x'], data['pos']['y'],
self.iview['height']['value'],
- self.view['persp']['value'],
- self.view['twist']['value'])
+ data['persp']['value'],
+ data['twist']['value'])
if event and event.zExag:
- self._display.SetZExag(self.view['z-exag']['value'])
+ self._display.SetZExag(data['z-exag']['value'])
- if event: event.Skip()
+ if event:
+ event.Skip()
+
+ def UpdateLight(self, event):
+ """!Change lighting settings"""
+ data = self.lighting
+ self._display.SetLight(x = data['pos']['x'], y = data['pos']['y'],
+ z = data['pos']['z'])
+ if event:
+ event.Skip()
+
def UpdateMap(self, render = True):
"""!Updates the canvas anytime there is a change to the
underlaying images or to the geometry of the canvas.
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py 2010-06-07 23:10:13 UTC (rev 42501)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py 2010-06-07 23:10:53 UTC (rev 42502)
@@ -5,7 +5,9 @@
Classes:
- NvizToolWindow
+ - PositionWindow
- ViewPositionWindow
+ - LightPositionWindow
- NvizPreferencesDialog
(C) 2008-2010 by the GRASS Development Team
@@ -35,8 +37,7 @@
import gcmd
from preferences import globalSettings as UserSettings
from preferences import PreferencesBaseDialog
-from nviz_mapdisp import wxUpdateView as wxUpdateView
-from nviz_mapdisp import wxUpdateProperties as wxUpdateProperties
+from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
try:
sys.path.append(os.path.join(globalvar.ETCWXDIR, "nviz"))
@@ -118,8 +119,8 @@
pos = (1, 0), flag = wx.ALIGN_CENTER)
posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
- self.viewPos = ViewPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
- mapwindow = self.mapWindow, win = self.win)
+ self.viewPos = ViewPositionWindow(panel, size = (175, 175),
+ mapwindow = self.mapWindow)
self.win['view']['pos'] = self.viewPos.GetId()
posSizer.Add(item=self.viewPos,
pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
@@ -1080,6 +1081,7 @@
show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
label = _("Show lighting model"))
+ show.Bind(wx.EVT_CHECKBOX, self.OnShowLightingModel)
pageSizer.Add(item = show, proportion = 0,
flag = wx.ALL, border = 3)
surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
@@ -1098,8 +1100,8 @@
pos = (1, 0), flag = wx.ALIGN_CENTER)
posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
- pos = ViewPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
- mapwindow = self.mapWindow, win = self.win)
+ pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
+ mapwindow = self.mapWindow)
self.win['lighting']['pos'] = pos.GetId()
posSizer.Add(item = pos,
pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
@@ -1270,7 +1272,7 @@
x = self.mapWindow.view['pos']['x']
y = self.mapWindow.view['pos']['y']
self.viewPos.UpdatePos(x, y)
- self.FindWindowById(self.win['view']['pos']).Draw()
+ self.FindWindowById(self.win['view']['pos']).Draw(pos = (x, y), scale = True)
self.FindWindowById(self.win['view']['pos']).Refresh(False)
# bgcolor = self.FindWindowById(self.win['settings']['general']['bgcolor']).GetColour()
@@ -1281,6 +1283,11 @@
self.mapWindow.render['quick'] = False
self.mapWindow.Refresh(False)
+ def OnShowLightingModel(self, event):
+ """!Show lighting model"""
+ self._display.showLight = event.IsChecked()
+ self.mapWindow.Refresh(False)
+
def OnBgColor(self, event):
"""!Background color changed"""
color = event.GetValue()
@@ -2222,14 +2229,13 @@
if pageId == 'view':
self.SetPage('view')
-
- # max = self.mapWindow.view['z-exag']['value'] * 10 #this value is essentially null
+ # max = self.mapWindow.view['z-exag']['value'] * 10 #this value is essentially null
hmin = self.mapWindow.iview['height']['min']
hmax = self.mapWindow.iview['height']['max']
hval = int(0.4 * (hmax - hmin)) + hmin
for control in ('spin', 'slider'):
- # self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(0,
- # max)
+ # self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(0,
+ # max)
self.FindWindowById(self.win['view']['height'][control]).SetRange(hmin,
hmax)
self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
@@ -2239,14 +2245,15 @@
if self.GetSelection() != self.page[pageId]['id']:
self.SetSelection(self.page[pageId]['id'])
- # self.ChangeSelection(current_page)
if pageId == 'surface':
self.UpdateSurfacePage(layer, data['surface'])
elif pageId == 'vector':
self.UpdateVectorPage(layer, data['vector'])
elif pageId == 'volume':
self.UpdateVectorPage(layer, data['vector'])
-
+ elif pageId == 'lighting':
+ print 'x'
+
self.Update()
self.pageChanging = False
@@ -2541,15 +2548,15 @@
"""!Get named page"""
self.SetSelection(self.page[name]['id'])
-class ViewPositionWindow(wx.Window):
- """!Position control window (for NvizToolWindow)"""
- def __init__(self, parent, id, mapwindow, win,
- pos = wx.DefaultPosition,
- size = wx.DefaultSize):
+class PositionWindow(wx.Window):
+ """!Abstract position control window, see subclasses
+ ViewPostionWindow and LightPositionWindow"""
+ def __init__(self, parent, mapwindow, id = wx.ID_ANY,
+ **kwargs):
self.mapWindow = mapwindow
- self.toolwin = parent.GetGrandParent()
+ self.quick = True
- wx.Window.__init__(self, parent, id, pos, size)
+ wx.Window.__init__(self, parent, id, **kwargs)
self.SetBackgroundColour("WHITE")
@@ -2557,25 +2564,18 @@
self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
-
- self.Draw()
-
+
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
self.Bind(wx.EVT_PAINT, self.OnPaint)
# self.Bind(wx.EVT_MOTION, self.OnMouse)
self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
- def Draw(self, pos = None):
+ def Draw(self, pos, scale = False):
w, h = self.GetClientSize()
-
- if pos is None:
- x = self.mapWindow.view['pos']['x']
- y = self.mapWindow.view['pos']['y']
+ x, y = pos
+ if scale:
x = x * w
y = y * h
- else:
- x, y = pos
-
self.pdc.Clear()
self.pdc.BeginDrawing()
self.pdc.DrawLine(w / 2, h / 2, x, y)
@@ -2590,18 +2590,24 @@
self.PrepareDC(dc)
self.pdc.DrawToDC(dc)
+ def UpdatePos(self, xcoord, ycoord):
+ if xcoord >= 0 and xcoord <= 1.0:
+ self.data['pos']['x'] = xcoord
+ if ycoord >= 0 and ycoord <= 1.0:
+ self.data['pos']['y'] = ycoord
+
def OnMouse(self, event):
if event.LeftIsDown():
x, y = event.GetPosition()
- self.mapWindow.view['x'] = x
- self.mapWindow.view['y'] = y
+ self.data['pos']['x'] = x
+ self.data['pos']['y'] = y
self.Draw(pos = (x, y))
self.Refresh(False)
w, h = self.GetClientSize()
x = float(x) / w
y = float(y) / h
self.UpdatePos(x, y)
- self.mapWindow.render['quick'] = True
+ self.mapWindow.render['quick'] = self.quick
self.mapWindow.Refresh(eraseBackground = False)
elif event.LeftUp():
@@ -2610,15 +2616,41 @@
event.Skip()
+ def PostDraw(self):
+ self.Draw(pos = (self.data['pos']['x'],
+ self.data['pos']['y']), scale = True)
+
+class ViewPositionWindow(PositionWindow):
+ """!View position control widget"""
+ def __init__(self, parent, mapwindow, id = wx.ID_ANY,
+ **kwargs):
+ PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
+
+ self.data = self.mapWindow.view
+ self.PostDraw()
+
def UpdatePos(self, xcoord, ycoord):
- if xcoord >= 0 and xcoord <= 1.0:
- self.mapWindow.view['pos']['x'] = xcoord
- if ycoord >= 0 and ycoord <= 1.0:
- self.mapWindow.view['pos']['y'] = ycoord
-
+ PositionWindow.UpdatePos(self, xcoord, ycoord)
+
event = wxUpdateView(zExag = True)
wx.PostEvent(self.mapWindow, event)
-
+
+class LightPositionWindow(PositionWindow):
+ """!Light position control widget"""
+ def __init__(self, parent, mapwindow, id = wx.ID_ANY,
+ **kwargs):
+ PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
+
+ self.data = self.mapWindow.lighting
+ self.quick = False
+ self.PostDraw()
+
+ def UpdatePos(self, xcoord, ycoord):
+ PositionWindow.UpdatePos(self, xcoord, ycoord)
+
+ event = wxUpdateLight()
+ wx.PostEvent(self.mapWindow, event)
+
class NvizPreferencesDialog(PreferencesBaseDialog):
"""!Nviz preferences dialog"""
def __init__(self, parent, title = _("3D view settings"),
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py 2010-06-07 23:10:13 UTC (rev 42501)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py 2010-06-07 23:10:53 UTC (rev 42502)
@@ -50,6 +50,7 @@
self.data_obj = nv_data()
self.data = pointer(self.data_obj)
self.width = self.height = -1
+ self.showLight = False
Debug.msg(1, "Nviz::Nviz()")
@@ -102,8 +103,6 @@
@param height
@param persp perpective
@param twist
-
- @return 1 on success
"""
Nviz_set_viewpoint_height(self.data, height)
Nviz_set_viewpoint_position(self.data, x, y)
@@ -113,8 +112,6 @@
Debug.msg(3, "Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
x, y, height, persp, twist)
- return 1
-
def SetZExag(self, z_exag):
"""!Set z-exag value
@@ -146,6 +143,9 @@
else:
Nviz_draw_all(self.data)
+ if self.showLight:
+ GS_draw_lighting_model()
+
def EraseMap(self):
"""!Erase map display (with background color)
"""
@@ -185,19 +185,30 @@
"""!Set default lighting model
"""
# first
- Nviz_set_light_position(self.data, 0, 0.68, -0.68, 0.80, 0.0)
- Nviz_set_light_bright(self.data, 0, 0.8)
- Nviz_set_light_color(self.data, 0, 1.0, 1.0, 1.0)
- Nviz_set_light_ambient(self.data, 0, 0.2, 0.2, 0.2)
+ Nviz_set_light_position(self.data, 0, 0.68, 0.68, 0.80, 0.0)
+ Nviz_set_light_bright(self.data, 0, 0.8)
+ Nviz_set_light_color(self.data, 0, 1.0, 1.0, 1.0)
+ Nviz_set_light_ambient(self.data, 0, 0.2, 0.2, 0.2)
# second
Nviz_set_light_position(self.data, 1, 0.0, 0.0, 1.0, 0.0)
- Nviz_set_light_bright(self.data, 1, 0.5)
- Nviz_set_light_color(self.data, 1, 1.0, 1.0, 1.0)
- Nviz_set_light_ambient(self.data, 1, 0.3, 0.3, 0.3)
+ Nviz_set_light_bright(self.data, 1, 0.5)
+ Nviz_set_light_color(self.data, 1, 1.0, 1.0, 1.0)
+ Nviz_set_light_ambient(self.data, 1, 0.3, 0.3, 0.3)
Debug.msg(3, "Nviz::SetLightsDefault()")
+ def SetLight(self, x, y, z, lid = 1):
+ """!Change lighting settings
+ @param x,y position
+ @param height
+ """
+ # Nviz_set_viewpoint_height(self.data, height)
+ Nviz_set_light_position(self.data, lid, x, y, z, 0)
+
+ Debug.msg(3, "Nviz::SetLight(): x=%f, y=%f, z=%f" %
+ (x, y, z))
+
def LoadSurface(self, name, color_name, color_value):
"""!Load raster map (surface)
@@ -1121,3 +1132,4 @@
GS_write_tif(filename)
self.ResizeWindow(widthOrig, heightOrig)
+
Modified: grass/branches/develbranch_6/visualization/nviz/src/lights.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz/src/lights.c 2010-06-07 23:10:13 UTC (rev 42501)
+++ grass/branches/develbranch_6/visualization/nviz/src/lights.c 2010-06-07 23:10:53 UTC (rev 42502)
@@ -225,7 +225,6 @@
int num, w;
float x, y, z;
double atof();
-
if (argc != 6)
return (TCL_ERROR);
@@ -235,6 +234,7 @@
data->light[num].y = y = (float)atof(argv[3]);
data->light[num].z = z = (float)atof(argv[4]);
data->light[num].w = w = (float)atoi(argv[5]);
+ fprintf(stderr, "%d %f %f %f %f\n", num, data->light[num].x, data->light[num].y, data->light[num].z, data->light[num].w);
GS_setlight_position(num, x, y, z, w);
return (TCL_OK);
}
More information about the grass-commit
mailing list