[GRASS-SVN] r42519 - in grass/trunk: gui/wxpython/gui_modules gui/wxpython/icons lib/nviz lib/ogsf

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 8 15:05:05 EDT 2010


Author: martinl
Date: 2010-06-08 15:05:02 -0400 (Tue, 08 Jun 2010)
New Revision: 42519

Modified:
   grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/wxnviz.py
   grass/trunk/gui/wxpython/icons/icon.py
   grass/trunk/lib/nviz/change_view.c
   grass/trunk/lib/nviz/cplanes_obj.c
   grass/trunk/lib/nviz/draw.c
   grass/trunk/lib/nviz/exag.c
   grass/trunk/lib/nviz/lights.c
   grass/trunk/lib/nviz/map_obj.c
   grass/trunk/lib/nviz/nviz.c
   grass/trunk/lib/nviz/position.c
   grass/trunk/lib/nviz/render.c
   grass/trunk/lib/ogsf/GS2.c
Log:
wxGUI/nviz: lighting in progress


Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py	2010-06-08 19:05:02 UTC (rev 42519)
@@ -126,7 +126,7 @@
         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.light = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'light')) # copy
 
         self.size = None
         self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
@@ -179,6 +179,7 @@
             
             if hasattr(self._layermanager, "nviz"):
                 self._layermanager.nviz.UpdatePage('view')
+                self._layermanager.nviz.UpdatePage('light')
                 layer = self.GetSelectedLayer()
                 if layer:
                     if layer.type ==  'raster':
@@ -225,7 +226,7 @@
             if prev_value !=  self.view['persp']['value']:
                 if hasattr(self._layermanager, "nviz"):
                     self._layermanager.nviz.UpdateSettings()
-
+                    
                     self._display.SetView(self.view['pos']['x'], self.view['pos']['y'],
                                           self.iview['height']['value'],
                                           self.view['persp']['value'],
@@ -258,14 +259,12 @@
             event.Skip()
 
     def UpdateLight(self, event):
-        """!Change lighting settings"""
-        data = self.lighting
+        """!Change light settings"""
+        data = self.light
         self._display.SetLight(x = data['pos']['x'], y = data['pos']['y'],
                                z = data['pos']['z'])
+        self._display.DrawLightingModel()
         
-        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.
@@ -275,6 +274,7 @@
         start = time.clock()
         
         self.resize = False
+        self.SwapBuffers()
         
         if self.render['quick'] is False:
             self.parent.statusbarWin['progress'].Show()
@@ -295,8 +295,6 @@
         else: # None -> reuse last rendered image
             pass # TODO
         
-        self.SwapBuffers()
-        
         stop = time.clock()
         
         if self.render['quick'] is False:
@@ -764,11 +762,13 @@
             self.iview['height']['value'], \
             self.iview['height']['min'], \
             self.iview['height']['max'] = self._display.SetViewDefault()
+        self.view['z-exag']['min'] = 0
+        self.view['z-exag']['max'] = self.view['z-exag']['value'] * 10
         
         self.view['pos']['x'] = UserSettings.Get(group = 'nviz', key = 'view',
                                                  subkey = ('pos', 'x'))
         self.view['pos']['y'] = UserSettings.Get(group = 'nviz', key = 'view',
-                                                 subkey = ('pos', 'x'))
+                                                 subkey = ('pos', 'y'))
         self.view['persp']['value'] = UserSettings.Get(group = 'nviz', key = 'view',
                                                        subkey = ('persp', 'value'))
         

Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py	2010-06-08 19:05:02 UTC (rev 42519)
@@ -60,7 +60,6 @@
         self.page = {} # page ids
         
         # view page
-        self.viewPos = ""
         self.AddPage(page = self._createViewPage(),
                      text = " %s " % _("View"))
         # surface page
@@ -72,9 +71,9 @@
         # volume page
         self.AddPage(page = self._createVolumePage(),
                      text = " %s " % _("Volume"))
-        # lighting page
-        self.AddPage(page = self._createLightingPage(),
-                     text = " %s " % _("Lighting"))
+        # light page
+        self.AddPage(page = self._createLightPage(),
+                     text = " %s " % _("Light"))
         
         self.UpdateSettings()
         self.pageChanging = False
@@ -117,10 +116,10 @@
                      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, size = (175, 175),
-                                          mapwindow = self.mapWindow)
-        self.win['view']['pos'] = self.viewPos.GetId()
-        posSizer.Add(item=self.viewPos,
+        view = ViewPositionWindow(panel, size = (175, 175),
+                                  mapwindow = self.mapWindow)
+        self.win['view']['pos'] = view.GetId()
+        posSizer.Add(item = view,
                      pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
                      pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
@@ -1067,19 +1066,19 @@
         
         return panel
     
-    def _createLightingPage(self):
-        """!Create lighting page"""
+    def _createLightPage(self):
+        """!Create light page"""
         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
         panel.SetupScrolling(scroll_x = False)
         
-        self.page['lighting'] = { 'id' : 4 } 
-        self.win['lighting'] = {}
+        self.page['light'] = { 'id' : 4 } 
+        self.win['light'] = {}
         
         pageSizer = wx.BoxSizer(wx.VERTICAL)
         
         show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
-                           label = _("Show lighting model"))
-        show.Bind(wx.EVT_CHECKBOX, self.OnShowLightingModel)
+                           label = _("Show light model"))
+        show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
         pageSizer.Add(item = show, proportion = 0,
                       flag = wx.ALL, border = 3)
         surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
@@ -1100,7 +1099,7 @@
                      pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
         pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
                                   mapwindow = self.mapWindow)
-        self.win['lighting']['pos'] = pos.GetId()
+        self.win['light']['pos'] = pos.GetId()
         posSizer.Add(item = pos,
                      pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
@@ -1110,16 +1109,16 @@
         gridSizer.Add(item = posSizer, pos = (0, 0))
         
         # height
-        self._createControl(panel, dict = self.win['lighting'], name = 'height', sliderHor = False,
-                            range = (0, 1),
-                            bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
+        self._createControl(panel, dict = self.win['light'], name = 'z', sliderHor = False,
+                            range = (0, 100),
+                            bind = (self.OnLightChange, None, self.OnLightChange))
         
         heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
         heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
                       pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
-        heightSizer.Add(item = self.FindWindowById(self.win['lighting']['height']['slider']),
+        heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
                         flag = wx.ALIGN_RIGHT, pos = (1, 0))
-        heightSizer.Add(item = self.FindWindowById(self.win['lighting']['height']['spin']),
+        heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['spin']),
                         flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
                         wx.BOTTOM | wx.RIGHT, pos = (1, 1))
         
@@ -1141,28 +1140,28 @@
                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
         color = csel.ColourSelect(panel, id = wx.ID_ANY,
                                   colour = UserSettings.Get(group = 'nviz', key = 'settings',
-                                                            subkey = ['lighting', 'color']),
+                                                            subkey = ['light', 'color']),
                                   size = globalvar.DIALOG_COLOR_SIZE)
         gridSizer.Add(item = color, pos = (0, 2))
 
         gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
                       pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
-        self._createControl(panel, dict = self.win['lighting'], name = 'brightness', size = 300,
+        self._createControl(panel, dict = self.win['light'], name = 'bright', size = 300,
                             range = (0, 1000),
                             bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
-        gridSizer.Add(item = self.FindWindowById(self.win['lighting']['brightness']['slider']),
+        gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
                       pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
-        gridSizer.Add(item = self.FindWindowById(self.win['lighting']['brightness']['spin']),
+        gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['spin']),
                       pos = (1, 2),
                       flag = wx.ALIGN_CENTER)
         gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
                       pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
-        self._createControl(panel, dict = self.win['lighting'], name = 'ambient', size = 300,
+        self._createControl(panel, dict = self.win['light'], name = 'ambient', size = 300,
                             range = (0, 1000),
                             bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
-        gridSizer.Add(item = self.FindWindowById(self.win['lighting']['ambient']['slider']),
+        gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
                       pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
-        gridSizer.Add(item = self.FindWindowById(self.win['lighting']['ambient']['spin']),
+        gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['spin']),
                       pos = (2, 2),
                       flag = wx.ALIGN_CENTER)
 
@@ -1204,9 +1203,6 @@
             val = self.mapWindow.view[name]['value']
         except KeyError:
             val = -1
-            
-        if name == 'z-exag':
-            val = 1
         
         slider = wx.Slider(parent = parent, id = wx.ID_ANY,
                            value = val,
@@ -1216,8 +1212,9 @@
                            size = sizeW)
         slider.SetName('slider')
         slider.Bind(wx.EVT_SCROLL, bind[0])
-        slider.Bind(wx.EVT_COMMAND_SCROLL_THUMBRELEASE, bind[1])
-        #        slider.Bind(wx.EVT_SCROLL_CHANGED, bind[1]) # this only works in MSW
+        # slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
+        if bind[1]:
+            slider.Bind(wx.EVT_SCROLL_CHANGED, bind[1]) # this only works in MSW
         dict[name]['slider'] = slider.GetId()
         
         slider.SetValue(val)
@@ -1229,11 +1226,6 @@
                            
         spin.SetValue(val)
         
-        #         spin = wx.SpinButton(parent = parent, id = wx.ID_ANY)
-        #         spin.SetValue (self.mapWindow.view[name]['value'])
-        #         spin.SetRange(self.mapWindow.view[name]['min'],
-        #                      self.mapWindow.view[name]['max'])
-        
         # no 'changed' event ... (FIXME)
         spin.SetName('spin')
         spin.Bind(wx.EVT_SPINCTRL, bind[2])
@@ -1267,11 +1259,11 @@
                     value = self.mapWindow.view[control]['value']
                 self.FindWindowById(win).SetValue(value)
         
-        x = self.mapWindow.view['pos']['x']
-        y = self.mapWindow.view['pos']['y']
-        self.viewPos.UpdatePos(x, y)        
-        self.FindWindowById(self.win['view']['pos']).Draw(pos = (x, y), scale = True)
-        self.FindWindowById(self.win['view']['pos']).Refresh(False)
+        viewWin = self.FindWindowById(self.win['view']['pos'])
+        x, y = viewWin.UpdatePos(self.mapWindow.view['pos']['x'],
+                                 self.mapWindow.view['pos']['y'])
+        viewWin.Draw(pos = (x, y), scale = True)
+        viewWin.Refresh(False)
         
         # bgcolor = self.FindWindowById(self.win['settings']['general']['bgcolor']).GetColour()
         # self.OnBgColor(event = bgcolor)
@@ -1281,11 +1273,27 @@
         self.mapWindow.render['quick'] = False
         self.mapWindow.Refresh(False)
         
-    def OnShowLightingModel(self, event):
-        """!Show lighting model"""
+    def OnShowLightModel(self, event):
+        """!Show light model"""
         self._display.showLight = event.IsChecked()
-        self.mapWindow.Refresh(False)
+        self._display.DrawLightingModel()
         
+    def OnLightChange(self, event):
+        """!Position of the light changed"""
+        winName = self.__GetWindowName(self.win['light'], event.GetId())
+        if not winName:
+            return
+        
+        val = event.GetInt()
+        self.mapWindow.light['pos']['z'] = val / 100.
+        for win in self.win['light'][winName].itervalues():
+            self.FindWindowById(win).SetValue(val)
+        
+        event = wxUpdateLight()
+        wx.PostEvent(self.mapWindow, event)
+        
+        event.Skip()
+
     def OnBgColor(self, event):
         """!Background color changed"""
         color = event.GetValue()
@@ -1363,11 +1371,8 @@
         
         self.UpdateSettings()
         
-        event.Skip()
-        
     def OnViewChangedSpin(self, event):
         """!View changed, render in full resolution"""
-        # TODO: use step value instead
         self.mapWindow.render['quick'] = False
         self.OnViewChange(event)
         self.OnViewChanged(None)
@@ -2227,16 +2232,19 @@
         
         if pageId == 'view':
             self.SetPage('view')
-            # 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
+            hval = self.mapWindow.iview['height']['value']
+            zmin = self.mapWindow.view['z-exag']['min']
+            zmax = self.mapWindow.view['z-exag']['max']
+            zval = self.mapWindow.view['z-exag']['value']
             for control in ('spin', 'slider'):
-                # 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)                                      
+                self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(zmin,
+                                                                                  zmax)
+                self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)                                      
         
         elif pageId in ('surface', 'vector', 'volume'):
             current_page = self.GetSelection()
@@ -2249,15 +2257,18 @@
                 self.UpdateVectorPage(layer, data['vector'])
             elif pageId == 'volume':
                 self.UpdateVectorPage(layer, data['vector'])
-        elif pageId == 'lighting':
-            print 'x'
+        elif pageId == 'light':
+            val = self.mapWindow.light['pos']['z'] * 100 # range 0.0 - 1.0
+            for control in ('spin', 'slider'):
+                self.FindWindowById(self.win['light']['z'][control]).SetRange(0,
+                                                                              100)
+                self.FindWindowById(self.win['light']['z'][control]).SetValue(val)
         
         self.Update()
         self.pageChanging = False
         
     def UpdateSurfacePage(self, layer, data, updateName = True):
         """!Update surface page"""
-        print layer, data
         ret = gcmd.RunCommand('r.info',
                               read = True,
                               flags = 'm',
@@ -2589,34 +2600,37 @@
         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
+        """!Update position coordinates (origin: UL)"""
+        if xcoord < 0.0:
+            xcoord = 0.0
+        elif xcoord > 1.0:
+            xcoord = 1.0
+        if ycoord < 0.0:
+            ycoord = 0.0
+        elif ycoord > 1.0:
+            ycoord = 1.0
+
+        self.data['pos']['x'] = xcoord        
+        self.data['pos']['y'] = ycoord
         
+        return xcoord, ycoord
+    
     def OnMouse(self, event):
         if event.LeftIsDown():
             x, y = event.GetPosition()
-            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'] = self.quick
-            
-            self.mapWindow.Refresh(eraseBackground = False)
-        elif event.LeftUp():
-            self.mapWindow.render['quick'] = False
-            self.mapWindow.Refresh(eraseBackground = False)
+            self.Refresh(False)
         
         event.Skip()
         
     def PostDraw(self):
-        self.Draw(pos = (self.data['pos']['x'],
-                         self.data['pos']['y']), scale = True)
+        x, y = self.UpdatePos(self.data['pos']['x'],
+                              self.data['pos']['y'])
+        self.Draw(pos = (x, y), scale = True)
 
 class ViewPositionWindow(PositionWindow):
     """!View position control widget"""
@@ -2628,35 +2642,55 @@
         self.PostDraw()
         
     def UpdatePos(self, xcoord, ycoord):
-        PositionWindow.UpdatePos(self, xcoord, ycoord)
+        x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
         
         event = wxUpdateView(zExag = True)
         wx.PostEvent(self.mapWindow, event)
 
+        return x, y
+
+    def OnMouse(self, event):
+        PositionWindow.OnMouse(self, event)
+        if event.LeftIsDown():
+            self.mapWindow.render['quick'] = self.quick
+            self.mapWindow.Refresh(eraseBackground = False)
+        elif event.LeftUp():
+            self.mapWindow.render['quick'] = False
+            self.mapWindow.Refresh(eraseBackground = False)
+        
+        event.Skip()
+    
 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.data = self.mapWindow.light
         self.quick = False
         self.PostDraw()
 
     def UpdatePos(self, xcoord, ycoord):
-        PositionWindow.UpdatePos(self, xcoord, ycoord)
+        x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
         
         event = wxUpdateLight()
         wx.PostEvent(self.mapWindow, event)
+    
+        return x, y
+
+    def OnMouse(self, event):
+        PositionWindow.OnMouse(self, event)
+        if event.LeftUp():
+            self.mapWindow.render['quick'] = False
+            self.mapWindow.Refresh(eraseBackground = False)
         
 class NvizPreferencesDialog(PreferencesBaseDialog):
     """!Nviz preferences dialog"""
     def __init__(self, parent, title = _("3D view settings"),
                  settings = UserSettings):
-        
         PreferencesBaseDialog.__init__(self, parent = parent, title = title,
                                        settings = settings)
-        
+        self.toolWin = self.parent.GetLayerManager().nviz
         self.win = dict()
         
         # create notebook pages
@@ -3078,7 +3112,7 @@
                                     except:
                                         continue
                                 
-        self.UpdateSettings()
+        self.toolWin.UpdateSettings()
         self.FindWindowById(self.win['view']['pos']).Draw()
         self.FindWindowById(self.win['view']['pos']).Refresh(False)
         
@@ -3093,11 +3127,13 @@
         fileSettings = {}
         UserSettings.ReadSettingsFile(settings = fileSettings)
         
-        self.UpdateSettings()
+        self.toolWin.UpdateSettings()
         
         nvsettings = UserSettings.Get(group = 'nviz')
         for subgroup, key in nvsettings.iteritems(): # view, surface, vector...
+            print subgroup, key
             for subkey, value in key.iteritems():
+                print subkey, value
                 if subkey == 'height': continue
                 for subvalue in value.keys():
                     if subvalue == 'step':

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-06-08 19:05:02 UTC (rev 42519)
@@ -432,12 +432,12 @@
             'nviz' : {
                 'view' : {
                     'persp' : {
-                        'value' : 40,
+                        'value' : 20,
                         'step' : 5,
                         },
                     'pos' : {
-                        'x' : 0.85,
-                        'y' : 0.85,
+                        'x' : 0.84,
+                        'y' : 0.16,
                         },
                     'height' : {
                         'step' : 100,
@@ -447,7 +447,6 @@
                         'step' : 5,
                         },
                     'z-exag' : {
-                        'value': 1,
                         'step' : 1,
                         },
                     },
@@ -511,10 +510,10 @@
                         'bgcolor' : (255, 255, 255, 255), # white
                         },
                     },
-                    'lighting' : {
+                    'light' : {
                         'color' : (255, 255, 255, 255), # white
                     },
-                'lighting' : {
+                'light' : {
                     'pos' : {
                         'x' : 0.68,
                         'y' : 0.68,

Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py	2010-06-08 19:05:02 UTC (rev 42519)
@@ -143,9 +143,6 @@
         else:
             Nviz_draw_all(self.data)
         
-        if self.showLight:
-            GS_draw_lighting_model()
-        
     def EraseMap(self):
         """!Erase map display (with background color)
         """
@@ -185,30 +182,26 @@
         """!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, 1, 0.68, -0.68, 0.80, 0.0)
+        Nviz_set_light_bright(self.data,   1, 0.8)
+        Nviz_set_light_color(self.data,    1, 1.0, 1.0, 1.0)
+        Nviz_set_light_ambient(self.data,  1, 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_position(self.data, 2, 0.0, 0.0, 1.0, 0.0)
+        Nviz_set_light_bright(self.data,   2, 0.5)
+        Nviz_set_light_color(self.data,    2, 1.0, 1.0, 1.0)
+        Nviz_set_light_ambient(self.data,  2, 0.3, 0.3, 0.3)
         
         Debug.msg(3, "Nviz::SetLightsDefault()")
         
-    def SetLight(self, x, y, z, lid = 1):
+    def SetLight(self, x, y, z, w = 0, lid = 1):
         """!Change lighting settings
-        @param x,y position
-        @param height
+        @param x,y,z position
+        @param w local coordinate (default to 0)
         """
-        # Nviz_set_viewpoint_height(self.data, height)
-        Nviz_set_light_position(self.data, lid, x, y, z, 0)
+        Nviz_set_light_position(self.data, lid, x, y, z, w)
         
-        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)
         
@@ -1133,3 +1126,7 @@
         
         self.ResizeWindow(widthOrig, heightOrig)
 
+    def DrawLightingModel(self):
+        """!Draw lighting model"""
+        if self.showLight:
+            GS_draw_lighting_model()

Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/gui/wxpython/icons/icon.py	2010-06-08 19:05:02 UTC (rev 42519)
@@ -369,6 +369,8 @@
                                 label=_("Show modeler settings")),
     "modelProperties" : MetaIcon (img=Icons["modelProperties"],
                                   label=_("Show model properties")),
+    "modelVariables" : MetaIcon (img=Icons["modelProperties"],
+                                 label=_("Manage model variables")),
     }
 
 # testing ...

Modified: grass/trunk/lib/nviz/change_view.c
===================================================================
--- grass/trunk/lib/nviz/change_view.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/change_view.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,19 +1,15 @@
 /*!
-   \file change_view.c
+   \file lib/nviz/change_view.c
 
-   \brief Change view settings
+   \brief Nviz library -- Change view settings
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
    Based on visualization/nviz/src/change_view.c
+   
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
-
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/glocale.h>
@@ -105,10 +101,11 @@
     ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
 
     if (x_pos < 0.0 || x_pos > 1.0 || y_pos < 0.0 || y_pos > 1.0) {
-	G_warning(_("Invalid view position coordinates, using %f,%f"),
+	G_debug(3, "Invalid view position coordinates, using %f,%f",
 		  xpos, 1.0 - ypos);
     }
 
+    G_debug(3, "Nviz_set_viewpoint_position(): x = %f y = %f", x_pos, y_pos);
     GS_get_from(from);
 
     tempx = xpos * RANGE - RANGE_OFFSET;

Modified: grass/trunk/lib/nviz/cplanes_obj.c
===================================================================
--- grass/trunk/lib/nviz/cplanes_obj.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/cplanes_obj.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,19 +1,15 @@
 /*!
-   \file cplanes_obj.c
-
+   \file lib/nviz/cplanes_obj.c
+   
    \brief Nviz library -- Clip planes manipulation
-
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
+   
    Based on visualization/nviz/src/cutplanes_obj.c
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/nviz.h>

Modified: grass/trunk/lib/nviz/draw.c
===================================================================
--- grass/trunk/lib/nviz/draw.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/draw.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,20 +1,16 @@
 /*!
-   \file draw.c
+   \file lib/nviz/draw.c
 
    \brief Nviz library -- Draw map objects to GLX context
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
    Based on visualization/nviz/src/draw.c and
    visualization/nviz/src/togl_flythrough.c
+   
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
-
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/nviz.h>

Modified: grass/trunk/lib/nviz/exag.c
===================================================================
--- grass/trunk/lib/nviz/exag.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/exag.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,19 +1,15 @@
 /*!
-   \file exag.c
+   \file lib/nviz/exag.c
 
    \brief Nviz library -- Exaggeration functions
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
    Based on visualization/nviz/src/exag.c
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/nviz.h>

Modified: grass/trunk/lib/nviz/lights.c
===================================================================
--- grass/trunk/lib/nviz/lights.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/lights.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,19 +1,15 @@
 /*!
-   \file lights.c
+   \file lib/nviz/lights.c
 
-   \brief Nviz library -- Change view settings
+   \brief Nviz library -- Change lighting settings
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
    Based on visualization/nviz/src/lights.c
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/glocale.h>
@@ -23,18 +19,34 @@
    \brief Set light position
 
    \param data nviz data
-   \param num light num (starts with 0)
+   \param num light num (starts at 1)
    \param x,y,z,w position, model coordinates
+
+   \return 1
  */
 int Nviz_set_light_position(nv_data * data, int num,
 			    float x, float y, float z, float w)
 {
+    float xpos, ypos;
+    xpos = x;
+    xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
+    ypos = 1.0 - y;
+    ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
+    
+    if (x < 0.0 || x > 1.0 || y < 0.0 || y > 1.0) {
+	G_debug(3, "Invalid view position coordinates, using %f,%f",
+		  xpos, 1.0 - ypos);
+    }
+
+    num--;
     data->light[num].id = num + 1;
     data->light[num].x = x;
     data->light[num].y = y;
     data->light[num].z = z;
     data->light[num].w = w;
 
+    G_debug(3, "Nviz_set_light_position(): num = %d x = %f y = %f z = %f w = %f",
+	    num + 1, x, y, z, w);
     GS_setlight_position(num + 1, x, y, z, w);
 
     return 1;
@@ -44,19 +56,22 @@
    \brief Set light brightness
 
    \param data nviz data
-   \param num light num (starts with 0)
+   \param num light num (starts at 1)
    \param value brightness value
  */
 int Nviz_set_light_bright(nv_data * data, int num, float value)
 {
     float r, g, b;
 
+    num--;
     data->light[num].brt = value;
 
     r = data->light[num].r * data->light[num].brt;
     g = data->light[num].g * data->light[num].brt;
     b = data->light[num].b * data->light[num].brt;
 
+    G_debug(3, "Nviz_set_light_bright(): num = %d r = %f g = %f b = %f",
+	    num + 1, r, g, b);
     GS_setlight_color(num + 1, r, g, b);
 
     return 1;
@@ -66,7 +81,7 @@
    \brief Set light color
 
    \param data nviz data
-   \param num light num (starts with 0)
+   \param num light num (starts at 1)
    \param red,green,blue rGB values (0-1)
  */
 int Nviz_set_light_color(nv_data * data, int num,
@@ -74,6 +89,7 @@
 {
     float r, g, b;
 
+    num--;
     data->light[num].r = red;
     data->light[num].g = green;
     data->light[num].b = blue;
@@ -82,6 +98,8 @@
     g = data->light[num].g * data->light[num].brt;
     b = data->light[num].b * data->light[num].brt;
 
+    G_debug(3, "Nviz_set_light_color(): num = %d r = %f g = %f b = %f",
+	    num + 1, r, g, b);
     GS_setlight_color(num + 1, r, g, b);
 
     return 1;
@@ -91,16 +109,19 @@
    \brief Set light ambient
 
    \param data nviz data
-   \param num light num (starts with 0)
+   \param num light num (starts at 1)
    \param red,green,blue rGB values (0-1)
  */
 int Nviz_set_light_ambient(nv_data * data, int num,
 			   float red, float green, float blue)
 {
+    num--;
     data->light[num].ar = red;
     data->light[num].ag = green;
     data->light[num].ab = blue;
 
+    G_debug(3, "Nviz_set_light_ambient(): num = %d r = %f g = %f b = %f",
+	    num + 1, red, green, blue);
     GS_setlight_ambient(num + 1, red, green, blue);
 
     return 1;
@@ -110,10 +131,11 @@
    \brief Init new light
 
    \param data nviz data
-   \param num light num (starts with 0)
+   \param num light num (starts at 1)
  */
 int Nviz_init_light(nv_data * data, int num)
 {
+    num--;
     if (num >= MAX_LIGHTS) {
 	return 0;
     }
@@ -134,6 +156,14 @@
     return 1;
 }
 
+/*!
+  \brief Define new light
+
+  \param data nviz data
+
+  \return 1 on success
+  \return 0 on failure
+*/
 int Nviz_new_light(nv_data * data)
 {
     int num;
@@ -145,7 +175,7 @@
 	return 0;
     }
 
-    Nviz_init_light(data, num - 1);
+    Nviz_init_light(data, num);
 
     return 1;
 }

Modified: grass/trunk/lib/nviz/map_obj.c
===================================================================
--- grass/trunk/lib/nviz/map_obj.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/map_obj.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,22 +1,18 @@
 /*!
-   \file map_obj.c
+   \file lib/nviz/map_obj.c
 
    \brief Nviz library -- Define creation and interface functions for map objects.
 
-   Map objects are considered to be surfaces, vector plots,
-   or site files.
+   Map objects are considered to be surfaces, vector plots, or site
+   files.
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
    Based on visualization/nviz/src/map_obj.c
+   
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
-
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <stdlib.h>

Modified: grass/trunk/lib/nviz/nviz.c
===================================================================
--- grass/trunk/lib/nviz/nviz.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/nviz.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,19 +1,15 @@
 /*!
-   \file nviz.c
+   \file lib/nviz/nviz.c
 
    \brief Nviz library -- Data management
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
    Based on visualization/nviz/src/
+   
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
-
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/colors.h>

Modified: grass/trunk/lib/nviz/position.c
===================================================================
--- grass/trunk/lib/nviz/position.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/position.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,19 +1,15 @@
 /*!
-   \file position.c
-
+   \file lib/nviz/position.c
+   
    \brief Nviz library -- Position, focus settings
-
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
+   
    Based on visualization/nviz/src/position.c
+   
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC)
-
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/glocale.h>

Modified: grass/trunk/lib/nviz/render.c
===================================================================
--- grass/trunk/lib/nviz/render.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/nviz/render.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -1,19 +1,15 @@
 /*!
-   \file render.c
+   \file lib/nviz/render.c
 
    \brief Nviz library -- GLX context manipulation
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
-
-   This program is free software under the GNU General Public
-   License (>=v2). Read the file COPYING that comes with GRASS
-   for details.
-
    Based on visualization/nviz/src/togl.c
+   
+   (C) 2008, 2010 by the GRASS Development Team
+   This program is free software under the GNU General Public License
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
-   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
-
-   \date 2008
+   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
  */
 
 #include <grass/glocale.h>

Modified: grass/trunk/lib/ogsf/GS2.c
===================================================================
--- grass/trunk/lib/ogsf/GS2.c	2010-06-08 19:03:01 UTC (rev 42518)
+++ grass/trunk/lib/ogsf/GS2.c	2010-06-08 19:05:02 UTC (rev 42519)
@@ -315,7 +315,7 @@
 /*!
    \brief Get light position
 
-   \param num light id (starts with 1?)
+   \param num light id (starts at 1)
    \param[out] xpos,ypos,zpos coordinates
    \param[out] local ?
  */
@@ -339,7 +339,7 @@
 /*!
    \brief Set light color
 
-   \param num light id (starts with 1?)
+   \param num light id (starts at 1)
    \param red,green,blue color values (from 0.0 to 1.0)
  */
 void GS_setlight_color(int num, float red, float green, float blue)
@@ -361,7 +361,7 @@
 /*!
    \brief Get light color
 
-   \param num light id (starts with 1?)
+   \param num light id (starts at 1)
    \param[out] red,green,blue color values
  */
 void GS_getlight_color(int num, float *red, float *green, float *blue)
@@ -383,7 +383,7 @@
 
    Red, green, blue from 0.0 to 1.0
 
-   \param num light id (starts with 1?)
+   \param num light id (starts at 1)
    \param red,green,blue color values
  */
 void GS_setlight_ambient(int num, float red, float green, float blue)
@@ -405,7 +405,7 @@
 /*!
    \brief Get light ambient
 
-   \param num light id (starts with 1?)
+   \param num light id (starts at 1)
    \param[out] red,green,blue color values
  */
 void GS_getlight_ambient(int num, float *red, float *green, float *blue)
@@ -454,7 +454,7 @@
 /*!
    \brief Switch on/off light
 
-   \param num light id (starts with 1?)
+   \param num light id (starts at 1)
    \param on non-zero for 'on' otherwise 'off'
  */
 void GS_switchlight(int num, int on)



More information about the grass-commit mailing list