commit | author | age
|
3a201f
|
1 |
#!/usr/bin/env python |
SP |
2 |
# -*- coding: utf-8 -*- |
|
3 |
# |
|
4 |
# by Panos Mavrogiorgos, email: pmav99 <> gmail |
|
5 |
|
|
6 |
from vtk import * |
|
7 |
|
|
8 |
# The source file |
|
9 |
#file_name = "uGridEx.vtk" |
|
10 |
file_name="timestep.vtu" |
|
11 |
# Read the source file. |
|
12 |
#reader = vtkUnstructuredGridReader() |
|
13 |
reader=vtkXMLUnstructuredGridReader() |
|
14 |
reader.SetFileName(file_name) |
|
15 |
reader.Update() # Needed because of GetScalarRange |
|
16 |
output = reader.GetOutput() |
|
17 |
scalar_range = output.GetScalarRange() |
|
18 |
|
|
19 |
# Create the mapper that corresponds the objects of the vtk file |
|
20 |
# into graphics elements |
|
21 |
mapper = vtkDataSetMapper() |
|
22 |
mapper.SetInput(output) |
|
23 |
mapper.SetScalarRange(scalar_range) |
|
24 |
|
|
25 |
# Create the Actor |
|
26 |
actor = vtkActor() |
|
27 |
actor.SetMapper(mapper) |
|
28 |
|
|
29 |
# Create the Renderer |
|
30 |
renderer = vtkRenderer() |
|
31 |
renderer.AddActor(actor) |
|
32 |
renderer.SetBackground(0, 0, 0) # Set background to white |
|
33 |
|
|
34 |
# Create the RendererWindow |
|
35 |
renderer_window = vtkRenderWindow() |
|
36 |
renderer_window.AddRenderer(renderer) |
|
37 |
|
|
38 |
# Create the RendererWindowInteractor and display the vtk_file |
|
39 |
interactor = vtkRenderWindowInteractor() |
|
40 |
interactor.SetRenderWindow(renderer_window) |
|
41 |
interactor.Initialize() |
|
42 |
interactor.Start() |