1 |
ksteube |
1147 |
""" |
2 |
jongui |
1197 |
@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 |
ksteube |
1147 |
""" |
9 |
|
|
|
10 |
jongui |
1197 |
__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 |
ksteube |
1147 |
import vtk |
22 |
|
|
from position import GlobalPosition |
23 |
|
|
|
24 |
|
|
class PointSource: |
25 |
|
|
""" |
26 |
|
|
Class that defines the source (location) to generate points. The points are |
27 |
|
|
generated within the radius of a sphere. |
28 |
|
|
""" |
29 |
|
|
|
30 |
jongui |
1148 |
def __init__(self): |
31 |
ksteube |
1147 |
""" |
32 |
|
|
Initialise the point source. |
33 |
|
|
""" |
34 |
|
|
|
35 |
|
|
self.__vtk_point_source = vtk.vtkPointSource() |
36 |
jongui |
1148 |
self.__center = None |
37 |
ksteube |
1147 |
|
38 |
jongui |
1148 |
def _setupPointSource(self, object): |
39 |
ksteube |
1147 |
""" |
40 |
|
|
Setup the point source. |
41 |
jongui |
1148 |
|
42 |
|
|
@type object: vtkPolyData, etc |
43 |
|
|
@param object: Used to define the location of the sphere |
44 |
ksteube |
1147 |
""" |
45 |
|
|
|
46 |
jongui |
1148 |
self.__object = object |
47 |
|
|
|
48 |
ksteube |
1147 |
# Default number of points to generate within the sphere is 10. |
49 |
|
|
self.setPointSourceNumberOfPoints(10) |
50 |
|
|
# Default radius of the sphere is 0.5. |
51 |
|
|
self.setPointSourceRadius(0.5) |
52 |
|
|
|
53 |
|
|
def setPointSourceRadius(self, radius): |
54 |
|
|
""" |
55 |
|
|
Set the radius of the sphere. |
56 |
|
|
|
57 |
|
|
@type radius: Number |
58 |
|
|
@param radius: Radius of the sphere |
59 |
|
|
""" |
60 |
|
|
|
61 |
|
|
self.__vtk_point_source.SetRadius(radius) |
62 |
|
|
|
63 |
jongui |
1148 |
# This method is used to delay the execution of setting the point source |
64 |
|
|
# center. |
65 |
|
|
def setPointSourceCenter(self, center): |
66 |
ksteube |
1147 |
""" |
67 |
jongui |
1148 |
Save the sphere's center. |
68 |
ksteube |
1147 |
|
69 |
jongui |
1148 |
@type center: L{GLobalPosition <position.GlobalPosition>} object |
70 |
|
|
@param center: Center of the sphere |
71 |
ksteube |
1147 |
""" |
72 |
jongui |
1148 |
|
73 |
|
|
self.__center = center |
74 |
ksteube |
1147 |
|
75 |
jongui |
1148 |
def _setPointSourceCenter(self): |
76 |
|
|
""" |
77 |
|
|
Set the sphere's center. |
78 |
|
|
""" |
79 |
ksteube |
1147 |
|
80 |
jongui |
1148 |
self.__vtk_point_source.SetCenter(self.__center._getGlobalPosition()) |
81 |
|
|
|
82 |
ksteube |
1147 |
def setPointSourceNumberOfPoints(self, points): |
83 |
|
|
""" |
84 |
|
|
Set the number of points to generate within the sphere (the larger the |
85 |
|
|
number of points, the more streamlines are generated) |
86 |
|
|
|
87 |
|
|
@type points: Number |
88 |
|
|
@param points: Number of points to generate |
89 |
|
|
""" |
90 |
|
|
|
91 |
|
|
self.__vtk_point_source.SetNumberOfPoints(points) |
92 |
|
|
|
93 |
jongui |
1148 |
def _getPointSourceOutput(self): |
94 |
ksteube |
1147 |
""" |
95 |
|
|
Return the output of the point source. |
96 |
|
|
|
97 |
|
|
@rtype: vtkPolyData |
98 |
|
|
@return: Polygonal data |
99 |
|
|
""" |
100 |
|
|
|
101 |
|
|
return self.__vtk_point_source.GetOutput() |
102 |
|
|
|
103 |
jongui |
1148 |
def _isPointSourceCenterSet(self): |
104 |
ksteube |
1147 |
""" |
105 |
jongui |
1148 |
Return whether the center has been specified. |
106 |
ksteube |
1147 |
|
107 |
jongui |
1148 |
@rtype: Boolean |
108 |
|
|
@return: True or False |
109 |
ksteube |
1147 |
""" |
110 |
|
|
|
111 |
jongui |
1148 |
if(self.__center != None): |
112 |
|
|
return True |
113 |
|
|
else: |
114 |
|
|
return False |
115 |
ksteube |
1147 |
|
116 |
|
|
|
117 |
|
|
############################################################################## |
118 |
|
|
|
119 |
|
|
|
120 |
|
|
class MaskPoints: |
121 |
|
|
""" |
122 |
|
|
Class that defines the masking of points. It is possible to mask |
123 |
|
|
every n'th point. This is useful to prevent the rendered object |
124 |
|
|
from being cluttered with arrows or ellipsoids. |
125 |
|
|
""" |
126 |
|
|
|
127 |
jongui |
1148 |
def __init__(self): |
128 |
ksteube |
1147 |
""" |
129 |
|
|
Initialise the mask points. |
130 |
|
|
""" |
131 |
|
|
|
132 |
|
|
self.__vtk_mask_points = vtk.vtkMaskPoints() |
133 |
|
|
|
134 |
jongui |
1148 |
def _setupMaskPoints(self, object): |
135 |
ksteube |
1147 |
""" |
136 |
|
|
Setup the mask points. |
137 |
jongui |
1148 |
|
138 |
|
|
@type object: vtkDataSet (i.e. vtkUnstructuredGrid, etc) |
139 |
|
|
@param object: Data source from which to mask points |
140 |
ksteube |
1147 |
""" |
141 |
|
|
|
142 |
jongui |
1148 |
self.__object = object |
143 |
ksteube |
1147 |
self.__setInput() |
144 |
|
|
|
145 |
|
|
def __setInput(self): |
146 |
|
|
""" |
147 |
|
|
Set the input for the mask points. |
148 |
|
|
""" |
149 |
|
|
|
150 |
|
|
self.__vtk_mask_points.SetInput(self.__object) |
151 |
|
|
|
152 |
|
|
def setRatio(self, ratio): |
153 |
|
|
""" |
154 |
|
|
Mask every nth point. |
155 |
|
|
|
156 |
|
|
@type ratio: Number |
157 |
|
|
@param ratio: Masking ratio |
158 |
|
|
""" |
159 |
|
|
|
160 |
|
|
self.__vtk_mask_points.SetOnRatio(ratio) |
161 |
|
|
|
162 |
|
|
def randomOn(self): |
163 |
|
|
""" |
164 |
|
|
Enables the randomization of the points selected for masking. |
165 |
|
|
""" |
166 |
|
|
|
167 |
|
|
self.__vtk_mask_points.RandomModeOn() |
168 |
|
|
|
169 |
|
|
def randomOff(self): |
170 |
|
|
""" |
171 |
|
|
Disables the randomization of the points selected for masking. |
172 |
|
|
""" |
173 |
|
|
|
174 |
|
|
self.__vtk_mask_points.RandomModeOff() |
175 |
|
|
|
176 |
jongui |
1148 |
def _getMaskPointsOutput(self): |
177 |
ksteube |
1147 |
""" |
178 |
|
|
Return the output of the masked points. |
179 |
|
|
|
180 |
|
|
@rtype: vtkPolyData |
181 |
|
|
@return: Polygonal datda |
182 |
|
|
""" |
183 |
|
|
|
184 |
|
|
return self.__vtk_mask_points.GetOutput() |
185 |
|
|
|
186 |
|
|
|