/[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 949 - (hide annotations)
Fri Feb 2 05:33:05 2007 UTC (12 years, 5 months ago) by jongui
File MIME type: text/x-python
File size: 2664 byte(s)
Fixed some more bugs and added more epydocs. Testing remains outstanding.
1 jongui 943 """
2     @author: John NGUI
3     """
4    
5     import vtk
6    
7     class Transform:
8     """
9 jongui 949 Class that defines the orientation of planes.
10 jongui 943 """
11    
12     def __init__(self):
13     """
14     Initialise the transform object.
15     """
16    
17 jongui 949 # NOTE: VTK's values are not 100% accurate. Origin is not exaclty
18     #(0,0,0) and normal is not exactly (0, 0, 1). There is a slight
19 jongui 943 # variance. As a result, a slight alteration has to be done in order
20 jongui 949 # for the plane to be displayed correctly. Otherwise, the
21     # plane may just fall outside the bounding box and nothing
22 jongui 943 # 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 jongui 949
30 jongui 943 @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 jongui 949 Rotate the plane along the x-axis.
43    
44 jongui 943 @type angle: Number
45     @param angle: Angle to rotate the camera
46     """
47    
48     self.__vtk_transform.RotateX(-angle)
49    
50     def rotateY(self, angle):
51     """
52 jongui 949 Rotate the plane along the y-axis.
53    
54 jongui 943 @type angle: Number
55     @param angle: Angle to rotate the camera
56     """
57    
58     self.__vtk_transform.RotateY(angle)
59    
60    
61     def rotateZ(self, angle):
62     """
63 jongui 949 Rotate the plane along the z-axis.
64    
65 jongui 943 @type angle: Number
66     @param angle: Angle to rotate the camera
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 jongui 949
75 jongui 943 @type offset: Number
76 jongui 949 @param offset: Amount to translate along the z-axis
77 jongui 943 """
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 jongui 949
85 jongui 943 @type offset: Number
86 jongui 949 @param offset: Amount to translate along the x-axis
87 jongui 943 """
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 jongui 949
98 jongui 943 @type offset: Number
99 jongui 949 @param offset: Amount to translate along the y-axis
100 jongui 943 """
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 jongui 949
110 jongui 943 @rtype: vtkTransform
111 jongui 949 @return: Transform instance that is used to specify the orientation
112     of the plane
113 jongui 943 """
114    
115     return self.__vtk_transform

  ViewVC Help
Powered by ViewVC 1.1.26