/[escript]/branches/windows_from_1456_trunk_merge_to_1459_trunk/pyvisi/py_src/transform.py
ViewVC logotype

Contents of /branches/windows_from_1456_trunk_merge_to_1459_trunk/pyvisi/py_src/transform.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1461 - (show annotations)
Fri Mar 28 07:51:34 2008 UTC (12 years, 11 months ago) by trankine
File MIME type: text/x-python
File size: 5092 byte(s)
get the name right
1 """
2 @var __author__: name of author
3 @var __copyright__: copyrights
4 @var __license__: licence agreement
5 @var __url__: url entry point on documentation
6 @var __version__: version
7 @var __date__: date of the version
8 """
9
10 __author__="John Ngui, john.ngui@uq.edu.au"
11 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
12 http://www.access.edu.au
13 Primary Business: Queensland, Australia"""
14 __license__="""Licensed under the Open Software License version 3.0
15 http://www.opensource.org/licenses/osl-3.0.php"""
16 __url__="http://www.iservo.edu.au/esys"
17 __version__="$Revision$"
18 __date__="$Date$"
19
20
21 import vtk
22
23 class Transform:
24 """
25 Class that defines the orientation of planes.
26
27 @attention: There is a difference between performing rotation first
28 followed by translation, and performing translation first followed
29 by rotation.
30
31 @attention: VTK's coordinate system and translation is NOT 100% precise.
32 Consequently, performing maximum rotation and translation can potentially
33 yield incorrect results. For instance, rotating a XY plane along the x-axis
34 90 degrees may NOT produce any results (as it is possible that the XY
35 plane has just fallen outside the visible range). Therefore, rotating the
36 XY plane 89.9 degrees instead, should be a better option in order to
37 produce the correct results.
38 """
39
40 def __init__(self):
41 """
42 Initialise the transform object.
43 """
44
45 # NOTE: VTK's coordinates are not 100% precise. The origin is not
46 # exaclty (0,0,0) and the normal is not exactly (0, 0, 1). There is a
47 # slight variance. As a result, a slight alteration has to be done
48 # in order for the plane to be displayed correctly. Otherwise, the
49 # plane may just fall outside the bounding box and nothing
50 # is displayed.
51 self.__OFFSET_VARIANCE = 0.0000000001
52 self.__vtk_transform = vtk.vtkTransform()
53
54 def translate(self, x_offset, y_offset, z_offset):
55 """
56 Translate the rendered object along the x, y and z-axes.
57
58 @type x_offset: Number
59 @param x_offset: Amount to translate along the x-axis
60 @type y_offset: Number
61 @param y_offset: Amount to translate along the y-axis
62 @type z_offset: Number
63 @param z_offset: Amount to translate along the z-axis
64 """
65
66 self.__vtk_transform.Translate(-x_offset, -y_offset, -z_offset)
67
68 def rotateX(self, angle):
69 """
70 Rotate the plane along the x-axis.
71
72 @type angle: Number
73 @param angle: Angle to rotate the plane
74 """
75
76 self.__vtk_transform.RotateX(-angle)
77
78 def rotateY(self, angle):
79 """
80 Rotate the plane along the y-axis.
81
82 @type angle: Number
83 @param angle: Angle to rotate the plane
84 """
85
86 self.__vtk_transform.RotateY(angle)
87
88 def rotateZ(self, angle):
89 """
90 Rotate the plane along the z-axis.
91
92 @type angle: Number
93 @param angle: Angle to rotate the plane
94 """
95
96 self.__vtk_transform.RotateZ(angle)
97
98 def setPlaneToXY(self, offset = 0):
99 """
100 Set the plane orthogonal to the z-axis.
101
102 @type offset: Number
103 @param offset: Amount to translate along the z-axis
104 """
105
106 self.translate(0, 0, offset + self.__OFFSET_VARIANCE)
107
108 def setPlaneToYZ(self, offset = 0):
109 """
110 Set the plane orthogonal to the x-axis.
111
112 @type offset: Number
113 @param offset: Amount to translate along the x-axis
114 """
115
116 # NOTE: rotateY must come first before translate. Otherwise,
117 # the output may be incorrect.
118 self.rotateY(90)
119 self.translate(offset, 0, 0)
120
121 def setPlaneToXZ(self, offset = 0):
122 """
123 Set the plane orthogonal to the y-axis.
124
125 @type offset: Number
126 @param offset: Amount to translate along the y-axis
127 """
128
129 # rotateX must come first before translate. Otherwise, it won't work.
130 self.rotateX(90)
131 self.translate(0, offset, 0)
132
133 def _getTransform(self):
134 """
135 Return the transform instance.
136
137 @rtype: vtkTransform
138 @return: Transform instance that is used to specify the orientation
139 of the plane
140 """
141
142 return self.__vtk_transform
143
144
145 ###############################################################################
146
147
148 class TransformFilter:
149 """
150 Class that defines a transform poly data filter.
151 """
152
153 def __init__(self):
154 """
155 Initialise the transoform poly data filter.
156 """
157
158 self.__vtk_transform_filter = vtk.vtkTransformPolyDataFilter()
159
160 def _setupTransformFilter(self, plane_source, transform):
161 """
162 Setup the transform filter.
163
164 @type plane_source: vtkPolyData
165 @param plane_source: Polygonal data
166 @type transform: L{Transform <transform.Transform>} object
167 @param transform: Specifies the orientation of the plane source
168 """
169
170 self.__plane_source = plane_source
171 self.__transform = transform
172
173 self.__setInput()
174 self.__setTransform()
175
176 def __setInput(self):
177 """
178 Set the input for the transform poly data filter.
179 """
180
181 self.__vtk_transform_filter.SetInput(self.__plane_source)
182
183 def __setTransform(self):
184 """
185 Set the transformation of the plane source.
186 """
187
188 self.__vtk_transform_filter.SetTransform(self.__transform)
189
190 def _getTransformFilterOutput(self):
191 """
192 Return the output of the transform poly data filter.
193 """
194
195 return self.__vtk_transform_filter.GetOutput()
196
197
198

  ViewVC Help
Powered by ViewVC 1.1.26