/[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 1029 - (show annotations)
Wed Mar 14 05:01:13 2007 UTC (12 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 3767 byte(s)
Fixed problems in relation to updates propagating when multiple files/sources are read.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6
7 class Transform:
8 """
9 Class that defines the orientation of planes.
10 """
11
12 def __init__(self):
13 """
14 Initialise the transform object.
15 """
16
17 # NOTE: VTK's coordinates are not 100% accurate. The origin is not
18 # exaclty (0,0,0) and the normal is not exactly (0, 0, 1). There is a
19 # slight variance. As a result, a slight alteration has to be done
20 # in order for the plane to be displayed correctly. Otherwise, the
21 # plane may just fall outside the bounding box and nothing
22 # is displayed.
23 self.__OFFSET_VARIANCE = 0.0000000001
24 self.__vtk_transform = vtk.vtkTransform()
25
26 def translate(self, x_offset, y_offset, z_offset):
27 """
28 Translate the rendered object along the x, y and z-axes.
29
30 @type x_offset: Number
31 @param x_offset: Amount to translate along the x-axis
32 @type y_offset: Number
33 @param y_offset: Amount to translate along the y-axis
34 @type z_offset: Number
35 @param z_offset: Amount to translate along the z-axis
36 """
37
38 self.__vtk_transform.Translate(-x_offset, -y_offset, -z_offset)
39
40 def rotateX(self, angle):
41 """
42 Rotate the plane along the x-axis.
43
44 @type angle: Number
45 @param angle: Angle to rotate the plane
46 """
47
48 self.__vtk_transform.RotateX(-angle)
49
50 def rotateY(self, angle):
51 """
52 Rotate the plane along the y-axis.
53
54 @type angle: Number
55 @param angle: Angle to rotate the plane
56 """
57
58 self.__vtk_transform.RotateY(angle)
59
60
61 def rotateZ(self, angle):
62 """
63 Rotate the plane along the z-axis.
64
65 @type angle: Number
66 @param angle: Angle to rotate the plane
67 """
68
69 self.__vtk_transform.RotateZ(angle)
70
71 def setPlaneToXY(self, offset = 0):
72 """
73 Set the plane orthogonal to the z-axis.
74
75 @type offset: Number
76 @param offset: Amount to translate along the z-axis
77 """
78
79 self.translate(0, 0, offset + self.__OFFSET_VARIANCE)
80
81 def setPlaneToYZ(self, offset = 0):
82 """
83 Set the plane orthogonal to the x-axis.
84
85 @type offset: Number
86 @param offset: Amount to translate along the x-axis
87 """
88
89 # NOTE: rotateY must come first before translate. Otherwise,
90 # the output may be incorrect.
91 self.rotateY(90)
92 self.translate(offset, 0, 0)
93
94 def setPlaneToXZ(self, offset = 0):
95 """
96 Set the plane orthogonal to the y-axis.
97
98 @type offset: Number
99 @param offset: Amount to translate along the y-axis
100 """
101
102 # rotateX must come first before translate. Otherwise, it won't work.
103 self.rotateX(90)
104 self.translate(0, offset, 0)
105
106 def _getTransform(self):
107 """
108 Return the transform instance.
109
110 @rtype: vtkTransform
111 @return: Transform instance that is used to specify the orientation
112 of the plane
113 """
114
115 return self.__vtk_transform
116
117
118 ###############################################################################
119
120
121 class TransformFilter:
122 """
123 Class that defines a transform poly data filter.
124 """
125
126 def __init__(self, plane_source, transform):
127 """
128 Initialise the transoform poly data filter.
129
130 @type plane_source: vtkPolyData
131 @param plane_source: Polygonal data
132 @type transform: L{Transform <transform.Transform>} object
133 @param transform: Specifies the orientation of the plane source
134 """
135
136 self.__plane_source = plane_source
137 self.__transform = transform
138
139 self.__vtk_transform_filter = vtk.vtkTransformPolyDataFilter()
140
141 self._setInput()
142 self._setTransform()
143
144 def _setInput(self):
145 """
146 Set the input for the transform poly data filter.
147 """
148
149 self.__vtk_transform_filter.SetInput(self.__plane_source)
150
151 def _setTransform(self):
152 """
153 Set the transformation of the plane source.
154 """
155
156 self.__vtk_transform_filter.SetTransform(self.__transform)
157
158 def _getOutput(self):
159 """
160 Return the output of the transform poly data filter.
161 """
162
163 return self.__vtk_transform_filter.GetOutput()
164
165
166
167
168
169

  ViewVC Help
Powered by ViewVC 1.1.26