Changeset 3493
- Timestamp:
- Aug 15, 2006, 4:45:28 PM (17 years ago)
- Location:
- inundation/visualiser
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/visualiser/realtime.py
r3465 r3493 5 5 """A VTK-powered realtime visualiser which runs in its own thread. 6 6 """ 7 def __init__(self, domain): 8 Visualiser.__init__(self,domain) 7 def __init__(self, source): 8 """The source parameter is assumed to be a Domain. 9 """ 10 Visualiser.__init__(self, source) 11 12 self.running = True 13 14 # Synchronisation Constructs 15 self.sync_idle = Event() 16 self.sync_idle.clear() 17 self.sync_unpaused = Event() 18 self.sync_unpaused.set() 19 self.sync_redrawReady = Event() 20 self.sync_redrawReady.clear() 21 22 def run(self): 23 Visualiser.run(self) 24 self.tk_root.after(100, self.sync_idle.set) 9 25 10 26 def setup_gui(self): … … 20 36 self.sync_unpaused.set() 21 37 self.tk_pauseResume.config(text="Pause") 38 39 def shutdown(self): 40 Visualiser.shutdown(self) 41 self.running = False 42 self.sync_idle.set() 43 self.sync_unpaused.set() -
inundation/visualiser/visualiser.py
r3465 r3493 1 1 from threading import Event, Thread 2 from Tkinter import Tk 3 from vtk import vtk Renderer2 from Tkinter import Tk, Button, N, E, S, W 3 from vtk import vtkActor, vtkPolyDataMapper, vtkRenderer 4 4 from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget 5 5 … … 7 7 """Superclass of both the realtime and offline VTK visualisers 8 8 """ 9 def __init__(self, domain):9 def __init__(self, source): 10 10 Thread.__init__(self) 11 11 12 self.domain = domain 13 self.running = True 14 15 # Synchronisation Constructs 16 self.sync_idle = Event() 17 self.sync_idle.clear() 18 self.sync_unpaused = Event() 19 self.sync_unpaused.set() 20 self.sync_redrawReady = Event() 21 self.sync_redrawReady.clear() 12 self.source = source 22 13 23 14 # Structures for Height Based quantities … … 25 16 self.height_zScales = {} 26 17 self.height_dynamic = {} 18 self.height_offset = {} 19 20 # Structures used for VTK 21 self.vtk_actors = {} 22 self.vtk_mappers = {} 23 self.vtk_polyData = {} 27 24 28 25 def run(self): 29 26 self.setup_gui() 30 self.tk_root.after(100, self.sync_idle.set) 27 self.setup_grid() 28 # Draw Height Quantities 29 for q in self.height_quantities: 30 self.update_height_quantity(q, self.height_dynamic[q]) 31 self.draw_height_quantity(q) 31 32 self.tk_root.mainloop() 33 34 def redraw_quantities(self, dynamic_only=False): 35 """Redraw all dynamic quantities, unless dynamic_only is True. 36 """ 37 # Height quantities 38 for q in self.height_quantities: 39 if (dynamic_only is False) or (self.height_dynamic[q]): 40 self.update_height_quantity(q, self.height_dynamic[q]) 41 self.draw_height_quantity(q) 32 42 33 43 # --- Height Based Rendering --- # 34 44 35 def render_quantity_height(self, quantityName, zScale=1.0, dynamic=True): 36 """Instruct the visualiser to render a quantity 37 using the value at a point as its height. 38 The value at each point is multiplied by z_scale, 39 and if dynamic=False, the quantity is not recalculated 40 on each update. 45 def setup_grid(self): 46 """Create the vtkCellArray instance that represents the 47 triangles. Subclasses are expected to override this function 48 to read from their source as appropriate. 41 49 """ 42 if quantityName in self.domain.quantities: 43 self.height_quantities.append(quantityName) 44 self.height_zScales[quantityName] = zScale 45 self.height_dynamic[quantityName] = dynamic 50 pass 51 52 def render_quantity_height(self, quantityName, zScale=1.0, offset=0.0, dynamic=True): 53 """Instruct the visualiser to render a quantity using the 54 value at a point as its height. The value at each point is 55 multiplied by z_scale and is added to offset, and if 56 dynamic=False, the quantity is not recalculated on each 57 update. 58 """ 59 self.height_quantities.append(quantityName) 60 self.height_zScales[quantityName] = zScale 61 self.height_offset[quantityName] = offset 62 self.height_dynamic[quantityName] = dynamic 63 64 def update_height_quantity(self, quantityName, dynamic=True): 65 """Create a vtkPolyData object and store it in 66 self.vtk_polyData[q]. Subclasses are expected to override this 67 function. 68 """ 69 pass 70 71 72 def draw_height_quantity(self, quantityName): 73 """Use the vtkPolyData and prepare/update the rest of the VTK 74 rendering pipeline. 75 """ 76 if self.vtk_mappers.has_key(quantityName): 77 mapper = self.vtk_mappers[quantityName] 78 else: 79 mapper = self.vtk_mappers[quantityName] = vtkPolyDataMapper() 80 mapper.SetInput(self.vtk_polyData[quantityName]) 81 mapper.Update() 82 83 if not self.vtk_actors.has_key(quantityName): 84 actor = self.vtk_actors[quantityName] = vtkActor() 85 actor.SetMapper(mapper) 86 actor.GetProperty().SetColor(0.5, 0.5, 0.5) 87 self.vtk_renderer.AddActor(actor) 46 88 47 89 # --- Colour Coding --- # … … 58 100 59 101 self.tk_renderWidget = vtkTkRenderWidget(self.tk_root, width=400, height=400) 60 self.tk_renderWidget.grid(row=0, column=0) 102 self.tk_renderWidget.grid(row=0, column=0, sticky=N+S+E+W) 103 self.tk_quit = Button(self.tk_root, text="Quit", command=self.shutdown) 104 self.tk_quit.grid(row=2, column=0, sticky=E+W) 61 105 self.vtk_renderer = vtkRenderer() 62 106 self.tk_renderWidget.GetRenderWindow().AddRenderer(self.vtk_renderer) … … 69 113 70 114 def redraw(self): 71 pass 115 self.tk_renderWidget.GetRenderWindow().Render() 116 self.tk_root.update_idletasks() 117 self.tk_root.after(100, self.redraw) 72 118 73 119 def shutdown(self): 74 self.running = False75 self.sync_idle.set()76 self.sync_unpaused.set()77 120 self.tk_root.withdraw() 78 121 self.tk_root.quit()
Note: See TracChangeset
for help on using the changeset viewer.