1 | #!/usr/bin/env python |
---|
2 | ########## |
---|
3 | # Demonstration of the VTK sww Visualiser |
---|
4 | # Jack Kelly |
---|
5 | # September 2006 |
---|
6 | ########## |
---|
7 | |
---|
8 | # Import the offline visualiser |
---|
9 | from anuga.visualiser import OfflineVisualiser |
---|
10 | from vtk import vtkCubeAxesActor2D |
---|
11 | |
---|
12 | # The argument to OfflineVisualiser is the path to a sww file |
---|
13 | o = OfflineVisualiser("../../anuga_viewer/tests/cylinders.sww") |
---|
14 | #o = OfflineVisualiser("../../../../anuga_validation/analytical solutions/circular_second_order.sww") |
---|
15 | |
---|
16 | # Specify the height-based-quantities to render. |
---|
17 | # Remember to set dynamic=True for time-varying quantities |
---|
18 | o.render_quantity_height("elevation", dynamic=False) |
---|
19 | o.render_quantity_height("stage", dynamic=True) |
---|
20 | |
---|
21 | # Colour the stage: |
---|
22 | # Either with an RGB value as a 3-tuple of Floats, |
---|
23 | #o.colour_height_quantity('stage', (0.0, 0.0, 0.8)) |
---|
24 | # Or with a function of the quantities at that point, such as the stage height: |
---|
25 | # 0 and 10 are the minimum and maximum values of the stage. |
---|
26 | o.colour_height_quantity('stage', (lambda q:q['stage'], 0, 10)) |
---|
27 | # Or with the magnitude of the momentum at that point: |
---|
28 | # Needs the sqrt function from Numeric. Again, 0 and 10 define the colour range. |
---|
29 | #o.colour_height_quantity('stage', (lambda q:sqrt((q['xmomentum'] ** 2) + |
---|
30 | # (q['ymomentum'] ** 2)), 0, 10)) |
---|
31 | |
---|
32 | # Draw some axes on the visualiser so we can see how big the wave is |
---|
33 | o.render_axes() |
---|
34 | |
---|
35 | # Increase the number of labels on the axes |
---|
36 | o.alter_axes(vtkCubeAxesActor2D.SetNumberOfLabels, (5,)) |
---|
37 | |
---|
38 | # Draw a yellow polygon at height 10 |
---|
39 | o.overlay_polygon([(20, 50), (40, 40), (50, 10), (30, 20), (10, 30)], 10, colour=(1.0, 1.0, 0.0)) |
---|
40 | |
---|
41 | # Precaching the height-based quantities reduces the time taken to draw each |
---|
42 | # frame, but increases the time taken when the visualiser starts. |
---|
43 | o.precache_height_quantities() |
---|
44 | |
---|
45 | # Start the visualiser (in its own thread). |
---|
46 | o.start() |
---|
47 | |
---|
48 | # Wait for the visualiser to terminate before shutting down. |
---|
49 | o.join() |
---|