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