/[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 889 - (show annotations)
Tue Nov 7 23:42:31 2006 UTC (14 years, 3 months ago) by jongui
File MIME type: text/x-python
File size: 5500 byte(s)
drivers added
1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 import vtk
7 from common import Common
8 from geo import Position
9
10 class Plane(Common):
11 """
12 Class that performs cutting and clipping using a plane
13 as its implicit function.
14 """
15
16 def __init__(self, scene, data_collector, component, transform, lut, mode):
17 """
18 @type scene: L{Scene <scene.Scene>} object
19 @param scene: Scene in which components are to be added to
20 @type data_collector: L{DataCollector <datacollector.DataCollector>}
21 object
22 @param data_collector: Source of data for visualization
23 @type component: String
24 @param component: Component to be cut using the plane
25 @type transform: L{Transform <geo.Transform>} object
26 @param transform: Orientation of the plane
27 @type lut: L{BlueToRed <colormap.BlueToRed>} or
28 L{RedToBlue <colormap.RedToBlue>} object
29 @param lut: Lookup table to be used by the mapper
30 """
31
32 Common.__init__(self, scene, data_collector)
33 if(mode == "Cut" or mode == "Clip"):
34 self.vtk_plane = vtk.vtkPlane()
35 self.transform = transform.getTransform()
36 self.setPlane()
37
38 # Convert unstructured grid data to polygonal data.
39 #vtk_geometry = vtk.vtkGeometryFilter()
40 #vtk_geometry.SetInput(component)
41
42 if(mode == "Cut"): # Executed only when cutting is performed.
43 self.vtk_cutter = vtk.vtkCutter()
44 self.setCutter(component)
45 Common.setMapperInput(self, self.vtk_cutter.GetOutput(), lut)
46 elif(mode == "Clip"): # Executed only when clipping is performed.
47 #self.vtk_clipper = vtk.vtkClipPolyData()
48 self.vtk_clipper = vtk.vtkClipDataSet()
49 #self.setClipper(vtk_geometry.GetOutput())
50 self.setClipper(component)
51 Common.setMapperInput(self, self.vtk_clipper.GetOutput(), lut)
52 elif(mode == "ScalarClip"): # Executed only for scalar clipping
53 self.vtk_clipper = vtk.vtkClipDataSet()
54 self.vtk_clipper.SetInput(component)
55 self.setInsideOutOn()
56 Common.setMapperInput(self, self.vtk_clipper.GetOutput(), lut)
57
58 Common.setActorInput(self)
59 Common.addActor(self)
60
61 def setPlane(self):
62 """
63 Set up the plane.
64 """
65
66 #print "--- in set plane..."
67 #bound = self.data_collector.getReader().GetOutput().GetBounds()
68 #print bound
69 #print bound[0]
70 #print bound[1]
71 #print bound[2]
72 #print bound[3]
73 #print bound[4]
74 #print bound[5]
75
76
77 # Default plane is an XY plane
78 # Default plane origin is the center. This causes the plane to cut
79 # and clip at the center to the rendered object.
80 #self.vtk_plane.SetOrigin(
81 # self.data_collector.getReader().GetOutput().GetCenter())
82 # Default plane origin. This causes the plane to cut and clip at
83 # the base/origin of the rendered object.
84 self.setPlaneOrigin(Position(0,0,0))
85 # Default plane normal is orthorgonal to the XY plane.
86 self.setPlaneNormal(Position(-0.00000000001, 0.0, 1.0))
87 #self.setPlaneNormal(Position(0.0, 0.0, 1.0))
88 #self.setPlaneNormal(Position(-1, 0.0, 0.0001))
89 #self.setPlaneNormal(Position(-0.287, 0.0, 0.9579))
90 self.vtk_plane.SetTransform(self.transform)
91
92 def setPlaneOrigin(self, position):
93 """
94 Set the plane origin.
95 @type position: L{Position <geo.Position>} object
96 @param position: Plane origin
97 """
98
99 self.vtk_plane.SetOrigin(position.getXCoor(), position.getYCoor(),
100 position.getZCoor())
101
102 def setPlaneNormal(self, position):
103 """
104 Set the plance normal.
105 @type position: L{Position <geo.Position>} object
106 @param position: Plane normal
107 """
108
109 self.vtk_plane.SetNormal(position.getXCoor(), position.getYCoor(),
110 position.getZCoor())
111
112 def setCutter(self, component):
113 """
114 Set up the cutter.
115 @type component: String
116 @param component: Component to be cut using the plane
117 """
118
119 self.vtk_cutter.SetInput(component)
120 self.vtk_cutter.SetCutFunction(self.vtk_plane)
121
122 def setClipper(self, component):
123 """
124 Set up the clipper.
125 @type component: String
126 @param component: Component to be clip using the plane
127 """
128
129 self.vtk_clipper.SetInput(component)
130 self.vtk_clipper.SetClipFunction(self.vtk_plane)
131 #self.vtk_clipper.SetValue(0.0)
132 # Use implicit function to clip and instead of input's scalar data
133 #self.vtk_clipper.GenerateClipScalarsOn()
134 # Generate the polygonal data that has been clipped away
135 self.vtk_clipper.GenerateClippedOutputOn()
136 # Specifies the clipping side of the plane.
137 self.setInsideOutOn()
138
139 def setValue(self, clipping_value):
140 """
141 Set the clipping value.
142 @type clipping_value: Number
143 @param clipping_value: Clipping value of the implicit function or
144 scalar value
145 """
146
147 self.vtk_clipper.SetValue(clipping_value)
148
149 def setInsideOutOn(self):
150 """
151 Set the clipping to inside out.
152 """
153
154 self.vtk_clipper.InsideOutOn()
155
156 def setInsideOutOff(self):
157 """
158 Disable the inside out clipping.
159 """
160
161 self.vtk_clipper.InsideOutOff()
162
163
164 #def Plane(object): ------------------------------------
165 """
166 A plane in global coordinates
167 """
168 pass
169
170 def Origin(Position):
171 """
172 The position of the origin
173 """
174 pass
175
176 def Direction(object):
177 """
178 A dirction in global coordinates
179 """
180 pass
181
182 def XAxis(Direction):
183 """
184 The direction of the x-axis
185 """
186 pass
187
188 def YAxis(Direction):
189 """
190 The direction of the y-axis
191 """
192 pass
193
194 def ZAxis(Direction):
195 """
196 The direction of the z-axis
197 """
198 pass
199
200
201 def YZPlane(Plane):
202 """
203 The YZ plane orthogonal to the x-axis
204 """
205 pass
206
207 def ZXPlane(Plane):
208 """
209 The ZX plane orthogonal to the y-axis
210 """
211 pass
212
213 def Sphere(object):
214 """
215 A sphere
216 """
217 pass
218

  ViewVC Help
Powered by ViewVC 1.1.26