[GRASS-SVN] r31935 - in grass/trunk: gui/wxpython gui/wxpython/gui_modules gui/wxpython/nviz include include/Make lib lib/nviz visualization visualization/nviz2 visualization/nviz2/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 1 16:02:22 EDT 2008


Author: martinl
Date: 2008-07-01 16:02:21 -0400 (Tue, 01 Jul 2008)
New Revision: 31935

Added:
   grass/trunk/gui/wxpython/nviz/
   grass/trunk/gui/wxpython/nviz/Makefile
   grass/trunk/gui/wxpython/nviz/change_view.cpp
   grass/trunk/gui/wxpython/nviz/dig_types.i
   grass/trunk/gui/wxpython/nviz/draw.cpp
   grass/trunk/gui/wxpython/nviz/init.cpp
   grass/trunk/gui/wxpython/nviz/lights.cpp
   grass/trunk/gui/wxpython/nviz/load.cpp
   grass/trunk/gui/wxpython/nviz/nviz.h
   grass/trunk/gui/wxpython/nviz/nviz.i
   grass/trunk/gui/wxpython/nviz/surface.cpp
   grass/trunk/include/nviz.h
   grass/trunk/lib/nviz/
   grass/trunk/lib/nviz/Makefile
   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/nviz/render.h
   grass/trunk/visualization/nviz2/
   grass/trunk/visualization/nviz2/cmd/
   grass/trunk/visualization/nviz2/cmd/Makefile
   grass/trunk/visualization/nviz2/cmd/args.c
   grass/trunk/visualization/nviz2/cmd/description.html
   grass/trunk/visualization/nviz2/cmd/local_proto.h
   grass/trunk/visualization/nviz2/cmd/main.c
   grass/trunk/visualization/nviz2/cmd/write_img.c
Modified:
   grass/trunk/gui/wxpython/Makefile
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
   grass/trunk/include/Make/Grass.make.in
   grass/trunk/lib/Makefile
   grass/trunk/visualization/Makefile
Log:
nviz2 moved from grass-addons to trunk

Modified: grass/trunk/gui/wxpython/Makefile
===================================================================
--- grass/trunk/gui/wxpython/Makefile	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/gui/wxpython/Makefile	2008-07-01 20:02:21 UTC (rev 31935)
@@ -4,10 +4,15 @@
 
 include $(MODULE_TOPDIR)/include/Make/Platform.make
 
+#compile if wxWidgets, Python, CXX present
 ifneq ($(USE_WXWIDGETS),)
   ifneq ($(USE_PYTHON),)
     ifneq ($(strip $(CXX)),)
        SUBDIRS += vdigit
+         #compile if OpenGL present
+         ifneq ($(strip $(OPENGLLIB)),)
+           SUBDIRS += nviz
+         endif
     endif
   endif
 endif
@@ -20,7 +25,7 @@
 	$(MAKE) parsubdirs
 
 install_scripts:
-	$(MKDIR) $(ETCDIR) $(ETCDIR)/compat $(ETCDIR)/gui_modules $(ETCDIR)/icons $(ETCDIR)/icons/silk $(ETCDIR)/images $(ETCDIR)/scripts $(ETCDIR)/vdigit $(ETCDIR)/xml
+	$(MKDIR) $(ETCDIR) $(ETCDIR)/compat $(ETCDIR)/gui_modules $(ETCDIR)/icons $(ETCDIR)/icons/silk $(ETCDIR)/images $(ETCDIR)/scripts $(ETCDIR)/vdigit $(ETCDIR)/xml $(ETCDIR)/nviz
 	$(INSTALL_DATA) compat/* $(ETCDIR)/compat/
 	$(INSTALL_DATA) gui_modules/* $(ETCDIR)/gui_modules/
 	$(INSTALL_DATA) icons/*.* $(ETCDIR)/icons/

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-07-01 20:02:21 UTC (rev 31935)
@@ -3,6 +3,7 @@
 
 CLASSES:
  - Command
+ - MapWindow
  - BufferedWindow
  - MapFrame
  - MapApp
@@ -121,8 +122,69 @@
 
         sys.exit()
 
-class BufferedWindow(wx.Window):
+class MapWindow(object):
+    """Abstract map window class
+
+    Parent for BufferedWindow class (2D display mode) and
+    GLWindow (3D display mode)
     """
+    def __init__(self, parent, id,
+                 pos=wx.DefaultPosition,
+                 size=wx.DefaultSize,
+                 style=wx.NO_FULL_REPAINT_ON_RESIZE,
+                 Map=None, tree=None, gismgr=None):
+        pass
+
+    def EraseMap(self):
+        """
+        Erase the canvas (virtual method)
+        """
+        pass
+
+    def UpdateMap(self):
+        """
+        Updates the canvas anytime there is a change to the
+        underlaying images or to the geometry of the canvas.
+        """
+        pass
+
+    def OnLeftDown(self, event):
+        pass
+
+    def OnLeftUp(self, event):
+        pass
+
+    def OnMouseMotion(self, event):
+        pass
+
+    def ZoomToMap(self, event):
+        pass
+
+    def GetSelectedLayer(self, nviz=False, index=False):
+        """Get selected layer from layer tree
+
+        @param nviz get nviz properties instead
+
+        @return map layer instance
+        @return None on failure
+        """
+        # get currently selected map layer
+        if not self.tree or not self.tree.GetSelection():
+            return None
+        
+        item = self.tree.GetSelection()
+        try:
+            if nviz:
+                layer = self.tree.GetPyData(item)[0]['nviz']
+            else:
+                layer = self.tree.GetPyData(item)[0]['maplayer']
+        except:
+            layer = None
+            
+        return layer
+
+class BufferedWindow(MapWindow, wx.Window):
+    """
     A Buffered window class.
 
     When the drawing needs to change, you app needs to call the
@@ -137,7 +199,10 @@
                  style=wx.NO_FULL_REPAINT_ON_RESIZE,
                  Map=None, tree=None, gismgr=None):
 
+        MapWindow.__init__(self, parent, id, pos, size, style,
+                           Map, tree, gismgr)
         wx.Window.__init__(self, parent, id, pos, size, style)
+
         self.parent = parent
         self.Map = Map
         self.tree = tree
@@ -539,13 +604,12 @@
 
     def UpdateMap(self, render=True, renderVector=True):
         """
-        Updates the canvas anytime there is a change to the underlaying images
-        or to the geometry of the canvas.
+        Updates the canvas anytime there is a change to the
+        underlaying images or to the geometry of the canvas.
 
         @param render re-render map composition
         @param renderVector re-render vector map layer enabled for editing (used for digitizer)
         """
-
         start = time.clock()
 
         self.resize = False
@@ -711,7 +775,7 @@
 
     def EraseMap(self):
         """
-        Erase the map display
+        Erase the canvas
         """
         self.Draw(self.pdc, pdctype='clear')
 
@@ -2037,16 +2101,8 @@
         """
         zoomreg = {}
 
-        # find selected map
-        if not self.tree or not self.tree.GetSelection():
-            return
+        layer = self.GetSelectedLayer()
 
-        item  = self.tree.GetSelection()
-        try:
-            layer = self.tree.GetPyData(item)[0]['maplayer']
-        except:
-            layer = None
-
         if layer is None:
             return
 
@@ -2308,7 +2364,8 @@
         #
         self.toolbars = { 'map' : None,
                           'vdigit' : None,
-                          'georect' : None }
+                          'georect' : None, 
+                          'nviz' : None }
         for toolb in toolbars:
             self.AddToolbar(toolb)
 
@@ -2368,9 +2425,14 @@
         #
         # Init map display (buffered DC & set default cursor)
         #
-        self.MapWindow = BufferedWindow(self, id=wx.ID_ANY, Map=self.Map, tree=self.tree, gismgr=self.gismanager)
+        self.MapWindow2D = BufferedWindow(self, id=wx.ID_ANY,
+                                          Map=self.Map, tree=self.tree, gismgr=self.gismanager)
+        # default is 2D display mode
+        self.MapWindow = self.MapWindow2D
         self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
         self.MapWindow.SetCursor(self.cursors["default"])
+        # used by Nviz (3D display mode)
+        self.MapWindow3D = None 
 
         #
         # initialize region values
@@ -2434,7 +2496,8 @@
          - map basic map toolbar
          - digit vector digitizer
          - georect georectifier
-         """
+        """
+        # default toolbar
         if name == "map":
             self.toolbars['map'] = toolbars.MapToolbar(self, self.Map)
 
@@ -2445,8 +2508,8 @@
                               LeftDockable(False).RightDockable(False).
                               BottomDockable(False).TopDockable(True).
                               CloseButton(False).Layer(2))
-
-        if name == "digit":
+        # vector digitizer
+        elif name == "vdigit":
             self.toolbars['vdigit'] = toolbars.VDigitToolbar(self, self.Map, self.tree)
 
             for toolRow in range(0, self.toolbars['vdigit'].numOfRows):
@@ -2463,18 +2526,75 @@
             self.MapWindow.zoomtype = 0
             self.MapWindow.pen     = wx.Pen(colour='red',   width=2, style=wx.SOLID)
             self.MapWindow.polypen = wx.Pen(colour='green', width=2, style=wx.SOLID)
-
-        if name == "georect":
+        # georectifier
+        elif name == "georect":
             self.toolbars['georect'] = toolbars.GRToolbar(self, self.Map)
 
             self._mgr.AddPane(self.toolbars['georect'].toolbar,
                               wx.aui.AuiPaneInfo().
-                              Name("georecttoolbar").Caption(_("Georectification Toolbar")).
+                              Name("georecttoolbar").Caption(_("Georectification toolbar")).
                               ToolbarPane().Top().
                               LeftDockable(False).RightDockable(False).
                               BottomDockable(False).TopDockable(True).
                               CloseButton(False).Layer(2))
+        # nviz
+        elif name == "nviz":
+            import nviz
+            # check for GLCanvas and OpenGL
+            msg = None
+            if not nviz.haveGLCanvas:
+                msg = _("Unable to start Nviz. The GLCanvas class has not been included with this build "
+                        "of wxPython! Switching back to 2D display mode.")
+            if not nviz.haveOpenGL:
+                msg = _("Unable to start Nviz. The OpenGL package was not found. You can get it "
+                        "at http://PyOpenGL.sourceforge.net. Switching back to 2D display mode.")
+            if not nviz.haveNviz:
+                msg = _("Unable to start Nviz. Python extension for Nviz was not found. "
+                        "Switching back to 2D display mode.")
 
+            if msg:
+                wx.MessageBox(parent=self,
+                              message=msg,
+                              caption=_("Error"))
+                return
+
+            #
+            # create GL window & NVIZ toolbar
+            #
+            if not self.MapWindow3D:
+                self.MapWindow3D = nviz.GLWindow(self, id=wx.ID_ANY,
+                                                 Map=self.Map, tree=self.tree, gismgr=self.gismanager)
+                self.nvizToolWin = nviz.NvizToolWindow(self, id=wx.ID_ANY,
+                                                       mapWindow=self.MapWindow3D)
+            
+            #
+            # add Nviz toolbar and disable 2D display mode tools
+            #
+            self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
+            self.toolbars['map'].Enable2D(False)
+            self.toggleStatus.Enable(False)
+
+            self.nvizToolWin.Show()
+
+            #
+            # switch from MapWindow to MapWindowGL
+            # add nviz toolbar
+            #
+            self._mgr.DetachPane(self.MapWindow2D)
+            self.MapWindow2D.Hide()
+            self._mgr.AddPane(self.MapWindow3D, wx.aui.AuiPaneInfo().CentrePane().
+                              Dockable(False).BestSize((-1,-1)).
+                              CloseButton(False).DestroyOnClose(True).
+                              Layer(0))
+            self._mgr.AddPane(self.toolbars['nviz'].toolbar,
+                              wx.aui.AuiPaneInfo().
+                              Name("nviztoolbar").Caption(_("Nviz toolbar")).
+                              ToolbarPane().Top().Row(1).
+                              LeftDockable(False).RightDockable(False).
+                              BottomDockable(False).TopDockable(True).
+                              CloseButton(False).Layer(2))
+            self.MapWindow = self.MapWindow3D
+            
         self._mgr.Update()
 
     def RemoveToolbar (self, name):
@@ -2487,14 +2607,36 @@
         # cannot hide main toolbar
         if name == "map":
             return
-        elif name == "digit":
+        elif name == "vdigit":
             # TODO: not destroy only hide
             for toolRow in range(0, self.toolbars['vdigit'].numOfRows):
                 self._mgr.DetachPane (self.toolbars['vdigit'].toolbar[toolRow])
                 self.toolbars['vdigit'].toolbar[toolRow].Destroy()
-            self.toolbars['vdigit'] = None
+        else:
+            self._mgr.DetachPane (self.toolbars[name].toolbar)
+            self.toolbars[name].toolbar.Destroy()
 
-        self.toolbars['map'].combo.SetValue ("Tools");
+        self.toolbars[name] = None
+
+        if name == 'nviz':
+            # hide nviz tools
+            self.nvizToolWin.Hide()
+            # unload data
+            self.MapWindow3D.Reset()
+            # switch from MapWindowGL to MapWindow
+            self._mgr.DetachPane(self.MapWindow3D)
+            self.MapWindow3D.Hide()
+            self.MapWindow2D.Show()
+            self._mgr.AddPane(self.MapWindow2D, wx.aui.AuiPaneInfo().CentrePane().
+                              Dockable(False).BestSize((-1,-1)).
+                              CloseButton(False).DestroyOnClose(True).
+                              Layer(0))
+            self.MapWindow = self.MapWindow2D
+        
+        self.toolbars['map'].combo.SetValue ("Tools")
+        self.toolbars['map'].Enable2D(True)
+        self.toggleStatus.Enable(True)
+
         self._mgr.Update()
 
     def __InitDisplay(self):

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-07-01 20:02:21 UTC (rev 31935)
@@ -196,8 +196,60 @@
                              'width' : 2,
                              },
                 },
+            'nviz' : {
+                'view' : {'persp' : { 'value' : 40,
+                                      'min' : 1,
+                                      'max' : 100,
+                                      'step' : 5,
+                                      'update' : False,
+                                      },
+                          'pos' : { 'x' : 0.85,
+                                    'y' : 0.85,
+                                    'update' : False,
+                                    },
+                          'height' : { 'value': -1,
+                                       'min' : -2245, # TODO: determine min/max height
+                                       'max' : 3695, 
+                                       'step' : 100,
+                                       'update' : False,
+                                       },
+                          'twist' : { 'value' : 0,
+                                      'min' : -180,
+                                      'max' : 180,
+                                      'step' : 5,
+                                      'update' : False,
+                                      },
+                          'z-exag' : { 'value': 1.0,
+                                       'min' : 0.0,
+                                       'max' : 10,
+                                       'step' : 1,
+                                       'update' : False
+                                       },
+                          },
+                'surface' : {
+                    'shine': { 'map' : False,
+                               'value' : 60.0,
+                                   },
+                    'color' : { 'map' : True,
+                                'value' : (0, 0, 0, 255), # constant: black
+                                },
+                    'draw' : {
+                        'color' : (136, 136, 136, 255),
+                        'mode' : 1, # fine
+                        'style' : 1, # surface
+                        'shading' : 1, # gouraud
+                        'res-fine' : 6,
+                        'res-coarse' : 9,
+                        },
+                    'position' : {
+                        'x' : 0,
+                        'y' : 0,
+                        'z' : 0,
+                        },
+                    },
+                },
             }
-
+        
         #
         # user settings
         #
@@ -283,9 +335,16 @@
                 line = line.rstrip('%s' % os.linesep)
                 group, key = line.split(':')[0:2]
                 kv = line.split(':')[2:]
+                subkeyMaster = None
+                if len(kv) % 2 != 0: # multiple (e.g. nviz)
+                    subkeyMaster = kv[0]
+                    del kv[0]
                 idx = 0
                 while idx < len(kv):
-                    subkey = kv[idx]
+                    if subkeyMaster:
+                        subkey = [subkeyMaster, kv[idx]]
+                    else:
+                        subkey = kv[idx]
                     value = kv[idx+1]
                     if len(value) == 0:
                         self.Append(settings, group, key, subkey, '')
@@ -301,13 +360,16 @@
                             tmp = value.replace('(','').replace(')', '').split(',')
                             try:
                                 value = tuple(map(int, tmp))
-                            except:
+                            except ValueError:
                                 value = tuple(tmp)
                         else:
                             try:
                                 value = int(value)
-                            except:
-                                pass
+                            except ValueError:
+                                try:
+                                    value = float(value)
+                                except ValueError:
+                                    pass
 
                         self.Append(settings, group, key, subkey, value)
                     idx += 2
@@ -337,13 +399,26 @@
         try:
             file = open(filePath, "w")
             for group in settings.keys():
-                for item in settings[group].keys():
-                    file.write('%s:%s:' % (group, item))
-                    items = settings[group][item].keys()
-                    for idx in range(len(items)):
-                        file.write('%s:%s' % (items[idx], settings[group][item][items[idx]]))
-                        if idx < len(items) - 1:
-                            file.write(':')
+                for key in settings[group].keys():
+                    file.write('%s:%s:' % (group, key))
+                    subkeys = settings[group][key].keys()
+                    for idx in range(len(subkeys)):
+                        value = settings[group][key][subkeys[idx]]
+                        if type(value) == type({}):
+                            if idx > 0:
+                                file.write('%s%s:%s:' % (os.linesep, group, key))
+                            file.write('%s:' % subkeys[idx])
+                            kvalues = settings[group][key][subkeys[idx]].keys()
+                            srange = range(len(kvalues))
+                            for sidx in srange:
+                                file.write('%s:%s' % (kvalues[sidx],
+                                                      settings[group][key][subkeys[idx]][kvalues[sidx]]))
+                                if sidx < len(kvalues) - 1:
+                                    file.write(':')
+                        else:
+                            file.write('%s:%s' % (subkeys[idx], value))
+                            if idx < len(subkeys) - 1:
+                                file.write(':')
                     file.write('%s' % os.linesep)
         except IOError, e:
             raise gcmd.SettingsError(e)
@@ -362,9 +437,10 @@
         @param group settings group
         @param key
         @param subkey if not given return dict of key
-        
+        @param subkey1 
+        @param internal use internal settings instead
+
         @return value
-
         """
         if internal is True:
             settings = self.internalSettings
@@ -378,7 +454,11 @@
                 else:
                     return settings[group][key]
             else:
-                return settings[group][key][subkey]
+                if type(subkey) == type([]):
+                    return settings[group][key][subkey[0]][subkey[1]]
+                else:
+                    return settings[group][key][subkey]  
+
         except KeyError:
             raise gcmd.SettingsError("%s %s:%s:%s." % (_("Unable to get value"),
                                                        group, key, subkey))
@@ -390,8 +470,9 @@
         
         @param group settings group
         @param key key
-        @param subkey subkey
+        @param subkey subkey (value or list)
         @param value value
+        @param internal use internal settings instead
         """
         if internal is True:
             settings = self.internalSettings
@@ -399,9 +480,10 @@
             settings = self.userSettings
 
         try:
-            if not settings[group][key].has_key(subkey):
-                raise KeyError
-            settings[group][key][subkey] = value
+            if type(subkey) == type([]):
+                settings[group][key][subkey[0]][subkey[1]] = value
+            else:
+                settings[group][key][subkey] = value
         except KeyError:
             raise gcmd.SettingsError("%s '%s:%s:%s'" % (_("Unable to set "), group, key, subkey))
 
@@ -413,7 +495,7 @@
         @param dict settings dictionary to use
         @param group settings group
         @param key key
-        @param subkey subkey
+        @param subkey subkey (value or list)
         @param value value
         """
         if not dict.has_key(group):
@@ -422,7 +504,13 @@
         if not dict[group].has_key(key):
             dict[group][key] = {}
 
-        dict[group][key][subkey] = value
+        if type(subkey) == type([]):
+            # TODO: len(subkey) > 2
+            if not dict[group][key].has_key(subkey[0]):
+                dict[group][key][subkey[0]] = {}
+            dict[group][key][subkey[0]][subkey[1]] = value
+        else:
+            dict[group][key][subkey] = value
 
     def GetDefaultSettings(self):
         """Get default user settings"""

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-07-01 20:02:21 UTC (rev 31935)
@@ -8,7 +8,8 @@
     * GCPToolbar
     * VDigitToolbar
     * ProfileToolbar
-    
+    * NvizToolbar
+
 PURPOSE: Toolbars for Map Display window
 
 AUTHORS: The GRASS Development Team
@@ -111,10 +112,10 @@
         
         # optional tools
         self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value='Tools',
-                                 choices=['Digitize'], style=wx.CB_READONLY, size=(90, -1))
+                                 choices=['Digitize', 'Nviz'], style=wx.CB_READONLY, size=(90, -1))
 
         self.comboid = self.toolbar.AddControl(self.combo)
-        self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelect, self.comboid)
+        self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
 
         # realize the toolbar
         self.toolbar.Realize()
@@ -188,15 +189,33 @@
             ("", "", "", "", "", "", "")
             )
 
-    def OnSelect(self, event):
+    def OnSelectTool(self, event):
         """
         Select / enable tool available in tools list
         """
         tool =  event.GetString()
 
         if tool == "Digitize" and not self.mapdisplay.toolbars['vdigit']:
-            self.mapdisplay.AddToolbar("digit")
+            self.mapdisplay.AddToolbar("vdigit")
 
+        elif tool == "Nviz" and not self.mapdisplay.toolbars['nviz']:
+            self.mapdisplay.AddToolbar("nviz")
+
+    def Enable2D(self, enabled):
+        """Enable/Disable 2D display mode specific tools"""
+        for tool in (self.pointer,
+                     self.query,
+                     self.pan,
+                     self.zoomin,
+                     self.zoomout,
+                     self.zoomback,
+                     self.zoommenu,
+                     self.analyze,
+                     self.dec,
+                     self.savefile,
+                     self.printmap):
+            self.toolbar.EnableTool(tool, enabled)
+
 class GRToolbar(AbstractToolbar):
     """
     Georectify Display toolbar
@@ -525,7 +544,7 @@
             self.parent.dialogs['attributes'].OnCancel(None)
 
         # disable the toolbar
-        self.parent.RemoveToolbar ("digit")
+        self.parent.RemoveToolbar ("vdigit")
 
     def OnMoveVertex(self, event):
         """Move line vertex"""
@@ -987,3 +1006,40 @@
              wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
              self.parent.OnQuit),
             )
+
+class NvizToolbar(AbstractToolbar):
+    """
+    Nviz toolbar
+    """
+    def __init__(self, parent, map):
+        self.parent     = parent
+        self.mapcontent = map
+
+        self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
+
+        # self.SetToolBar(self.toolbar)
+        self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
+
+        self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
+
+        # realize the toolbar
+        self.toolbar.Realize()
+
+    def ToolbarData(self):
+        """Toolbar data"""
+
+        self.quit = wx.NewId()
+                
+        # tool, label, bitmap, kind, shortHelp, longHelp, handler
+        return   (
+            (self.quit, 'quit', Icons["quit"].GetBitmap(),
+             wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
+             self.OnExit),
+            )
+
+    def OnExit (self, event=None):
+        """Quit nviz tool (swith to 2D mode)"""
+
+        # disable the toolbar
+        self.parent.RemoveToolbar ("nviz")
+

Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-01 20:02:21 UTC (rev 31935)
@@ -214,6 +214,7 @@
             self.popupID8 = wx.NewId()
             self.popupID9 = wx.NewId()
             self.popupID10 = wx.NewId()
+            self.popupID11 = wx.NewId() # nviz
 
         self.popupMenu = wx.Menu()
         # general item
@@ -247,7 +248,9 @@
             mltype = self.GetPyData(self.layer_selected)[0]['type']
         except:
             mltype = None
-        # vector specific items
+        #
+        # vector layers (specific items)
+        #
         if mltype and mltype == "vector":
             self.popupMenu.AppendSeparator()
             self.popupMenu.Append(self.popupID4, text=_("Show attribute data"))
@@ -278,8 +281,9 @@
             self.popupMenu.Append(self.popupID7, _("Metadata"))
             self.Bind (wx.EVT_MENU, self.OnMetadata, id=self.popupID7)
 
-
-        # raster
+        #
+        # raster layers (specific items)
+        #
         elif mltype and mltype == "raster":
             self.popupMenu.AppendSeparator()
             self.popupMenu.Append(self.popupID4, _("Histogram"))
@@ -288,6 +292,9 @@
             self.Bind (wx.EVT_MENU, self.OnProfile, id=self.popupID5)
             self.popupMenu.Append(self.popupID6, _("Metadata"))
             self.Bind (wx.EVT_MENU, self.OnMetadata, id=self.popupID6)
+            if self.mapdisplay.toolbars['nviz']:
+                self.popupMenu.Append(self.popupID11, _("Nviz properties"))
+                self.Bind (wx.EVT_MENU, self.OnNvizProperties, id=self.popupID11)
 
         ## self.PopupMenu(self.popupMenu, pos)
         self.PopupMenu(self.popupMenu)
@@ -445,7 +452,17 @@
 
         self.RefreshSelected()
         self.Refresh()
-        
+
+    def OnNvizProperties(self, event):
+        """Nviz-related properties (raster/vector/volume)
+
+        @todo vector/volume
+        """
+        import nviz
+        dlg = nviz.RasterPropertiesDialog(parent=self,
+                                          map=self.GetPyData(self.layer_selected)[0]['maplayer'].name)
+        dlg.Show()
+
     def RenameLayer (self, event):
         """Rename layer"""
         self.EditLabel(self.layer_selected)
@@ -602,6 +619,7 @@
                                     'type' : ltype,
                                     'ctrl' : ctrlId,
                                     'maplayer' : None,
+                                    'nviz' : None,
                                     'prowin' : None}, 
                                    None))
 
@@ -857,6 +875,10 @@
         except:
             pass
 
+        # update nviz tools
+        if self.mapdisplay.toolbars['nviz']:
+            self.mapdisplay.nvizToolWin.UpdatePage('surface')
+
     def OnCollapseNode(self, event):
         """
         Collapse node

Copied: grass/trunk/gui/wxpython/nviz/Makefile (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/Makefile)
===================================================================
--- grass/trunk/gui/wxpython/nviz/Makefile	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/Makefile	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,39 @@
+MODULE_TOPDIR = ../../..
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+
+LIB_NAME = grass6_wxnviz
+SOURCES := $(wildcard *.cpp) $(LIB_NAME)_wrap.cpp
+SHLIB_OBJS := $(patsubst %.cpp, $(OBJDIR)/%.o, $(SOURCES))
+
+EXTRA_CFLAGS = $(SHLIB_CFLAGS) $(GDALCFLAGS) $(PYTHONCFLAGS) $(WXWIDGETSCXXFLAGS) $(XCFLAGS) $(XMINC)
+EXTRA_LIBS = $(GISLIB) $(WXWIDGETSLIB) $(PYTHONLDFLAGS) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB) $(NVIZLIB)
+
+LOCAL_HEADERS = nviz.h
+
+ETCDIR = $(ETC)/wxpython
+
+SHLIB = $(OBJDIR)/_$(LIB_NAME).so
+
+EXTRA_CLEAN_FILES = $(SHLIB) $(LIB_NAME).i $(LIB_NAME).py $(LIB_NAME)_wrap.cpp
+
+default: install_nviz
+
+$(LIB_NAME).i: nviz.i dig_types.i nviz.h
+	cat nviz.i dig_types.i > $(LIB_NAME).i
+	echo "/* auto-generated swig typedef file */" >> $(LIB_NAME).i
+	cat nviz.h >> $(LIB_NAME).i
+
+$(LIB_NAME).py $(LIB_NAME)_wrap.cpp: $(LIB_NAME).i
+	$(SWIG) -c++ -python -shadow -o $(LIB_NAME)_wrap.cpp $<
+
+$(SHLIB): $(SHLIB_OBJS)
+ifeq ($(findstring darwin,$(ARCH)),darwin)
+	$(CXX) -o $@ $(LDFLAGS) $^ $(EXTRA_LIBS)
+else
+	$(SHLIB_LD) -o $@ $(LDFLAGS) $^ $(EXTRA_LIBS)
+endif
+
+install_nviz: $(SHLIB) $(LIB_NAME).py
+	$(INSTALL) $(SHLIB) $(ETCDIR)/nviz
+	$(INSTALL_DATA) $(LIB_NAME).py $(ETCDIR)/nviz

Copied: grass/trunk/gui/wxpython/nviz/change_view.cpp (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp)
===================================================================
--- grass/trunk/gui/wxpython/nviz/change_view.cpp	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/change_view.cpp	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,115 @@
+/**
+   \file change_view.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- Change viewport
+
+   Used by wxGUI Nviz extension.
+
+   Copyright: (C) 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 Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+   \date 2008
+*/
+
+#include "nviz.h"
+
+/*!
+  \brief GL canvas resized
+
+  \param width window width
+  \param height window height
+
+  \return 1 on success
+  \return 0 on failure (window resized by dafault to 20x20 px)
+ */
+int Nviz::ResizeWindow(int width, int height)
+{
+    int ret;
+
+    ret = Nviz_resize_window(width, height);
+
+    G_debug(1, "Nviz::ResizeWindow(): width=%d height=%d",
+	    width, height);
+
+    return ret;
+}
+
+/*!
+  \brief Set default view (based on loaded data)
+
+  \return height, z-exag value
+*/
+std::vector<double> Nviz::SetViewDefault()
+{
+    std::vector<double> ret;
+
+    float vp_height, z_exag;
+
+    /* determine z-exag */
+    z_exag = Nviz_get_exag();
+    ret.push_back(z_exag);
+    Nviz_change_exag(data,
+		     z_exag);
+
+    /* determine height */
+    Nviz_get_exag_height(&vp_height, NULL, NULL);
+    ret.push_back(vp_height);
+
+    SetView(VIEW_DEFAULT_POS_X, VIEW_DEFAULT_POS_Y,
+	    vp_height, VIEW_DEFAULT_PERSP, VIEW_DEFAULT_TWIST);
+
+    G_debug(1, "Nviz::SetViewDefault()");
+
+    return ret;
+}
+
+/*!
+  \brief Change view settings
+
+  \param x,y position
+  \param height
+  \param persp perpective
+  \param twist
+
+  \return 1 on success
+*/
+int Nviz::SetView(float x, float y,
+		  float height, float persp, float twist)
+{
+    Nviz_set_viewpoint_height(data,
+			      height);
+    Nviz_set_viewpoint_position(data,
+				x, y);
+    Nviz_set_viewpoint_twist(data,
+			     twist);
+    Nviz_set_viewpoint_persp(data,
+			     persp);
+
+    G_debug(1, "Nviz::SetView(): x=%f, y=%f, height=%f, persp=%f, twist=%f",
+	    x, y, height, persp, twist);
+	
+    return 1;
+}
+
+/*!
+  \brief Set z-exag value
+
+  \param z_exag value
+
+  \return 1
+*/
+int Nviz::SetZExag(float z_exag)
+{
+    int ret;
+    
+    ret = Nviz_change_exag(data, z_exag);
+
+    G_debug(1, "Nviz::SetZExag(): z_exag=%f", z_exag);
+
+    return ret;
+}

Copied: grass/trunk/gui/wxpython/nviz/dig_types.i (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/dig_types.i)
===================================================================
--- grass/trunk/gui/wxpython/nviz/dig_types.i	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/dig_types.i	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,43 @@
+/* extracted from include/vect/dig_defines.h */
+
+#define GV_POINT      0x01
+#define GV_LINE       0x02
+#define GV_BOUNDARY   0x04
+#define GV_CENTROID   0x08
+#define GV_FACE       0x10
+#define GV_KERNEL     0x20
+#define GV_AREA       0x40
+#define GV_VOLUME     0x80
+
+#define GV_POINTS (GV_POINT | GV_CENTROID )
+#define GV_LINES (GV_LINE | GV_BOUNDARY )
+
+#define PORT_DOUBLE_MAX 1.7976931348623157e+308
+
+/* extracted from gui/wxpython/nviz/nviz.h */
+
+#define VIEW_DEFAULT_POS_X 0.85
+#define VIEW_DEFAULT_POS_Y 0.85
+#define VIEW_DEFAULT_PERSP 40.0
+#define VIEW_DEFAULT_TWIST 0.0
+#define VIEW_DEFAULT_ZEXAG 1.0
+
+#define DRAW_COARSE 0
+#define DRAW_FINE 1
+#define DRAW_BOTH 2
+
+/* extracted from include/gsurf.h */
+#define DM_GOURAUD   0x00000100
+#define DM_FLAT      0x00000200
+
+#define DM_FRINGE    0x00000010
+
+#define DM_WIRE      0x00000001
+#define DM_COL_WIRE  0x00000002
+#define DM_POLY      0x00000004
+#define DM_WIRE_POLY 0x00000008
+
+#define DM_GRID_WIRE 0x00000400
+#define DM_GRID_SURF 0x00000800
+
+#define WC_COLOR_ATT 0xFF000000

Copied: grass/trunk/gui/wxpython/nviz/draw.cpp (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp)
===================================================================
--- grass/trunk/gui/wxpython/nviz/draw.cpp	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/draw.cpp	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,82 @@
+/*!
+  \file draw.cpp
+ 
+  \brief Experimental C++ wxWidgets Nviz prototype -- 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
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include "nviz.h"
+
+/*!
+  \brief Draw map
+
+  \param quick true for forcing coarse draw mode 
+*/
+void Nviz::Draw(bool quick)
+{
+
+    Nviz_draw_cplane(data, -1, -1); // ?
+
+    if (data->draw_mode == DRAW_COARSE || 
+	data->draw_mode == DRAW_BOTH || quick) {
+	Nviz_draw_quick(data, 1); // clear screen
+    }
+
+    if (data->draw_mode == DRAW_FINE ||
+	data->draw_mode == DRAW_BOTH) {
+	if (data->draw_mode == DRAW_FINE) {
+	    Nviz_draw_all (data, 1); // clear screen
+	}
+	else {
+	    Nviz_draw_all (data, 0);
+	}
+    }
+
+    G_debug(1, "Nviz::Draw(): mode=%d, quick=%d",
+	    data->draw_mode, quick);
+    
+    return;
+}
+
+/*!
+  \brief Erase map display (with background color)
+*/
+void Nviz::EraseMap()
+{
+    GS_clear(data->bgcolor);
+
+    G_debug(1, "Nviz::EraseMap()");
+
+    return;
+}
+
+/*!
+  \brief Set draw mode
+
+  Draw modes:
+   - DRAW_COARSE
+   - DRAW_FINE
+   - DRAW_BOTH
+
+  \param mode draw mode
+*/
+void Nviz::SetDrawMode(int mode)
+{
+    Nviz_set_draw_mode(data, mode);
+
+    G_debug(1, "Nviz::SetDrawMode(): mode=%d",
+	    mode);
+    return;
+}

Copied: grass/trunk/gui/wxpython/nviz/init.cpp (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/init.cpp)
===================================================================
--- grass/trunk/gui/wxpython/nviz/init.cpp	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/init.cpp	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,116 @@
+/**
+   \file init.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- initialization
+
+   Used by wxGUI Nviz extension.
+
+   Copyright: (C) 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 Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+   \date 2008
+*/
+#include "nviz.h"
+
+static void swap_gl();
+
+/*!
+  \brief Initialize Nviz class instance
+*/
+Nviz::Nviz()
+{
+    G_gisinit(""); /* GRASS functions */
+
+    G_set_verbose(0); // TODO: read progress info
+
+    GS_libinit();
+    /* GVL_libinit(); TODO */
+
+    GS_set_swap_func(swap_gl);
+
+    data = (nv_data*) G_malloc(sizeof (nv_data));
+
+    /* GLCanvas */
+    glCanvas = NULL;
+
+    G_debug(1, "Nviz::Nviz()");
+}
+
+/*!
+  \brief Destroy Nviz class instance
+*/
+Nviz::~Nviz()
+{
+    G_free((void *) data);
+
+    data = NULL;
+    glCanvas = NULL;
+}
+
+/*!
+  \brief Associate display with render window
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetDisplay(void *display)
+{
+    glCanvas = (wxGLCanvas *) display;
+    // glCanvas->SetCurrent();
+
+    G_debug(1, "Nviz::SetDisplay()");
+
+    return 1;
+}
+
+void Nviz::InitView()
+{
+    /* initialize nviz data */
+    Nviz_init_data(data);
+
+    /* define default attributes for map objects */
+    Nviz_set_attr_default();
+    /* set background color */
+    Nviz_set_bgcolor(data, Nviz_color_from_str("white")); /* TODO */
+
+    /* initialize view */
+    Nviz_init_view();
+
+    /* set default lighting model */
+    SetLightsDefault();
+
+    /* clear window */
+    GS_clear(data->bgcolor);
+
+    G_debug(1, "Nviz::InitView()");
+
+    return;
+}
+
+/*!
+  \brief Reset session
+
+  Unload all data layers
+
+  @todo vector, volume
+*/
+void Nviz::Reset()
+{
+    int i;
+    int *surf_list, nsurfs;
+
+    surf_list = GS_get_surf_list(&nsurfs);
+    for (i = 0; i < nsurfs; i++) {
+	GS_delete_surface(surf_list[i]);
+    }
+}
+
+void swap_gl()
+{
+    return;
+}

Copied: grass/trunk/gui/wxpython/nviz/lights.cpp (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/lights.cpp)
===================================================================
--- grass/trunk/gui/wxpython/nviz/lights.cpp	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/lights.cpp	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,49 @@
+/**
+   \file load.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- light manipulation
+
+   Used by wxGUI Nviz extension.
+
+   Copyright: (C) 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 Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+   \date 2008
+*/
+
+#include "nviz.h"
+
+/*!
+  \brief Set default lighting model
+*/
+void Nviz::SetLightsDefault()
+{
+    /* first */
+    Nviz_set_light_position(data, 0,
+			    0.68, -0.68, 0.80, 0.0);
+    Nviz_set_light_bright(data, 0,
+			  0.8);
+    Nviz_set_light_color(data, 0,
+			 1.0, 1.0, 1.0);
+    Nviz_set_light_ambient(data, 0,
+			   0.2, 0.2, 0.2);
+
+    /* second */
+    Nviz_set_light_position(data, 1,
+			    0.0, 0.0, 1.0, 0.0);
+    Nviz_set_light_bright(data, 1,
+			  0.5);
+    Nviz_set_light_color(data, 1,
+			 1.0, 1.0, 1.0);
+    Nviz_set_light_ambient(data, 1,
+			   0.3, 0.3, 0.3);
+
+    G_debug(1, "Nviz::SetLightsDefault()");
+
+    return;
+}

Copied: grass/trunk/gui/wxpython/nviz/load.cpp (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/load.cpp)
===================================================================
--- grass/trunk/gui/wxpython/nviz/load.cpp	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/load.cpp	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,87 @@
+/**
+   \file load.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- load data layers
+
+   Used by wxGUI Nviz extension.
+
+   Copyright: (C) 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 Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+   \date 2008
+*/
+
+#include "nviz.h"
+
+extern "C" {
+#include <grass/glocale.h>
+}
+
+/*!
+  \brief Load raster map (surface)
+
+  \param name raster map name
+  \param color_name raster map for color (NULL for color_value)
+  \param color_value color string (named color or RGB triptet)
+
+  \return object id
+  \return -1 on failure
+*/
+int Nviz::LoadRaster(const char* name, const char *color_name, const char *color_value)
+{
+    char *mapset;
+    int id;
+
+    mapset = G_find_cell2 (name, "");
+    if (mapset == NULL) {
+	G_warning(_("Raster map <%s> not found"),
+		  name);
+	return -1;
+    }
+	    
+    /* topography */
+    id = Nviz_new_map_obj(MAP_OBJ_SURF,
+			  G_fully_qualified_name(name, mapset), 0.0,
+			  data);
+
+    if (color_name) { /* check for color map */
+	mapset = G_find_cell2 (color_name, "");
+	if (mapset == NULL) {
+	    G_warning(_("Raster map <%s> not found"),
+		      color_name);
+	    GS_delete_surface(id);
+	    return -1;
+	}
+
+	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+		      G_fully_qualified_name(color_name, mapset), -1.0,
+		      data);
+    }
+    else if (color_value) { /* check for color value */
+	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
+		      NULL, Nviz_color_from_str(color_value),
+		      data);
+    }
+    else { /* use by default elevation map for coloring */
+	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+		      G_fully_qualified_name(name, mapset), -1.0,
+		      data);
+    }
+	    
+    /*
+      if (i > 1)
+      set_default_wirecolors(data, i);
+    */
+
+    /* focus on loaded data */
+    Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
+
+    G_debug(1, "Nviz::LoadRaster(): name=%s", name);
+
+    return id;
+}

Copied: grass/trunk/gui/wxpython/nviz/nviz.h (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/nviz.h)
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.h	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/nviz.h	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,87 @@
+#ifndef __NVIZ_H__
+#define __NVIZ_H__
+
+#include <vector>
+
+extern "C" {
+#include <grass/gis.h>
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+#include <grass/nviz.h>
+}
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+// Include your minimal set of headers here, or wx.h
+#include <wx/wx.h>
+#endif
+
+#include <wx/glcanvas.h>
+
+#define VIEW_DEFAULT_POS_X 0.85
+#define VIEW_DEFAULT_POS_Y 0.85
+#define VIEW_DEFAULT_PERSP 40.0
+#define VIEW_DEFAULT_TWIST 0.0
+
+class Nviz
+{
+private:
+    nv_data *data;
+    wxGLCanvas *glCanvas;
+
+    /* surface.cpp */
+    int SetSurfaceAttr(int, int, bool, const char *);
+    int UnsetSurfaceAttr(int, int);
+
+public:
+    /* constructor */
+    Nviz();
+
+    /* destructor */
+    ~Nviz();
+
+    /* change_view.cpp */
+    int ResizeWindow(int, int);
+    std::vector<double> SetViewDefault();
+    int SetView(float, float,
+		float, float, float);
+    int SetZExag(float);
+
+    /* init.cpp */
+    int SetDisplay(void *);
+    void InitView();
+    void Reset();
+
+    /* lights.cpp */
+    void SetLightsDefault();
+
+    /* load.cpp */
+    int LoadRaster(const char*, const char *, const char *);
+
+    /* draw.cpp */
+    void Draw(bool);
+    void EraseMap();
+    void SetDrawMode(int);
+
+    /* surface.cpp */
+    int SetSurfaceTopo(int, bool, const char *);
+    int SetSurfaceColor(int, bool, const char *);
+    int SetSurfaceMask(int, bool, const char *);
+    int SetSurfaceTransp(int, bool, const char *);
+    int SetSurfaceShine(int, bool, const char *);
+    int SetSurfaceEmit(int, bool, const char *);
+    int UnsetSurfaceMask(int);
+    int UnsetSurfaceTransp(int);
+    int UnsetSurfaceEmit(int);
+    int SetSurfaceRes(int, int, int);
+    int SetSurfaceStyle(int, int);
+    int SetWireColor(int, const char *);
+};
+
+#endif /* __NVIZ_H__ */

Copied: grass/trunk/gui/wxpython/nviz/nviz.i (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/nviz.i)
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.i	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/nviz.i	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,19 @@
+/* File: nviz.i */
+
+%module grass6_wxnviz
+%{
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+#include "nviz.h"
+%}
+
+%include "std_vector.i"
+namespace std { 
+   %template(IntVector) vector<int>;
+   %template(DoubleVector) vector<double>;
+}
+%include "std_map.i"
+namespace std { 
+   %template(IntVecIntMap) map<int, vector<int> >;
+}
+%include "nviz.h"

Copied: grass/trunk/gui/wxpython/nviz/surface.cpp (from rev 31934, grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp)
===================================================================
--- grass/trunk/gui/wxpython/nviz/surface.cpp	                        (rev 0)
+++ grass/trunk/gui/wxpython/nviz/surface.cpp	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,269 @@
+/**
+   \file map_obj.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- map object management
+
+   Used by wxGUI Nviz extension.
+
+   Copyright: (C) 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 Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+   \date 2008
+*/
+
+#include "nviz.h"
+
+/*!
+  \brief Set surface topography
+
+  \param id surface id
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceTopo(int id, bool map, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_TOPO, map, value);
+}
+
+/*!
+  \brief Set surface color
+
+  \param id surface id
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceColor(int id, bool map, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_COLOR, map, value);
+}
+
+/*!
+  \brief Set surface mask
+
+  @todo invert
+
+  \param id surface id
+  \param invert if true invert mask 
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceMask(int id, bool invert, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_MASK, true, value);
+}
+
+/*!
+  \brief Set surface mask
+
+  @todo invert
+
+  \param id surface id
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceTransp(int id, bool map, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_TRANSP, map, value);
+}
+
+/*!
+  \brief Set surface shininess
+
+  \param id surface id
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceShine(int id, bool map, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_SHINE, map, value);
+}
+
+/*!
+  \brief Set surface emission
+
+  \param id surface id
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceEmit(int id, bool map, const char *value)
+{
+    return SetSurfaceAttr(id, ATT_EMIT, map, value);
+}
+
+/*!
+  \brief Set surface attribute
+
+  \param id surface id
+  \param attr attribute desc
+  \param map if true use map otherwise constant
+  \param value map name of value
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::SetSurfaceAttr(int id, int attr, bool map, const char *value)
+{
+    int ret;
+
+    if (map) {
+	ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
+			    value, -1.0,
+			    data);
+    }
+    else {
+	float val;
+	if (attr == ATT_COLOR) {
+	    val = Nviz_color_from_str(value);
+	}
+	else {
+	    val = atof(value);
+	}
+	ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, CONST_ATT,
+			    NULL, val,
+			    data);
+    }
+	
+    G_debug(1, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
+	    id, attr, map, value);
+
+    return ret;
+}
+
+/*!
+  \brief Unset surface mask
+
+  \param id surface id
+
+  \return 1 on success
+  \return 0 on failure
+*/
+
+int Nviz::UnsetSurfaceMask(int id)
+{
+    return UnsetSurfaceAttr(id, ATT_MASK);
+}
+
+/*!
+  \brief Unset surface transparency
+
+  \param id surface id
+
+  \return 1 on success
+  \return 0 on failure
+*/
+
+int Nviz::UnsetSurfaceTransp(int id)
+{
+    return UnsetSurfaceAttr(id, ATT_TRANSP);
+}
+
+/*!
+  \brief Unset surface emission
+
+  \param id surface id
+
+  \return 1 on success
+  \return 0 on failure
+*/
+
+int Nviz::UnsetSurfaceEmit(int id)
+{
+    return UnsetSurfaceAttr(id, ATT_EMIT);
+}
+
+/*!
+  \brief Unset surface attribute
+
+  \param id surface id
+  \param attr attribute descriptor
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::UnsetSurfaceAttr(int id, int attr)
+{
+    return Nviz_unset_attr(id, MAP_OBJ_SURF, attr);
+}
+
+/*!
+  \brief Set surface resolution
+
+  \param id surface id
+  \param fine x/y fine resolution
+  \param coarse x/y coarse resolution
+
+  \return -1 on error
+  \return 0 on success
+*/
+int Nviz::SetSurfaceRes(int id, int fine, int coarse)
+{
+    return GS_set_drawres(id, fine, fine, coarse, coarse);
+}
+
+/*!
+  \brief Set draw style
+
+  Draw styles:
+   - DM_GOURAUD
+   - DM_FLAT
+   - DM_FRINGE
+   - DM_WIRE
+   - DM_COL_WIRE
+   - DM_POLY
+   - DM_WIRE_POLY
+   - DM_GRID_WIRE
+   - DM_GRID_SURF
+
+  \param id surface id (<= 0 for all)
+  \param style draw style
+
+  \return 0 on success
+  \return -1 on error
+*/
+int Nviz::SetSurfaceStyle(int id, int style)
+{
+    if (id > 0) {
+	return GS_set_drawmode(id, style);
+    }
+
+    return GS_setall_drawmode(style);
+}
+
+/*!
+  \brief Set color of wire
+
+  \todo all
+
+  \param surface id
+  \param color color string (R:G:B)
+
+  \return 1
+*/
+int Nviz::SetWireColor(int id, const char* color)
+{
+    GS_set_wire_color(id, Nviz_color_from_str(color));
+
+    return 1;
+}

Modified: grass/trunk/include/Make/Grass.make.in
===================================================================
--- grass/trunk/include/Make/Grass.make.in	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/include/Make/Grass.make.in	2008-07-01 20:02:21 UTC (rev 31935)
@@ -144,6 +144,7 @@
 
 # NVIZ related
 OGSF_LIBNAME          = grass_ogsf
+NVIZ_LIBNAME          = grass_nviz
 
 # triangulation libraries
 SOS_LIBNAME           = grass_sos
@@ -247,6 +248,7 @@
 
 # NVIZ related
 OGSFLIB       = -l$(OGSF_LIBNAME) $(BITMAPLIB) $(G3DLIB) $(GISLIB) $(SITESLIB) $(VECTRLIB) 
+NVIZLIB       = -l$(NVIZ_LIBNAME) $(BITMAPLIB) $(G3DLIB) $(GISLIB) $(VECTRLIB) 
 
 # triangulation libraries
 SOSLIB        = -l$(SOS_LIBNAME)
@@ -342,6 +344,7 @@
 
 # NVIZ related
 OGSFDEP      = $(ARCH_LIBDIR)/$(LIB_PREFIX)$(OGSF_LIBNAME)$(LIB_SUFFIX)
+NVIZDEP      = $(ARCH_LIBDIR)/$(LIB_PREFIX)$(NVIZ_LIBNAME)$(LIB_SUFFIX)
 
 # triangulation libraries
 SOSDEP      = $(ARCH_LIBDIR)/$(LIB_PREFIX)$(SOS_LIBNAME)$(LIB_SUFFIX)

Copied: grass/trunk/include/nviz.h (from rev 31934, grass-addons/visualization/nviz2/lib/nviz.h)
===================================================================
--- grass/trunk/include/nviz.h	                        (rev 0)
+++ grass/trunk/include/nviz.h	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,184 @@
+#ifndef GRASS_NVIZ_H
+#define GRASS_NVIZ_H
+
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+
+/*** Windows headers ***/
+#if defined(OPENGL_WINDOWS)
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+#  undef WIN32_LEAN_AND_MEAN
+#  include <winnt.h>
+
+/*** X Window System headers ***/
+#elif defined(OPENGL_X11)
+#  include <X11/Xlib.h>
+#  include <X11/Xutil.h>
+#  include <X11/Xatom.h>         /* for XA_RGB_DEFAULT_MAP atom */
+#  if defined(__vms)
+#    include <X11/StdCmap.h>     /* for XmuLookupStandardColormap */
+#  else
+#    include <X11/Xmu/StdCmap.h> /* for XmuLookupStandardColormap */
+#  endif
+#  include <GL/glx.h>
+
+/*** Mac headers ***/
+#elif defined(OPENGL_AQUA)
+#  define Cursor QDCursor
+#  include <AGL/agl.h>
+#  undef Cursor
+#  include <ApplicationServices/ApplicationServices.h>
+
+#else /* make sure only one platform defined */
+#  error Unsupported platform, or confused platform defines...
+#endif
+
+#define MAP_OBJ_UNDEFINED 0
+#define MAP_OBJ_SURF 1
+#define MAP_OBJ_VOL 2
+#define MAP_OBJ_VECT 3
+
+#define DRAW_COARSE 0
+#define DRAW_FINE 1
+#define DRAW_BOTH 2
+
+#define RANGE (5 * GS_UNIT_SIZE)
+#define RANGE_OFFSET (2 * GS_UNIT_SIZE)
+#define ZRANGE (3 * GS_UNIT_SIZE)
+#define ZRANGE_OFFSET (1 * GS_UNIT_SIZE)
+
+#define DEFAULT_SURF_COLOR 0x33BBFF
+
+#define RED_MASK 0x000000FF
+#define GRN_MASK 0x0000FF00
+#define BLU_MASK 0x00FF0000
+
+#define FORMAT_PPM 1
+#define FORMAT_TIF 2
+
+/* data structures */
+typedef struct{
+    int id;
+    float brt;
+    float r, g, b;
+    float ar, ag, ab;  /* ambient rgb */
+    float x, y, z, w; /* position */
+} light_data;
+
+typedef struct {
+    /* ranges */
+    float zrange, xyrange;
+    
+    /* cplanes */
+    int num_cplanes;
+    int cur_cplane, cp_on[MAX_CPLANES];
+    float cp_trans[MAX_CPLANES][3];
+    float cp_rot[MAX_CPLANES][3];
+    
+    /* light */
+    light_data light[MAX_LIGHTS];
+    
+    /* background color */
+    int bgcolor;
+
+    /* draw */
+    int draw_mode;
+} nv_data;
+
+/* The following structure is used to associate client data with surfaces.
+ * We do this so that we don't have to rely on the surface ID (which is libal to change
+ * between subsequent executions of nviz) when saving set-up info to files.
+ */
+
+typedef struct {
+    /* We use logical names to assign textual names to map objects.
+       When Nviz needs to refer to a map object it uses the logical name
+       rather than the map ID.  By setting appropriate logical names, we
+       can reuse names inbetween executions of Nviz.  The Nviz library
+       also provides a mechanism for aliasing between logical names.
+       Thus several logical names may refer to the same map object.
+       Aliases are meant to support the case in which two logical names
+       happen to be the same.  The Nviz library automatically assigns
+       logical names uniquely if they are not specified in the creation
+       of a map object.  When loading a saved file containing several map
+       objects, it is expected that the map 0bjects will be aliased to
+       their previous names.  This ensures that old scripts will work.
+    */
+    
+    char *logical_name;
+    
+} nv_clientdata;
+
+struct render_window {
+    Display *displayId;   /* display connection */
+    GLXContext contextId; /* GLX rendering context */
+    Pixmap pixmap;
+    GLXPixmap windowId;
+};
+
+/* change_view.c */
+int Nviz_resize_window(int, int);
+int Nviz_update_ranges(nv_data *);
+int Nviz_set_viewpoint_position(nv_data *,
+				float, float);
+int Nviz_set_viewpoint_height(nv_data *,
+			      float);
+int Nviz_set_viewpoint_persp(nv_data *, int);
+int Nviz_set_viewpoint_twist(nv_data *, int);
+int Nviz_change_exag(nv_data *, float);
+
+/* cplanes_obj.c */
+int Nviz_new_cplane(nv_data *, int);
+int Nviz_off_cplane(nv_data *, int);
+int Nviz_draw_cplane(nv_data *, int, int);
+
+/* draw.c */
+int Nviz_draw_all_surf(nv_data *);
+int Nviz_draw_all(nv_data *, int);
+int Nviz_draw_quick(nv_data *, int);
+int Nviz_draw_all_vect(nv_data *);
+void Nviz_set_draw_mode(nv_data *, int);
+
+/* exag.c */
+int Nviz_get_exag_height(float *, float *, float *);
+float Nviz_get_exag();
+
+/* lights.c */
+int Nviz_set_light_position(nv_data *, int,
+			    float, float, float, float);
+int Nviz_set_light_bright(nv_data *, int, float);
+int Nviz_set_light_color(nv_data *, int,
+			 float, float, float);
+int Nviz_set_light_ambient(nv_data *, int,
+			   float, float, float);
+int Nviz_init_light(nv_data *, int);
+int Nviz_new_light(nv_data *);
+
+/* map_obj.c */
+int Nviz_new_map_obj(int, const char *, float,
+		     nv_data *);
+int Nviz_set_attr(int, int, int, int, const char *, float,
+		  nv_data *);
+void Nviz_set_attr_default();
+int Nviz_unset_attr(int, int, int);
+
+/* nviz.c */
+void Nviz_init_data(nv_data *);
+void Nviz_set_bgcolor(nv_data *, int);
+int Nviz_color_from_str(const char *);
+
+/* position.c */
+void Nviz_init_view();
+int Nviz_set_focus_state(int);
+int Nviz_set_focus_map(int, int);
+
+/* render.c */
+struct render_window* Nviz_new_render_window();
+void Nviz_init_render_window(struct render_window*);
+void Nviz_destroy_render_window(struct render_window *);
+int Nviz_create_render_window(struct render_window *, void *,
+			      int, int);
+int Nviz_make_current_render_window(const struct render_window *);
+
+#endif /* GRASS_NVIZ_H */

Modified: grass/trunk/lib/Makefile
===================================================================
--- grass/trunk/lib/Makefile	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/lib/Makefile	2008-07-01 20:02:21 UTC (rev 31935)
@@ -38,7 +38,9 @@
 
 include $(MODULE_TOPDIR)/include/Make/Platform.make
 
-OPENGLBASED = ogsf
+OPENGLBASED = \
+	ogsf \
+	nviz
 
 #compile if OPENGLBASED present:
 ifneq ($(strip $(OPENGLLIB)),)

Copied: grass/trunk/lib/nviz/Makefile (from rev 31934, grass-addons/visualization/nviz2/lib/Makefile)
===================================================================
--- grass/trunk/lib/nviz/Makefile	                        (rev 0)
+++ grass/trunk/lib/nviz/Makefile	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,15 @@
+MODULE_TOPDIR = ../..
+
+LIB_NAME = $(NVIZ_LIBNAME)
+
+DEPENDENCIES = $(BITMAPDEP) $(DBMIDEP) $(GISDEP) $(OGSFDEP) $(G3DDEP) $(VECTRDEP)
+
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(INC) \
+	$(TIFFINCPATH) $(DSPINC) \
+	$(VECT_CFLAGS) $(OPENGLINC)
+EXTRA_LIBS = $(GISLIB) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB)
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+
+default: lib

Copied: grass/trunk/lib/nviz/change_view.c (from rev 31934, grass-addons/visualization/nviz2/lib/change_view.c)
===================================================================
--- grass/trunk/lib/nviz/change_view.c	                        (rev 0)
+++ grass/trunk/lib/nviz/change_view.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,221 @@
+/*!
+  \file change_view.c
+ 
+  \brief 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
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  \brief GL canvas resized
+
+  \param width window width
+  \param height window height
+
+  \return 1 on success
+  \return 0 on failure (window resized by dafault to 20x20 px)
+ */
+int Nviz_resize_window(int width, int height)
+{
+    int ret;
+
+    ret = 1;
+
+    if (width < 1 || height < 1) {
+	width = 20;
+	height = 20;
+	ret = 0;
+    }
+
+    GS_set_viewport(0, width, 0, height);
+
+    /*   GS_clear(0x0000FF); causes red flash - debug only */
+    GS_set_draw(GSD_BACK);
+    GS_ready_draw();
+    GS_alldraw_wire();
+    GS_done_draw();
+
+    return ret;
+}
+
+/*!
+  \brief Update ranges
+
+  Call whenever a new surface is added, deleted, or exag changes
+
+  \return 1
+*/
+int Nviz_update_ranges(nv_data *dc)
+{
+    float zmin, zmax, exag;
+
+    GS_get_longdim(&(dc->xyrange));
+
+    dc->zrange = 0.;
+
+    /* Zrange is based on a minimum of Longdim */
+    if (GS_global_exag()) {
+	exag = GS_global_exag();
+	dc->zrange = dc->xyrange / exag;
+    }
+    else {
+	exag = 1.0;
+    }
+
+    GS_get_zrange_nz(&zmin, &zmax);	/* actual */
+
+    zmax = zmin + (3. * dc->xyrange / exag);
+    zmin = zmin - (2. * dc->xyrange / exag);
+
+    if ((zmax - zmin) > dc->zrange)
+	dc->zrange = zmax - zmin;
+
+    return 1;
+}
+
+/*!
+  \brief Change position of view
+
+  \param data nviz data
+  \param x_pos,y_pos x,y position (model coordinates)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_position(nv_data *data,
+				float x_pos, float y_pos)
+{
+    float xpos, ypos, from[3];
+    float tempx, tempy;
+    
+    xpos = x_pos;
+    xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
+    ypos = 1.0 - y_pos;
+    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"),
+		   xpos, 1.0 - ypos);
+    }
+
+    GS_get_from(from);
+    
+    tempx = xpos * RANGE - RANGE_OFFSET;
+    tempy = ypos * RANGE - RANGE_OFFSET;
+
+    if ((from[X] != tempx) || (from[Y] != tempy)) {
+
+	from[X] = tempx;
+	from[Y] = tempy;
+
+	GS_moveto(from);
+
+	/* Nviz_draw_quick(data); */
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Change viewpoint height
+
+  \param data nviz data
+  \param height height value (world coordinates)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_height(nv_data *data, float height)
+{
+    float from[3];
+
+    GS_get_from_real(from);
+
+    if (height != from[Z]) {
+	from[Z] = height;
+
+	GS_moveto_real(from);
+
+	/*
+	   normalize (from);
+	   GS_setlight_position(1, from[X], from[Y], from[Z], 0);
+	*/
+
+	/* Nviz_draw_quick(data); */
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Change viewpoint perspective (field of view)
+
+  \param data nviz data
+  \param persp perspective value (0-100, in degrees)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_persp(nv_data *data, int persp)
+{
+    int fov;
+
+    fov = (int) (10 * persp);
+    GS_set_fov(fov);
+
+    /* Nviz_draw_quick(data); */
+
+    return 1;
+}
+
+/*!
+  \brief Change viewpoint twist
+
+  \param data nviz data
+  \param persp twist value (-180-180, in degrees)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_twist(nv_data *data, int twist)
+{
+    GS_set_twist(10 * twist);
+    
+    /* Nviz_draw_quick(data); */
+
+    return 1;
+}
+
+/*!
+  \brief Change z-exag value
+
+  \param data nviz data
+  \param exag exag value
+
+  \return 1
+*/
+int Nviz_change_exag(nv_data *data, float exag)
+{
+    float temp;
+
+    temp = GS_global_exag();
+
+    if (exag != temp) {
+	GS_set_global_exag(exag);
+	Nviz_update_ranges(data);
+	
+	/* Nviz_draw_quick(data); */
+    }
+
+    return 1;
+}

Copied: grass/trunk/lib/nviz/cplanes_obj.c (from rev 31934, grass-addons/visualization/nviz2/lib/cplanes_obj.c)
===================================================================
--- grass/trunk/lib/nviz/cplanes_obj.c	                        (rev 0)
+++ grass/trunk/lib/nviz/cplanes_obj.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,123 @@
+/*!
+  \file 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)
+
+  \date 2008
+*/
+
+#include <grass/nviz.h>
+
+static void cp_draw(nv_data *, int, int, int);
+
+/*!
+  \brief Creates a clip plane object
+   
+  The number of clip planes is fixed (MAX_CPLANES) and
+  we'll create them all ahead of time anyway we just let
+  the user decide on the id for each.
+*/
+int Nviz_new_cplane(nv_data *data, int id)
+{
+    data->num_cplanes++;
+    /* Initialize internal attributes for this cutplane */
+    data->cp_rot[id][X] = data->cp_rot[id][Y] = data->cp_rot[id][Z] = 0.0;
+    data->cp_trans[id][X] = data->cp_trans[id][Y] = data->cp_trans[id][Z] = 0.0;
+    data->cp_on[id] = 0;
+
+    return 1;
+}
+
+/*!
+  \brief Turn off (make inactive) the given clip plane
+
+  \param data nviz data
+  \param cplane id
+*/
+int Nviz_off_cplane(nv_data *data, int id)
+{
+    data->cp_on[id] = 0;
+    GS_unset_cplane(id);
+
+    return 1;
+}
+
+/*!
+   \brief Draw the clip plane
+
+   \param bound1
+   \param bound2
+*/
+int Nviz_draw_cplane(nv_data *data, int bound1, int bound2)
+{
+    cp_draw(data, data->cur_cplane, bound1, bound2);
+
+    return 1;
+}
+
+/*!
+  \brief Draw current clip plane
+
+  \param data nviz data
+  \param current id of current clip plane
+  \param surf1 first surface id
+  \param surf2 second surface id
+*/
+void cp_draw(nv_data *data, int current, int surf1, int surf2)
+{
+    int i, nsurfs;
+    int surf_min=0, surf_max=0, temp;
+    int *surf_list;
+
+    GS_set_draw(GSD_BACK);
+    GS_clear(data->bgcolor);
+    GS_ready_draw();
+
+    /* If surf boundaries present then find them */
+    surf_list = GS_get_surf_list(&nsurfs);
+    if ((surf1 != -1) && (surf2 != -1)) {
+	for (i = 0; i < nsurfs; i++) {
+	    if (surf_list[i] == surf1)
+		surf_min = i;
+	    if (surf_list[i] == surf2)
+		surf_max = i;
+	}
+
+	if (surf_max < surf_min) {
+	    temp = surf_min;
+	    surf_min = surf_max;
+	    surf_max = temp;
+	}
+
+	surf_max++;
+    }
+    else {
+	surf_min = 0;
+	surf_max = nsurfs;
+    }
+
+    if (nsurfs > 1) {
+	for (i = 0; i < MAX_CPLANES; i++) {
+	    if (data->cp_on[i])
+		GS_draw_cplane_fence(surf_list[0], surf_list[1], i);
+	}
+    }
+
+    for (i = surf_min; i < surf_max; i++) {
+	GS_draw_wire(surf_list[i]);
+    }
+
+    GS_done_draw();
+
+    return;
+}

Copied: grass/trunk/lib/nviz/draw.c (from rev 31934, grass-addons/visualization/nviz2/lib/draw.c)
===================================================================
--- grass/trunk/lib/nviz/draw.c	                        (rev 0)
+++ grass/trunk/lib/nviz/draw.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,405 @@
+/*!
+  \file 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
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/nviz.h>
+
+static int sort_surfs_max(int *, int *, int *, int);
+static int check_blank(int);
+
+/*!
+  \brief Draw all loaded surfaces
+
+  \param dc nviz data
+
+  \return 1
+*/
+int Nviz_draw_all_surf(nv_data *dc)
+{
+    int i, nsurfs;
+    int sortSurfs[MAX_SURFS], sorti[MAX_SURFS];
+    int *surf_list;
+    float x, y, z;
+    int num, w;
+
+/* Get position for Light 1 */
+    num = 1;
+    x = dc->light[num].x;
+    y = dc->light[num].y;
+    z = dc->light[num].z;
+    w = dc->light[num].z;
+
+    surf_list = GS_get_surf_list(&nsurfs);
+
+    sort_surfs_max(surf_list, sortSurfs, sorti, nsurfs);
+
+    G_free (surf_list);
+
+    /* re-initialize lights */
+    GS_setlight_position(num, x, y, z, w);
+    num = 2;
+    GS_setlight_position(num, 0., 0., 1., 0);
+
+    for (i = 0; i < nsurfs; i++) {
+	if (!check_blank(sortSurfs[i])) {
+	    GS_draw_surf(sortSurfs[i]);
+	}
+    }
+    
+    /* GS_draw_cplane_fence params will change - surfs aren't used anymore */
+    for (i = 0; i < MAX_CPLANES; i++) {
+	if (dc->cp_on[i])
+	    GS_draw_cplane_fence(sortSurfs[0], sortSurfs[1], i);
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Sorts surfaces by max elevation, lowest to highest.
+
+  Puts ordered id numbers in id_sort, leaving id_orig unchanged.
+  Puts ordered indices of surfaces from id_orig in indices.
+
+  \param surf pointer to surface array
+  \param id_sort
+  \param indices
+  \param num
+
+  \return 1
+*/
+int sort_surfs_max(int *surf, int *id_sort, int *indices, int num)
+{
+    int i, j;
+    float maxvals[MAX_SURFS];
+    float tmp, max=0., tmin, tmax, tmid;
+
+    for (i = 0; i < num; i++) {
+	GS_get_zextents(surf[i], &tmin, &tmax, &tmid);
+	if (i == 0)
+	    max = tmax;
+	else
+	    max = max < tmax ? tmax : max;
+	maxvals[i] = tmax;
+    }
+
+    for (i = 0; i < num; i++) {
+	tmp = maxvals[0];
+	indices[i] = 0;
+	for (j = 0; j < num; j++) {
+	    if (maxvals[j] < tmp) {
+		tmp = maxvals[j];
+		indices[i] = j;
+	    }
+	}
+
+	maxvals[indices[i]] = max + 1;
+	id_sort[i] = surf[indices[i]];
+    }
+
+    return 1;
+}
+
+/*
+  \brief Check if a specific map object should be blanked for
+  a draw.
+
+  This option is used by one of the script tools for
+  blanking maps during specific frames.
+  
+  \param map_id map object id
+  
+  \return 0 not blank
+  \return 1 blank
+*/
+int check_blank(int map_id)
+{
+    return 0;
+}
+
+/*!
+  \brief Draw all 
+
+  \param data nviz data
+  \param clear clear screen before drawing
+*/
+int Nviz_draw_all(nv_data *data, int clear)
+{
+    int draw_surf, draw_vect, draw_site, draw_vol;
+    int draw_north_arrow, arrow_x, draw_label, draw_legend;
+    int draw_fringe, draw_scalebar, draw_bar_x;
+    // const char* draw_is_drawing = Tcl_GetVar(interp, "is_drawing", TCL_GLOBAL_ONLY);
+    // const char* EMPTYSTRING = "";
+
+    draw_surf = 1;
+    draw_vect = 1;
+    draw_site = 0;
+    draw_vol = 0;
+    draw_north_arrow = 0;
+    arrow_x = 0;
+    draw_label = 0;
+    draw_legend = 0;
+    draw_fringe = 0;
+    draw_scalebar = 0;
+    draw_bar_x = 0;
+
+    /*
+    if (buf_is_drawing && atoi(buf_is_drawing))
+	return (TCL_OK);
+    */
+
+    // Tcl_SetVar(interp, "is_drawing", "1", TCL_GLOBAL_ONLY);
+    
+    GS_set_draw(GSD_BACK); /* needs to be BACK to avoid flickering */
+    if (clear)
+	GS_clear(data->bgcolor);
+    GS_ready_draw();
+
+/*
+    buf_surf     = Tcl_GetVar(interp, "surface", TCL_GLOBAL_ONLY);
+    buf_vect     = Tcl_GetVar(interp, "vector", TCL_GLOBAL_ONLY);
+    buf_site     = Tcl_GetVar(interp, "sites", TCL_GLOBAL_ONLY);
+    buf_vol      = Tcl_GetVar(interp, "volume", TCL_GLOBAL_ONLY);
+    buf_north_arrow = Tcl_GetVar(interp, "n_arrow", TCL_GLOBAL_ONLY);
+    arrow_x      = Tcl_GetVar(interp, "n_arrow_x", TCL_GLOBAL_ONLY);
+    buf_label    = Tcl_GetVar(interp, "labels", TCL_GLOBAL_ONLY);
+    buf_legend   = Tcl_GetVar(interp, "legend", TCL_GLOBAL_ONLY);
+    buf_fringe   = Tcl_GetVar(interp, "fringe", TCL_GLOBAL_ONLY);
+    buf_scalebar = Tcl_GetVar(interp, "scalebar", TCL_GLOBAL_ONLY);
+    bar_x        = Tcl_GetVar(interp, "scalebar_x", TCL_GLOBAL_ONLY);
+*/  
+    if (draw_surf)
+	Nviz_draw_all_surf(data);
+
+    if (draw_vect)
+	Nviz_draw_all_vect (data);
+
+    if (draw_site)
+	; // site_draw_all_together(data, interp);
+
+    if (draw_vol)
+	; // vol_draw_all_cmd(data, interp, argc, argv);
+    
+    GS_done_draw();
+    GS_set_draw(GSD_BACK);
+    
+    if (!draw_north_arrow)
+	; // draw_north_arrow = EMPTYSTRING; 
+    
+    if (!arrow_x)
+	; // arrow_x = EMPTYSTRING; 
+    
+    if (!draw_scalebar)
+	; // draw_scalebar = EMPTYSTRING; 
+    
+    if (!draw_bar_x)
+	; // bar_x = EMPTYSTRING; 
+    
+    if (!draw_fringe)
+	; // draw_fringe = EMPTYSTRING; 
+    
+    if (!draw_label)
+	; // draw_label = EMPTYSTRING; 
+    
+    if (!draw_legend)
+	; // draw_legend = EMPTYSTRING; 
+    
+    /* Draw decorations */
+    
+    /* North Arrow
+    if (atoi(draw_north_arrow) == 1 && atoi(arrow_x) != 999 ) {
+	const char *arrow_y, *arrow_z, *arrow_len;
+	float coords[3], len;
+	int arrow_clr, text_clr;
+	
+	arrow_y = Tcl_GetVar(interp, "n_arrow_y", TCL_GLOBAL_ONLY);
+	arrow_z = Tcl_GetVar(interp, "n_arrow_z", TCL_GLOBAL_ONLY);
+	arrow_len = Tcl_GetVar(interp, "n_arrow_size", TCL_GLOBAL_ONLY);
+	arrow_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "arw_clr", TCL_GLOBAL_ONLY));
+	text_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "arw_text_clr", TCL_GLOBAL_ONLY));
+	coords[0] = atoi(arrow_x);
+	coords[1] = atoi(arrow_y);
+	coords[2] = atoi(arrow_z);
+	len = atof(arrow_len);
+	
+	FontBase = load_font(TOGL_BITMAP_HELVETICA_18);
+	gsd_north_arrow(coords, len, FontBase, arrow_clr, text_clr);
+    }
+    */
+
+    /* Scale Bar
+    if (atoi(draw_scalebar) == 1 && atoi(bar_x) != 999 ) {
+	const char *bar_y, *bar_z, *bar_len;
+	float coords[3], len;
+	int bar_clr, text_clr;
+	
+	bar_y = Tcl_GetVar(interp, "scalebar_y", TCL_GLOBAL_ONLY);
+	bar_z = Tcl_GetVar(interp, "scalebar_z", TCL_GLOBAL_ONLY);
+	bar_len = Tcl_GetVar(interp, "scalebar_size", TCL_GLOBAL_ONLY);
+	bar_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "bar_clr", TCL_GLOBAL_ONLY));
+	text_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "bar_text_clr", TCL_GLOBAL_ONLY));
+	coords[0] = atoi(bar_x);
+	coords[1] = atoi(bar_y);
+	coords[2] = atoi(bar_z);
+	len = atof(bar_len);
+	
+	FontBase = load_font(TOGL_BITMAP_HELVETICA_18);
+	gsd_scalebar(coords, len, FontBase, bar_clr, bar_clr);
+    }
+    */
+
+    /* fringe
+    if (atoi(draw_fringe) == 1) {
+	const char *fringe_ne, *fringe_nw, *fringe_se, *fringe_sw;
+	const char *surf_id;
+	int flags[4], id;
+	int fringe_clr;
+	float fringe_elev;
+	
+	fringe_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "fringe_color", TCL_GLOBAL_ONLY));
+	fringe_elev = (float) atof(Tcl_GetVar(interp, "fringe_elev", TCL_GLOBAL_ONLY));
+	fringe_ne = Tcl_GetVar(interp, "fringe_ne", TCL_GLOBAL_ONLY);
+	fringe_nw = Tcl_GetVar(interp, "fringe_nw", TCL_GLOBAL_ONLY);
+	fringe_se = Tcl_GetVar(interp, "fringe_se", TCL_GLOBAL_ONLY);
+	fringe_sw = Tcl_GetVar(interp, "fringe_sw", TCL_GLOBAL_ONLY);
+	flags[0] = atoi(fringe_nw);
+	flags[1] = atoi(fringe_ne);
+	flags[2] = atoi(fringe_sw);
+	flags[3] = atoi(fringe_se);
+	surf_id = Tcl_GetVar2(interp, "Nv_", "CurrSurf", TCL_GLOBAL_ONLY);
+	id = atoi(surf_id);
+	
+	GS_draw_fringe(id, fringe_clr, fringe_elev, flags);
+    }
+    */
+
+    /* Legend and/or labels
+    if (atoi(draw_label) == 1 || atoi(draw_legend) == 1)
+	GS_draw_all_list();
+    */
+
+    // Tcl_SetVar(interp, "is_drawing", "0", TCL_GLOBAL_ONLY);
+    // flythrough_postdraw_cb();
+    
+    return 1;
+}
+
+/*!
+  \brief Draw in coarse mode
+
+  \param dc nviz data
+  \param clear clear screen before drawing
+  \return 1
+*/
+int Nviz_draw_quick(nv_data *dc, int clear)
+{
+    int i, max;
+    int *surf_list, *vol_list;
+
+    GS_set_draw(GSD_BACK);
+    
+    if (clear)
+	GS_clear(dc->bgcolor);
+
+    GS_ready_draw();
+
+    GS_alldraw_wire();
+
+    /*
+    surf_list = GS_get_surf_list(&max);
+
+    max = GS_num_surfs();
+    for (i = 0; i < max; i++) {
+	if (!check_blank(surf_list[i])) {
+	    GS_draw_wire(surf_list[i]);
+	}
+    }
+
+    G_free (surf_list);
+    */
+
+    /*
+    vol_list = GVL_get_vol_list(&max);
+    max = GVL_num_vols();
+    for (i = 0; i < max; i++) {
+	if (check_blank(interp, vol_list[i]) == 0) {
+	    GVL_draw_wire(vol_list[i]);
+	}
+    }
+    */
+
+    GS_done_draw();
+
+    // flythrough_postdraw_cb();
+
+    return 1;
+}
+
+/*!
+  \brief Draw all loaded vector sets
+
+  \param dc nviz data
+
+  \return 1
+*/
+int Nviz_draw_all_vect(nv_data *dc)
+{
+    int i, nvects;
+    int *vect_list;
+
+    // GS_set_cancel(0);
+    vect_list = GV_get_vect_list(&nvects);
+
+    /* in case transparency is set */
+    GS_set_draw(GSD_BOTH);
+
+    GS_ready_draw();
+
+    for (i = 0; i < nvects; i++) {
+	if (!check_blank(vect_list[i])) {
+	    GV_draw_vect(vect_list[i]);
+	}
+    }
+    G_free (vect_list);
+
+    GS_done_draw();
+    
+    GS_set_draw(GSD_BACK);
+
+    // GS_set_cancel(0);
+
+    return 1;
+}
+
+/*!
+  \brief Set draw mode
+
+  Draw modes:
+   - DRAW_COARSE
+   - DRAW_FINE
+   - DRAW_BOTH
+
+  \param data nviz data
+  \param mode draw mode
+*/
+void Nviz_set_draw_mode(nv_data *data, int mode)
+{
+    data->draw_mode = mode;
+
+    return;
+}

Copied: grass/trunk/lib/nviz/exag.c (from rev 31934, grass-addons/visualization/nviz2/lib/exag.c)
===================================================================
--- grass/trunk/lib/nviz/exag.c	                        (rev 0)
+++ grass/trunk/lib/nviz/exag.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,99 @@
+/*!
+  \file 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)
+
+  \date 2008
+*/
+
+#include <grass/nviz.h>
+
+/*!
+  \brief Get view height
+
+  Call after initial data has been loaded
+
+  \param[out] val height value
+  \param[out] min min value (or NULL)
+  \param[out] max max value (or NULL)
+
+  \return 1
+*/
+int Nviz_get_exag_height(float *val, float *min, float *max)
+{
+    float longdim, exag, texag, hmin, hmax, fmin, fmax;
+    int nsurfs, i, *surf_list;
+
+    surf_list = GS_get_surf_list(&nsurfs);
+    if (nsurfs) {
+	GS_get_longdim(&longdim);
+	GS_get_zrange_nz(&hmin, &hmax);
+
+	exag = 0.0;
+	for (i = 0; i < nsurfs; i++) {
+	    if (GS_get_exag_guess(surf_list[i], &texag) > -1)
+		if (texag)
+		    exag = texag > exag ? texag : exag;
+	}
+	if (exag == 0.0)
+	    exag = 1.0;
+	
+	fmin = hmin - (2. * longdim / exag);
+	fmax = hmin + (3 * longdim / exag);
+    }
+    else {
+	fmax = 10000.0;
+	fmin = 0.0;
+    }
+
+    *val = fmin + (fmax - fmin) / 2.0;
+
+    if (min)
+	*min = fmin;
+
+    if (max)
+	*max = fmax;
+
+    return 1;
+}
+
+/*!
+  \brief Get view z-exag value
+
+  Call after initial data has been loaded
+
+  \return value
+*/
+float Nviz_get_exag()
+{
+    float exag, texag;
+    int nsurfs, i, *surf_list;
+
+    surf_list = GS_get_surf_list(&nsurfs);
+
+    exag = 0.0;
+    for (i = 0; i < nsurfs; i++) {
+	if (GS_get_exag_guess(surf_list[i], &texag) > -1) {
+	    if (texag)
+		exag = (texag > exag) ? texag : exag;
+	}
+    }
+
+    if (exag == 0.0)
+	exag = 1.0;
+
+    if (nsurfs > 0)
+	G_free(surf_list);
+
+    return exag;
+}

Copied: grass/trunk/lib/nviz/lights.c (from rev 31934, grass-addons/visualization/nviz2/lib/lights.c)
===================================================================
--- grass/trunk/lib/nviz/lights.c	                        (rev 0)
+++ grass/trunk/lib/nviz/lights.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,151 @@
+/*!
+  \file lights.c
+ 
+  \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/lights.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  \brief Set light position
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param x,y,z,w position, model coordinates
+*/
+int Nviz_set_light_position(nv_data *data, int num,
+			    float x, float y, float z, float w)
+{
+    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;
+
+    GS_setlight_position(num + 1, x, y, z, w);
+
+    return 1;
+}
+
+/*!
+  \brief Set light brightness
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param value brightness value
+*/
+int Nviz_set_light_bright(nv_data * data, int num, float value)
+{
+    float r, g, b;
+
+    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;
+
+    GS_setlight_color(num + 1, r, g, b);
+
+    return 1;
+}
+
+/*!
+  \brief Set light color
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param red,green,blue rGB values (0-1)
+*/
+int Nviz_set_light_color(nv_data * data, int num,
+			 float red, float green, float blue)
+{
+    float r, g, b;
+
+    data->light[num].r = red;
+    data->light[num].g = green;
+    data->light[num].b = blue;
+
+    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;
+
+    GS_setlight_color(num + 1, r, g, b);
+
+    return 1;
+}
+
+/*!
+  \brief Set light ambient
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param red,green,blue rGB values (0-1)
+*/
+int Nviz_set_light_ambient(nv_data *data, int num,
+			   float red, float green, float blue)
+{
+    data->light[num].ar = red;
+    data->light[num].ag = green;
+    data->light[num].ab = blue;
+
+    GS_setlight_ambient(num + 1, red, green, blue);
+
+    return 1;
+}
+
+/*!
+  \brief Init new light
+
+  \param data nviz data
+  \param num light num (starts with 0)
+*/
+int Nviz_init_light(nv_data *data, int num)
+{
+    if (num >= MAX_LIGHTS) {
+	return 0;
+    }
+
+    data->light[num].id = 0;
+    data->light[num].brt = 0.8;
+    data->light[num].ar = 0.3;
+    data->light[num].ag = 0.3;
+    data->light[num].ab = 0.3;
+    data->light[num].r = 1.0;
+    data->light[num].b = 1.0;
+    data->light[num].g = 1.0;
+    data->light[num].x = 1.0;
+    data->light[num].y = 1.0;
+    data->light[num].z = 1.0;
+    data->light[num].w = 1.0;
+
+    return 1;
+}
+
+int Nviz_new_light(nv_data *data)
+{
+    int num;
+
+    num = GS_new_light();
+
+    if (num < 1) {
+	G_warning(_("Unable to define new light"));
+	return 0;
+    }
+
+    Nviz_init_light(data, num - 1);
+
+    return 1;
+}

Copied: grass/trunk/lib/nviz/map_obj.c (from rev 31934, grass-addons/visualization/nviz2/lib/map_obj.c)
===================================================================
--- grass/trunk/lib/nviz/map_obj.c	                        (rev 0)
+++ grass/trunk/lib/nviz/map_obj.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,294 @@
+/*!
+  \file 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.
+
+  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
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <stdlib.h>
+#include <time.h>
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  \brief Create a new map object which can be one of surf, vect, vol or site.
+
+  This routine creates the object internally in the gsf libraryb.
+  Optionally, a logical name may be specified for the new map object.
+  If no name is specified, a logical name is assigned to the new
+  object automatically.  Note that maintaining unique logical names is
+  not the responsibility of the library (currently).
+  
+  Initially map objects contain no data, use the attribute commands to
+  set attributes such as topology, color, etc.
+
+  \param type map object type
+  \param name map name (NULL for constant)
+  \param value constant (used if <i>name</i> is NULL)
+  \param data nviz data
+
+  \return map object id
+  \return -1 on error
+*/
+int Nviz_new_map_obj(int type, const char *name, float value,
+		     nv_data *data)
+{
+    int new_id, i;
+    int num_surfs, *surf_list;
+
+    nv_clientdata *client_data;
+
+    /*
+     * For each type of map obj do the following --
+     *   1) Verify we havn't maxed out the number of
+     *      allowed objects.
+     *   2) Call the internal library to generate a new
+     *      map object of the specified type.
+     */
+    /* raster -> surface */
+    if (type == MAP_OBJ_SURF) {
+	if (GS_num_surfs() >= MAX_SURFS) {
+	    G_warning (_("Maximum surfaces loaded!"));
+	    return -1;
+	}
+
+	new_id = GS_new_surface();
+
+	if (new_id < 0) {
+	    return -1;
+	}
+	
+	if (name) {
+	    /* map */
+	    if (!Nviz_set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, MAP_ATT, name, -1.0,
+			  data)) {
+		return -1;
+	    }
+	}
+	else {
+	    /* constant */
+	    if (!Nviz_set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, NULL, value,
+			       data)) {
+		return -1;
+	    }
+	}	  
+    }
+    /* vector overlay */
+    else if (type == MAP_OBJ_VECT) {
+	if (GV_num_vects() >= MAX_VECTS) {
+	    G_warning (_("Maximum vectors loaded!"));
+	    return -1;
+	}
+
+	new_id = GV_new_vector();
+
+	if (name) {
+	    if (GV_load_vector(new_id, name) < 0) {
+		GV_delete_vector(new_id);
+		G_warning (_("Error loading vector <%s>"), name);
+		return -1;
+	    }
+	}
+	 
+	/* initialize display parameters
+	   automatically select all surfaces to draw vector */
+	GV_set_vectmode(new_id, 1, 0xFF0000, 2, 0);
+	surf_list = GS_get_surf_list(&num_surfs);
+	if (num_surfs) {
+	    for (i = 0; i < num_surfs; i++) {
+		GV_select_surf(new_id, surf_list[i]);
+	    }
+	}
+	G_free (surf_list);
+    }
+
+    /* initialize the client data filled for the new map object */
+    client_data = (nv_clientdata *) G_malloc (sizeof(nv_clientdata));
+
+    if (name) {
+	client_data->logical_name = G_store(name);
+    }
+    else {
+	char temp_space[80];
+	time_t tp;
+	
+	/* Need to generate a random id */
+	time(&tp);
+	switch (type) {
+	case MAP_OBJ_SURF: {
+	    sprintf(temp_space, "%s*%ld", "surface", tp);
+	    break;
+	}
+	default: {
+	    sprintf(temp_space, "%s*%ld", "unknown", tp);
+	    break;
+	}
+	}
+	client_data->logical_name = G_store (temp_space);
+    }
+    
+    G_debug(3, "new_map_obj(): logical name=%s",
+	    client_data->logical_name);
+    
+    GS_Set_ClientData(new_id, (void *) client_data);
+    
+    return new_id;
+}
+
+/*!
+  Set map object attribute
+
+  \param id map object id
+  \param type map object type (MAP_OBJ_SURF, MAP_OBJ_VECT, ...)
+  \param desc attribute descriptor
+  \param src attribute source
+  \param str_value attribute value as string (if NULL, check for <i>num_value</i>)
+  \param num_value attribute value as float 
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz_set_attr(int id, int type, int desc, int src,
+		  const char *str_value, float num_value,
+		  nv_data *data)
+{
+    int ret;
+    float value;
+    
+    switch (type) {
+    case(MAP_OBJ_SURF): {
+	/* Basically two cases, either we are setting to a constant field, or
+	 * we are loading an actual file. Setting a constant is the easy part
+	 * so we try and do that first.
+	 */
+	if (src == CONST_ATT) {
+	    /* Get the value for the constant
+	     * Note that we require the constant to be an integer
+	     */
+	    if (str_value)
+		value = (float) atof(str_value);
+	    else
+		value = num_value;
+	    
+	    /* Only special case is setting constant color.
+	     * In this case we have to decode the constant Tcl
+	     * returns so that the gsf library understands it.
+	     */
+	    if (desc == ATT_COLOR) {
+		/* TODO check this - sometimes gets reversed when save state
+		   saves a surface with constant color
+
+		int r, g, b;
+		r = (((int) value) & RED_MASK) >> 16;
+		g = (((int) value) & GRN_MASK) >> 8;
+		b = (((int) value) & BLU_MASK);
+		value = r + (g << 8) + (b << 16);
+		*/
+	    }
+	    
+	    /* Once the value is parsed, set it */
+	    ret = GS_set_att_const(id, desc, value);
+	}
+	else if (src == MAP_ATT) {
+	    ret = GS_load_att_map(id, str_value, desc);
+	}
+	
+	/* After we've loaded a constant map or a file,
+	 * may need to adjust resolution if we are resetting
+	 * topology (for example)
+	 */
+	if (0 <= ret) {
+	    if (desc == ATT_TOPO) {
+		int rows, cols, max;
+		int max2;
+		
+		/* If topology attribute is being set then need to set
+		 * resolution of incoming map to some sensible value so we
+		 * don't wait all day for drawing.
+		 */
+		GS_get_dims(id, &rows, &cols);
+		max = (rows > cols) ? rows : cols;
+		max = max / 50;
+		if (max < 1)
+		    max = 1;
+		max2 = max / 5;
+		if (max2 < 1)
+		    max2 = 1;
+		/* reset max to finer for coarse surf drawing */
+		max = max2 + max2/2;
+		if (max < 1)
+		    max = 1;
+		
+		GS_set_drawres(id, max2, max2, max, max);
+		GS_set_drawmode(id, DM_GOURAUD | DM_POLY | DM_GRID_SURF);
+	    }
+	    
+	    /* Not sure about this next line, should probably just
+	     * create separate routines to figure the Z range as well
+	     * as the XYrange
+	     */
+	    Nviz_update_ranges(data);
+	    
+	    break;
+	}
+	default: {
+	    return 0;
+	}
+    }
+    }
+    
+    return 1;
+}
+
+/*!
+  \brief Set default map object attributes
+*/
+void Nviz_set_attr_default()
+{
+    float defs[MAX_ATTS];
+    
+    defs[ATT_TOPO] = 0;
+    defs[ATT_COLOR] = DEFAULT_SURF_COLOR;
+    defs[ATT_MASK] = 0;
+    defs[ATT_TRANSP] = 0;
+    defs[ATT_SHINE] = 60;
+    defs[ATT_EMIT] = 0;
+
+    GS_set_att_defaults(defs, defs);
+
+    return;
+}
+
+/*!
+  Unset map object attribute
+
+  \param id map object id
+  \param type map object type (MAP_OBJ_SURF, MAP_OBJ_VECT, ...)
+  \param desc attribute descriptor
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz_unset_attr(int id, int type, int desc)
+{
+    if (type == MAP_OBJ_SURF) {
+	return GS_unset_att(id, desc);
+    }
+    
+    return 0;
+}

Copied: grass/trunk/lib/nviz/nviz.c (from rev 31934, grass-addons/visualization/nviz2/lib/nviz.c)
===================================================================
--- grass/trunk/lib/nviz/nviz.c	                        (rev 0)
+++ grass/trunk/lib/nviz/nviz.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,82 @@
+/*!
+  \file 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/
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  \brief Initialize Nviz data
+
+  \param data nviz data
+*/
+void Nviz_init_data(nv_data *data)
+{
+    unsigned int i;
+
+    /* data range */
+    data->zrange = 0;
+    data->xyrange = 0;
+    
+    /* clip planes, turn off by default*/
+    data->num_cplanes = 0;
+    data->cur_cplane = 0;
+    for (i = 0; i < MAX_CPLANES; i++) {
+	Nviz_new_cplane(data, i);
+	Nviz_off_cplane(data, i);
+    }
+    
+    /* lights */
+    for (i = 0; i < MAX_LIGHTS; i++) {
+	Nviz_new_light(data);
+    }
+
+    return;
+}
+
+/*!
+  \brief Set background color
+
+  \param data nviz data
+  \param color color value
+*/
+void Nviz_set_bgcolor(nv_data *data, int color)
+{
+    data->bgcolor = color;
+    
+    return;
+}
+
+/*!
+  \brief Get color value from color string (name or RGB triplet)
+
+  \param color_str color string
+
+  \return color value
+*/
+int Nviz_color_from_str(const char *color_str)
+{
+    int red, grn, blu;
+
+    if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
+	G_warning (_("Invalid color (%s), using \"white\" as default"),
+		   color_str);
+	red = grn = blu = 255;
+    }
+
+    return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) + ((int)((blu) << 16) & BLU_MASK);
+}

Copied: grass/trunk/lib/nviz/position.c (from rev 31934, grass-addons/visualization/nviz2/lib/position.c)
===================================================================
--- grass/trunk/lib/nviz/position.c	                        (rev 0)
+++ grass/trunk/lib/nviz/position.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,105 @@
+/*!
+  \file 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
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  Initialize view and position settings (focus)
+
+  Set position to center of view
+*/
+void Nviz_init_view()
+{
+    GS_init_view();
+    Nviz_set_focus_state(1); /* center of view */
+
+    return;
+}
+
+/*!
+  \brief Set focus state
+
+  \param state_flag 1 for center view, 0 use viewdir
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz_set_focus_state(int state_flag)
+{
+    if (state_flag == 1)
+	GS_set_infocus(); /* return center of view */
+    else if (state_flag == 0)
+	GS_set_nofocus(); /* no center of view -- use viewdir */
+    else {
+	G_warning (_("Unable to set focus"));
+	return 0;
+    }
+    
+    return 1;
+}
+
+/*!
+  \brief Set focus based on loaded map
+
+  If <i>map</i> is MAP_OBJ_UNDEFINED, set focus from first
+  surface/volume in the list.
+
+  \param type map object type
+  \param id map object id
+
+  \return 0 on no focus
+  \return id id of map object used for setting focus
+*/
+int Nviz_set_focus_map(int type, int id)
+{
+    if (GS_num_surfs() < 0 && GVL_num_vols() < 0) {
+	GS_set_nofocus();
+	return 0;
+    }
+
+    if (type == MAP_OBJ_UNDEFINED) {
+	int *surf_list, num_surfs, *vol_list;
+
+	if (GS_num_surfs() > 0) {
+	    surf_list = GS_get_surf_list(&num_surfs);
+	    id = surf_list[0];
+	    G_free (surf_list);
+	    
+	    GS_set_focus_center_map(id);
+	}
+
+	if (GVL_num_vols() > 0) {
+	    vol_list = GVL_get_vol_list(&num_surfs);
+	    id = vol_list[0];
+	    G_free (vol_list);
+	    
+	    GVL_set_focus_center_map(id);
+	}
+	return id;
+    }
+
+    if (type == MAP_OBJ_SURF) {
+	GS_set_focus_center_map(id);
+    }
+    else if (type == MAP_OBJ_VOL) {
+	GVL_set_focus_center_map(id);
+    }
+    
+    return id;
+}

Copied: grass/trunk/lib/nviz/render.c (from rev 31934, grass-addons/visualization/nviz2/lib/render.c)
===================================================================
--- grass/trunk/lib/nviz/render.c	                        (rev 0)
+++ grass/trunk/lib/nviz/render.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,144 @@
+/*!
+  \file 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 etc.
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  \brief Allocate memory for render window
+
+  \return pointer to render_window struct
+  \return NULL on failure
+*/
+struct render_window *Nviz_new_render_window()
+{
+  struct render_window *rwin;
+
+  /* G_malloc() calls G_fatal_error() on failure */
+  rwin = (struct render_window *) G_malloc (sizeof (struct render_window));
+  
+  return rwin;
+}
+					    
+/*!
+  \brief Initialize render window
+
+  \param win pointer to render_window struct
+*/
+void Nviz_init_render_window(struct render_window *rwin)
+{
+    rwin->displayId = NULL;
+    rwin->contextId = NULL;
+    rwin->pixmap = 0;
+    rwin->windowId = 0;
+
+    return;
+}
+
+/*!
+  \brief Free render window
+
+  \param win pointer to render_window struct
+*/
+void Nviz_destroy_render_window(struct render_window *rwin)
+{
+    glXDestroyContext(rwin->displayId, rwin->contextId);
+    XFreePixmap(rwin->displayId, rwin->pixmap);
+
+    G_free ((void *) rwin);
+
+    return;
+}
+
+/*!
+  \brief Create render window
+
+  \param rwin pointer to render_window struct
+  \param display display instance (NULL for offscreen)
+  \param width window width
+  \param height window height
+
+  \return 1
+*/
+int Nviz_create_render_window(struct render_window *rwin, void *display,
+			      int width, int height)
+{
+    XVisualInfo  *v;
+
+    int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1,
+			    GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
+			    GLX_DEPTH_SIZE, 1, None };
+
+    /* get the default display connection */
+    rwin->displayId = XOpenDisplay((char *) display);
+    if (!rwin->displayId) {
+	G_fatal_error (_("Bad X server connection"));
+    }
+
+    /* get visual info and set up pixmap buffer */
+    v = glXChooseVisual(rwin->displayId,
+			DefaultScreen(rwin->displayId),
+			attributeList);
+
+    rwin->contextId = glXCreateContext(rwin->displayId,
+				      v, NULL, GL_FALSE);
+    if (!rwin->contextId) {
+	G_fatal_error (_("Unable to create GLX rendering context"));
+    }
+
+    /* create win pixmap to render to (same depth as RootWindow) */
+    rwin->pixmap = XCreatePixmap(rwin->displayId,
+				RootWindow(rwin->displayId, v->screen),
+				width,
+				height,
+				v->depth);
+
+    /* create an off-screen GLX rendering area */
+    rwin->windowId = glXCreateGLXPixmap(rwin->displayId,
+					v, rwin->pixmap);
+
+    if (v) {
+	XFree(v);
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Make window current for rendering
+
+  \param win pointer to render_window struct
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz_make_current_render_window(const struct render_window *rwin)
+{
+    if (!rwin->displayId || !rwin->contextId)
+	return 0;
+
+    if (rwin->contextId == glXGetCurrentContext())
+	return 1;
+
+    glXMakeCurrent(rwin->displayId, rwin->windowId,
+		   rwin->contextId);
+
+    /* TODO: AQUA */
+
+    return 1;
+}

Copied: grass/trunk/lib/nviz/render.h (from rev 31934, grass-addons/visualization/nviz2/lib/render.h)
===================================================================
--- grass/trunk/lib/nviz/render.h	                        (rev 0)
+++ grass/trunk/lib/nviz/render.h	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,44 @@
+#ifndef __RENDER_H__
+#define __RENDER_H__
+
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+
+/*** Windows headers ***/
+#if defined(OPENGL_WINDOWS)
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+#  undef WIN32_LEAN_AND_MEAN
+#  include <winnt.h>
+
+/*** X Window System headers ***/
+#elif defined(OPENGL_X11)
+#  include <X11/Xlib.h>
+#  include <X11/Xutil.h>
+#  include <X11/Xatom.h>        /* for XA_RGB_DEFAULT_MAP atom */
+#  if defined(__vms)
+#    include <X11/StdCmap.h>    /* for XmuLookupStandardColormap */
+#  else
+#    include <X11/Xmu/StdCmap.h>        /* for XmuLookupStandardColormap */
+#  endif
+#  include <GL/glx.h>
+
+/*** Mac headers ***/
+#elif defined(OPENGL_AQUA)
+#  define Cursor QDCursor
+#  include <AGL/agl.h>
+#  undef Cursor
+#  include <ApplicationServices/ApplicationServices.h>
+
+#else /* make sure only one platform defined */
+#  error Unsupported platform, or confused platform defines...
+#endif
+
+typedef struct {
+    Display *displayId; /* display connection */
+    GLXContext contextId; /* GLX rendering context */
+    Pixmap pixmap;
+    GLXPixmap windowId;
+} render_window;
+
+#endif /* __RENDER_H__ */

Modified: grass/trunk/visualization/Makefile
===================================================================
--- grass/trunk/visualization/Makefile	2008-07-01 14:56:27 UTC (rev 31934)
+++ grass/trunk/visualization/Makefile	2008-07-01 20:02:21 UTC (rev 31935)
@@ -11,6 +11,11 @@
 endif
 endif
 
+#compile if OpenGL present
+ifneq ($(strip $(OPENGLLIB)),)
+    SUBDIRS += nviz2
+endif
+
 #compile if Motif present:
 ifneq ($(strip $(XMLIB)),)
     SUBDIRS += xganim

Copied: grass/trunk/visualization/nviz2/cmd/Makefile (from rev 31934, grass-addons/visualization/nviz2/cmd/Makefile)
===================================================================
--- grass/trunk/visualization/nviz2/cmd/Makefile	                        (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/Makefile	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,38 @@
+#MODULE_TOPDIR = ../../..
+MODULE_TOPDIR = $(HOME)/src/grass6_devel
+
+PGM = nviz_cmd
+
+ifeq ($(OPENGL_X11),1)
+OGL_LIBS := $(OPENGLULIB) $(OPENGLLIB) $(XLIBPATH) $(XLIB) -lXmu -lXext $(XEXTRALIBS) $(MATHLIB)
+endif
+ifeq ($(OPENGL_WINDOWS),1)
+OGL_LIBS := $(OPENGLULIB) $(OPENGLLIB) -lgdi32 $(MATHLIB)
+endif
+ifeq ($(OPENGL_AQUA),1)
+OGL_LIBS := $(OPENGLULIB) $(OPENGLLIB) $(MATHLIB)
+endif
+
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(INC) \
+	$(TIFFINCPATH) $(DSPINC) \
+	$(VECT_CFLAGS) $(OPENGLINC) 
+
+ifeq ($(OPENGL_X11),1)
+EXTRA_CFLAGS += $(XCFLAGS)
+endif
+
+XTRA_LDFLAGS = $(OGL_LIBS)
+
+EXTRA_CFLAGS=$(XCFLAGS) $(XMINC)
+
+# TODO
+NVIZLIB= -lgrass_nviz $(GISLIB)
+NVIZDEP=$(ARCH_LIBDIR)/$(LIB_PREFIX)grass_nviz$(LIB_SUFFIX)
+
+LIBES = $(GISLIB) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB) $(NVIZLIB)
+DEPENDENCIES = $(GISDEP) $(NVIZDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd

Copied: grass/trunk/visualization/nviz2/cmd/args.c (from rev 31934, grass-addons/visualization/nviz2/cmd/args.c)
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c	                        (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/args.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,211 @@
+/*!
+  \file args.c
+ 
+  \brief Parse command
+  
+  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.
+
+  \author Martin Landa <landa.martin gmail.com>
+
+  \date 2008
+*/
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+/*!
+   \brief Parse command
+
+   \param argc number of arguments
+   \param argv arguments array
+   \param params GRASS parameters
+
+   \return 1
+*/
+void parse_command(int argc, char* argv[], struct GParams *params)
+{
+    /* surface */
+    params->elev_map = G_define_standard_option(G_OPT_R_ELEV);
+    params->elev_map->required = NO;
+    params->elev_map->multiple = YES;
+    params->elev_map->description = _("Name of raster map(s) for elevation");
+    params->elev_map->guisection = _("Surface");
+
+    params->elev_const = G_define_option();
+    params->elev_const->key = "elevation_value";
+    params->elev_const->key_desc = "value";
+    params->elev_const->type = TYPE_INTEGER;
+    params->elev_const->required = NO;
+    params->elev_const->multiple = YES;
+    params->elev_const->description = _("Elevation value(s)");
+    params->elev_const->guisection = _("Surface");
+
+    params->color_map = G_define_standard_option(G_OPT_R_MAP);
+    params->color_map->multiple = YES;
+    params->color_map->required = NO;
+    params->color_map->description = _("Name of raster map(s) for color");
+    params->color_map->guisection = _("Surface");
+    params->color_map->key = "color_map";
+
+    params->color_const = G_define_standard_option(G_OPT_C_FG);
+    params->color_const->multiple = YES;
+    params->color_const->label = _("Color value(s)");
+    params->color_const->guisection = _("Surface");
+    params->color_const->key = "color_value";
+    params->color_const->answer = NULL;
+
+    params->mask_map = G_define_standard_option(G_OPT_R_MAP);
+    params->mask_map->multiple = YES;
+    params->mask_map->required = NO;
+    params->mask_map->description = _("Name of raster map(s) for mask");
+    params->mask_map->guisection = _("Surface");
+    params->mask_map->key = "mask_map";
+
+    params->transp_map = G_define_standard_option(G_OPT_R_MAP);
+    params->transp_map->multiple = YES;
+    params->transp_map->required = NO;
+    params->transp_map->description = _("Name of raster map(s) for transparency");
+    params->transp_map->guisection = _("Surface");
+    params->transp_map->key = "transparency_map";
+
+    params->transp_const = G_define_option();
+    params->transp_const->key = "transparency_value";
+    params->transp_const->key_desc = "value";
+    params->transp_const->type = TYPE_INTEGER;
+    params->transp_const->required = NO;
+    params->transp_const->multiple = YES;
+    params->transp_const->description = _("Transparency value(s)");
+    params->transp_const->guisection = _("Surface");
+    params->transp_const->options = "0-255";
+
+    params->shine_map = G_define_standard_option(G_OPT_R_MAP);
+    params->shine_map->multiple = YES;
+    params->shine_map->required = NO;
+    params->shine_map->description = _("Name of raster map(s) for shininess");
+    params->shine_map->guisection = _("Surface");
+    params->shine_map->key = "shininess_map";
+
+    params->shine_const = G_define_option();
+    params->shine_const->key = "shininess_value";
+    params->shine_const->key_desc = "value";
+    params->shine_const->type = TYPE_INTEGER;
+    params->shine_const->required = NO;
+    params->shine_const->multiple = YES;
+    params->shine_const->description = _("Shininess value(s)");
+    params->shine_const->guisection = _("Surface");
+    params->shine_const->options = "0-255";
+
+    params->emit_map = G_define_standard_option(G_OPT_R_MAP);
+    params->emit_map->multiple = YES;
+    params->emit_map->required = NO;
+    params->emit_map->description = _("Name of raster map(s) for emission");
+    params->emit_map->guisection = _("Surface");
+    params->emit_map->key = "emission_map";
+
+    params->emit_const = G_define_option();
+    params->emit_const->key = "emission_value";
+    params->emit_const->key_desc = "value";
+    params->emit_const->type = TYPE_INTEGER;
+    params->emit_const->required = NO;
+    params->emit_const->multiple = YES;
+    params->emit_const->description = _("Emission value(s)");
+    params->emit_const->guisection = _("Surface");
+    params->emit_const->options = "0-255";
+
+    /* vector */
+    params->vector = G_define_standard_option(G_OPT_V_MAP);
+    params->vector->multiple = YES;
+    params->vector->required = NO;
+    params->vector->description = _("Name of vector overlay map(s)");
+    params->vector->guisection = _("Vector");
+    params->vector->key = "vector";
+
+    /* misc */
+    params->exag = G_define_option();
+    params->exag->key = "zexag";
+    params->exag->key_desc = "value";
+    params->exag->type = TYPE_DOUBLE;
+    params->exag->required = NO;
+    params->exag->multiple = NO;
+    params->exag->description = _("Vertical exaggeration");
+
+    params->bgcolor = G_define_standard_option(G_OPT_C_BG);
+
+    /* viewpoint */
+    params->pos = G_define_option();
+    params->pos->key = "position";
+    params->pos->key_desc = "x,y";
+    params->pos->type = TYPE_DOUBLE;
+    params->pos->required = NO;
+    params->pos->multiple = NO;
+    params->pos->description = _("Viewpoint position (x,y model coordinates)");
+    params->pos->guisection = _("Viewpoint");
+    params->pos->answer = "0.85,0.85";
+
+    params->height = G_define_option();
+    params->height->key = "height";
+    params->height->key_desc = "value";
+    params->height->type = TYPE_INTEGER;
+    params->height->required = NO;
+    params->height->multiple = NO;
+    params->height->description = _("Viewpoint height (in map units)");
+    params->height->guisection = _("Viewpoint");
+
+    params->persp = G_define_option();
+    params->persp->key = "perspective";
+    params->persp->key_desc = "value";
+    params->persp->type = TYPE_INTEGER;
+    params->persp->required = NO;
+    params->persp->multiple = NO;
+    params->persp->description = _("Viewpoint field of view (in degrees)");
+    params->persp->guisection = _("Viewpoint");
+    params->persp->answer = "40";
+    params->persp->options = "1-100";
+
+    params->twist = G_define_option();
+    params->twist->key = "twist";
+    params->twist->key_desc = "value";
+    params->twist->type = TYPE_INTEGER;
+    params->twist->required = NO;
+    params->twist->multiple = NO;
+    params->twist->description = _("Viewpoint twist angle (in degrees)");
+    params->twist->guisection = _("Viewpoint");
+    params->twist->answer = "0";
+    params->twist->options = "-180-180";
+
+    /* image */
+    params->output = G_define_standard_option(G_OPT_F_OUTPUT);
+    params->output->description = _("Name for output file (do not add extension)");
+    params->output->guisection = _("Image");
+
+    params->format = G_define_option();
+    params->format->key = "format";
+    params->format->type = TYPE_STRING;
+    params->format->options = "ppm,tif"; /* TODO: png */
+    params->format->answer = "ppm";
+    params->format->description = _("Graphics file format");
+    params->format->required = YES;
+    params->format->guisection = _("Image");
+
+    params->size = G_define_option();
+    params->size->key = "size";
+    params->size->type = TYPE_INTEGER;
+    params->size->key_desc = "width,height";
+    params->size->answer = "640,480";
+    params->size->description = _("Width and height of output image");
+    params->size->required = YES;
+    params->size->guisection = _("Image");
+
+    if (G_parser(argc, argv))
+        exit(EXIT_FAILURE);
+
+    return;
+}

Copied: grass/trunk/visualization/nviz2/cmd/description.html (from rev 31934, grass-addons/visualization/nviz2/cmd/description.html)
===================================================================
--- grass/trunk/visualization/nviz2/cmd/description.html	                        (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/description.html	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,19 @@
+<h2>DESCRIPTION</h2>
+
+Experimental CLI prototype of NVIZ.
+
+<p>
+TODO
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a HREF="nviz.html">TCL/TK-based NVIZ</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Martin Landa (Google Summer of Code 2008)
+
+<p>
+<i>Last changed: $Date$</i>

Copied: grass/trunk/visualization/nviz2/cmd/local_proto.h (from rev 31934, grass-addons/visualization/nviz2/cmd/local_proto.h)
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h	                        (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,29 @@
+#ifndef __LOCAL_PROTO_H__
+#define __LOCAL_PROTO_H__
+
+#include <grass/nviz.h>
+
+/* module flags and parameters */
+struct GParams { 
+  /* raster */
+  struct Option *elev_map, *elev_const, *color_map, *color_const,
+    *mask_map, *transp_map, *transp_const, *shine_map, *shine_const,
+    *emit_map, *emit_const,
+  /* vector */
+    *vector, 
+  /* misc */
+    *exag, *bgcolor, 
+  /* viewpoint */
+    *pos, *height, *persp, *twist, 
+  /* output */
+    *output, *format, *size; 
+};
+
+/* args.c */
+void parse_command(int, char**, struct GParams *);
+int color_from_cmd(const char *);
+
+/* write_img.c */
+int write_img(const char *, int);
+
+#endif /* __LOCAL_PROTO_H__ */

Copied: grass/trunk/visualization/nviz2/cmd/main.c (from rev 31934, grass-addons/visualization/nviz2/cmd/main.c)
===================================================================
--- grass/trunk/visualization/nviz2/cmd/main.c	                        (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/main.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,334 @@
+/****************************************************************************
+ *
+ * MODULE:       nviz_cmd
+ *               
+ * AUTHOR(S):    Martin Landa <landa.martin gmail.com>
+ *               
+ * PURPOSE:      Experimental NVIZ CLI prototype
+ *               Google SoC 2008
+ *               
+ * 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.
+ *
+ *****************************************************************************/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+#include "local_proto.h"
+
+static void swap_gl();
+static int opt_get_num_answers(const struct Option *);
+
+int main (int argc, char *argv[])
+{
+    struct GModule *module;
+    struct GParams *params;
+
+    char *mapset;
+    unsigned int i;
+    unsigned int ncolor_map, ncolor_const, nmask_map;
+    unsigned int ntransp_map, ntransp_const, nshine_map, nshine_const;
+    unsigned int nemit_map, nemit_const;
+    int *surf_list, nsurfs;
+    int id, ret;
+    float vp_height, z_exag; /* calculated viewpoint height, z-exag */
+    int width, height; /* output image size */
+    char *output_name;
+
+    nv_data data;
+    struct render_window *offscreen;
+
+    /* initialize GRASS */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("visualization, raster, vector");
+    module->description = _("Experimental NVIZ CLI prototype.");
+
+    params = (struct GParams*) G_malloc(sizeof (struct GParams));
+
+    /* define options, call G_parser() */
+    parse_command(argc, argv, params);
+
+    width = atoi(params->size->answers[0]);
+    height = atoi(params->size->answers[1]);
+    G_asprintf(&output_name, "%s.%s", params->output->answer, params->format->answer);
+
+    GS_libinit();
+    /* GVL_libinit(); TODO */
+
+    GS_set_swap_func(swap_gl);
+
+    /* define render window */
+    offscreen = Nviz_new_render_window();
+    Nviz_init_render_window(offscreen);
+    Nviz_create_render_window(offscreen, NULL, width, height); /* offscreen display */
+    Nviz_make_current_render_window(offscreen);
+
+    /* initialize nviz data */
+    Nviz_init_data(&data);
+
+    /* define default attributes for map objects */
+    Nviz_set_attr_default();
+
+    /* set background color */
+    Nviz_set_bgcolor(&data, Nviz_color_from_str(params->bgcolor->answer)); 
+
+    /* init view */
+    Nviz_init_view();
+    /* set lights */
+    /* TODO: add options */
+    Nviz_set_light_position(&data, 0,
+			    0.68, -0.68, 0.80, 0.0);
+    Nviz_set_light_bright(&data, 0,
+			  0.8);
+    Nviz_set_light_color(&data, 0,
+			 1.0, 1.0, 1.0);
+    Nviz_set_light_ambient(&data, 0,
+			   0.2, 0.2, 0.2);
+    Nviz_set_light_position(&data, 1,
+			    0.0, 0.0, 1.0, 0.0);
+    Nviz_set_light_bright(&data, 1,
+			  0.5);
+    Nviz_set_light_color(&data, 1,
+			 1.0, 1.0, 1.0);
+    Nviz_set_light_ambient(&data, 1,
+			   0.3, 0.3, 0.3);
+
+    /*
+     * load raster maps (surface topography) map/constant
+     */
+    if (params->elev_map->answer) {
+	/* maps */
+	for (i = 0; params->elev_map->answers[i]; i++) {
+	    mapset = G_find_cell2 (params->elev_map->answers[i], "");
+	    if (mapset == NULL) {
+		G_fatal_error(_("Raster map <%s> not found"),
+			      params->elev_map->answers[i]);
+	    }
+	    
+	    /* topography */
+	    id = Nviz_new_map_obj(MAP_OBJ_SURF,
+				  G_fully_qualified_name(params->elev_map->answers[i], mapset), 0.0,
+				  &data);
+	}
+    }
+
+    ncolor_map = opt_get_num_answers(params->color_map);
+    ncolor_const = opt_get_num_answers(params->color_const);
+    if (params->elev_const->answer) {
+	/* constants */
+	float value;
+	surf_list = GS_get_surf_list(&nsurfs);
+	for (i = 0; params->elev_const->answers[i]; i++) {
+	    value = atof(params->elev_const->answers[i]);
+	    /* check for color */
+	    if (i + nsurfs >= ncolor_map + ncolor_const) {
+		G_fatal_error (_("Missing color settings for elevation value %f"),
+			       value);
+		/* topography */
+		id = Nviz_new_map_obj(MAP_OBJ_SURF,
+				      NULL, value,
+				      &data);
+	    }
+	}
+    }
+
+    /* set surface attributes */
+    surf_list = GS_get_surf_list(&nsurfs);
+    nmask_map = opt_get_num_answers(params->mask_map);
+    ntransp_map = opt_get_num_answers(params->transp_map);
+    ntransp_const = opt_get_num_answers(params->transp_const);
+    nshine_map = opt_get_num_answers(params->shine_map);
+    nshine_const = opt_get_num_answers(params->shine_const);
+    nemit_map = opt_get_num_answers(params->emit_map);
+    nemit_const = opt_get_num_answers(params->emit_const);
+    for (i = 0; i < (unsigned int) nsurfs; i++) {
+	id = surf_list[i];
+	/* color */
+	if (i < ncolor_map) {
+	    mapset = G_find_cell2 (params->color_map->answers[i], "");
+	    if (mapset == NULL) {
+		G_fatal_error(_("Raster map <%s> not found"),
+			      params->color_map->answers[i]);
+	    }
+	    
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+			  G_fully_qualified_name(params->color_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	else if (i < ncolor_map + ncolor_const) { /* check for color value */
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
+			  NULL, Nviz_color_from_str(params->color_const->answers[i]),
+			  &data);
+	}
+	else { /* use by default elevation map for coloring */
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+			  G_fully_qualified_name(params->elev_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	/* mask */
+	if (i < nmask_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_MASK, MAP_ATT,
+			  G_fully_qualified_name(params->mask_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+
+	/* transparency */
+	if (i < ntransp_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, MAP_ATT,
+			  G_fully_qualified_name(params->transp_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	else if (i < ntransp_map + ntransp_const) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, CONST_ATT,
+			  NULL, atof(params->transp_const->answers[i-ntransp_map]),
+			  &data);
+	}
+
+	/* shininess */
+	if (i < nshine_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, MAP_ATT,
+			  G_fully_qualified_name(params->shine_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	else if (i < nshine_map + nshine_const) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, CONST_ATT,
+			  NULL, atof(params->shine_const->answers[i-nshine_map]),
+			  &data);
+	}
+
+	/* emission */
+	if (i < nemit_map) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, MAP_ATT,
+			  G_fully_qualified_name(params->emit_map->answers[i], mapset), -1.0,
+			  &data);
+	}
+	else if (i < nemit_map + nemit_const) {
+	    Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, CONST_ATT,
+			  NULL, atof(params->emit_const->answers[i-nemit_map]),
+			  &data);
+	}
+
+        /*
+	  if (i > 1)
+	  set_default_wirecolors(data, i);
+	*/
+    }
+
+    /* load vectors */
+    if (params->vector->answer) {
+	if (!params->elev_map->answer && GS_num_surfs() == 0) { /* load base surface if no loaded */
+	    int *surf_list, nsurf;
+
+	    Nviz_new_map_obj(MAP_OBJ_SURF, NULL, 0.0, &data);
+
+	    surf_list = GS_get_surf_list(&nsurf);
+	    GS_set_att_const(surf_list[0], ATT_TRANSP, 255);
+	}
+
+	for (i = 0; params->vector->answers[i]; i++) {
+	    mapset = G_find_vector2 (params->vector->answers[i], "");
+	    if (mapset == NULL) {
+		G_fatal_error(_("Vector map <%s> not found"),
+			      params->vector->answers[i]);
+	    }
+	    Nviz_new_map_obj(MAP_OBJ_VECT,
+			     G_fully_qualified_name(params->vector->answers[i], mapset), 0.0,
+			     &data);
+	}
+    }
+
+    /* focus on loaded data */
+    Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
+
+    /* define view point */
+    if (params->exag->answer) {
+	z_exag = atof(params->exag->answer);
+    }
+    else {
+	z_exag = Nviz_get_exag();
+	G_message(_("Vertical exaggeration not given, using calculated value %f"),
+		  z_exag);
+    }
+    Nviz_change_exag(&data,
+		     z_exag);
+
+    if (params->height->answer) {
+	vp_height = atof(params->height->answer);
+    }
+    else {
+	Nviz_get_exag_height(&vp_height, NULL, NULL);
+	G_message(_("Viewpoint height not given, using calculated value %f"), vp_height);
+    }
+    Nviz_set_viewpoint_height(&data,
+			      vp_height);
+    
+    Nviz_set_viewpoint_position(&data,
+				atof(params->pos->answers[0]),
+				atof(params->pos->answers[1]));
+    Nviz_set_viewpoint_twist(&data,
+			     atoi(params->twist->answer));
+    Nviz_set_viewpoint_persp(&data,
+			     atoi(params->persp->answer));
+
+    GS_clear(data.bgcolor);
+
+    /* draw */
+    Nviz_draw_cplane(&data, -1, -1);
+    Nviz_draw_all (&data, 1); /* clear screen */
+
+    /* write to image */
+    ret = 0;
+    if (strcmp(params->format->answer, "ppm") == 0)
+	ret = write_img(output_name, FORMAT_PPM); 
+    if (strcmp(params->format->answer, "tif") == 0)
+	ret = write_img(output_name, FORMAT_TIF); 
+    
+    if (!ret)
+	G_fatal_error(_("Unsupported output format"));
+
+    G_done_msg(_("File <%s> created."), output_name);
+
+    Nviz_destroy_render_window(offscreen);
+
+    G_free ((void *) output_name);
+    G_free ((void *) params);
+
+    exit(EXIT_SUCCESS);
+}
+
+void swap_gl()
+{
+    return;
+}
+
+/*!
+  \brief Get number of answers of given option
+
+  \param pointer to option
+
+  \return number
+*/
+int opt_get_num_answers(const struct Option *opt)
+{
+    int i, num;
+    i = num = 0;
+    if (opt->answer) {
+	while (opt->answers[i]) {
+	    if (strcmp(opt->answers[i++], "")) {
+		num++; /* skip empty values */
+	    }
+	}
+    }
+
+    return i;
+}

Copied: grass/trunk/visualization/nviz2/cmd/write_img.c (from rev 31934, grass-addons/visualization/nviz2/cmd/write_img.c)
===================================================================
--- grass/trunk/visualization/nviz2/cmd/write_img.c	                        (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/write_img.c	2008-07-01 20:02:21 UTC (rev 31935)
@@ -0,0 +1,43 @@
+/*!
+  \file write_img.c
+ 
+  \brief Save current GL screen to image file.
+  
+  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/anim_support.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com>
+
+  \date 2008
+*/
+
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+
+#include "local_proto.h"
+
+/*!
+  \brief Save current GL screen to an ppm file.
+
+  \param name filename
+
+  \return 1 on success
+  \return 0 on failure (unsupported format)
+*/
+
+int write_img(const char *name, int format)
+{
+    if (format == FORMAT_PPM) 
+	GS_write_ppm(name);
+    else if (format == FORMAT_TIF)
+	GS_write_tif(name);
+    else
+	return 0;
+    
+    return 1;
+}



More information about the grass-commit mailing list