Changeset 3538
- Timestamp:
- Aug 29, 2006, 4:00:34 PM (18 years ago)
- Location:
- anuga_core/source/anuga/visualiser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/visualiser/offline.py
r3537 r3538 7 7 class OfflineVisualiser(Visualiser): 8 8 """A VTK-powered offline visualiser which runs in its own thread. 9 In addition to the functions provided by the standard visualiser, 10 the following additional functions are provided: 11 12 precache_height_quantities() - Precache all the vtkpoints 13 structures for any dynamic height based quantities to render. 9 14 """ 10 15 def __init__(self, source): … … 56 61 y = ravel(array(fin.variables['y'], Float)) 57 62 if dynamic is True: 58 q = array(fin.variables[quantityName][ self.frameNumber], Float)63 q = array(fin.variables[quantityName][frameNumber], Float) 59 64 else: 60 65 q = ravel(array(fin.variables[quantityName], Float)) … … 67 72 fin.close() 68 73 return points 74 75 def precache_height_quantities(self): 76 """Precache any height-based quantities. Call before rendering 77 beigns.""" 78 for q in self.height_quantities: 79 if self.height_dynamic[q] is True: 80 print 'Precaching %s' % q 81 for i in range(self.maxFrameNumber + 1): # maxFrameNumber is zero-indexed 82 print ' - Frame %d of %d' % (i, self.maxFrameNumber) 83 self.vtk_heightQuantityCache[i][q]\ 84 = self.read_height_quantity(q, True, i) 85 86 def build_quantity_dict(self): 87 quantities = {} 88 fin = NetCDFFile(self.source, 'r') 89 for q in filter(lambda n:n != 'x' and n != 'y' and n != 'z' and n != 'time' and n != 'volumes', fin.variables.keys()): 90 if len(fin.variables[q].shape) == 1: # Not a time-varying quantity 91 quantities[q] = ravel(array(fin.variables[q], Float)) 92 else: # Time-varying, get the current timestep data 93 quantities[q] = array(fin.variables[q][self.frameNumber], Float) 94 fin.close() 95 return quantities 69 96 70 97 def setup_gui(self): -
anuga_core/source/anuga/visualiser/run_offline.py
r3520 r3538 2 2 3 3 o = OfflineVisualiser("../../../../swollen_viewer/tests/cylinders.sww") 4 #o = OfflineVisualiser("../../../../swollen_viewer/tests/karratha_100m.sww") 4 5 o.render_quantity_height("elevation", dynamic=False) 5 6 o.render_quantity_height("stage", dynamic=True) 7 #o.colour_height_quantity('stage', (0.0, 0.0, 0.8)) 8 o.colour_height_quantity('stage', (lambda q:q['stage'], 0, 10)) 9 #o.precache_height_quantities() 6 10 o.run() -
anuga_core/source/anuga/visualiser/visualiser.py
r3493 r3538 1 1 from threading import Event, Thread 2 2 from Tkinter import Tk, Button, N, E, S, W 3 from vtk import vtkActor, vtkPolyDataMapper, vtkRenderer 3 from types import FunctionType, TupleType 4 from vtk import vtkActor, vtkFloatArray, vtkPolyDataMapper, vtkRenderer 4 5 from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget 5 6 … … 17 18 self.height_dynamic = {} 18 19 self.height_offset = {} 20 21 # Structures for colouring quantities 22 self.colours_height = {} 19 23 20 24 # Structures used for VTK … … 84 88 actor = self.vtk_actors[quantityName] = vtkActor() 85 89 actor.SetMapper(mapper) 90 self.vtk_renderer.AddActor(actor) 91 92 if self.colours_height.has_key(quantityName): 93 colour = self.colours_height[quantityName] 94 if type(colour) == TupleType: 95 if type(colour[0]) == FunctionType: 96 # It's a function, so take colour[1] as the 97 # lower bound on the scalar range and 98 # colour[2] as the upper bound on the scalar 99 # range. 100 scalars = vtkFloatArray() 101 map(scalars.InsertNextValue, colour[0](self.build_quantity_dict())) 102 self.vtk_polyData[quantityName].GetPointData().SetScalars(scalars) 103 mapper.SetScalarRange(colour[1:]) 104 mapper.Update() 105 else: 106 # It's a 3-tuple representing an RGB value. 107 actor.GetProperty().SetColor(colour) 108 else: 109 actor.GetProperty().SetColor(0.5, 0.5, 0.5) 110 else: 86 111 actor.GetProperty().SetColor(0.5, 0.5, 0.5) 87 self.vtk_renderer.AddActor(actor)88 112 89 113 # --- Colour Coding --- # 90 114 115 def build_quantity_dict(self): 116 """Build a dictionary mapping quantity name->list of vertex 117 values for that quantity. Subclasses are expected to override 118 this function.""" 119 pass 120 121 def colour_height_quantity(self, quantityName, colour=(0.5, 0.5, 0.5)): 122 """Add colouring to a height based quantity. 123 124 The colour parameter can be one of the following: 125 - a 3-tuple of values in [0,1] to specify R, G, B values 126 - a 3-tuple of values: 127 - a function that takes a dictionary mapping quantity name->Numeric array of vertex values. 128 This function returns a list of vertex values to be used in the colour coding. 129 - a float for the lower bound on the colouring 130 - a float for the upper bound on the colouring 131 """ 132 self.colours_height[quantityName] = colour 133 91 134 # --- Vector Fields --- # 92 135
Note: See TracChangeset
for help on using the changeset viewer.