1#!/usr/bin/env python 2 3# This example shows how to color an isosurface with other 4# data. Basically an isosurface is generated, and a data array is 5# selected and used by the mapper to color the surface. 6 7import vtk 8from vtk.util.misc import vtkGetDataRoot 9VTK_DATA_ROOT = vtkGetDataRoot() 10 11# Read some data. The important thing here is to read a function as a 12# data array as well as the scalar and vector. (here function 153 is 13# named "Velocity Magnitude").Later this data array will be used to 14# color the isosurface. 15pl3d = vtk.vtkMultiBlockPLOT3DReader() 16pl3d.SetXYZFileName(VTK_DATA_ROOT + "/Data/combxyz.bin") 17pl3d.SetQFileName(VTK_DATA_ROOT + "/Data/combq.bin") 18pl3d.SetScalarFunctionNumber(100) 19pl3d.SetVectorFunctionNumber(202) 20pl3d.AddFunction(153) 21pl3d.Update() 22pl3d.DebugOn() 23pl3d_output = pl3d.GetOutput().GetBlock(0) 24 25# The contour filter uses the labeled scalar (function number 100 26# above to generate the contour surface; all other data is 27# interpolated during the contouring process. 28iso = vtk.vtkContourFilter() 29iso.SetInputData(pl3d_output) 30iso.SetValue(0, .24) 31 32normals = vtk.vtkPolyDataNormals() 33normals.SetInputConnection(iso.GetOutputPort()) 34normals.SetFeatureAngle(45) 35 36# We indicate to the mapper to use the velcoity magnitude, which is a 37# vtkDataArray that makes up part of the point attribute data. 38isoMapper = vtk.vtkPolyDataMapper() 39isoMapper.SetInputConnection(normals.GetOutputPort()) 40isoMapper.ScalarVisibilityOn() 41isoMapper.SetScalarRange(0, 1500) 42isoMapper.SetScalarModeToUsePointFieldData() 43isoMapper.ColorByArrayComponent("VelocityMagnitude", 0) 44 45isoActor = vtk.vtkLODActor() 46isoActor.SetMapper(isoMapper) 47isoActor.SetNumberOfCloudPoints(1000) 48 49outline = vtk.vtkStructuredGridOutlineFilter() 50outline.SetInputData(pl3d_output) 51outlineMapper = vtk.vtkPolyDataMapper() 52outlineMapper.SetInputConnection(outline.GetOutputPort()) 53outlineActor = vtk.vtkActor() 54outlineActor.SetMapper(outlineMapper) 55 56# Create the usual rendering stuff. 57ren = vtk.vtkRenderer() 58renWin = vtk.vtkRenderWindow() 59renWin.AddRenderer(ren) 60iren = vtk.vtkRenderWindowInteractor() 61iren.SetRenderWindow(renWin) 62 63# Add the actors to the renderer, set the background and size 64ren.AddActor(outlineActor) 65ren.AddActor(isoActor) 66ren.SetBackground(1, 1, 1) 67renWin.SetSize(500, 500) 68ren.SetBackground(0.1, 0.2, 0.4) 69 70cam1 = ren.GetActiveCamera() 71cam1.SetClippingRange(3.95297, 50) 72cam1.SetFocalPoint(9.71821, 0.458166, 29.3999) 73cam1.SetPosition(2.7439, -37.3196, 38.7167) 74cam1.SetViewUp(-0.16123, 0.264271, 0.950876) 75 76iren.Initialize() 77renWin.Render() 78iren.Start() 79