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