1#!/usr/bin/env python 2import vtk 3from vtk.util.misc import vtkGetDataRoot 4VTK_DATA_ROOT = vtkGetDataRoot() 5 6# This version of the script 7# test plotting arbitrary array components (Momentum) 8# without using the dataset to data object filter 9# and its cryptic indexing of arrays. 10# create pipeline 11# 12pl3d = vtk.vtkMultiBlockPLOT3DReader() 13pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") 14pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") 15pl3d.SetScalarFunctionNumber(100) 16pl3d.SetVectorFunctionNumber(202) 17pl3d.Update() 18output = pl3d.GetOutput().GetBlock(0) 19# create three line probes 20line = vtk.vtkLineSource() 21line.SetResolution(30) 22transL1 = vtk.vtkTransform() 23transL1.Translate(3.7,0.0,28.37) 24transL1.Scale(5,5,5) 25transL1.RotateY(90) 26tf = vtk.vtkTransformPolyDataFilter() 27tf.SetInputConnection(line.GetOutputPort()) 28tf.SetTransform(transL1) 29probe = vtk.vtkProbeFilter() 30probe.SetInputConnection(tf.GetOutputPort()) 31probe.SetSourceData(output) 32transL2 = vtk.vtkTransform() 33transL2.Translate(9.2,0.0,31.20) 34transL2.Scale(5,5,5) 35transL2.RotateY(90) 36tf2 = vtk.vtkTransformPolyDataFilter() 37tf2.SetInputConnection(line.GetOutputPort()) 38tf2.SetTransform(transL2) 39probe2 = vtk.vtkProbeFilter() 40probe2.SetInputConnection(tf2.GetOutputPort()) 41probe2.SetSourceData(output) 42transL3 = vtk.vtkTransform() 43transL3.Translate(13.27,0.0,33.40) 44transL3.Scale(4.5,4.5,4.5) 45transL3.RotateY(90) 46tf3 = vtk.vtkTransformPolyDataFilter() 47tf3.SetInputConnection(line.GetOutputPort()) 48tf3.SetTransform(transL3) 49probe3 = vtk.vtkProbeFilter() 50probe3.SetInputConnection(tf3.GetOutputPort()) 51probe3.SetSourceData(output) 52appendF = vtk.vtkAppendPolyData() 53appendF.AddInputData(probe.GetPolyDataOutput()) 54appendF.AddInputData(probe2.GetPolyDataOutput()) 55appendF.AddInputData(probe3.GetPolyDataOutput()) 56tuber = vtk.vtkTubeFilter() 57tuber.SetInputConnection(appendF.GetOutputPort()) 58tuber.SetRadius(0.1) 59lineMapper = vtk.vtkPolyDataMapper() 60lineMapper.SetInputConnection(tuber.GetOutputPort()) 61lineActor = vtk.vtkActor() 62lineActor.SetMapper(lineMapper) 63# probe the line and plot it 64triangle = vtk.vtkGlyphSource2D() 65triangle.SetGlyphTypeToTriangle() 66triangle.Update() 67cross = vtk.vtkGlyphSource2D() 68cross.SetGlyphTypeToCross() 69cross.Update() 70xyplot = vtk.vtkXYPlotActor() 71xyplot.AddDataSetInputConnection(probe.GetOutputPort()) 72xyplot.AddDataSetInputConnection(probe2.GetOutputPort()) 73xyplot.AddDataSetInputConnection(probe3.GetOutputPort()) 74xyplot.GetPositionCoordinate().SetValue(0.0,0.67,0) 75xyplot.GetPosition2Coordinate().SetValue(1.0,0.33,0) 76#relative to Position 77xyplot.SetXValuesToArcLength() 78xyplot.SetNumberOfXLabels(6) 79xyplot.SetTitle("Pressure vs. Arc Length (Zoomed View)") 80xyplot.SetXTitle("") 81xyplot.SetYTitle("P") 82xyplot.SetXRange(.1,.35) 83xyplot.SetYRange(.2,.4) 84xyplot.GetProperty().SetColor(0,0,0) 85xyplot.PlotLinesOn() 86xyplot.GetProperty().SetLineWidth(1) 87xyplot.PlotPointsOn() 88xyplot.GetProperty().SetPointSize(3) 89xyplot.LegendOn() 90xyplot.SetPlotSymbol(2,triangle.GetOutput()) 91xyplot.SetPlotColor(2,0,0,1) 92xyplot.SetPlotColor(1,0,0,0) 93xyplot.SetPlotColor(0,0,0,0) 94xyplot.SetGlyphSize(0.025) 95# Set text prop color (same color for backward compat with test) 96# Assign same object to all text props 97tprop = xyplot.GetTitleTextProperty() 98tprop.SetColor(xyplot.GetProperty().GetColor()) 99xyplot.SetAxisTitleTextProperty(tprop) 100xyplot.SetAxisLabelTextProperty(tprop) 101xyplot.SetLabelFormat("%-#6.2f") 102vertexGlyph = vtk.vtkSphereSource() 103vertexGlyph.Update() 104xyplot2 = vtk.vtkXYPlotActor() 105xyplot2.AddDataSetInputConnection(probe.GetOutputPort()) 106xyplot2.AddDataSetInputConnection(probe2.GetOutputPort()) 107xyplot2.AddDataSetInputConnection(probe3.GetOutputPort()) 108xyplot2.GetPositionCoordinate().SetValue(0.00,0.33,0) 109xyplot2.GetPosition2Coordinate().SetValue(1.0,0.33,0) 110#relative to Position 111xyplot2.SetXValuesToNormalizedArcLength() 112xyplot2.SetNumberOfXLabels(6) 113xyplot2.SetXRange(0.2,1.0) 114xyplot2.SetTitle("VTK Quality vs. Alcohol Consumption") 115xyplot2.SetXTitle("") 116xyplot2.SetYTitle("A") 117xyplot2.PlotPointsOn() 118xyplot2.PlotLinesOff() 119xyplot2.LegendOn() 120xyplot2.SetLegendPosition(0.4,0.6) 121xyplot2.SetLegendPosition2(0.40,0.25) 122xyplot2.GetProperty().SetColor(1,0,0) 123xyplot2.GetProperty().SetPointSize(2) 124xyplot2.SetPlotSymbol(0,vertexGlyph.GetOutput()) 125xyplot2.SetPlotLabel(0,"Ken's Mudslide Consumption") 126xyplot2.SetPlotColor(0,1,0,0) 127xyplot2.SetPlotSymbol(1,cross.GetOutput()) 128xyplot2.SetPlotColor(1,1,0,1) 129xyplot2.SetPlotLabel(1,"Bill's Beer Consumption") 130xyplot2.SetPlotSymbol(2,triangle.GetOutput()) 131xyplot2.SetPlotColor(2,0,0,1) 132xyplot2.SetPlotLabel(2,"VTK Quality") 133# Set text prop color (same color for backward compat with test) 134# Assign same object to all text props 135tprop = xyplot2.GetTitleTextProperty() 136tprop.SetColor(xyplot2.GetProperty().GetColor()) 137xyplot2.SetAxisTitleTextProperty(tprop) 138xyplot2.SetAxisLabelTextProperty(tprop) 139xyplot2.SetLabelFormat(xyplot.GetLabelFormat()) 140xyplot3 = vtk.vtkXYPlotActor() 141xyplot3.AddDataSetInputConnection(probe.GetOutputPort(),"Momentum",0) 142xyplot3.AddDataSetInputConnection(probe.GetOutputPort(),"Density",0) 143xyplot3.AddDataSetInputConnection(probe.GetOutputPort(),"Momentum",1) 144xyplot3.AddDataSetInputConnection(probe.GetOutputPort(),"Momentum",2) 145xyplot3.RemoveDataSetInputConnection(probe.GetOutputPort(),"Density",0) 146xyplot3.SetPlotLabel(0,"Mx") 147xyplot3.SetPlotColor(0,1,0,0) 148xyplot3.SetPlotLabel(1,"My") 149xyplot3.SetPlotColor(1,0,1,0) 150xyplot3.SetPlotColor(2,0,0,1) 151xyplot3.SetPlotLabel(2,"Mz") 152#xyplot3 SetPlotColor 3 1 0 1 153#xyplot3 SetPlotLabel 3 "D" 154xyplot3.GetPositionCoordinate().SetValue(0.0,0.0,0) 155xyplot3.GetPosition2Coordinate().SetValue(1.0,0.33,0) 156#relative to Position 157xyplot3.SetXValuesToIndex() 158xyplot3.SetNumberOfXLabels(6) 159xyplot3.SetTitle("Momentum Component vs. Point Id") 160xyplot3.SetXTitle("Point Id") 161xyplot3.SetYTitle("M") 162xyplot3.PlotPointsOn() 163xyplot3.GetProperty().SetColor(0,0,1) 164xyplot3.GetProperty().SetPointSize(3) 165xyplot3.LegendOn() 166xyplot3.SetLegendPosition(0.8,0.28) 167xyplot3.SetLegendPosition2(0.20,0.20) 168# Set text prop color (same color for backward compat with test) 169# Assign same object to all text props 170tprop = xyplot3.GetTitleTextProperty() 171tprop.SetColor(xyplot3.GetProperty().GetColor()) 172xyplot3.SetAxisTitleTextProperty(tprop) 173xyplot3.SetAxisLabelTextProperty(tprop) 174xyplot3.SetLabelFormat("%4.f") 175# draw an outline 176outline = vtk.vtkStructuredGridOutlineFilter() 177outline.SetInputData(output) 178outlineMapper = vtk.vtkPolyDataMapper() 179outlineMapper.SetInputConnection(outline.GetOutputPort()) 180outlineActor = vtk.vtkActor() 181outlineActor.SetMapper(outlineMapper) 182outlineActor.GetProperty().SetColor(0,0,0) 183# Create graphics stuff 184# 185ren1 = vtk.vtkRenderer() 186ren2 = vtk.vtkRenderer() 187renWin = vtk.vtkRenderWindow() 188renWin.SetMultiSamples(0) 189renWin.AddRenderer(ren1) 190renWin.AddRenderer(ren2) 191iren = vtk.vtkRenderWindowInteractor() 192iren.SetRenderWindow(renWin) 193ren1.SetBackground(0.6784,0.8471,0.9020) 194ren1.SetViewport(0,0,.5,1) 195ren1.AddActor(outlineActor) 196ren1.AddActor(lineActor) 197ren2.SetBackground(1,1,1) 198ren2.SetViewport(0.5,0.0,1.0,1.0) 199ren2.AddActor2D(xyplot) 200ren2.AddActor2D(xyplot2) 201ren2.AddActor2D(xyplot3) 202renWin.SetSize(790,400) 203cam1 = ren1.GetActiveCamera() 204cam1.SetClippingRange(3.95297,100) 205cam1.SetFocalPoint(8.88908,0.595038,29.3342) 206cam1.SetPosition(-12.3332,31.7479,41.2387) 207cam1.SetViewUp(0.060772,-0.319905,0.945498) 208iren.Initialize() 209renWin.Render() 210# render the image 211# 212# prevent the tk window from showing up then start the event loop 213# --- end of script -- 214