1 |
""" |
2 |
@author: John NGUI |
3 |
""" |
4 |
|
5 |
import vtk |
6 |
from position import GlobalPosition |
7 |
|
8 |
class Plane: |
9 |
""" |
10 |
Class that defines a plane that cuts/clips rendered objects. |
11 |
""" |
12 |
|
13 |
def __init__(self, transform): |
14 |
""" |
15 |
Initialise the plane. |
16 |
|
17 |
@type transform: L{Transform <transform.Transform>} object |
18 |
@param transform: Specifies the orientation of the plane |
19 |
""" |
20 |
|
21 |
self.__transform = transform |
22 |
self.__vtk_plane = vtk.vtkPlane() |
23 |
self.__setupPlane() |
24 |
|
25 |
def __setupPlane(self): |
26 |
""" |
27 |
Setup the plane. |
28 |
""" |
29 |
|
30 |
# Default origin of the of the plane is (0,0,0). |
31 |
self.__setOrigin(GlobalPosition(0,0,0)) |
32 |
# Default normal of the plane is parrallel to the z-axis. |
33 |
self.__setNormal(GlobalPosition(0, 0, 1)) |
34 |
self.__setTransform() |
35 |
|
36 |
def __setOrigin(self, position): |
37 |
""" |
38 |
Set the origin of the plane. |
39 |
|
40 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
41 |
@param position: Origin of the plane |
42 |
""" |
43 |
self.__vtk_plane.SetOrigin(position._getGlobalPosition()) |
44 |
|
45 |
def __setNormal(self, position): |
46 |
""" |
47 |
Set the normal of the plane. |
48 |
|
49 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
50 |
@param position: Normal of the plane |
51 |
""" |
52 |
|
53 |
self.__vtk_plane.SetNormal(position._getGlobalPosition()) |
54 |
|
55 |
def __setTransform(self): |
56 |
""" |
57 |
Set the transformation of the plane. |
58 |
""" |
59 |
|
60 |
self.__vtk_plane.SetTransform(self.__transform) |
61 |
|
62 |
def _getPlane(self): |
63 |
""" |
64 |
Return the plane. |
65 |
|
66 |
@rtype: vtkPlane |
67 |
@return: Plane that cuts through rendered objects |
68 |
""" |
69 |
|
70 |
return self.__vtk_plane |
71 |
|
72 |
|
73 |
############################################################################### |
74 |
|
75 |
|
76 |
class PlaneSource: |
77 |
""" |
78 |
Class that defines a plane source. |
79 |
""" |
80 |
|
81 |
def __init__(self): |
82 |
""" |
83 |
Initialise the plane source. A plane source is defined by an origin |
84 |
and two other points, which form the axes. By default the origin is |
85 |
set to (0, 0, 0) and the two points are set to (1, 0, 0) and (0, 1, 0). |
86 |
""" |
87 |
|
88 |
self.__vtk_plane_source = vtk.vtkPlaneSource() |
89 |
# Default origin of the plane source is (0, 0, 0). |
90 |
self.__setOrigin(GlobalPosition(0, 0, 0)) |
91 |
# Default position of the two point from the origin is (1, 0, 0) and |
92 |
# (0, 1, 0). |
93 |
self.setPoint1(GlobalPosition(1, 0, 0)) |
94 |
self.setPoint2(GlobalPosition(0, 1, 0)) |
95 |
|
96 |
def __setOrigin(self, position): |
97 |
""" |
98 |
Set the origin of the plane source. |
99 |
|
100 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
101 |
@param position: Plane source origin |
102 |
""" |
103 |
|
104 |
self.__vtk_plane_source.SetOrigin(position._getGlobalPosition()) |
105 |
|
106 |
def setPoint1(self, position): |
107 |
""" |
108 |
Set the first point from the origin of the plane source. |
109 |
|
110 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
111 |
@param position: Position of the first axis of the plane source |
112 |
""" |
113 |
|
114 |
self.__vtk_plane_source.SetPoint1(position._getGlobalPosition()) |
115 |
|
116 |
def setPoint2(self, position): |
117 |
""" |
118 |
Set the second point from the origin of the plane source. |
119 |
|
120 |
@type position: L{GlobalPosition <position.GlobalPosition>} object |
121 |
@param position: Position of the second axis of the plane source |
122 |
""" |
123 |
|
124 |
self.__vtk_plane_source.SetPoint2(position._getGlobalPosition()) |
125 |
|
126 |
|
127 |
def _getOutput(self): |
128 |
""" |
129 |
Return the output of the plane source. |
130 |
|
131 |
@rtype: vtkPolyData |
132 |
@return: Polygonal data |
133 |
""" |
134 |
|
135 |
return self.__vtk_plane_source.GetOutput() |
136 |
|