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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2365 - (show annotations)
Mon Apr 6 01:25:25 2009 UTC (10 years, 4 months ago) by gross
File MIME type: text/x-python
File size: 5828 byte(s)
all tests passed under scons on 4 mpi processes with  openmpi on shake34
1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 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-2008 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 from esys.escript import getMPISizeWorld
34 if getMPISizeWorld()==1: import vtk
35
36 class Transform:
37 """
38 Class that defines the orientation of planes.
39
40 @attention: There is a difference between performing rotation first
41 followed by translation, and performing translation first followed
42 by rotation.
43
44 @attention: VTK's coordinate system and translation is NOT 100% precise.
45 Consequently, performing maximum rotation and translation can potentially
46 yield incorrect results. For instance, rotating a XY plane along the x-axis
47 90 degrees may NOT produce any results (as it is possible that the XY
48 plane has just fallen outside the visible range). Therefore, rotating the
49 XY plane 89.9 degrees instead, should be a better option in order to
50 produce the correct results.
51 """
52
53 def __init__(self):
54 """
55 Initialise the transform object.
56 """
57 if getMPISizeWorld()>1:
58 raise ValueError,"pyvisi.Transform is not running on more than one processor."
59 # NOTE: VTK's coordinates are not 100% precise. The origin is not
60 # exaclty (0,0,0) and the normal is not exactly (0, 0, 1). There is a
61 # slight variance. As a result, a slight alteration has to be done
62 # in order for the plane to be displayed correctly. Otherwise, the
63 # plane may just fall outside the bounding box and nothing
64 # is displayed.
65 self.__OFFSET_VARIANCE = 0.0000000001
66 self.__vtk_transform = vtk.vtkTransform()
67
68 def translate(self, x_offset, y_offset, z_offset):
69 """
70 Translate the rendered object along the x, y and z-axes.
71
72 @type x_offset: Number
73 @param x_offset: Amount to translate along the x-axis
74 @type y_offset: Number
75 @param y_offset: Amount to translate along the y-axis
76 @type z_offset: Number
77 @param z_offset: Amount to translate along the z-axis
78 """
79
80 self.__vtk_transform.Translate(-x_offset, -y_offset, -z_offset)
81
82 def rotateX(self, angle):
83 """
84 Rotate the plane along the x-axis.
85
86 @type angle: Number
87 @param angle: Angle to rotate the plane
88 """
89
90 self.__vtk_transform.RotateX(-angle)
91
92 def rotateY(self, angle):
93 """
94 Rotate the plane along the y-axis.
95
96 @type angle: Number
97 @param angle: Angle to rotate the plane
98 """
99
100 self.__vtk_transform.RotateY(angle)
101
102 def rotateZ(self, angle):
103 """
104 Rotate the plane along the z-axis.
105
106 @type angle: Number
107 @param angle: Angle to rotate the plane
108 """
109
110 self.__vtk_transform.RotateZ(angle)
111
112 def setPlaneToXY(self, offset = 0):
113 """
114 Set the plane orthogonal to the z-axis.
115
116 @type offset: Number
117 @param offset: Amount to translate along the z-axis
118 """
119
120 self.translate(0, 0, offset + self.__OFFSET_VARIANCE)
121
122 def setPlaneToYZ(self, offset = 0):
123 """
124 Set the plane orthogonal to the x-axis.
125
126 @type offset: Number
127 @param offset: Amount to translate along the x-axis
128 """
129
130 # NOTE: rotateY must come first before translate. Otherwise,
131 # the output may be incorrect.
132 self.rotateY(90)
133 self.translate(offset, 0, 0)
134
135 def setPlaneToXZ(self, offset = 0):
136 """
137 Set the plane orthogonal to the y-axis.
138
139 @type offset: Number
140 @param offset: Amount to translate along the y-axis
141 """
142
143 # rotateX must come first before translate. Otherwise, it won't work.
144 self.rotateX(90)
145 self.translate(0, offset, 0)
146
147 def _getTransform(self):
148 """
149 Return the transform instance.
150
151 @rtype: vtkTransform
152 @return: Transform instance that is used to specify the orientation
153 of the plane
154 """
155
156 return self.__vtk_transform
157
158
159 ###############################################################################
160
161
162 class TransformFilter:
163 """
164 Class that defines a transform poly data filter.
165 """
166
167 def __init__(self):
168 """
169 Initialise the transoform poly data filter.
170 """
171 if getMPISizeWorld()>1:
172 raise ValueError,"pyvisi.TransformFilter is not running on more than one processor."
173 self.__vtk_transform_filter = vtk.vtkTransformPolyDataFilter()
174
175 def _setupTransformFilter(self, plane_source, transform):
176 """
177 Setup the transform filter.
178
179 @type plane_source: vtkPolyData
180 @param plane_source: Polygonal data
181 @type transform: L{Transform <transform.Transform>} object
182 @param transform: Specifies the orientation of the plane source
183 """
184
185 self.__plane_source = plane_source
186 self.__transform = transform
187
188 self.__setInput()
189 self.__setTransform()
190
191 def __setInput(self):
192 """
193 Set the input for the transform poly data filter.
194 """
195
196 self.__vtk_transform_filter.SetInput(self.__plane_source)
197
198 def __setTransform(self):
199 """
200 Set the transformation of the plane source.
201 """
202
203 self.__vtk_transform_filter.SetTransform(self.__transform)
204
205 def _getTransformFilterOutput(self):
206 """
207 Return the output of the transform poly data filter.
208 """
209
210 return self.__vtk_transform_filter.GetOutput()
211
212
213

  ViewVC Help
Powered by ViewVC 1.1.26