/[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 2881 - (show annotations)
Thu Jan 28 02:03:15 2010 UTC (11 years, 1 month ago) by jfenwick
File MIME type: text/x-python
File size: 4780 byte(s)
Don't panic.
Updating copyright stamps

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2010 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 :var __author__: name of author
24 :var __copyright__: copyrights
25 :var __license__: licence agreement
26 :var __url__: url entry point on documentation
27 :var __version__: version
28 :var __date__: date of the version
29 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33
34 from position import GlobalPosition
35 from esys.escript import getMPISizeWorld
36 if getMPISizeWorld()==1: import vtk
37
38 class PointSource:
39 """
40 Class that defines the source (location) to generate points. The points are
41 generated within the radius of a sphere.
42 """
43
44 def __init__(self):
45 """
46 Initialise the point source.
47 """
48 if getMPISizeWorld()>1:
49 raise ValueError,"pyvisi.PointSource is not running on more than one processor."
50 self.__vtk_point_source = vtk.vtkPointSource()
51 self.__center = None
52
53 def _setupPointSource(self, object):
54 """
55 Setup the point source.
56
57 :type object: vtkPolyData, etc
58 :param object: Used to define the location of the sphere
59 """
60
61 self.__object = object
62
63 # Default number of points to generate within the sphere is 10.
64 self.setPointSourceNumberOfPoints(10)
65 # Default radius of the sphere is 0.5.
66 self.setPointSourceRadius(0.5)
67
68 def setPointSourceRadius(self, radius):
69 """
70 Set the radius of the sphere.
71
72 :type radius: Number
73 :param radius: Radius of the sphere
74 """
75
76 self.__vtk_point_source.SetRadius(radius)
77
78 # This method is used to delay the execution of setting the point source
79 # center.
80 def setPointSourceCenter(self, center):
81 """
82 Specity the sphere's center.
83
84 :type center: `GlobalPosition` object
85 :param center: Center of the sphere
86 """
87
88 self.__center = center
89
90 def _setPointSourceCenter(self):
91 """
92 Set the sphere's center.
93 """
94
95 self.__vtk_point_source.SetCenter(self.__center._getGlobalPosition())
96
97 def setPointSourceNumberOfPoints(self, points):
98 """
99 Set the number of points to generate within the sphere (the larger the
100 number of points, the more streamlines are generated)
101
102 :type points: Number
103 :param points: Number of points to generate
104 """
105
106 self.__vtk_point_source.SetNumberOfPoints(points)
107
108 def _getPointSourceOutput(self):
109 """
110 Return the output of the point source.
111
112 :rtype: vtkPolyData
113 :return: Polygonal data
114 """
115
116 return self.__vtk_point_source.GetOutput()
117
118 def _isPointSourceCenterSet(self):
119 """
120 Return whether the center has been specified.
121
122 :rtype: Boolean
123 :return: True or False
124 """
125
126 if(self.__center != None):
127 return True
128 else:
129 return False
130
131
132 ##############################################################################
133
134
135 class MaskPoints:
136 """
137 Class that defines the masking of points
138 every n'th point. This is useful to prevent the rendered object
139 from being cluttered with arrows or ellipsoids.
140 """
141
142 def __init__(self):
143 """
144 Initialise the mask points.
145 """
146 if getMPISizeWorld()>1:
147 raise ValueError,"pyvisi.MaskPoints is not running on more than one processor."
148 self.__vtk_mask_points = vtk.vtkMaskPoints()
149
150 def _setupMaskPoints(self, object):
151 """
152 Setup the mask points.
153
154 :type object: vtkDataSet (i.e. vtkUnstructuredGrid, etc)
155 :param object: Data source from which to mask points
156 """
157
158 self.__object = object
159 self.__setInput()
160
161 def __setInput(self):
162 """
163 Set the input for the mask points.
164 """
165
166 self.__vtk_mask_points.SetInput(self.__object)
167
168 def setRatio(self, ratio):
169 """
170 Mask every n'th point.
171
172 :type ratio: Number
173 :param ratio: Masking ratio
174 """
175
176 self.__vtk_mask_points.SetOnRatio(ratio)
177
178 def randomOn(self):
179 """
180 Enables the randomization of the points selected for masking.
181 """
182
183 self.__vtk_mask_points.RandomModeOn()
184
185 def randomOff(self):
186 """
187 Disables the randomization of the points selected for masking.
188 """
189
190 self.__vtk_mask_points.RandomModeOff()
191
192 def _getMaskPointsOutput(self):
193 """
194 Return the output of the masked points.
195
196 :rtype: vtkPolyData
197 :return: Polygonal datda
198 """
199
200 return self.__vtk_mask_points.GetOutput()
201
202

  ViewVC Help
Powered by ViewVC 1.1.26