/[escript]/trunk/pyvisi/py_src/streamlines.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/streamlines.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 886 - (show annotations)
Thu Nov 2 01:34:58 2006 UTC (14 years ago) by jongui
File MIME type: text/x-python
File size: 4351 byte(s)
- Fixed a couple of minor bugs but the bug relating to the plane normal still exists.
- Updated the documentation.

1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 import vtk
7 from common import Common
8 from geo import Position
9
10 class StreamLines(Common):
11 """
12 Class that shows the path of particles (within a specified cloud of points)
13 in a vector field.
14 """
15
16 def __init__(self, scene, data_collector, lut = None):
17 """
18 @type scene: L{Scene <scene.Scene>} object
19 @param scene: Scene in which components are to be added to
20 @type data_collector: L{DataCollector <datacollector.DataCollector>}
21 object
22 @param data_collector: Source of data for visualization
23 @type lut: L{BlueToRed <colormap.BlueToRed>} or
24 L{RedToBlue <colormap.RedToBlue>} object
25 @param lut: Lookup table to be used by the mapper
26 """
27
28 Common.__init__(self, scene, data_collector)
29 # Create a spherical cloud of points.
30 self.vtk_point_source = vtk.vtkPointSource()
31 # Create streamlines
32 self.vtk_stream_lines = vtk.vtkStreamLine()
33 # Create tube to be wrapped around the streamlines.
34 self.vtk_tube = vtk.vtkTubeFilter()
35
36 self.setSource()
37 self.setStreamLines()
38 self.setTube()
39
40 Common.setMapperInput(self, self.vtk_tube.GetOutput(), lut)
41 Common.setActorInput(self)
42 Common.addActor(self)
43
44 def setSource(self):
45 """
46 Set the default parameters for the spherical cloud of points.
47 """
48
49 self.setCloudRadius(0.2)
50 self.setCenter(Position(0.2, 2.1, 0.5))
51 self.setNumberOfPoints(8)
52
53 def setStreamLines(self):
54 """
55 Set the default parameters for the streamlines.
56 """
57
58 self.vtk_stream_lines.SetInput(
59 self.data_collector.getReader().GetOutput())
60 self.vtk_stream_lines.SetSource(self.vtk_point_source.GetOutput())
61 self.setMaximumPropagationTime(500)
62 self.setStreamLinesSize(0.2)
63 self.setAccuracy(0.05)
64
65 self.setIntegrationToBothDirections()
66 self.vtk_stream_lines.SetIntegrator(vtk.vtkRungeKutta4())
67
68
69 def setTube(self):
70 """
71 Set the default parameters for the tube.
72 """
73
74 self.vtk_tube.SetInput(self.vtk_stream_lines.GetOutput())
75 self.setTubeRadius(0.01)
76 self.setNumberOfSides(12)
77 self.setVaryRadiusByVector()
78
79 def setCloudRadius(self, radius):
80 """
81 Set the radius for the cloud of points.
82 @type radius: Number
83 @param radius: Radius for the cloud of points
84 """
85
86 self.vtk_point_source.SetRadius(radius)
87
88 def setCenter(self, position):
89 """
90 Set the center for the cloud of points.
91 @type position: L{Position <geo.Position>} object
92 @param position: Center for the cloud of points
93 """
94
95 self.vtk_point_source.SetCenter(position.getXCoor(),
96 position.getYCoor(), position.getZCoor())
97
98 def setNumberOfPoints(self, points):
99 """
100 Set the number of points to generate for the cloud of points.
101 @type points: Number
102 @param points: Number of points to generate for the cloud of points
103 """
104
105 self.vtk_point_source.SetNumberOfPoints(points)
106
107 def setMaximumPropagationTime(self, time):
108 """
109 Set the maximum length for the streamlines in units of time.
110 @type time: Number
111 @param time: Units of time specifying the maximum length of streamlines
112 """
113
114 self.vtk_stream_lines.SetMaximumPropagationTime(time)
115
116 def setStreamLinesSize(self, stream_lines_size):
117 """
118 Set the size of the streamlines.
119 @type stream_lines_size: Number
120 @param stream_lines_size: Size of the streamlines
121 """
122
123 self.vtk_stream_lines.SetStepLength(stream_lines_size)
124
125 def setAccuracy(self, accuracy):
126 """
127 Set the level of accuracy for the streamlines. The smaller the value
128 the more accurate it is.
129 @type accuracy: Number
130 @param accuracy: Accuracy for the streamlines (between 0 to 1)
131 """
132
133 self.vtk_stream_lines.SetIntegrationStepLength(accuracy)
134
135 def setIntegrationToBothDirections(self):
136 """
137 Set the integration to occur in both directions.
138 """
139
140 self.vtk_stream_lines.SetIntegrationDirectionToIntegrateBothDirections()
141
142 def setTubeRadius(self, radius):
143 """
144 Set the minimum radius of the tube.
145 @type radius: Number
146 @param radius: Minimum radius of the tube
147 """
148
149 self.vtk_tube.SetRadius(radius)
150
151 def setNumberOfSides(self, sides):
152 """
153 Set the number of sides for the tube.
154 @type sides: Number
155 @param sides: Number of sides for the tube (mimimum is 3)
156 """
157
158 self.vtk_tube.SetNumberOfSides(sides)
159
160 def setVaryRadiusByVector(self):
161 """
162 Set the variation of the tube radius with vector data.
163 """
164
165 self.vtk_tube.SetVaryRadiusToVaryRadiusByVector()

  ViewVC Help
Powered by ViewVC 1.1.26