source: anuga_work/development/demos/sww_file_visualiser_example.py @ 4605

Last change on this file since 4605 was 4539, checked in by ole, 17 years ago

Moved files from examples to anuga_work

File size: 1.9 KB
Line 
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
9from anuga.visualiser import OfflineVisualiser
10from vtk import vtkCubeAxesActor2D
11
12# The argument to OfflineVisualiser is the path to a sww file
13o = 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
18o.render_quantity_height("elevation", dynamic=False)
19o.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.
26o.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
33o.render_axes()
34
35# Increase the number of labels on the axes
36o.alter_axes(vtkCubeAxesActor2D.SetNumberOfLabels, (5,))
37
38# Draw a yellow polygon at height 10
39o.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.
43o.precache_height_quantities()
44
45# Start the visualiser (in its own thread).
46o.start()
47
48# Wait for the visualiser to terminate before shutting down.
49o.join()
Note: See TracBrowser for help on using the repository browser.