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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 946 - (hide annotations)
Wed Jan 31 03:08:04 2007 UTC (14 years, 9 months ago) by jongui
File MIME type: text/x-python
File size: 5195 byte(s)
added colouring option to use either scalar data or vector data.
1 jongui 943 """
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, object):
15     """
16     Initialise the point source.
17     """
18    
19     self.__object = object
20     self.__vtk_point_source = vtk.vtkPointSource()
21    
22     self.__setupPointSource()
23    
24     def __setupPointSource(self):
25     """
26     Setup the point source.
27     """
28    
29     # Default number of points to generate is 10.
30 jongui 946 self.setPointSourceNumberOfPoints(10)
31 jongui 943 # Default center is of the sphere is the center of the data object.
32     center = self.__object.GetCenter()
33 jongui 946 self.setPointSourceCenter(GlobalPosition(center[0], center[1], center[2]))
34     # Default radius of the sphere is 0.5.
35 jongui 943 self.setPointSourceRadius(0.1)
36     self.__vtk_point_source.Update()
37    
38     def setPointSourceRadius(self, radius):
39     """
40     Set the radius of the sphere.
41    
42     @type radius: Number
43     @param radius: Radius of the sphere
44     """
45    
46     self.__vtk_point_source.SetRadius(radius)
47    
48 jongui 946 def setPointSourceCenter(self, position):
49 jongui 943 """
50     Set the center of the sphere.
51    
52     @type position: L{GLobalPosition <position.GlobalPosition>} object
53     @param position: Center of the sphere
54     """
55    
56     self.__vtk_point_source.SetCenter(position._getGlobalPosition())
57    
58 jongui 946 def setPointSourceNumberOfPoints(self, points):
59 jongui 943 """
60 jongui 946 Set the number of points to generate within the sphere. The larger the
61     number of points, the more streamlines are generated.
62 jongui 943
63     @type points: Number
64     @param points: Number of points to generate
65     """
66    
67     self.__vtk_point_source.SetNumberOfPoints(points)
68    
69     def _getOutput(self):
70     """
71     Return the point source.
72    
73     @rtype: vtkPolyData
74     @return: Polygonal data
75     """
76    
77     return self.__vtk_point_source.GetOutput()
78    
79    
80     class StructuredPoints:
81     """
82     Class that defines the structured points.
83     """
84    
85 jongui 945 # NOTE: The algorithm of this class was extracted from Mayavi's
86     # online source code.
87 jongui 943 def __init__(self, object):
88     """
89     Initialise the structured points.
90    
91     @type object: vtkUnstructuredGrid, etc
92     @param object: Input for the structured points
93     """
94    
95     self.__object = object
96     self.__vtk_structured_points = vtk.vtkStructuredPoints()
97     self.__setupStructuredPoints()
98    
99     def __setupStructuredPoints(self):
100     """
101     Setup the structured points.
102     """
103    
104     b = self.__object.GetBounds()
105     self.__vtk_structured_points.SetOrigin(b[0], b[2], b[4])
106     self.__l = [b[1] - b[0], b[3] - b[2], b[5] - b[4]]
107     tot_len = float(self.__l[0] + self.__l[1] + self.__l[2])
108     npnt = pow(self.__object.GetNumberOfPoints(), 1. / 3.) + 0.5
109     self.__fac = 3.0*npnt / tot_len
110    
111     # Default dimension is 1, 1, 1.
112     self.setDimension(1, 1, 1)
113    
114     def __setExtent(self, x0, x1, y0, y1, z0, z1):
115     """
116     Set the extent in the order of x, y, z axes.
117    
118     @type x0: Index of the first point on the x-axis
119     @param x1: Index of the last point on the x-axis
120     @type y0: Index of the first point on the y-axis
121     @param y1: Index of the last point on the y-axis
122     @type z0: Index of the first point on the z-axis
123     @param z1: Index of the last point on the z-axis
124     """
125    
126     self.__vtk_structured_points.SetExtent(x0, x1, y0, y1, z0, z1)
127    
128     def __setUpdateExtent(self, x0, x1, y0, y1, z0, z1):
129     """
130     Set the update extent in the oder of x, y, z axes.
131    
132     @type x0: Number
133     @param x1: Index of the last point on the x-axis
134     @type y0: Number
135     @param y1: Index of the last point on the y-axis
136     @type z0: Number
137     @param z1: Index of the last point on the z-axis
138     """
139    
140     self.__vtk_structured_points.SetUpdateExtent(x0, x1, y0, y1, z0, z1)
141    
142     #def __setWholeExtent(self, x0, x1, y0, y1, z0, z1):
143     # self.__vtk_structured_points.SetWholeExtent(x0, x1, y0, y1, z0, z1)
144    
145     def setDimension(self, x, y, z):
146     """
147 jongui 945 Set the dimension (number of points) on the x, y and z axes. The
148     smaller the dimension, the more points are populated.
149 jongui 943
150     @type x: Number
151     @param x: Number of points on the x-axis
152     @type y: Number
153     @param y: Number of points on the y-axis
154     @type z: Number
155     @param z: Number of points on the z-axis
156     """
157    
158     self.__dims = [int((self.__l[0]*self.__fac)/x) + 1,
159     int((self.__l[1] * self.__fac) / y) + 1,
160     int((self.__l[2] * self.__fac) / z) + 1]
161    
162     self.__setExtent(0, self.__dims[0] - 1, 0, self.__dims[1] - 1, 0,
163     self.__dims[2] - 1)
164     self.__setUpdateExtent(0, self.__dims[0] - 1, 0, self.__dims[1] - 1, 0,
165     self.__dims[2] - 1)
166    
167     #self.__setWholeExtent(0, self.__dims[0] - 1, 0, self.__dims[1] - 1, 0,
168     # self.__dims[2] - 1)
169    
170     self.__vtk_structured_points.SetDimensions(self.__dims)
171     self.__setSpacing()
172    
173     def __setSpacing(self):
174     """
175     Set the spacing (width, height and length) of the cells that make up
176     the dataset.
177     """
178    
179     self.__dims = [max(1, x - 1) for x in self.__dims]
180     self.__l = [max(1e-3, x) for x in self.__l]
181     sp = [self.__l[0] / self.__dims[0], self.__l[1] / self.__dims[1],
182     self.__l[2] / self.__dims[2]]
183    
184     self.__vtk_structured_points.SetSpacing(sp)
185     # Update the changes made.
186     self.__vtk_structured_points.Update()
187    
188     def _getStructuredPoints(self):
189     """
190     Return the structured points.
191    
192     @rtype: vtkStructuredPoints
193     @return: Structured points
194     """
195    
196     return self.__vtk_structured_points
197    

  ViewVC Help
Powered by ViewVC 1.1.26