/[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 1809 - (show annotations)
Thu Sep 25 06:43:44 2008 UTC (11 years, 2 months ago) by ksteube
File MIME type: text/x-python
File size: 5485 byte(s)
Copyright updated in all python files

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

  ViewVC Help
Powered by ViewVC 1.1.26