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