An Introduction to VTK Anders Hast Visualization Expert

  • Slides: 35
Download presentation
An Introduction to VTK Anders Hast Visualization Expert

An Introduction to VTK Anders Hast Visualization Expert

Hello. World # This program demonstrates how VTK can be used to render a

Hello. World # This program demonstrates how VTK can be used to render a text # The user can also interact with the text by using the mouse # load VTK import vtk # Create a Text source and set the text = vtk. Text. Source() text. Set. Text("UPPMAX") #text. Set. Foreground. Color(0. 6, 0. 2) # Create a mapper and set the Text source as input text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) # Create an actor and set the mapper as input text. Actor = vtk. Actor() text. Actor. Set. Mapper(text. Mapper) # Create a renderer ren = vtk. Renderer() # Assign the actor to the renderer ren. Add. Actor(text. Actor) # Create a rendering window ren. Win = vtk. Render. Window() # Add the renderer to the window ren. Win. Add. Renderer(ren) # Set the name of the window (this is optional) ren. Win. Set. Window. Name("Hello World!") # Make sure that we can interact with the application iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) # Initialze and start the application iren. Initialize() iren. Start()

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) text. Actor = vtk. Actor() text. Actor. Set. Mapper(text. Mapper) ren = vtk. Renderer() ren. Add. Actor(text. Actor) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Hello World!") iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # load VTK

Hello. World import vtk # Create a Text source text = vtk. Text. Source()

Hello. World import vtk # Create a Text source text = vtk. Text. Source() and set the text. Set. Text("UPPMAX") text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) text. Actor = vtk. Actor() text. Actor. Set. Mapper(text. Mapper) ren = vtk. Renderer() ren. Add. Actor(text. Actor) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Hello World!") iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start()

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) text. Actor = vtk. Actor() text. Actor. Set. Mapper(text. Mapper) ren = vtk. Renderer() ren. Add. Actor(text. Actor) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Hello World!") iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # Create a mapper and set the Text source as input

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) # Create an actor and text. Actor = vtk. Actor() set the mapper as input text. Actor. Set. Mapper(text. Mapper) ren = vtk. Renderer() ren. Add. Actor(text. Actor) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Hello World!") iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start()

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) text. Actor = vtk. Actor() text. Actor. Set. Mapper(text. Mapper) # Create a renderer ren = vtk. Renderer() # Assign the actor to the renderer ren. Add. Actor(text. Actor) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Hello World!") iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start()

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) text. Actor = vtk. Actor() text. Actor. Set. Mapper(text. Mapper) ren = vtk. Renderer() ren. Add. Actor(text. Actor) # Create a rendering window ren. Win = vtk. Render. Window() # Add the renderer to the window ren. Win. Add. Renderer(ren) # Set the name of the window ren. Win. Set. Window. Name("Hello World!") iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start()

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper

Hello. World import vtk text = vtk. Text. Source() text. Set. Text("UPPMAX") text. Mapper = vtk. Poly. Data. Mapper() text. Mapper. Set. Input. Connection(text. Get. Output. Port()) text. Actor = vtk. Actor() text. Actor. Set. Mapper(text. Mapper) ren = vtk. Renderer() ren. Add. Actor(text. Actor) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Hello World!") # Make sure that we can iren = vtk. Render. Window. Interactor() interact with the application iren. Set. Render. Window(ren. Win) # Initialze and iren. Initialize() start the application iren. Start()

Hungarian? import vtk s. Text = vtk. Text. Source() s. Text. Set. Text("UPPMAX") Color

Hungarian? import vtk s. Text = vtk. Text. Source() s. Text. Set. Text("UPPMAX") Color the text s. Text. Set. Foreground. Color(0. 6, 1. 0, 0. 2) m. Text = vtk. Poly. Data. Mapper() m. Text. Set. Input. Connection(s. Text. Get. Output. Port()) a. Text = vtk. Actor() a. Text. Set. Mapper(m. Text) r. Main = vtk. Renderer() r. Main. Add. Actor(a. Text) w. Main = vtk. Render. Window() w. Main. Add. Renderer(r. Main) w. Main. Set. Window. Name("Hello World!") i. Main = vtk. Render. Window. Interactor() i. Main. Set. Render. Window(w. Main) i. Main. Initialize() i. Main. Start()

A Cylinder • Render and interact with a Cylinder • Set the size of

A Cylinder • Render and interact with a Cylinder • Set the size of the window • Change background color

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder.

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder. Set. Radius(3) cylinder. Mapper = vtk. Poly. Data. Mapper() cylinder. Mapper. Set. Input. Connection(cylinder. Get. Output. Port()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cylinder") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # Import VTK

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder.

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder. Set. Radius(3) cylinder. Mapper = vtk. Poly. Data. Mapper() cylinder. Mapper. Set. Input. Connection(cylinder. Get. Output. Port()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cylinder") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # Create a Cylinder

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder.

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder. Set. Radius(3) cylinder. Mapper = vtk. Poly. Data. Mapper() # Create a Mapper cylinder. Mapper. Set. Input. Connection(cylinder. Get. Output. Port()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cylinder") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start()

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder.

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder. Set. Radius(3) cylinder. Mapper = vtk. Poly. Data. Mapper() cylinder. Mapper. Set. Input. Connection(cylinder. Get. Output. Port()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cylinder") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # Create an Actor

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder.

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder. Set. Radius(3) cylinder. Mapper = vtk. Poly. Data. Mapper() cylinder. Mapper. Set. Input. Connection(cylinder. Get. Output. Port()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cylinder") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # Create a Renderer and add Cylinder # Set background Color

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder.

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder. Set. Radius(3) cylinder. Mapper = vtk. Poly. Data. Mapper() cylinder. Mapper. Set. Input. Connection(cylinder. Get. Output. Port()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cylinder") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # Create a rendering window # Add the renderer to the window # Set the name of the window

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder.

import vtk cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(12) cylinder. Set. Radius(3) cylinder. Mapper = vtk. Poly. Data. Mapper() cylinder. Mapper. Set. Input. Connection(cylinder. Get. Output. Port()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cylinder") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() # Make sure that we can interact with the application # Initialze and start the application

Playing with actors and color

Playing with actors and color

import vtk # Create a Cylinder, giving size, resolution and color cylinder = vtk.

import vtk # Create a Cylinder, giving size, resolution and color cylinder = vtk. Cylinder. Source() cylinder. Set. Resolution(8) cylinder. Set. Height(4) cylinder. Set. Radius(4) cylinder. Mapper = vtk. Poly. Data. Mapper() cylinder. Mapper. Set. Input(cylinder. Get. Output()) cylinder. Actor = vtk. Actor() cylinder. Actor. Set. Mapper(cylinder. Mapper) cylinder. Actor. Get. Property(). Set. Color(0. 0, 1. 0) #Set the color!

# Create a Cone, giving size, resolution, position and color cone = vtk. Cone.

# Create a Cone, giving size, resolution, position and color cone = vtk. Cone. Source() cone. Set. Resolution(12) cone. Set. Height(12) cone. Set. Radius(3) cone. Set. Center(5, 0, 0) cone. Mapper = vtk. Poly. Data. Mapper() cone. Mapper. Set. Input. Connection(cone. Get. Output. Port()) cone. Actor = vtk. Actor() cone. Actor. Set. Mapper(cone. Mapper) cone. Actor. Get. Property(). Set. Color(1. 0, 0. 0, 1. 0)

# Create a renderer and assign the actors to the renderer ren = vtk.

# Create a renderer and assign the actors to the renderer ren = vtk. Renderer() ren. Add. Actor(cylinder. Actor) ren. Add. Actor(cone. Actor) ren. Set. Background(0. 6, 0. 7) # Create the window and set the name and size of the window ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Cone & Cylinder") ren. Win. Set. Size(500, 500) # Make sure that we can interact with the application iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) # Initialze and start the application iren. Initialize() iren. Start()

Reading Files • VTK file format –. vtk • Graphics objects –. obj •

Reading Files • VTK file format –. vtk • Graphics objects –. obj • Your own data files, use python! – Text files – Binary files

Graphics • teapot. obj • Ascii v -3. 000000 1. 800000 0. 000000 v

Graphics • teapot. obj • Ascii v -3. 000000 1. 800000 0. 000000 v -2. 991600 1. 800000 -0. 081000 v -2. 991600 1. 800000 0. 081000 v -2. 989450 1. 666162 0. 000000 v -2. 985000 1. 921950 0. 000000 v -2. 981175 1. 667844 -0. 081000 v -2. 981175 1. 667844 0. 081000 v -2. 976687 1. 920243 -0. 081000 v -2. 976687 1. 920243 0. 081000 v -2. 968800 1. 800000 -0. 144000 v -2. 968800 1. 800000 0. 144000

import vtk # Read the teapot from file object = vtk. OBJReader() object. Set.

import vtk # Read the teapot from file object = vtk. OBJReader() object. Set. File. Name('teapot. obj') object. Mapper = vtk. Poly. Data. Mapper() object. Mapper. Set. Input. Connection(object. Get. Output. Port()) object. Actor=vtk. Actor() object. Actor. Set. Mapper(object. Mapper) object. Actor. Get. Property(). Set. Color(0. 2, 0. 6) ren = vtk. Renderer() ren. Add. Actor(object. Actor) ren. Set. Background(0. 6, 0. 7) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Teapot") ren. Win. Set. Size(500, 500) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start() The usual stuff!

VTK files and Color Transfer Functions

VTK files and Color Transfer Functions

import sys import string import vtk # Use the VTK reader to read the

import sys import string import vtk # Use the VTK reader to read the vtk file reader = vtk. Unstructured. Grid. Reader() # Don't forget to give the file name as an argument: "python Vectors. py data. vtk" reader. Set. File. Name(sys. argv[1]) # Put spheres at each point in the dataset ball = vtk. Sphere. Source() ball. Set. Radius(0. 12) ball. Set. Theta. Resolution(12) ball. Set. Phi. Resolution(12) ball. Glyph = vtk. Glyph 3 D() ball. Glyph. Set. Source(ball. Get. Output()) ball. Glyph. Set. Input. Connection(reader. Get. Output. Port()) # We do not want the Ball to have the size depending on the Scalar ball. Glyph. Set. Scale. Mode. To. Data. Scaling. Off() ball. Mapper = vtk. Poly. Data. Mapper() ball. Mapper. Set. Input. Connection(ball. Glyph. Get. Output. Port())

Color Transfer Functions # Create a color transfer function to be used for both

Color Transfer Functions # Create a color transfer function to be used for both the balls and arrows. color. Transfer. Function = vtk. Color. Transfer. Function() color. Transfer. Function. Add. RGBPoint(5. 0 , 0. 0, 1. 0) color. Transfer. Function. Add. RGBPoint(10. 0, 1. 0) color. Transfer. Function. Add. RGBPoint(15. 0, 0. 0, 1. 0, 0. 0) color. Transfer. Function. Add. RGBPoint(20. 0, 1. 0, 0. 0) color. Transfer. Function. Add. RGBPoint(25. 0, 1. 0, 0. 0) color. Transfer. Function. Add. RGBPoint(30. 0, 1. 0, 0. 0, 1. 0) # Set colors depending on the color transfer functions ball. Mapper. Set. Lookup. Table(color. Transfer. Function) ball. Actor = vtk. Actor() ball. Actor. Set. Mapper(ball. Mapper)

#Put an arrow (vector) at each ball arrow = vtk. Arrow. Source() arrow. Set.

#Put an arrow (vector) at each ball arrow = vtk. Arrow. Source() arrow. Set. Tip. Radius(0. 2) arrow. Set. Shaft. Radius(0. 075) arrow. Glyph = vtk. Glyph 3 D() arrow. Glyph. Set. Input. Connection(reader. Get. Output. Port()) arrow. Glyph. Set. Source(arrow. Get. Output()) arrow. Glyph. Set. Scale. Factor(0. 4) # We do not want the Arrow's size to depend on the Scalar arrow. Glyph. Set. Scale. Mode. To. Data. Scaling. Off() arrow. Mapper = vtk. Poly. Data. Mapper() arrow. Mapper. Set. Input. Connection(arrow. Glyph. Get. Output. Port()) # Set colors depending on the color transfer functions arrow. Mapper. Set. Lookup. Table(color. Transfer. Function) arrow. Actor = vtk. Actor() arrow. Actor. Set. Mapper(arrow. Mapper)

As usual. . . # Create the Render. Window, Renderer and Interator ren =

As usual. . . # Create the Render. Window, Renderer and Interator ren = vtk. Renderer() ren. Add. Actor(ball. Actor) ren. Add. Actor(arrow. Actor) ren. Set. Background(0. 2, 0. 3) ren. Win = vtk. Render. Window() ren. Win. Add. Renderer(ren) ren. Win. Set. Window. Name("Balls and Arrows from a VTK file") ren. Win. Set. Size(600, 600) iren = vtk. Render. Window. Interactor() iren. Set. Render. Window(ren. Win) iren. Initialize() iren. Start()

# vtk Data. File Version 1. 0 Unstructured Grid Example ASCII DATASET UNSTRUCTURED_GRID POINTS

# vtk Data. File Version 1. 0 Unstructured Grid Example ASCII DATASET UNSTRUCTURED_GRID POINTS 36 float POINT_DATA 36 SCALARS scalars float LOOKUP_TABLE default 0. 0 2. 0 3. 0 1. 0 2. 0 3. 0 4. 0 3. 0 5. 0 3. 0 0. 0 3. 0 1. 0 3. 0 2. 0 4. 0 3. 0 4. 0 5. 0 4. 0 0. 0 5. 0 4. 0 1. 0 5. 0 4. 0 2. 0 5. 0 4. 0 3. 0 5. 0 4. 0 1. 0 4. 0 5. 0 1. 0 4. 0 0. 0 1. 0 4. 0 2. 0 3. 0 2. 0 4. 0 3. 0 2. 0 5. 0 3. 0 2. 0 0. 0 4. 0 2. 0 1. 0 4. 0 2. 0 3. 0 4. 0 2. 0 4. 0 5. 0 2. 0 0. 0 5. 0 1. 0 2. 0 1. 0 3. 0 2. 0 5. 0 4. 0 2. 0 5. 0 7. 0 9. 0 11. 0 13. 0 14. 0 20. 0 21. 0 24. 0 7. 5 9. 0 10. 0 11. 5 12. 0 13. 5 14. 5 29. 0 3. 0 4. 0 6. 0 8. 0 10. 0 12. 0 15. 0 17. 0 19. 0 20. 5 21. 5 22. 0 23. 0 24. 5 25. 0 28. 0 29. 0 30. 0 Position Colors are taken from here VECTORS vectors float 010 100 110 001 Vectors 010 100 110 001 001 111 001 101 001 011 001 001 001

Your Own Files data 1. txt # nb = 0. 6744 0. 5362 0.

Your Own Files data 1. txt # nb = 0. 6744 0. 5362 0. 3671 0. 1866 0. 0175 -0. 1259 -0. 2399 -0. 3273 -0. 3929 -0. 4409 -0. 4746 -0. 4958 -0. 5053 -0. 5023 -0. 4845 -0. 4472 0. 1113 0. 2407 0. 3744 0. 4948 0. 5904 0. 6597 0. 7078 0. 7412 0. 7654 0. 7843 0. 8005 0. 8159 0. 8321 0. 8501 0. 8708 0. 8944 data 2. txt 0. 7300 0. 8091 0. 8515 0. 8487 0. 8069 0. 7409 0. 6644 0. 5860 0. 5096 0. 4364 0. 3661 0. 2973 0. 2287 0. 1581 0. 0830 0. 0000 #c= 0. 8798 0. 9105 0. 9299 0. 9345 0. 9194 0. 8781 0. 8029 0. 6864 0. 5248 0. 3230 0. 0976 -0. 1271 -0. 3287 -0. 4943 -0. 6198 -0. 7071 0. 0573 0. 1226 0. 1968 0. 2806 0. 3746 0. 4783 0. 5890 0. 7007 0. 8028 0. 8813 0. 9243 0. 9275 0. 8966 0. 8425 0. 7766 0. 7071 -0. 4718 -0. 3950 -0. 3107 -0. 2189 -0. 1200 -0. 0154 0. 0916 0. 1944 0. 2831 0. 3449 0. 3690 0. 3515 0. 2968 0. 2141 0. 1128 -0. 0000

import sys import string import vtk Main # This import style makes it possible

import sys import string import vtk Main # This import style makes it possible to write just read. Points from Read. Points import * # Read the data into a vtk. Poly. Data using the functions in Read. Points. py data=vtk. Unstructured. Grid() # Read arguments data. Set. Points(read. Points(sys. argv[1])) data. Get. Point. Data(). Set. Vectors(read. Vectors(sys. argv[2])) # Put spheres at each point in the dataset. ball = vtk. Sphere. Source() ball. Set. Radius(0. 05) ball. Set. Theta. Resolution(12) ball. Set. Phi. Resolution(12) ball. Glyph = vtk. Glyph 3 D() ball. Glyph. Set. Input(data) ball. Glyph. Set. Source(ball. Get. Output())

import string #Read Points def read. Points(file): # Create an array of Points points

import string #Read Points def read. Points(file): # Create an array of Points points = vtk. Points() Read Points #Open the file = open(file) # Read one line = file. readline() # Loop through lines while line: # Split the line into data = string. split(line) # Skip the commented lines if data and data[0] != '#': # Convert data into floats x, y, z = float(data[0]), float(data[1]), float(data[2]) # Insert floats into the point array points. Insert. Next. Point(x, y, z) # read next line = file. readline() return points;

Read vectors # Read Vectors. # This method works in the same way as

Read vectors # Read Vectors. # This method works in the same way as read. Points but returns a different type of array def read. Vectors(file): # Create a Double array which represents the vectors = vtk. Double. Array() # Define number of elements vectors. Set. Number. Of. Components(3) file = open(file) line = file. readline() while line: data = string. split(line) if data and data[0] != '#': x, y, z = float(data[0]), float(data[1]), float(data[2]) vectors. Insert. Next. Tuple 3(x, y, z) line = file. readline() return vectors