/[escript]/trunk/pyvisi/py_src/point.py
ViewVC logotype

Contents of /trunk/pyvisi/py_src/point.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1148 - (show annotations)
Wed May 16 22:45:33 2007 UTC (12 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 3486 byte(s)
Added the updated files for pyvisi and removed some incorrect reference images.
1 """
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 def __init__(self):
15 """
16 Initialise the point source.
17 """
18
19 self.__vtk_point_source = vtk.vtkPointSource()
20 self.__center = None
21
22 def _setupPointSource(self, object):
23 """
24 Setup the point source.
25
26 @type object: vtkPolyData, etc
27 @param object: Used to define the location of the sphere
28 """
29
30 self.__object = object
31
32 # 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 # This method is used to delay the execution of setting the point source
48 # center.
49 def setPointSourceCenter(self, center):
50 """
51 Save the sphere's center.
52
53 @type center: L{GLobalPosition <position.GlobalPosition>} object
54 @param center: Center of the sphere
55 """
56
57 self.__center = center
58
59 def _setPointSourceCenter(self):
60 """
61 Set the sphere's center.
62 """
63
64 self.__vtk_point_source.SetCenter(self.__center._getGlobalPosition())
65
66 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 def _getPointSourceOutput(self):
78 """
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 def _isPointSourceCenterSet(self):
88 """
89 Return whether the center has been specified.
90
91 @rtype: Boolean
92 @return: True or False
93 """
94
95 if(self.__center != None):
96 return True
97 else:
98 return False
99
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 def __init__(self):
112 """
113 Initialise the mask points.
114 """
115
116 self.__vtk_mask_points = vtk.vtkMaskPoints()
117
118 def _setupMaskPoints(self, object):
119 """
120 Setup the mask points.
121
122 @type object: vtkDataSet (i.e. vtkUnstructuredGrid, etc)
123 @param object: Data source from which to mask points
124 """
125
126 self.__object = object
127 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 def _getMaskPointsOutput(self):
161 """
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

  ViewVC Help
Powered by ViewVC 1.1.26