1#!/usr/bin/env python
2
3# This example demonstrates the use of a single streamline and the
4# tube filter to create a streamtube.
5
6import vtk
7from vtk.util.misc import vtkGetDataRoot
8from vtk.util.colors import *
9VTK_DATA_ROOT = vtkGetDataRoot()
10
11# We read a data file the is a CFD analysis of airflow in an office
12# (with ventilation and a burning cigarette). We force an update so
13# that we can query the output for its length, i.e., the length of the
14# diagonal of the bounding box. This is useful for normalizing the
15# data.
16reader = vtk.vtkStructuredGridReader()
17reader.SetFileName(VTK_DATA_ROOT + "/Data/office.binary.vtk")
18reader.Update()
19
20length = reader.GetOutput().GetLength()
21
22maxVelocity =reader.GetOutput().GetPointData().GetVectors().GetMaxNorm()
23maxTime = 35.0*length/maxVelocity
24
25# Now we will generate a single streamline in the data. We select the
26# integration order to use (RungeKutta order 4) and associate it with
27# the streamer. The start position is the position in world space
28# where we want to begin streamline integration; and we integrate in
29# both directions. The step length is the length of the line segments
30# that make up the streamline (i.e., related to display). The
31# IntegrationStepLength specifies the integration step length as a
32# fraction of the cell size that the streamline is in.
33integ = vtk.vtkRungeKutta4()
34streamer = vtk.vtkStreamTracer()
35streamer.SetInputConnection(reader.GetOutputPort())
36streamer.SetStartPosition(0.1, 2.1, 0.5)
37streamer.SetMaximumPropagation(500)
38streamer.SetInitialIntegrationStep(0.05)
39streamer.SetIntegrationDirectionToBoth()
40streamer.SetIntegrator(integ)
41
42# The tube is wrapped around the generated streamline. By varying the
43# radius by the inverse of vector magnitude, we are creating a tube
44# whose radius is proportional to mass flux (in incompressible flow).
45streamTube = vtk.vtkTubeFilter()
46streamTube.SetInputConnection(streamer.GetOutputPort())
47streamTube.SetInputArrayToProcess(1, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "vectors")
48streamTube.SetRadius(0.02)
49streamTube.SetNumberOfSides(12)
50streamTube.SetVaryRadiusToVaryRadiusByVector()
51mapStreamTube = vtk.vtkPolyDataMapper()
52mapStreamTube.SetInputConnection(streamTube.GetOutputPort())
53mapStreamTube.SetScalarRange(reader.GetOutput().GetPointData().GetScalars().GetRange())
54streamTubeActor = vtk.vtkActor()
55streamTubeActor.SetMapper(mapStreamTube)
56streamTubeActor.GetProperty().BackfaceCullingOn()
57
58# From here on we generate a whole bunch of planes which correspond to
59# the geometry in the analysis; tables, bookshelves and so on.
60table1 = vtk.vtkStructuredGridGeometryFilter()
61table1.SetInputConnection(reader.GetOutputPort())
62table1.SetExtent(11, 15, 7, 9, 8, 8)
63mapTable1 = vtk.vtkPolyDataMapper()
64mapTable1.SetInputConnection(table1.GetOutputPort())
65mapTable1.ScalarVisibilityOff()
66table1Actor = vtk.vtkActor()
67table1Actor.SetMapper(mapTable1)
68table1Actor.GetProperty().SetColor(.59, .427, .392)
69
70table2 = vtk.vtkStructuredGridGeometryFilter()
71table2.SetInputConnection(reader.GetOutputPort())
72table2.SetExtent(11, 15, 10, 12, 8, 8)
73mapTable2 = vtk.vtkPolyDataMapper()
74mapTable2.SetInputConnection(table2.GetOutputPort())
75mapTable2.ScalarVisibilityOff()
76table2Actor = vtk.vtkActor()
77table2Actor.SetMapper(mapTable2)
78table2Actor.GetProperty().SetColor(.59, .427, .392)
79
80FilingCabinet1 = vtk.vtkStructuredGridGeometryFilter()
81FilingCabinet1.SetInputConnection(reader.GetOutputPort())
82FilingCabinet1.SetExtent(15, 15, 7, 9, 0, 8)
83mapFilingCabinet1 = vtk.vtkPolyDataMapper()
84mapFilingCabinet1.SetInputConnection(FilingCabinet1.GetOutputPort())
85mapFilingCabinet1.ScalarVisibilityOff()
86FilingCabinet1Actor = vtk.vtkActor()
87FilingCabinet1Actor.SetMapper(mapFilingCabinet1)
88FilingCabinet1Actor.GetProperty().SetColor(.8, .8, .6)
89
90FilingCabinet2 = vtk.vtkStructuredGridGeometryFilter()
91FilingCabinet2.SetInputConnection(reader.GetOutputPort())
92FilingCabinet2.SetExtent(15, 15, 10, 12, 0, 8)
93mapFilingCabinet2 = vtk.vtkPolyDataMapper()
94mapFilingCabinet2.SetInputConnection(FilingCabinet2.GetOutputPort())
95mapFilingCabinet2.ScalarVisibilityOff()
96FilingCabinet2Actor = vtk.vtkActor()
97FilingCabinet2Actor.SetMapper(mapFilingCabinet2)
98FilingCabinet2Actor.GetProperty().SetColor(.8, .8, .6)
99
100bookshelf1Top = vtk.vtkStructuredGridGeometryFilter()
101bookshelf1Top.SetInputConnection(reader.GetOutputPort())
102bookshelf1Top.SetExtent(13, 13, 0, 4, 0, 11)
103mapBookshelf1Top = vtk.vtkPolyDataMapper()
104mapBookshelf1Top.SetInputConnection(bookshelf1Top.GetOutputPort())
105mapBookshelf1Top.ScalarVisibilityOff()
106bookshelf1TopActor = vtk.vtkActor()
107bookshelf1TopActor.SetMapper(mapBookshelf1Top)
108bookshelf1TopActor.GetProperty().SetColor(.8, .8, .6)
109
110bookshelf1Bottom = vtk.vtkStructuredGridGeometryFilter()
111bookshelf1Bottom.SetInputConnection(reader.GetOutputPort())
112bookshelf1Bottom.SetExtent(20, 20, 0, 4, 0, 11)
113mapBookshelf1Bottom = vtk.vtkPolyDataMapper()
114mapBookshelf1Bottom.SetInputConnection(bookshelf1Bottom.GetOutputPort())
115mapBookshelf1Bottom.ScalarVisibilityOff()
116bookshelf1BottomActor = vtk.vtkActor()
117bookshelf1BottomActor.SetMapper(mapBookshelf1Bottom)
118bookshelf1BottomActor.GetProperty().SetColor(.8, .8, .6)
119
120bookshelf1Front = vtk.vtkStructuredGridGeometryFilter()
121bookshelf1Front.SetInputConnection(reader.GetOutputPort())
122bookshelf1Front.SetExtent(13, 20, 0, 0, 0, 11)
123mapBookshelf1Front = vtk.vtkPolyDataMapper()
124mapBookshelf1Front.SetInputConnection(bookshelf1Front.GetOutputPort())
125mapBookshelf1Front.ScalarVisibilityOff()
126bookshelf1FrontActor = vtk.vtkActor()
127bookshelf1FrontActor.SetMapper(mapBookshelf1Front)
128bookshelf1FrontActor.GetProperty().SetColor(.8, .8, .6)
129
130bookshelf1Back = vtk.vtkStructuredGridGeometryFilter()
131bookshelf1Back.SetInputConnection(reader.GetOutputPort())
132bookshelf1Back.SetExtent(13, 20, 4, 4, 0, 11)
133mapBookshelf1Back = vtk.vtkPolyDataMapper()
134mapBookshelf1Back.SetInputConnection(bookshelf1Back.GetOutputPort())
135mapBookshelf1Back.ScalarVisibilityOff()
136bookshelf1BackActor = vtk.vtkActor()
137bookshelf1BackActor.SetMapper(mapBookshelf1Back)
138bookshelf1BackActor.GetProperty().SetColor(.8, .8, .6)
139
140bookshelf1LHS = vtk.vtkStructuredGridGeometryFilter()
141bookshelf1LHS.SetInputConnection(reader.GetOutputPort())
142bookshelf1LHS.SetExtent(13, 20, 0, 4, 0, 0)
143mapBookshelf1LHS = vtk.vtkPolyDataMapper()
144mapBookshelf1LHS.SetInputConnection(bookshelf1LHS.GetOutputPort())
145mapBookshelf1LHS.ScalarVisibilityOff()
146bookshelf1LHSActor = vtk.vtkActor()
147bookshelf1LHSActor.SetMapper(mapBookshelf1LHS)
148bookshelf1LHSActor.GetProperty().SetColor(.8, .8, .6)
149
150bookshelf1RHS = vtk.vtkStructuredGridGeometryFilter()
151bookshelf1RHS.SetInputConnection(reader.GetOutputPort())
152bookshelf1RHS.SetExtent(13, 20, 0, 4, 11, 11)
153mapBookshelf1RHS = vtk.vtkPolyDataMapper()
154mapBookshelf1RHS.SetInputConnection(bookshelf1RHS.GetOutputPort())
155mapBookshelf1RHS.ScalarVisibilityOff()
156bookshelf1RHSActor = vtk.vtkActor()
157bookshelf1RHSActor.SetMapper(mapBookshelf1RHS)
158bookshelf1RHSActor.GetProperty().SetColor(.8, .8, .6)
159
160bookshelf2Top = vtk.vtkStructuredGridGeometryFilter()
161bookshelf2Top.SetInputConnection(reader.GetOutputPort())
162bookshelf2Top.SetExtent(13, 13, 15, 19, 0, 11)
163mapBookshelf2Top = vtk.vtkPolyDataMapper()
164mapBookshelf2Top.SetInputConnection(bookshelf2Top.GetOutputPort())
165mapBookshelf2Top.ScalarVisibilityOff()
166bookshelf2TopActor = vtk.vtkActor()
167bookshelf2TopActor.SetMapper(mapBookshelf2Top)
168bookshelf2TopActor.GetProperty().SetColor(.8, .8, .6)
169
170bookshelf2Bottom = vtk.vtkStructuredGridGeometryFilter()
171bookshelf2Bottom.SetInputConnection(reader.GetOutputPort())
172bookshelf2Bottom.SetExtent(20, 20, 15, 19, 0, 11)
173mapBookshelf2Bottom = vtk.vtkPolyDataMapper()
174mapBookshelf2Bottom.SetInputConnection(bookshelf2Bottom.GetOutputPort())
175mapBookshelf2Bottom.ScalarVisibilityOff()
176bookshelf2BottomActor = vtk.vtkActor()
177bookshelf2BottomActor.SetMapper(mapBookshelf2Bottom)
178bookshelf2BottomActor.GetProperty().SetColor(.8, .8, .6)
179
180bookshelf2Front = vtk.vtkStructuredGridGeometryFilter()
181bookshelf2Front.SetInputConnection(reader.GetOutputPort())
182bookshelf2Front.SetExtent(13, 20, 15, 15, 0, 11)
183mapBookshelf2Front = vtk.vtkPolyDataMapper()
184mapBookshelf2Front.SetInputConnection(bookshelf2Front.GetOutputPort())
185mapBookshelf2Front.ScalarVisibilityOff()
186bookshelf2FrontActor = vtk.vtkActor()
187bookshelf2FrontActor.SetMapper(mapBookshelf2Front)
188bookshelf2FrontActor.GetProperty().SetColor(.8, .8, .6)
189
190bookshelf2Back = vtk.vtkStructuredGridGeometryFilter()
191bookshelf2Back.SetInputConnection(reader.GetOutputPort())
192bookshelf2Back.SetExtent(13, 20, 19, 19, 0, 11)
193mapBookshelf2Back = vtk.vtkPolyDataMapper()
194mapBookshelf2Back.SetInputConnection(bookshelf2Back.GetOutputPort())
195mapBookshelf2Back.ScalarVisibilityOff()
196bookshelf2BackActor = vtk.vtkActor()
197bookshelf2BackActor.SetMapper(mapBookshelf2Back)
198bookshelf2BackActor.GetProperty().SetColor(.8, .8, .6)
199
200bookshelf2LHS = vtk.vtkStructuredGridGeometryFilter()
201bookshelf2LHS.SetInputConnection(reader.GetOutputPort())
202bookshelf2LHS.SetExtent(13, 20, 15, 19, 0, 0)
203mapBookshelf2LHS = vtk.vtkPolyDataMapper()
204mapBookshelf2LHS.SetInputConnection(bookshelf2LHS.GetOutputPort())
205mapBookshelf2LHS.ScalarVisibilityOff()
206bookshelf2LHSActor = vtk.vtkActor()
207bookshelf2LHSActor.SetMapper(mapBookshelf2LHS)
208bookshelf2LHSActor.GetProperty().SetColor(.8, .8, .6)
209
210bookshelf2RHS = vtk.vtkStructuredGridGeometryFilter()
211bookshelf2RHS.SetInputConnection(reader.GetOutputPort())
212bookshelf2RHS.SetExtent(13, 20, 15, 19, 11, 11)
213mapBookshelf2RHS = vtk.vtkPolyDataMapper()
214mapBookshelf2RHS.SetInputConnection(bookshelf2RHS.GetOutputPort())
215mapBookshelf2RHS.ScalarVisibilityOff()
216bookshelf2RHSActor = vtk.vtkActor()
217bookshelf2RHSActor.SetMapper(mapBookshelf2RHS)
218bookshelf2RHSActor.GetProperty().SetColor(.8, .8, .6)
219
220window = vtk.vtkStructuredGridGeometryFilter()
221window.SetInputConnection(reader.GetOutputPort())
222window.SetExtent(20, 20, 6, 13, 10, 13)
223mapWindow = vtk.vtkPolyDataMapper()
224mapWindow.SetInputConnection(window.GetOutputPort())
225mapWindow.ScalarVisibilityOff()
226windowActor = vtk.vtkActor()
227windowActor.SetMapper(mapWindow)
228windowActor.GetProperty().SetColor(.3, .3, .5)
229
230outlet = vtk.vtkStructuredGridGeometryFilter()
231outlet.SetInputConnection(reader.GetOutputPort())
232outlet.SetExtent(0, 0, 9, 10, 14, 16)
233mapOutlet = vtk.vtkPolyDataMapper()
234mapOutlet.SetInputConnection(outlet.GetOutputPort())
235mapOutlet.ScalarVisibilityOff()
236outletActor = vtk.vtkActor()
237outletActor.SetMapper(mapOutlet)
238outletActor.GetProperty().SetColor(0, 0, 0)
239
240inlet = vtk.vtkStructuredGridGeometryFilter()
241inlet.SetInputConnection(reader.GetOutputPort())
242inlet.SetExtent(0, 0, 9, 10, 0, 6)
243mapInlet = vtk.vtkPolyDataMapper()
244mapInlet.SetInputConnection(inlet.GetOutputPort())
245mapInlet.ScalarVisibilityOff()
246inletActor = vtk.vtkActor()
247inletActor.SetMapper(mapInlet)
248inletActor.GetProperty().SetColor(0, 0, 0)
249
250outline = vtk.vtkStructuredGridOutlineFilter()
251outline.SetInputConnection(reader.GetOutputPort())
252mapOutline = vtk.vtkPolyDataMapper()
253mapOutline.SetInputConnection(outline.GetOutputPort())
254outlineActor = vtk.vtkActor()
255outlineActor.SetMapper(mapOutline)
256outlineActor.GetProperty().SetColor(0, 0, 0)
257
258# Now create the usual graphics stuff.
259ren = vtk.vtkRenderer()
260renWin = vtk.vtkRenderWindow()
261renWin.AddRenderer(ren)
262iren = vtk.vtkRenderWindowInteractor()
263iren.SetRenderWindow(renWin)
264
265ren.AddActor(table1Actor)
266ren.AddActor(table2Actor)
267ren.AddActor(FilingCabinet1Actor)
268ren.AddActor(FilingCabinet2Actor)
269ren.AddActor(bookshelf1TopActor)
270ren.AddActor(bookshelf1BottomActor)
271ren.AddActor(bookshelf1FrontActor)
272ren.AddActor(bookshelf1BackActor)
273ren.AddActor(bookshelf1LHSActor)
274ren.AddActor(bookshelf1RHSActor)
275ren.AddActor(bookshelf2TopActor)
276ren.AddActor(bookshelf2BottomActor)
277ren.AddActor(bookshelf2FrontActor)
278ren.AddActor(bookshelf2BackActor)
279ren.AddActor(bookshelf2LHSActor)
280ren.AddActor(bookshelf2RHSActor)
281ren.AddActor(windowActor)
282ren.AddActor(outletActor)
283ren.AddActor(inletActor)
284ren.AddActor(outlineActor)
285ren.AddActor(streamTubeActor)
286
287ren.SetBackground(slate_grey)
288
289# Here we specify a particular view.
290aCamera = vtk.vtkCamera()
291aCamera.SetClippingRange(0.726079, 36.3039)
292aCamera.SetFocalPoint(2.43584, 2.15046, 1.11104)
293aCamera.SetPosition(-4.76183, -10.4426, 3.17203)
294aCamera.SetViewUp(0.0511273, 0.132773, 0.989827)
295aCamera.SetViewAngle(18.604)
296aCamera.Zoom(1.2)
297
298ren.SetActiveCamera(aCamera)
299renWin.SetSize(500, 300)
300
301iren.Initialize()
302renWin.Render()
303iren.Start()
304