1 |
|
2 |
######################################################## |
3 |
# |
4 |
# Copyright (c) 2003-2008 by University of Queensland |
5 |
# Earth Systems Science Computational Center (ESSCC) |
6 |
# http://www.uq.edu.au/esscc |
7 |
# |
8 |
# Primary Business: Queensland, Australia |
9 |
# Licensed under the Open Software License version 3.0 |
10 |
# http://www.opensource.org/licenses/osl-3.0.php |
11 |
# |
12 |
######################################################## |
13 |
|
14 |
__copyright__="""Copyright (c) 2003-2008 by University of Queensland |
15 |
Earth Systems Science Computational Center (ESSCC) |
16 |
http://www.uq.edu.au/esscc |
17 |
Primary Business: Queensland, Australia""" |
18 |
__license__="""Licensed under the Open Software License version 3.0 |
19 |
http://www.opensource.org/licenses/osl-3.0.php""" |
20 |
__url__="http://www.uq.edu.au/esscc/escript-finley" |
21 |
|
22 |
""" |
23 |
@var __author__: name of author |
24 |
@var __copyright__: copyrights |
25 |
@var __license__: licence agreement |
26 |
@var __url__: url entry point on documentation |
27 |
@var __version__: version |
28 |
@var __date__: date of the version |
29 |
""" |
30 |
|
31 |
__author__="John Ngui, john.ngui@uq.edu.au" |
32 |
|
33 |
|
34 |
import vtk |
35 |
|
36 |
class StreamLineModule: |
37 |
""" |
38 |
Class that defines the streamline module. |
39 |
""" |
40 |
|
41 |
def __init__(self): |
42 |
""" |
43 |
Initialise the streamline module. |
44 |
""" |
45 |
|
46 |
self.__vtk_stream_line = vtk.vtkStreamLine() |
47 |
|
48 |
def _setupStreamLineModule(self, object, source): |
49 |
""" |
50 |
Setup the streamline. |
51 |
|
52 |
@type object: vtkUnstructuredGrid, etc |
53 |
@param object: Input for the streamline |
54 |
@type source: vtkPolyData |
55 |
@param source: Source to generate the starting points |
56 |
""" |
57 |
|
58 |
self.__object = object |
59 |
self.__source = source |
60 |
|
61 |
self.__setInput() |
62 |
self.__setSource() |
63 |
# Default maximum propagation time is 100. |
64 |
self.setMaximumPropagationTime(100) |
65 |
# Default step length is 0.01 |
66 |
self.setStepLength(0.01) |
67 |
# Default integration step length is 0.01 |
68 |
self.setIntegrationStepLength(0.01) |
69 |
# Default integration is set to both directions. |
70 |
self.setIntegrationToBothDirections() |
71 |
# Default integrator is set to vtkRungeKutta4 |
72 |
self.setIntegrator(vtk.vtkRungeKutta4()) |
73 |
|
74 |
def __setInput(self): |
75 |
""" |
76 |
Set the input for the streamline. |
77 |
""" |
78 |
|
79 |
self.__vtk_stream_line.SetInput(self.__object) |
80 |
|
81 |
def __setSource(self): |
82 |
""" |
83 |
Set the source to generate the starting points for the streamline. |
84 |
""" |
85 |
|
86 |
self.__vtk_stream_line.SetSource(self.__source) |
87 |
|
88 |
def setMaximumPropagationTime(self, time): |
89 |
""" |
90 |
Set the maximum length of the streamline expressed in elapsed time. |
91 |
|
92 |
@type time: Number |
93 |
@param time: Maximum length of the streamline expressed in elapsed time |
94 |
""" |
95 |
|
96 |
self.__vtk_stream_line.SetMaximumPropagationTime(time) |
97 |
|
98 |
def setStepLength(self, length): |
99 |
""" |
100 |
Set the length of the streamline segment expressed in elapsed time. |
101 |
A smaller value results in a smoother streamline |
102 |
(but is more expensive). Setting the step length usually goes |
103 |
hand-in-hand with setting the integration step length. Otherwise, |
104 |
errors such as "... can't compute normals" may arise. If such an |
105 |
error occurs try changing the values. |
106 |
|
107 |
@type length: Number |
108 |
@param length: Length of the streamline segment expressed in |
109 |
elapsed time |
110 |
""" |
111 |
|
112 |
self.__vtk_stream_line.SetStepLength(length) |
113 |
|
114 |
def setIntegrationStepLength(self, length): |
115 |
""" |
116 |
Set the integration step size expressed as a fraction of the size of |
117 |
each cell. A smaller length results in a better image (but is more |
118 |
expensive). |
119 |
|
120 |
@type length: Number |
121 |
@param length: Length of the integration step expressed as a fraction |
122 |
of the size of each cell |
123 |
""" |
124 |
|
125 |
self.__vtk_stream_line.SetIntegrationStepLength(length) |
126 |
|
127 |
def setIntegrationToBothDirections(self): |
128 |
""" |
129 |
Set the integration to occur both sides: forward (where the streamline |
130 |
goes) and backward (where the streamline came from). |
131 |
""" |
132 |
|
133 |
self.__vtk_stream_line.\ |
134 |
SetIntegrationDirectionToIntegrateBothDirections() |
135 |
|
136 |
def setIntegrator(self, integrator): |
137 |
""" |
138 |
Set the integrator to be used in the streamline calculation. |
139 |
|
140 |
@type integrator: vtkInitialValueProblemSolver |
141 |
@param integrator: Integrator type. i.e. vtkRungeKutta2, vtkRungeKutta4 |
142 |
""" |
143 |
|
144 |
self.__vtk_stream_line.SetIntegrator(integrator) |
145 |
|
146 |
def _setSpeedScalarsOn(self): |
147 |
""" |
148 |
Turn on the creation of scalar data from velocity magnitude. |
149 |
""" |
150 |
|
151 |
self.__vtk_stream_line.SpeedScalarsOn() |
152 |
|
153 |
def _setSpeedScalarsOff(self): |
154 |
""" |
155 |
Turn off the creation of scalar data from velocity magnitude. If |
156 |
input dataset has scalars, input dataset scalars are used. |
157 |
""" |
158 |
|
159 |
self.__vtk_stream_line.SpeedScalarsOff() |
160 |
|
161 |
def _getStreamLineModuleOutput(self): |
162 |
""" |
163 |
Return the output of the streamline. |
164 |
|
165 |
@rtype: vtkPolyData |
166 |
@return Polygonal data |
167 |
""" |
168 |
|
169 |
return self.__vtk_stream_line.GetOutput() |