1 |
""" |
2 |
@author: John Ngui |
3 |
@author: Lutz Gross |
4 |
""" |
5 |
|
6 |
class Position: |
7 |
""" |
8 |
Class that defines the x, y and z coordinates of components. |
9 |
""" |
10 |
|
11 |
def __init__(self, x_coor, y_coor, z_coor): |
12 |
""" |
13 |
@type x_coor: Number |
14 |
@param x_coor: X coordinate |
15 |
@type y_coor: Number |
16 |
@param y_coor: Y coordinate |
17 |
@type z_coor: Number |
18 |
@param z_coor: Z coordinate |
19 |
""" |
20 |
|
21 |
self.x_coor = x_coor |
22 |
self.y_coor = y_coor |
23 |
self.z_coor = z_coor |
24 |
|
25 |
def getXCoor(self): |
26 |
""" |
27 |
Return the x coordinate. |
28 |
|
29 |
@rtype: Number |
30 |
@return: X coordinate |
31 |
""" |
32 |
return self.x_coor |
33 |
|
34 |
def getYCoor(self): |
35 |
""" |
36 |
Return the y coordinate. |
37 |
|
38 |
@rtype: Number |
39 |
@return: Y coordiante |
40 |
""" |
41 |
|
42 |
return self.y_coor |
43 |
|
44 |
def getZCoor(self): |
45 |
""" |
46 |
Return the z coordinate |
47 |
|
48 |
@rtype: Number |
49 |
@return: Z coordinate |
50 |
""" |
51 |
|
52 |
return self.z_coor |
53 |
|
54 |
import vtk |
55 |
|
56 |
class Transform: |
57 |
""" |
58 |
Class that defines the orientation of rendered objects. |
59 |
""" |
60 |
|
61 |
def __init__(self): |
62 |
self.vtk_transform = vtk.vtkTransform() |
63 |
# Set the transformation to occur after any transformations |
64 |
# represented by the current matrix. |
65 |
#self.vtk_transform.PostMultiply() |
66 |
|
67 |
def translate(self, x_offset, y_offset, z_offset): |
68 |
""" |
69 |
Translate the rendered object along the x, y and z-axes. |
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 rendered object along the x-axis. |
83 |
@type angle: Number |
84 |
@param angle: Angle to rotate the camera |
85 |
""" |
86 |
|
87 |
self.vtk_transform.RotateX(-angle) |
88 |
|
89 |
def rotateY(self, angle): |
90 |
""" |
91 |
Rotate the rendered object along the y-axis. |
92 |
@type angle: Number |
93 |
@param angle: Angle to rotate the camera |
94 |
""" |
95 |
|
96 |
self.vtk_transform.RotateY(angle) |
97 |
|
98 |
def rotateZ(self, angle): |
99 |
""" |
100 |
Rotate the rendered object along the z-axis. |
101 |
@type angle: Number |
102 |
@param angle: Angle to rotate the camera |
103 |
""" |
104 |
|
105 |
self.vtk_transform.RotateZ(angle) |
106 |
|
107 |
def xyPlane(self, offset = 0): |
108 |
""" |
109 |
Set the plane orthogonal to the z-axis. |
110 |
@type offset: Number |
111 |
@param offset: Amount to translate |
112 |
""" |
113 |
|
114 |
self.translate(0, 0, offset) |
115 |
|
116 |
def yzPlane(self, offset = 0): |
117 |
""" |
118 |
Set the plane orthogonal to the x-axis. |
119 |
@type offset: Number |
120 |
@param offset: Amount to translate |
121 |
""" |
122 |
|
123 |
# rotateY must come first before translate. Otherwise, it won't work. |
124 |
self.rotateY(89.9) |
125 |
self.translate(offset, 0, 0) |
126 |
|
127 |
def xzPlane(self, offset = 0): |
128 |
""" |
129 |
Set the plane orthogonal to the y-axis. |
130 |
@type offset: Number |
131 |
@param offset: Amount to translate |
132 |
""" |
133 |
|
134 |
# rotateX must come first before translate. Otherwise, it won't work. |
135 |
self.rotateX(89.9) |
136 |
self.translate(0, offset, 0) |
137 |
|
138 |
def getTransform(self): |
139 |
""" |
140 |
Return the transform instance. |
141 |
@rtype: vtkTransform |
142 |
@return: VTK transform that is used to specify the orientation |
143 |
of objects |
144 |
""" |
145 |
|
146 |
return self.vtk_transform |