1#!/usr/bin/env python 2import vtk 3from vtk.test import Testing 4from vtk.util.misc import vtkGetDataRoot 5VTK_DATA_ROOT = vtkGetDataRoot() 6 7def GetRGBColor(colorName): 8 ''' 9 Return the red, green and blue components for a 10 color as doubles. 11 ''' 12 rgb = [0.0, 0.0, 0.0] # black 13 vtk.vtkNamedColors().GetColorRGB(colorName, rgb) 14 return rgb 15 16VTK_VARY_RADIUS_BY_VECTOR = 2 17# create pipeline 18# 19# Make sure all algorithms use the composite data pipeline 20cdp = vtk.vtkCompositeDataPipeline() 21 22reader = vtk.vtkGenericEnSightReader() 23reader.SetDefaultExecutivePrototype(cdp) 24reader.SetCaseFileName(VTK_DATA_ROOT + "/Data/EnSight/RectGrid_bin.case") 25reader.Update() 26 27toRectilinearGrid = vtk.vtkCastToConcrete() 28toRectilinearGrid.SetInputData(reader.GetOutput().GetBlock(0)) 29toRectilinearGrid.Update() 30 31plane = vtk.vtkRectilinearGridGeometryFilter() 32plane.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) 33plane.SetExtent(0, 100, 0, 100, 15, 15) 34 35tri = vtk.vtkTriangleFilter() 36tri.SetInputConnection(plane.GetOutputPort()) 37 38warper = vtk.vtkWarpVector() 39warper.SetInputConnection(tri.GetOutputPort()) 40warper.SetScaleFactor(0.05) 41 42planeMapper = vtk.vtkDataSetMapper() 43planeMapper.SetInputConnection(warper.GetOutputPort()) 44planeMapper.SetScalarRange(0.197813, 0.710419) 45 46planeActor = vtk.vtkActor() 47planeActor.SetMapper(planeMapper) 48 49cutPlane = vtk.vtkPlane() 50cutPlane.SetOrigin(reader.GetOutput().GetBlock(0).GetCenter()) 51cutPlane.SetNormal(1, 0, 0) 52 53planeCut = vtk.vtkCutter() 54planeCut.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) 55planeCut.SetCutFunction(cutPlane) 56 57cutMapper = vtk.vtkDataSetMapper() 58cutMapper.SetInputConnection(planeCut.GetOutputPort()) 59cutMapper.SetScalarRange( 60 reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) 61 62cutActor = vtk.vtkActor() 63cutActor.SetMapper(cutMapper) 64 65iso = vtk.vtkContourFilter() 66iso.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) 67iso.SetValue(0, 0.7) 68 69normals = vtk.vtkPolyDataNormals() 70normals.SetInputConnection(iso.GetOutputPort()) 71normals.SetFeatureAngle(45) 72 73isoMapper = vtk.vtkPolyDataMapper() 74isoMapper.SetInputConnection(normals.GetOutputPort()) 75isoMapper.ScalarVisibilityOff() 76 77isoActor = vtk.vtkActor() 78isoActor.SetMapper(isoMapper) 79isoActor.GetProperty().SetColor(GetRGBColor('bisque')) 80isoActor.GetProperty().SetRepresentationToWireframe() 81 82streamer = vtk.vtkStreamLine() 83streamer.SetInputData(reader.GetOutput().GetBlock(0)) 84streamer.SetStartPosition(-1.2, -0.1, 1.3) 85streamer.SetMaximumPropagationTime(500) 86streamer.SetStepLength(0.05) 87streamer.SetIntegrationStepLength(0.05) 88streamer.SetIntegrationDirectionToIntegrateBothDirections() 89 90streamTube = vtk.vtkTubeFilter() 91streamTube.SetInputConnection(streamer.GetOutputPort()) 92streamTube.SetRadius(0.025) 93streamTube.SetNumberOfSides(6) 94streamTube.SetVaryRadius(VTK_VARY_RADIUS_BY_VECTOR) 95 96mapStreamTube = vtk.vtkPolyDataMapper() 97mapStreamTube.SetInputConnection(streamTube.GetOutputPort()) 98mapStreamTube.SetScalarRange( 99 reader.GetOutput().GetBlock(0).GetPointData().GetScalars().GetRange()) 100 101streamTubeActor = vtk.vtkActor() 102streamTubeActor.SetMapper(mapStreamTube) 103streamTubeActor.GetProperty().BackfaceCullingOn() 104 105outline = vtk.vtkOutlineFilter() 106outline.SetInputData(toRectilinearGrid.GetRectilinearGridOutput()) 107 108outlineMapper = vtk.vtkPolyDataMapper() 109outlineMapper.SetInputConnection(outline.GetOutputPort()) 110 111outlineActor = vtk.vtkActor() 112outlineActor.SetMapper(outlineMapper) 113outlineActor.GetProperty().SetColor(GetRGBColor('black')) 114 115# Graphics stuff 116# Create the RenderWindow, Renderer and both Actors 117# 118ren1 = vtk.vtkRenderer() 119renWin = vtk.vtkRenderWindow() 120renWin.SetMultiSamples(0) 121renWin.AddRenderer(ren1) 122iren = vtk.vtkRenderWindowInteractor() 123iren.SetRenderWindow(renWin) 124 125# Add the actors to the renderer, set the background and size 126# 127ren1.AddActor(outlineActor) 128ren1.AddActor(planeActor) 129ren1.AddActor(cutActor) 130ren1.AddActor(isoActor) 131ren1.AddActor(streamTubeActor) 132ren1.SetBackground(1, 1, 1) 133 134renWin.SetSize(400, 400) 135 136cam1 = ren1.GetActiveCamera() 137cam1.SetClippingRange(3.76213, 10.712) 138cam1.SetFocalPoint(-0.0842503, -0.136905, 0.610234) 139cam1.SetPosition(2.53813, 2.2678, -5.22172) 140cam1.SetViewUp(-0.241047, 0.930635, 0.275343) 141 142reader.SetDefaultExecutivePrototype(None) 143 144iren.Initialize() 145# render the image 146# 147#iren.Start() 148