1#!/usr/bin/env python 2import vtk 3from vtk.test import Testing 4from vtk.util.misc import vtkGetDataRoot 5VTK_DATA_ROOT = vtkGetDataRoot() 6 7# create pipeline 8# 9pl3d = vtk.vtkMultiBlockPLOT3DReader() 10pl3d.SetXYZFileName("" + str(VTK_DATA_ROOT) + "/Data/combxyz.bin") 11pl3d.SetQFileName("" + str(VTK_DATA_ROOT) + "/Data/combq.bin") 12pl3d.SetScalarFunctionNumber(100) 13pl3d.SetVectorFunctionNumber(202) 14pl3d.Update() 15output = pl3d.GetOutput().GetBlock(0) 16# create three line probes 17line = vtk.vtkLineSource() 18line.SetResolution(30) 19transL1 = vtk.vtkTransform() 20transL1.Translate(3.7,0.0,28.37) 21transL1.Scale(5,5,5) 22transL1.RotateY(90) 23tf = vtk.vtkTransformPolyDataFilter() 24tf.SetInputConnection(line.GetOutputPort()) 25tf.SetTransform(transL1) 26probe = vtk.vtkProbeFilter() 27probe.SetInputConnection(tf.GetOutputPort()) 28probe.SetSourceData(output) 29transL2 = vtk.vtkTransform() 30transL2.Translate(9.2,0.0,31.20) 31transL2.Scale(5,5,5) 32transL2.RotateY(90) 33tf2 = vtk.vtkTransformPolyDataFilter() 34tf2.SetInputConnection(line.GetOutputPort()) 35tf2.SetTransform(transL2) 36probe2 = vtk.vtkProbeFilter() 37probe2.SetInputConnection(tf2.GetOutputPort()) 38probe2.SetSourceData(output) 39transL3 = vtk.vtkTransform() 40transL3.Translate(13.27,0.0,33.40) 41transL3.Scale(4.5,4.5,4.5) 42transL3.RotateY(90) 43tf3 = vtk.vtkTransformPolyDataFilter() 44tf3.SetInputConnection(line.GetOutputPort()) 45tf3.SetTransform(transL3) 46probe3 = vtk.vtkProbeFilter() 47probe3.SetInputConnection(tf3.GetOutputPort()) 48probe3.SetSourceData(output) 49appendF = vtk.vtkAppendPolyData() 50appendF.AddInputData(probe.GetPolyDataOutput()) 51appendF.AddInputData(probe2.GetPolyDataOutput()) 52appendF.AddInputData(probe3.GetPolyDataOutput()) 53tuber = vtk.vtkTubeFilter() 54tuber.SetInputConnection(appendF.GetOutputPort()) 55tuber.SetRadius(0.1) 56lineMapper = vtk.vtkPolyDataMapper() 57lineMapper.SetInputConnection(tuber.GetOutputPort()) 58lineActor = vtk.vtkActor() 59lineActor.SetMapper(lineMapper) 60# probe the line and plot it 61triangle = vtk.vtkGlyphSource2D() 62triangle.SetGlyphTypeToTriangle() 63triangle.Update() 64cross = vtk.vtkGlyphSource2D() 65cross.SetGlyphTypeToCross() 66cross.Update() 67xyplot = vtk.vtkXYPlotActor() 68xyplot.AddDataSetInputConnection(probe.GetOutputPort()) 69xyplot.AddDataSetInputConnection(probe2.GetOutputPort()) 70xyplot.AddDataSetInputConnection(probe3.GetOutputPort()) 71xyplot.GetPositionCoordinate().SetValue(0.0,0.5,0) 72xyplot.GetPosition2Coordinate().SetValue(1.0,0.5,0) 73#relative to Position 74xyplot.SetXValuesToValue() 75xyplot.SetPointComponent(0,2) 76xyplot.SetPointComponent(1,2) 77xyplot.SetPointComponent(2,2) 78xyplot.LogxOn() 79xyplot.SetNumberOfXLabels(6) 80xyplot.SetTitle("Pressure vs. Log10 Probe Z-Value") 81xyplot.SetXTitle("") 82xyplot.SetYTitle("P") 83xyplot.PlotCurveLinesOn() 84xyplot.PlotCurvePointsOn() 85xyplot.SetPlotLines(0,1) 86xyplot.SetPlotLines(1,0) 87xyplot.SetPlotLines(2,1) 88xyplot.SetPlotPoints(0,0) 89xyplot.SetPlotPoints(1,1) 90xyplot.SetPlotPoints(2,1) 91xyplot.GetProperty().SetColor(0,0,0) 92xyplot.GetProperty().SetLineWidth(1) 93xyplot.GetProperty().SetPointSize(3) 94xyplot.SetPlotSymbol(2,triangle.GetOutput()) 95xyplot.SetPlotColor(2,0,0,1) 96xyplot.SetGlyphSize(0.025) 97# Set text prop color (same color for backward compat with test) 98# Assign same object to all text props 99tprop = xyplot.GetTitleTextProperty() 100tprop.SetColor(xyplot.GetProperty().GetColor()) 101xyplot.SetAxisTitleTextProperty(tprop) 102xyplot.SetAxisLabelTextProperty(tprop) 103xyplot.SetLabelFormat("%-#6.2f") 104#Okay exercise data object stuff 105ds2do = vtk.vtkDataSetToDataObjectFilter() 106ds2do.SetInputConnection(probe.GetOutputPort()) 107ds2do.Update() 108ds2do2 = vtk.vtkDataSetToDataObjectFilter() 109ds2do2.SetInputConnection(probe.GetOutputPort()) 110ds2do3 = vtk.vtkDataSetToDataObjectFilter() 111ds2do3.SetInputConnection(probe.GetOutputPort()) 112ds2do3.Update() 113xyplot3 = vtk.vtkXYPlotActor() 114xyplot3.AddDataObjectInput(ds2do.GetOutput()) 115xyplot3.SetDataObjectXComponent(0,2) 116xyplot3.SetDataObjectYComponent(0,5) 117xyplot3.SetPlotColor(0,1,0,0) 118xyplot3.SetPlotLabel(0,"Mx") 119xyplot3.AddDataObjectInputConnection(ds2do2.GetOutputPort()) 120xyplot3.SetDataObjectXComponent(1,2) 121xyplot3.SetDataObjectYComponent(1,6) 122xyplot3.SetPlotColor(1,0,1,0) 123xyplot3.SetPlotLabel(1,"My") 124xyplot3.AddDataObjectInput(ds2do3.GetOutput()) 125xyplot3.SetDataObjectXComponent(2,2) 126xyplot3.SetDataObjectYComponent(2,7) 127xyplot3.SetPlotColor(2,0,0,1) 128xyplot3.SetPlotLabel(2,"Mz") 129xyplot3.GetPositionCoordinate().SetValue(0.0,0.0,0) 130xyplot3.GetPosition2Coordinate().SetValue(1.0,0.5,0) 131#relative to Position 132xyplot3.SetXValuesToValue() 133xyplot3.SetNumberOfXLabels(6) 134xyplot3.SetTitle("Momentum Component vs. Log10 Probe Z-Value") 135xyplot3.SetXTitle("Log10 Probe Z-Value") 136xyplot3.SetYTitle("M") 137xyplot3.GetProperty().SetColor(0,0,1) 138xyplot3.GetProperty().SetPointSize(5) 139xyplot3.PlotCurveLinesOn() 140xyplot3.PlotCurvePointsOn() 141xyplot3.SetPlotLines(0,1) 142xyplot3.SetPlotLines(1,0) 143xyplot3.SetPlotLines(2,1) 144xyplot3.SetPlotPoints(0,0) 145xyplot3.SetPlotPoints(1,1) 146xyplot3.SetPlotPoints(2,1) 147xyplot3.LogxOn() 148# Set text prop color (same color for backward compat with test) 149# Assign same object to all text props 150tprop = xyplot3.GetTitleTextProperty() 151tprop.SetColor(xyplot3.GetProperty().GetColor()) 152xyplot3.SetAxisTitleTextProperty(tprop) 153xyplot3.SetAxisLabelTextProperty(tprop) 154xyplot3.GetYAxisActor2D().SetLabelFormat("%4.f") 155xyplot3.GetXAxisActor2D().SetLabelFormat("%-#6.2f") 156# draw an outline 157outline = vtk.vtkStructuredGridOutlineFilter() 158outline.SetInputData(output) 159outlineMapper = vtk.vtkPolyDataMapper() 160outlineMapper.SetInputConnection(outline.GetOutputPort()) 161outlineActor = vtk.vtkActor() 162outlineActor.SetMapper(outlineMapper) 163outlineActor.GetProperty().SetColor(0,0,0) 164# Create graphics stuff 165# 166ren1 = vtk.vtkRenderer() 167ren2 = vtk.vtkRenderer() 168renWin = vtk.vtkRenderWindow() 169renWin.SetMultiSamples(0) 170renWin.AddRenderer(ren1) 171renWin.AddRenderer(ren2) 172iren = vtk.vtkRenderWindowInteractor() 173iren.SetRenderWindow(renWin) 174ren1.SetBackground(0.6784,0.8471,0.9020) 175ren1.SetViewport(0,0,.5,1) 176ren1.AddActor(outlineActor) 177ren1.AddActor(lineActor) 178ren2.SetBackground(1,1,1) 179ren2.SetViewport(0.5,0.0,1.0,1.0) 180ren2.AddActor2D(xyplot) 181ren2.AddActor2D(xyplot3) 182renWin.SetSize(790,400) 183cam1 = ren1.GetActiveCamera() 184cam1.SetClippingRange(3.95297,100) 185cam1.SetFocalPoint(8.88908,0.595038,29.3342) 186cam1.SetPosition(-12.3332,31.7479,41.2387) 187cam1.SetViewUp(0.060772,-0.319905,0.945498) 188iren.Initialize() 189renWin.Render() 190# render the image 191# 192# prevent the tk window from showing up then start the event loop 193# --- end of script -- 194