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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26