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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 889 - (show annotations)
Tue Nov 7 23:42:31 2006 UTC (14 years, 4 months ago) by jongui
File MIME type: text/x-python
File size: 4979 byte(s)
drivers added
1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 import vtk
7 from common import Common
8
9 class Tensor(Common):
10 """
11 Class that show a tensor field by ellipsoids.
12 """
13
14 def __init__(self, scene, data_collector, lut = None):
15 """
16 @type scene: L{Scene <scene.Scene>} object
17 @param scene: Scene in which components are to be added to
18 @type data_collector: L{DataCollector <datacollector.DataCollector>}
19 object
20 @param data_collector: Source of data for visualization
21 @type lut: L{BlueToRed <colormap.BlueToRed>} object or
22 L{RedToBlue <colormap.RedToBlue>} object
23 @param lut: Lookup table to be used by the mapper
24 """
25
26 Common.__init__(self, scene, data_collector)
27 self.vtk_tensor_glyph = vtk.vtkTensorGlyph()
28 self.vtk_sphere = vtk.vtkSphereSource()
29 self.vtk_poly_data_normals = vtk.vtkPolyDataNormals()
30 self.setTensor()
31
32 Common.setMapperInput(self, self.vtk_poly_data_normals.GetOutput(), lut)
33 Common.setActorInput(self)
34 Common.addActor(self)
35
36 def setTensor(self):
37 """
38 Set up the tensor glyph and use sphere as the source.
39 """
40
41 # Default theta and phi resolution is 10.
42 self.setThetaResolution(10)
43 self.setPhiResolution(10)
44
45 self.vtk_tensor_glyph.SetInput(
46 self.data_collector.getReader().GetOutput())
47 # Use sphere are the source for the glyph.
48 self.vtk_tensor_glyph.SetSource(self.vtk_sphere.GetOutput())
49 # Default scale and max scale factor is 0.2 and 5 respectively.
50 self.setScaleFactor(0.2)
51 self.setMaxScaleFactor(5)
52
53 # Needed to generate the right colors. If not used, some glyphs
54 # will be black in color.
55 self.vtk_poly_data_normals.SetInput(self.vtk_tensor_glyph.GetOutput())
56
57 def setThetaResolution(self, resolution):
58 """
59 Set the number of points in the longitude direction.
60 @type resolution: Number
61 @param resolution: Number of points in the longitude direction
62 """
63
64 self.vtk_sphere.SetThetaResolution(resolution)
65
66 def setPhiResolution(self, resolution):
67 """
68 Set the number of points in the latitude direction.
69 @type resolution: Number
70 @param resolution: Number of points in the latitude direction
71 """
72
73 self.vtk_sphere.SetPhiResolution(resolution)
74
75 def setScaleFactor(self, scale_factor):
76 """
77 Set the tensor glyph scale factor.
78 @type scale_factor: Number
79 @param scale_factor: Size of the sphere
80 """
81
82 self.vtk_tensor_glyph.SetScaleFactor(scale_factor)
83
84 def setMaxScaleFactor(self, max_scale_factor):
85 """
86 Set the maximum allowable scale factor.
87 @type max_scale_factor: Number
88 @param max_scale_factor: Maximum size of the sphere
89 """
90
91 self.vtk_tensor_glyph.SetMaxScaleFactor(max_scale_factor)
92
93 from tensor import Tensor
94 from plane import Plane
95
96 class TensorOnPlane(Tensor, Plane):
97 """
98 Class that show a tensor field by ellipsoids on given a plane.
99 """
100
101 def __init__(self, scene, data_collector, transform, lut = None):
102 """
103 @type scene: L{Scene <scene.Scene>} object
104 @param scene: Scene in which components are to be added to
105 @type data_collector: L{DataCollector <datacollector.DataCollector>}
106 object
107 @param data_collector: Source of data for visualization
108 @type transform: L{Transform <geo.Transform>} object
109 @param transform: Orientation of the plane
110 @type lut: L{BlueToRed <colormap.BlueToRed>} or
111 L{RedToBlue <colormap.RedToBlue>} object
112 @param lut: Lookup table to be used by the mapper
113 """
114
115 # Declared because they are needed by the setTensor method.
116 self.data_collector = data_collector
117 self.vtk_tensor_glyph = vtk.vtkTensorGlyph()
118 self.vtk_sphere = vtk.vtkSphereSource()
119 self.vtk_poly_data_normals = vtk.vtkPolyDataNormals()
120
121 Tensor.setTensor(self)
122 # "Cut" is used to distinguish cutting from clipping.
123 Plane.__init__(self, scene, data_collector,
124 self.vtk_poly_data_normals.GetOutput(), transform, lut, "Cut")
125
126 from tensor import Tensor
127 from plane import Plane
128
129 class TensorOnClip(Tensor, Plane):
130 """
131 Class that show a tensor field by ellipsoids on a given clip.
132 """
133
134 def __init__(self, scene, data_collector, transform, lut = None):
135 """
136 @type scene: L{Scene <scene.Scene>} object
137 @param scene: Scene in which components are to be added to
138 @type data_collector: L{DataCollector <datacollector.DataCollector>}
139 object
140 @param data_collector: Source of data for visualization
141 @type transform: L{Transform <geo.Transform>} object
142 @param transform: Orientation of the plane
143 @type lut: L{BlueToRed <colormap.BlueToRed>} or
144 L{RedToBlue <colormap.RedToBlue>} object
145 @param lut: Lookup table to be used by the mapper
146 """
147
148 # Declared because they are needed by the setTensor method.
149 self.data_collector = data_collector
150 self.vtk_tensor_glyph = vtk.vtkTensorGlyph()
151 self.vtk_sphere = vtk.vtkSphereSource()
152 self.vtk_poly_data_normals = vtk.vtkPolyDataNormals()
153
154 Tensor.setTensor(self)
155 # "Clip" is used to distinguish clipping from cutting.
156 Plane.__init__(self, scene, data_collector,
157 self.vtk_poly_data_normals.GetOutput(), transform, lut, "Clip")
158
159

  ViewVC Help
Powered by ViewVC 1.1.26