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