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

Contents of /trunk/pyvisi/py_src/plane.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2344 - (show annotations)
Mon Mar 30 02:13:58 2009 UTC (10 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 4588 byte(s)
Change __url__ to launchpad site

1
2 ########################################################
3 #
4 # Copyright (c) 2003-2008 by University of Queensland
5 # Earth Systems Science Computational Center (ESSCC)
6 # http://www.uq.edu.au/esscc
7 #
8 # Primary Business: Queensland, Australia
9 # Licensed under the Open Software License version 3.0
10 # http://www.opensource.org/licenses/osl-3.0.php
11 #
12 ########################################################
13
14 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15 Earth Systems Science Computational Center (ESSCC)
16 http://www.uq.edu.au/esscc
17 Primary Business: Queensland, Australia"""
18 __license__="""Licensed under the Open Software License version 3.0
19 http://www.opensource.org/licenses/osl-3.0.php"""
20 __url__="https://launchpad.net/escript-finley"
21
22 """
23 @var __author__: name of author
24 @var __copyright__: copyrights
25 @var __license__: licence agreement
26 @var __url__: url entry point on documentation
27 @var __version__: version
28 @var __date__: date of the version
29 """
30
31 __author__="John Ngui, john.ngui@uq.edu.au"
32
33
34 import vtk
35 from position import GlobalPosition
36 from esys.escript import getMPISizeWorld
37
38 class Plane:
39 """
40 Class that defines a plane that cuts or clips rendered objects.
41 """
42
43 def __init__(self):
44 """
45 Initialise the plane.
46 """
47 if getMPISizeWorld()>1:
48 raise ValueError,"pyvisi.Plane is not running on more than one processor."
49 self.__vtk_plane = vtk.vtkPlane()
50
51 def _setupPlane(self, transform):
52 """
53 Setup the plane.
54
55 @type transform: L{Transform <transform.Transform>} object
56 @param transform: Specifies the orientation of the plane
57 """
58
59 self.__transform = transform
60
61 # Default origin of the of the plane is (0,0,0).
62 self.__setOrigin(GlobalPosition(0,0,0))
63 # Default normal of the plane is parrallel to the z-axis.
64 self.__setNormal(GlobalPosition(0, 0, 1))
65 self.__setTransform()
66
67 def __setOrigin(self, position):
68 """
69 Set the origin of the plane.
70
71 @type position: L{GlobalPosition <position.GlobalPosition>} object
72 @param position: Origin of the plane
73 """
74 self.__vtk_plane.SetOrigin(position._getGlobalPosition())
75
76 def __setNormal(self, position):
77 """
78 Set the normal of the plane.
79
80 @type position: L{GlobalPosition <position.GlobalPosition>} object
81 @param position: Normal of the plane
82 """
83
84 self.__vtk_plane.SetNormal(position._getGlobalPosition())
85
86 def __setTransform(self):
87 """
88 Set the transformation of the plane.
89 """
90
91 self.__vtk_plane.SetTransform(self.__transform)
92
93 def _getPlane(self):
94 """
95 Return the plane.
96
97 @rtype: vtkPlane
98 @return: Plane that cuts through rendered objects
99 """
100
101 return self.__vtk_plane
102
103
104 ###############################################################################
105
106
107 class PlaneSource:
108 """
109 Class that defines a plane source.
110 """
111
112 def __init__(self):
113 """
114 Initialise the plane source. A plane source is defined by an origin
115 and two other points, which form the axes (X and Y). By default the
116 origin is set to (0, 0, 0) and the two points are set to (1, 0, 0)
117 and (0, 1, 0).
118 """
119 if getMPISizeWorld()>1:
120 raise ValueError,"pyvisi.PlaneSource is not running on more than one processor."
121 self.__vtk_plane_source = vtk.vtkPlaneSource()
122 # Default origin of the plane source is (0, 0, 0).
123 self.__setOrigin(GlobalPosition(0, 0, 0))
124 # Default position of the two point from the origin is (1, 0, 0) and
125 # (0, 1, 0).
126 self.setPoint1(GlobalPosition(1, 0, 0))
127 self.setPoint2(GlobalPosition(0, 1, 0))
128
129 def __setOrigin(self, position):
130 """
131 Set the origin of the plane source.
132
133 @type position: L{GlobalPosition <position.GlobalPosition>} object
134 @param position: Plane source origin
135 """
136
137 self.__vtk_plane_source.SetOrigin(position._getGlobalPosition())
138
139 def setPoint1(self, position):
140 """
141 Set the first point from the origin of the plane source.
142
143 @type position: L{GlobalPosition <position.GlobalPosition>} object
144 @param position: Position of the first axis of the plane source
145 """
146
147 self.__vtk_plane_source.SetPoint1(position._getGlobalPosition())
148
149 def setPoint2(self, position):
150 """
151 Set the second point from the origin of the plane source.
152
153 @type position: L{GlobalPosition <position.GlobalPosition>} object
154 @param position: Position of the second axis of the plane source
155 """
156
157 self.__vtk_plane_source.SetPoint2(position._getGlobalPosition())
158
159 def _getPlaneSourceOutput(self):
160 """
161 Return the output of the plane source.
162
163 @rtype: vtkPolyData
164 @return: Polygonal data
165 """
166
167 return self.__vtk_plane_source.GetOutput()
168

  ViewVC Help
Powered by ViewVC 1.1.26