Changeset 3813


Ignore:
Timestamp:
Oct 17, 2006, 3:04:13 PM (17 years ago)
Author:
jack
Message:

Added support for overlaying polygons in the vtk visualisers. See the updated example.

Location:
anuga_core/source/anuga
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/examples/sww_file_visualiser_example.py

    r3678 r3813  
    3131o.render_axes()
    3232
     33# Draw a polygon (here, a triangle) at height 10
     34o.overlay_polygon([(20, 50), (40, 40), (50, 10), (30, 20), (10, 30)], 10, colour=(1.0, 1.0, 0.0))
     35
    3336# Precaching the height-based quantities reduces the time taken to draw each
    3437# frame, but increases the time taken when the visualiser starts.
  • anuga_core/source/anuga/visualiser/visualiser.py

    r3670 r3813  
    22from Tkinter import Tk, Button, Frame, N, E, S, W
    33from types import FunctionType, TupleType
    4 from vtk import vtkActor, vtkCubeAxesActor2D, vtkFloatArray, vtkPolyDataMapper, vtkRenderer
     4from vtk import vtkActor, vtkCubeAxesActor2D, vtkDelaunay2D, vtkFloatArray, vtkPoints, vtkPolyData, vtkPolyDataMapper, vtkRenderer
    55from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget
    66
     
    162162        """
    163163        self.colours_height[quantityName] = colour
    164            
     164
     165    # --- Overlaid Polygons --- #
     166
     167    def overlay_polygon(self, coords, height=0.0, colour=(1.0, 0.0, 0.0)):
     168        """Add a polygon to the output of the visualiser.
     169
     170        coords is a list of 2-tuples representing x and y coordinates.
     171        These are triangulated by vtkDelaunay2D.
     172
     173        height is the z-value given to all points.
     174
     175        colour is the colour of the polygon, as a 3-tuple representing
     176        r, g, b values between 0 and 1."""
     177        points = vtkPoints()
     178        for coord in coords:
     179            points.InsertNextPoint(coord[0], coord[1], height)
     180        profile = vtkPolyData()
     181        profile.SetPoints(points)
     182        delny = vtkDelaunay2D()
     183        delny.SetInput(profile)
     184        mesh = vtkPolyDataMapper()
     185        mesh.SetInput(delny.GetOutput())
     186        actor = vtkActor()
     187        actor.SetMapper(mesh)
     188        actor.GetProperty().SetColor(colour)
     189        self.vtk_renderer.AddActor(actor)
     190       
    165191    # --- Vector Fields --- #
    166192
Note: See TracChangeset for help on using the changeset viewer.