Переглянути джерело

wxNviz: volume slices implemented

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47102 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 13 роки тому
батько
коміт
d31a133c20

+ 35 - 7
gui/wxpython/gui_modules/nviz_mapdisp.py

@@ -1172,14 +1172,25 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
     def UpdateVolumeProperties(self, id, data, isosurfId = None):
         """!Update volume (isosurface/slice) map object properties"""
         if 'update' in data['draw']['resolution']:
-            self._display.SetIsosurfaceRes(id, data['draw']['resolution']['value'])
+            if data['draw']['mode']['value'] == 0:
+                self._display.SetIsosurfaceRes(id, data['draw']['resolution']['isosurface']['value'])
+            else:
+                self._display.SetSliceRes(id, data['draw']['resolution']['slice']['value'])                
             data['draw']['resolution'].pop('update')
         
         if 'update' in data['draw']['shading']:
-            if data['draw']['shading']['value'] < 0: # need to calculate
-                data['draw']['shading']['value'] = \
-                    self.nvizDefault.GetDrawMode(shade = data['draw']['shading'],
-                                                 string = False)
+            if data['draw']['mode']['value'] == 0:
+                if data['draw']['shading']['isosurface']['value'] < 0: # need to calculate
+                    mode = data['draw']['shading']['isosurface']['value'] = \
+                        self.nvizDefault.GetDrawMode(shade = data['draw']['shading']['isosurface'],
+                                                     string = False)
+                    self._display.SetIsosurfaceMode(id, mode)
+            else:
+                if data['draw']['shading']['slice']['value'] < 0: # need to calculate
+                    mode = data['draw']['shading']['slice']['value'] = \
+                        self.nvizDefault.GetDrawMode(shade = data['draw']['shading']['slice'],
+                                                     string = False)
+                    self._display.SetSliceMode(id, mode)
             data['draw']['shading'].pop('update')
         
         #
@@ -1222,6 +1233,23 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
                         self._display.SetIsosurfaceShine(id, isosurfId, map, str(value))  
                 isosurf[attrb].pop('update')
             isosurfId +=  1
+        #
+        # slice attributes
+        #
+        sliceId = 0
+        for slice in data['slice']:
+            ret = self._display.AddSlice(id, slice_id = sliceId)
+            if 'update' in slice['position']:
+                pos = slice['position']
+                ret = self._display.SetSlicePosition(id, sliceId, pos['x1'], pos['x2'],
+                                               pos['y1'], pos['y2'], pos['z1'], pos['z2'], pos['axis'])
+                
+                slice['position'].pop('update')
+            if 'update' in slice['transp']:
+                tr = slice['transp']['value']
+                self._display.SetSliceTransp(id, sliceId, tr)
+            sliceId += 1
+                
         # position
         if 'update' in data['position']:
             x = data['position']['x']
@@ -1538,8 +1566,8 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
             for i, volume in enumerate(volumes):
                 nvizData = self.tree.GetPyData(volume)[0]['nviz']['volume']
                 cmdName += "%s," % self.tree.GetPyData(volume)[0]['maplayer'].GetName()
-                cmdShade += "%s," % nvizData['draw']['shading']['desc']
-                cmdRes += "%d," % nvizData['draw']['resolution']['value']
+                cmdShade += "%s," % nvizData['draw']['shading']['isosurface']['desc']
+                cmdRes += "%d," % nvizData['draw']['resolution']['isosurface']['value']
                 if nvizData['position']:
                     cmdPos += "%d,%d,%d," % (nvizData['position']['x'], nvizData['position']['y'],
                                             nvizData['position']['z'])

Різницю між файлами не показано, бо вона завелика
+ 654 - 260
gui/wxpython/gui_modules/nviz_tools.py


+ 9 - 0
gui/wxpython/gui_modules/preferences.py

@@ -565,6 +565,15 @@ class Settings:
                     'mask': {
                         'map' : None,
                         'value': ''
+                        },
+                    'slice_position': {
+                        'x1' : 0,
+                        'x2' : 1,
+                        'y1' : 0,
+                        'y2' : 1,
+                        'z1' : 0,
+                        'z2' : 1,
+                        'axis' : 0,
                         }
                     },
                 'cplane' : {

+ 22 - 7
gui/wxpython/gui_modules/workspace.py

@@ -19,6 +19,7 @@ for details.
 
 import os
 import sys
+import copy
 
 import wx
 
@@ -605,14 +606,15 @@ class Nviz:
         # draw
         #
         for control, value in UserSettings.Get(group='nviz', key='volume', subkey='draw').iteritems():
-            if control == 'mode':
-                continue
             if control == 'shading':
                 sel = UserSettings.Get(group='nviz', key='volume', subkey=['draw', 'shading'])
                 value, desc = self.GetDrawMode(shade=sel, string=False)
-
-                data['draw']['shading'] = { 'value' : value,
-                                            'desc' : desc['shading'] }
+                
+                data['draw']['shading'] = {}
+                data['draw']['shading']['isosurface'] = { 'value' : value,
+                                                          'desc' : desc['shading'] }
+                data['draw']['shading']['slice'] = { 'value' : value,
+                                                     'desc' : desc['shading'] }
             elif control == 'mode':
                 sel = UserSettings.Get(group='nviz', key='volume', subkey=['draw', 'mode'])
                 if sel == 0:
@@ -622,7 +624,9 @@ class Nviz:
                 data['draw']['mode'] = { 'value' : sel,
                                          'desc' : desc, }
             else:
-                data['draw'][control] = { 'value' : value }
+                data['draw'][control] = {}
+                data['draw'][control]['isosurface'] = { 'value' : value }
+                data['draw'][control]['slice'] = { 'value' : value }
 
             if 'update' not in data['draw'][control]:
                 data['draw'][control]['update'] = None
@@ -648,7 +652,18 @@ class Nviz:
                 data[attr][key] = value
             data[attr]['update'] = None
         return data
-
+    
+    def SetSliceDefaultProp(self):
+        """!Set default slice properties"""
+        data = dict()
+        data['position'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
+                                               subkey = 'slice_position'))
+        data['position']['update'] = None
+        
+        data['transp'] = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'volume',
+                                               subkey = 'transp'))
+        return data
+    
     def SetVectorDefaultProp(self):
         """Set default vector data properties"""
         data = dict()

+ 165 - 1
gui/wxpython/gui_modules/wxnviz.py

@@ -974,6 +974,27 @@ class Nviz(object):
         
         return GVL_isosurf_set_att_const(id, nisosurfs - 1, ATT_TOPO, level)
     
+    def AddSlice(self, id, slice_id = None):
+        """!Add new slice
+        
+        @param id volume id
+        
+        @return -1 on failure
+        @return number of slices
+        """
+        if not GVL_vol_exists(id):
+            return -1
+        
+        if slice_id is not None:
+            num = GVL_slice_num_slices(id)
+            if num < 0 or slice_id != num:
+                return -1
+                
+        if GVL_slice_add(id) < 0:
+            return -1
+        
+        return GVL_slice_num_slices(id)
+    
     def DeleteIsosurface(self, id, isosurf_id):
         """!Delete isosurface
         
@@ -998,6 +1019,30 @@ class Nviz(object):
 
         return 1
     
+    def DeleteSlice(self, id, slice_id):
+        """!Delete slice
+        
+        @param id volume id
+        @param slice_id slice id
+        
+        @return 1 on success
+        @return -1 volume not found
+        @return -2 slice not found
+        @return -3 on failure
+        """
+        if not GVL_vol_exists(id):
+            return -1
+        
+        if slice_id > GVL_slice_num_slices(id):
+            return -2
+        
+        ret = GVL_slice_del(id, slice_id)
+        
+        if ret < 0:
+            return -3
+
+        return 1
+    
     def MoveIsosurface(self, id, isosurf_id, up):
         """!Move isosurface up/down in the list
         
@@ -1026,6 +1071,34 @@ class Nviz(object):
 
         return 1
 
+    def MoveSlice(self, id, slice_id, up):
+        """!Move slice up/down in the list
+        
+        @param id volume id
+        @param slice_id slice id
+        @param up if true move up otherwise down
+        
+        @return 1 on success
+        @return -1 volume not found
+        @return -2 slice not found
+        @return -3 on failure
+        """
+        if not GVL_vol_exists(id):
+            return -1
+        
+        if slice_id > GVL_slice_num_slices(id):
+            return -2
+        
+        if up:
+            ret = GVL_slice_move_up(id, slice_id)
+        else:
+            ret = GVL_slice_move_down(id, slice_id)
+        
+        if ret < 0:
+            return -3
+
+        return 1
+    
     def SetIsosurfaceTopo(self, id, isosurf_id, map, value):
         """!Set isosurface level
         
@@ -1149,7 +1222,7 @@ class Nviz(object):
             ret = GVL_isosurf_set_att_const(id, isosurf_id, attr, val)
         
         Debug.msg(3, "Nviz::SetIsosurfaceAttr(): id=%d, isosurf=%d, "
-                  "attr=%d, map=%d, value=%s",
+                  "attr=%d, map=%s, value=%s",
                   id, isosurf_id, attr, map, value)
         
         if ret < 0:
@@ -1243,6 +1316,25 @@ class Nviz(object):
         
         return 1
     
+    def SetSliceMode(self, id, mode):
+        """!Set draw mode for slices
+        
+        @param mode
+        
+        @return 1 on success
+        @return -1 volume set not found
+        @return -2 on failure
+        """
+        if not GVL_vol_exists(id):
+            return -1
+        
+        ret = GVL_slice_set_drawmode(id, mode)
+        
+        if ret < 0:
+            return -2
+        
+        return 1
+    
     def SetIsosurfaceRes(self, id, res):
         """!Set draw resolution for isosurfaces
         
@@ -1262,6 +1354,78 @@ class Nviz(object):
         
         return 1
     
+    def SetSliceRes(self, id, res):
+        """!Set draw resolution for slices
+        
+        @param res resolution value
+        
+        @return 1 on success
+        @return -1 volume set not found
+        @return -2 on failure
+        """
+        if not GVL_vol_exists(id):
+            return -1
+        
+        ret = GVL_slice_set_drawres(id, res, res, res)
+        
+        if ret < 0:
+            return -2
+        
+        return 1
+    
+    def SetSlicePosition(self, id, slice_id, x1, x2, y1, y2, z1, z2, dir):
+        """!Set slice position
+        
+        @param id volume id
+        @param slice_id slice id
+        @param x1,x2,y1,y2,z1,z2 slice coordinates
+        @param dir axis
+        
+        @return 1 on success
+        @return -1 volume not found
+        @return -2 slice not found
+        @return -3 on failure
+        """
+        if not GVL_vol_exists(id):
+            return -1
+        
+        if slice_id > GVL_slice_num_slices(id):
+            return -2
+        
+        ret = GVL_slice_set_pos(id, slice_id, x1, x2, y1, y2, z1, z2, dir)
+        
+        if ret < 0:
+            return -2
+        
+        return 1
+    
+    def SetSliceTransp(self, id, slice_id, value):
+        """!Set slice transparency
+        
+        @param id volume id
+        @param slice_id slice id
+        @param x1,x2,y1,y2,z1,z2 slice coordinates
+        @param value transparency value (0 - 255)
+        
+        @return 1 on success
+        @return -1 volume not found
+        @return -2 slice not found
+        @return -3 on failure
+        """
+        
+        if not GVL_vol_exists(id):
+            return -1
+        
+        if slice_id > GVL_slice_num_slices(id):
+            return -2
+        
+        ret = GVL_slice_set_transp(id, slice_id, value)
+        
+        if ret < 0:
+            return -2
+        
+        return 1
+    
     def SetIsosurfaceInOut(self, id, isosurf_id, inout):
         """!Set inout mode