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 |
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 |
def __init__(self): |
31 |
""" |
32 |
Initialise the point source. |
33 |
""" |
34 |
|
35 |
self.__vtk_point_source = vtk.vtkPointSource() |
36 |
self.__center = None |
37 |
|
38 |
def _setupPointSource(self, object): |
39 |
""" |
40 |
Setup the point source. |
41 |
|
42 |
@type object: vtkPolyData, etc |
43 |
@param object: Used to define the location of the sphere |
44 |
""" |
45 |
|
46 |
self.__object = object |
47 |
|
48 |
# 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 |
# This method is used to delay the execution of setting the point source |
64 |
# center. |
65 |
def setPointSourceCenter(self, center): |
66 |
""" |
67 |
Specity the sphere's center. |
68 |
|
69 |
@type center: L{GLobalPosition <position.GlobalPosition>} object |
70 |
@param center: Center of the sphere |
71 |
""" |
72 |
|
73 |
self.__center = center |
74 |
|
75 |
def _setPointSourceCenter(self): |
76 |
""" |
77 |
Set the sphere's center. |
78 |
""" |
79 |
|
80 |
self.__vtk_point_source.SetCenter(self.__center._getGlobalPosition()) |
81 |
|
82 |
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 |
def _getPointSourceOutput(self): |
94 |
""" |
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 |
def _isPointSourceCenterSet(self): |
104 |
""" |
105 |
Return whether the center has been specified. |
106 |
|
107 |
@rtype: Boolean |
108 |
@return: True or False |
109 |
""" |
110 |
|
111 |
if(self.__center != None): |
112 |
return True |
113 |
else: |
114 |
return False |
115 |
|
116 |
|
117 |
############################################################################## |
118 |
|
119 |
|
120 |
class MaskPoints: |
121 |
""" |
122 |
Class that defines the masking of points |
123 |
every n'th point. This is useful to prevent the rendered object |
124 |
from being cluttered with arrows or ellipsoids. |
125 |
""" |
126 |
|
127 |
def __init__(self): |
128 |
""" |
129 |
Initialise the mask points. |
130 |
""" |
131 |
|
132 |
self.__vtk_mask_points = vtk.vtkMaskPoints() |
133 |
|
134 |
def _setupMaskPoints(self, object): |
135 |
""" |
136 |
Setup the mask points. |
137 |
|
138 |
@type object: vtkDataSet (i.e. vtkUnstructuredGrid, etc) |
139 |
@param object: Data source from which to mask points |
140 |
""" |
141 |
|
142 |
self.__object = object |
143 |
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 n'th 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 |
def _getMaskPointsOutput(self): |
177 |
""" |
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 |
|