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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1029 - (show annotations)
Wed Mar 14 05:01:13 2007 UTC (12 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 3688 byte(s)
Fixed problems in relation to updates propagating when multiple files/sources are read.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6
7 class StreamLineModule:
8 """
9 Class that defines streamlines.
10 """
11
12 def __init__(self, object, source):
13 """
14 Initialise the streamline.
15
16 @type object: vtkUnstructuredGrid, etc
17 @param object: Input for the streamline
18 @type source: vtkPolyData
19 @param source: Source to generate the starting points
20 """
21
22 self.__object = object
23 self.__source = source
24 self.__vtk_stream_line = vtk.vtkStreamLine()
25
26 self.__setupStreamLineModule()
27
28 def __setupStreamLineModule(self):
29 """
30 Setup the streamline.
31 """
32
33 self.__setInput()
34 self.__setSource()
35 # Default maximum propagation time is 100.
36 self.setMaximumPropagationTime(100)
37 # Default step length is 0.01
38 self.setStepLength(0.01)
39 # Default integration step length is 0.01
40 self.setIntegrationStepLength(0.01)
41 # Default integration is set to both directions.
42 self.setIntegrationToBothDirections()
43 # Default integrator is set to vtkRungeKutta4
44 self.setIntegrator(vtk.vtkRungeKutta4())
45 self.__vtk_stream_line.Update()
46
47 def __setInput(self):
48 """
49 Set the input for the streamline.
50 """
51
52 self.__vtk_stream_line.SetInput(self.__object)
53
54 def __setSource(self):
55 """
56 Set the source to generate the starting points for the streamlines.
57 """
58
59 self.__vtk_stream_line.SetSource(self.__source)
60
61 def setMaximumPropagationTime(self, time):
62 """
63 Set the maximum length of the streamline expressed in elapsed time.
64
65 @type time: Number
66 @param time: Maximum length of the streamline expressed in elapsed time
67 """
68
69 self.__vtk_stream_line.SetMaximumPropagationTime(time)
70
71 def setStepLength(self, length):
72 """
73 Set the length of the streamline segment expressed in elapsed time.
74 A smaller value results in a smoother streamline
75 (but is more expensive). Setting the step length usually goes
76 hand-in-hand with setting the integration step length. Otherwise,
77 errors such as "... can't compute normals" may arise. If such an
78 error occurs try changing the value. However, it does not usually
79 apply the other way around.
80
81 @type length: Number
82 @param length: Length of the streamline segment expressed in
83 elapsed time
84 """
85
86 self.__vtk_stream_line.SetStepLength(length)
87
88 def setIntegrationStepLength(self, length):
89 """
90 Set the integration step size expressed as a fraction of the size of
91 each cell. A smaller length results in a better image (but is more
92 expensive).
93
94 @type length: Number
95 @param length: Length of the integration step expressed as a fraction
96 """
97
98 self.__vtk_stream_line.SetIntegrationStepLength(length)
99
100 def setIntegrationToBothDirections(self):
101 """
102 Set the integration to occur both sides: forward (where the streamline
103 goes) and backward (where the streamline came from).
104 """
105
106 self.__vtk_stream_line.SetIntegrationDirectionToIntegrateBothDirections()
107
108 def setIntegrator(self, integrator):
109 """
110 Set the integrator to be used in the streamline calculation.
111
112 @type integrator: vtkInitialValueProblemSolver
113 @param integrator: Integrator type. i.e. vtkRungeKutta2, vtkRungeKutta4
114 """
115
116 self.__vtk_stream_line.SetIntegrator(integrator)
117
118 def _setSpeedScalarsOn(self):
119 """
120 Turn on the creation of scalar data from velocity magnitude.
121 """
122
123 self.__vtk_stream_line.SpeedScalarsOn()
124
125 def _setSpeedScalarsOff(self):
126 """
127 Turn off the creation of scalar data from velocity magnitude. If
128 input dataset has scalars, input dataset scalars are used.
129 """
130
131 self.__vtk_stream_line.SpeedScalarsOff()
132
133 def _getOutput(self):
134 """
135 Return the output of the streamline.
136
137 @rtype: vtkPolyData
138 @return Polygonal data
139 """
140
141 return self.__vtk_stream_line.GetOutput()

  ViewVC Help
Powered by ViewVC 1.1.26