source: inundation/visualiser/visualiser.py @ 3465

Last change on this file since 3465 was 3465, checked in by jack, 18 years ago

More work on the basic setup of the visualiser.

File size: 2.3 KB
Line 
1from threading import Event, Thread
2from Tkinter import Tk
3from vtk import vtkRenderer
4from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget
5
6class Visualiser(Thread):
7    """Superclass of both the realtime and offline VTK visualisers
8    """
9    def __init__(self, domain):
10        Thread.__init__(self)
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()
22
23        # Structures for Height Based quantities
24        self.height_quantities = []
25        self.height_zScales = {}
26        self.height_dynamic = {}
27
28    def run(self):
29        self.setup_gui()
30        self.tk_root.after(100, self.sync_idle.set)
31        self.tk_root.mainloop()
32
33    # --- Height Based Rendering --- #
34
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.
41        """
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
46
47    # --- Colour Coding --- #
48
49    # --- Vector Fields --- #
50
51    # --- GUI Setup --- #
52
53    def setup_gui(self):
54        self.tk_root = Tk()
55        self.tk_root.title("Visualisation")
56        self.tk_root.after(100, self.redraw)
57        self.tk_root.bind("<Destroy>", self.destroyed)
58
59        self.tk_renderWidget = vtkTkRenderWidget(self.tk_root, width=400, height=400)
60        self.tk_renderWidget.grid(row=0, column=0)
61        self.vtk_renderer = vtkRenderer()
62        self.tk_renderWidget.GetRenderWindow().AddRenderer(self.vtk_renderer)
63
64    # --- GUI Events --- #
65
66    def destroyed(self, event):
67        if event.widget == self.tk_root:
68            self.shutdown()
69
70    def redraw(self):
71        pass
72
73    def shutdown(self):
74        self.running = False
75        self.sync_idle.set()
76        self.sync_unpaused.set()
77        self.tk_root.withdraw()
78        self.tk_root.quit()
Note: See TracBrowser for help on using the repository browser.