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

Last change on this file since 6842 was 4539, checked in by ole, 18 years ago

Moved files from examples to anuga_work

File size: 1.9 KB
RevLine 
[3873]1#!/usr/bin/env python
[3623]2##########
3# Demonstration of the VTK sww Visualiser
4# Jack Kelly
5# September 2006
6##########
[3493]7
[3623]8# Import the offline visualiser
9from anuga.visualiser import OfflineVisualiser
[3873]10from vtk import vtkCubeAxesActor2D
[3623]11
12# The argument to OfflineVisualiser is the path to a sww file
[3958]13o = OfflineVisualiser("../../anuga_viewer/tests/cylinders.sww")
[3678]14#o = OfflineVisualiser("../../../../anuga_validation/analytical solutions/circular_second_order.sww")
[3623]15
16# Specify the height-based-quantities to render.
17# Remember to set dynamic=True for time-varying quantities
[3493]18o.render_quantity_height("elevation", dynamic=False)
19o.render_quantity_height("stage", dynamic=True)
[3623]20
21# Colour the stage:
22# Either with an RGB value as a 3-tuple of Floats,
[3538]23#o.colour_height_quantity('stage', (0.0, 0.0, 0.8))
[3623]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.
[3538]26o.colour_height_quantity('stage', (lambda q:q['stage'], 0, 10))
[3623]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
[3670]32# Draw some axes on the visualiser so we can see how big the wave is
33o.render_axes()
34
[3873]35# Increase the number of labels on the axes
36o.alter_axes(vtkCubeAxesActor2D.SetNumberOfLabels, (5,))
37
38# Draw a yellow polygon at height 10
[3813]39o.overlay_polygon([(20, 50), (40, 40), (50, 10), (30, 20), (10, 30)], 10, colour=(1.0, 1.0, 0.0))
40
[3623]41# Precaching the height-based quantities reduces the time taken to draw each
42# frame, but increases the time taken when the visualiser starts.
[3547]43o.precache_height_quantities()
[3623]44
45# Start the visualiser (in its own thread).
[3873]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.