From 3a201fe0cfc8a9fb9c9be4017dda9b9ee19e86a7 Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@gmail.com> Date: Wed, 06 Jul 2016 21:16:49 +0000 Subject: [PATCH] vtk visualization --- python/pythonvtk.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/python/pythonvtk.py b/python/pythonvtk.py new file mode 100644 index 0000000..b50ff7c --- /dev/null +++ b/python/pythonvtk.py @@ -0,0 +1,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() -- Gitblit v1.9.3