[GRASS-SVN] r31880 - in grass-addons/visualization/nviz2: cmd lib wxpython wxpython/nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 29 05:58:40 EDT 2008


Author: martinl
Date: 2008-06-29 05:58:39 -0400 (Sun, 29 Jun 2008)
New Revision: 31880

Modified:
   grass-addons/visualization/nviz2/cmd/args.c
   grass-addons/visualization/nviz2/cmd/main.c
   grass-addons/visualization/nviz2/lib/exag.c
   grass-addons/visualization/nviz2/lib/nviz.h
   grass-addons/visualization/nviz2/wxpython/nviz.py
   grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
   grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp
   grass-addons/visualization/nviz2/wxpython/preferences.py
Log:
nvzi2: calculate z-exag value after loading data
wxGUI: surface attribute fixes


Modified: grass-addons/visualization/nviz2/cmd/args.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/args.c	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/cmd/args.c	2008-06-29 09:58:39 UTC (rev 31880)
@@ -69,8 +69,6 @@
     params->exag->required = NO;
     params->exag->multiple = NO;
     params->exag->description = _("Vertical exaggeration");
-    params->exag->answer = "1.0";
-    params->exag->options = "0-10";
 
     params->bgcolor = G_define_standard_option(G_OPT_C_BG);
 

Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/cmd/main.c	2008-06-29 09:58:39 UTC (rev 31880)
@@ -35,7 +35,7 @@
     unsigned int i;
     int id, ret;
     unsigned int nelev, ncolor_map, ncolor_const, nvect;
-    float vp_height; /* calculated viewpoint height */
+    float vp_height, z_exag; /* calculated viewpoint height, z-exag */
     int width, height; /* output image size */
     char *output_name;
 
@@ -181,16 +181,26 @@
     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, 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_change_exag(&data,
-		     atof(params->exag->answer));
+    
     Nviz_set_viewpoint_position(&data,
 				atof(params->pos->answers[0]),
 				atof(params->pos->answers[1]));
@@ -215,6 +225,8 @@
     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);

Modified: grass-addons/visualization/nviz2/lib/exag.c
===================================================================
--- grass-addons/visualization/nviz2/lib/exag.c	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/lib/exag.c	2008-06-29 09:58:39 UTC (rev 31880)
@@ -19,11 +19,10 @@
 #include <grass/nviz.h>
 
 /*!
-  \brief Get viewpoint height
+  \brief Get view height
 
   Call after initial data has been loaded
 
-  \param data nviz data
   \param[out] val height value
   \param[out] min min value (or NULL)
   \param[out] max max value (or NULL)
@@ -67,3 +66,34 @@
 
     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;
+}

Modified: grass-addons/visualization/nviz2/lib/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.h	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/lib/nviz.h	2008-06-29 09:58:39 UTC (rev 31880)
@@ -134,6 +134,7 @@
 
 /* exag.c */
 int Nviz_get_exag_height(float *, float *, float *);
+float Nviz_get_exag();
 
 /* lights.c */
 int Nviz_set_light_position(nv_data *, int,

Modified: grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp	2008-06-29 09:58:39 UTC (rev 31880)
@@ -42,24 +42,30 @@
 /*!
   \brief Set default view (based on loaded data)
 
-  \return height value
+  \return height, z-exag value
 */
-float Nviz::SetViewDefault()
+std::vector<double> Nviz::SetViewDefault()
 {
-    float vp_height;
+    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);
 
-    Nviz_change_exag(data,
-		     VIEW_DEFAULT_ZEXAG);
-
     SetView(VIEW_DEFAULT_POS_X, VIEW_DEFAULT_POS_Y,
 	    vp_height, VIEW_DEFAULT_PERSP, VIEW_DEFAULT_TWIST);
 
     G_debug(1, "Nviz::SetViewDefault()");
 
-    return vp_height;
+    return ret;
 }
 
 /*!

Modified: grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-29 09:58:39 UTC (rev 31880)
@@ -28,7 +28,6 @@
 #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
 
 class Nviz
 {
@@ -36,6 +35,9 @@
     nv_data *data;
     wxGLCanvas *glCanvas;
 
+    /* surface.cpp */
+    int SetSurfaceAttr(int, int, bool, const char *);
+
 public:
     /* constructor */
     Nviz();
@@ -45,7 +47,7 @@
 
     /* change_view.cpp */
     int ResizeWindow(int, int);
-    float SetViewDefault();
+    std::vector<double> SetViewDefault();
     int SetView(float, float,
 		float, float, float);
     int SetZExag(float);
@@ -66,7 +68,9 @@
     void EraseMap();
 
     /* surface.cpp */
-    void SetSurfaceColor(int, bool, const char *);
+    int SetSurfaceTopo(int, bool, const char *);
+    int SetSurfaceColor(int, bool, const char *);
+    int SetSurfaceShine(int, bool, const char *);
 };
 
 #endif /* __NVIZ_H__ */

Modified: grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/wxpython/nviz/surface.cpp	2008-06-29 09:58:39 UTC (rev 31880)
@@ -18,23 +18,86 @@
 
 #include "nviz.h"
 
-void Nviz::SetSurfaceColor(int id, bool map, const char *value)
+/*!
+  \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 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 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) {
-	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
-		      value, -1.0,
-		      data);
+	ret = Nviz_set_attr(id, MAP_OBJ_SURF, attr, MAP_ATT,
+			    value, -1.0,
+			    data);
     }
     else {
 	float val;
-	val = Nviz_color_from_str(value);
-	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
-		      NULL, val,
-		      data);
+	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::SetSurfaceColor(): id=%d, map=%d, value=%s",
-	    id, map, value);
+    G_debug(1, "Nviz::SetSurfaceAttr(): id=%d, attr=%d, map=%d, value=%s",
+	    id, attr, map, value);
 
-    return;
+    return ret;
 }

Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-29 09:58:39 UTC (rev 31880)
@@ -139,8 +139,11 @@
         if not self.init:
             self.nvizClass.InitView()
             self.LoadDataLayers()
-            self.view['height']['value'] = self.nvizClass.SetViewDefault()
+            (self.view['z-exag']['value'],
+             self.view['height']['value']) = self.nvizClass.SetViewDefault()
+            
             if hasattr(self.parent, "nvizToolWin"):
+                self.parent.nvizToolWin.UpdatePage('view')
                 self.parent.nvizToolWin.UpdateSettings()
             self.init = True
         self.UpdateMap()
@@ -556,22 +559,32 @@
                           pos=(row, 2))
 
             if code == 'color':
-                value = csel.ColourSelect(panel, id=wx.ID_ANY)
+                value = csel.ColourSelect(panel, id=wx.ID_ANY,
+                                          colour=UserSettings.Get(group='nviz', key='surface',
+                                                                 subkey=['color', 'value']))
                 value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
+            elif code == 'mask':
+                value = None
             else:
                 value = wx.SpinCtrl(parent=panel, id=wx.ID_ANY, size=(65, -1),
-                                    initial=0,
-                                    min=0,
-                                    max=100)
+                                    initial=0)
+                if code == 'topo':
+                    value.SetRange(minVal=-1e9, maxVal=1e9)
+                elif code in ('shine', 'transp', 'emis'):
+                    value.SetRange(minVal=0, maxVal=255)
+                else:
+                    value.SetRange(minVal=0, maxVal=100)
                 value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
-            self.win['surface'][code]['constant'] = value.GetId()
-            value.Enable(False)
+            
+            if value:
+                self.win['surface'][code]['constant'] = value.GetId()
+                value.Enable(False)
+                gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
+                              pos=(row, 3))
+                self.SetSurfaceUseMap(code) # -> enable map / disable constant
+            else:
+                use.Delete(1) # delete 'constant' from list
 
-            gridSizer.Add(item=value, flag=wx.ALIGN_CENTER_VERTICAL,
-                          pos=(row, 3))
-
-            self.SetSurfaceUseMap(code) # -> enable map / disable constant
-
             row += 1
 
         boxSizer.Add(item=gridSizer, proportion=1,
@@ -861,10 +874,17 @@
         layer = self.mapWindow.GetSelectedLayer()
         id = self.mapWindow.GetMapObjId(layer)
 
-        if self.mapWindow.update.has_key('color'):
-            map, value = self.mapWindow.update['color']
-            self.mapWindow.nvizClass.SetSurfaceColor(id, map, str(value)) 
-            del self.mapWindow.update['color']
+        for attr in ('topo', 'color', 'mask',
+                     'transp', 'shine', 'emis'):
+            if self.mapWindow.update.has_key(attr):
+                map, value = self.mapWindow.update[attr]
+                if attr == 'topo':
+                    self.mapWindow.nvizClass.SetSurfaceTopo(id, map, str(value)) 
+                elif attr == 'color':
+                    self.mapWindow.nvizClass.SetSurfaceColor(id, map, str(value)) 
+                elif attr == 'shine':
+                    self.mapWindow.nvizClass.SetSurfaceShine(id, map, str(value)) 
+                del self.mapWindow.update[attr]
 
         self.mapWindow.Refresh(False)
 
@@ -877,6 +897,9 @@
 
     def OnSurfaceUse(self, event):
         """Surface attribute -- use -- map/constant"""
+        if not self.mapWindow.init:
+            return
+
         # find attribute row
         attrName = self.__GetWindowName(self.win['surface'], event.GetId())
         if not attrName:
@@ -884,14 +907,20 @@
 
         if event.GetSelection() == 0:
             useMap = True
-            value = self.win['surface'][attrName]['map']
+            value = self.FindWindowById(self.win['surface'][attrName]['map']).GetValue()
         else:
             useMap = False
-            value = self.win['surface'][attrName]['constant']
+            if attrName == 'color':
+                value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetColour()
+                value = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
+            else:
+                value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetValue()
 
         self.SetSurfaceUseMap(attrName, useMap)
 
         self.mapWindow.update[attrName] = (useMap, str(value))
+        if self.parent.autoRender.IsChecked():
+            self.OnApply(None)
 
     def SetSurfaceUseMap(self, attrName, map=True):
         if map: # map
@@ -916,8 +945,11 @@
             value = self.FindWindowById(self.win['surface'][attrName]['map']).GetValue()
             map = True
         else:
-            value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetValue()
-            value = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
+            if attrName == 'color':
+                value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetColour()
+                value = str(value[0]) + ':' + str(value[1]) + ':' + str(value[2])
+            else:
+                value = self.FindWindowById(self.win['surface'][attrName]['constant']).GetValue()
             map = False
 
         self.mapWindow.update[attrName] = (map, str(value))
@@ -939,7 +971,12 @@
         layer = self.mapWindow.GetSelectedLayer()
         nvizLayer = self.mapWindow.GetSelectedLayer(nviz=True)
 
-        if pageId == 'surface':
+        if pageId == 'view':
+            max = self.settings['z-exag']['value'] * 10
+            for control in ('spin', 'slider'):
+                self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(0,
+                                                                                  max)
+        elif pageId == 'surface':
             if nvizLayer is None:
                 for attr in ('topo', 'color'):
                     self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)

Modified: grass-addons/visualization/nviz2/wxpython/preferences.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/preferences.py	2008-06-29 09:29:44 UTC (rev 31879)
+++ grass-addons/visualization/nviz2/wxpython/preferences.py	2008-06-29 09:58:39 UTC (rev 31880)
@@ -230,6 +230,9 @@
                     'shininess': { 'map' : False,
                                    'value' : 60.0,
                                    },
+                    'color' : { 'map' : True,
+                                'value' : (0, 0, 0, 255), # constant: black
+                                },
                     'draw' : {
                         'color' : (136, 136, 136, 255),
                         'mode' : 1, # fine



More information about the grass-commit mailing list