Changeset 3538 for anuga_core/source/anuga/visualiser/visualiser.py
- Timestamp:
- Aug 29, 2006, 4:00:34 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.