1#!/usr/bin/env python 2import vtk 3from vtk.util.misc import vtkGetDataRoot 4VTK_DATA_ROOT = vtkGetDataRoot() 5 6# Create the RenderWindow, Renderer and both Actors 7# 8ren1 = vtk.vtkRenderer() 9renWin = vtk.vtkRenderWindow() 10renWin.SetMultiSamples(0) 11renWin.AddRenderer(ren1) 12iren = vtk.vtkRenderWindowInteractor() 13iren.SetRenderWindow(renWin) 14# read data 15# 16pl3d = vtk.vtkMultiBlockPLOT3DReader() 17pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") 18pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") 19pl3d.SetScalarFunctionNumber(100) 20pl3d.SetVectorFunctionNumber(202) 21pl3d.Update() 22output = pl3d.GetOutput().GetBlock(0) 23# planes to connect 24plane1 = vtk.vtkStructuredGridGeometryFilter() 25plane1.SetInputData(output) 26plane1.SetExtent(20,20,0,100,0,100) 27conn = vtk.vtkPolyDataConnectivityFilter() 28conn.SetInputConnection(plane1.GetOutputPort()) 29conn.ScalarConnectivityOn() 30conn.SetScalarRange(0.19,0.25) 31conn.Update() 32#conn.Print() 33plane1Map = vtk.vtkPolyDataMapper() 34plane1Map.SetInputConnection(conn.GetOutputPort()) 35plane1Map.SetScalarRange(output.GetScalarRange()) 36plane1Actor = vtk.vtkActor() 37plane1Actor.SetMapper(plane1Map) 38plane1Actor.GetProperty().SetOpacity(0.999) 39# outline 40outline = vtk.vtkStructuredGridOutlineFilter() 41outline.SetInputData(output) 42outlineMapper = vtk.vtkPolyDataMapper() 43outlineMapper.SetInputConnection(outline.GetOutputPort()) 44outlineActor = vtk.vtkActor() 45outlineActor.SetMapper(outlineMapper) 46outlineProp = outlineActor.GetProperty() 47outlineProp.SetColor(0,0,0) 48# Add the actors to the renderer, set the background and size 49# 50ren1.AddActor(outlineActor) 51ren1.AddActor(plane1Actor) 52ren1.SetBackground(1,1,1) 53renWin.SetSize(300,300) 54cam1 = vtk.vtkCamera() 55cam1.SetClippingRange(14.29,63.53) 56cam1.SetFocalPoint(8.58522,1.58266,30.6486) 57cam1.SetPosition(37.6808,-20.1298,35.4016) 58cam1.SetViewAngle(30) 59cam1.SetViewUp(-0.0566235,0.140504,0.98846) 60ren1.SetActiveCamera(cam1) 61iren.Initialize() 62# render the image 63# 64# prevent the tk window from showing up then start the event loop 65# --- end of script -- 66