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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 860 - (show annotations)
Thu Sep 28 08:17:29 2006 UTC (14 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 4257 byte(s)
- added sample drivers on how to use all of the currently available modules.
- completed the epydocs for all the currently available modules.
- added the rotation feature for camera and plane cutting.


1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 import vtk
7 from common import Common
8
9 class Arrows(Common):
10 """
11 Class that shows a vector field by arrows.
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>} 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_glyph = vtk.vtkGlyph3D()
28 self.setArrows()
29
30 Common.setMapperInput(self, self.vtk_glyph.GetOutput(), lut)
31 Common.setActorInput(self)
32 Common.addActor(self)
33
34 def setArrows(self):
35 """
36 Set up the glyph and use arrows as the source.
37 """
38
39 vtk_arrows = vtk.vtkArrowSource()
40
41 self.vtk_glyph.SetInput(self.data_collector.getReader().GetOutput())
42 self.vtk_glyph.SetSource(vtk_arrows.GetOutput())
43 # Default vector mode is vector.
44 self.setVectorMode("Vector")
45 # Default scale mode is vector.
46 self.setScaleMode("Vector")
47 # Default color mode is scalar.
48 self.setColorMode("Scalar")
49 self.setScaleFactor(0.2)
50
51 def setVectorMode(self, vector_mode):
52 """
53 Set the arrows vector mode.
54 @type vector_mode: String
55 @param vector_mode: Arrows vector mode
56 """
57
58 eval("self.vtk_glyph.SetVectorModeToUse%s" % vector_mode)
59
60 def setScaleMode(self, scale_mode):
61 """
62 Set the arrows scale mode.
63 @type scale_mode: String
64 @param scale_mode: Arrows scale mode
65 """
66
67 eval("self.vtk_glyph.SetScaleModeToScaleBy%s" % scale_mode)
68
69 def setScaleFactor(self, scale_factor):
70 """
71 Set the arrows scale factor.
72 @type scale_factor: Number
73 @param scale_factor: Size of the arrows
74 """
75
76 self.vtk_glyph.SetScaleFactor(scale_factor)
77
78 def setColorMode(self, color_mode):
79 """
80 Set the arrows color mode.
81 @type color_mode: String
82 @param color_mode: Arrows color mode
83 """
84
85 eval("self.vtk_glyph.SetColorModeToColorBy%s()" % color_mode)
86
87
88 from arrows import Arrows
89 from plane import Plane
90
91 class ArrowsOnPlane(Arrows, Plane):
92 """
93 Class that shows a vector field by arrows on a given plane.
94 """
95
96 def __init__(self, scene, data_collector, transform, lut = None):
97 """
98 @type scene: L{Scene <scene.Scene>} object
99 @param scene: Scene in which components are to be added to
100 @type data_collector: L{DataCollector <datacollector.DataCollector>}
101 object
102 @param data_collector: Source of data for visualization
103 @type transform: L{Transform <geo.Transform>} object
104 @param transform: Orientation of the plane
105 @type lut: L{BlueToRed <colormap.BlueToRed>} or
106 L{RedToBlue <colormap.RedToBlue>} object
107 @param lut: Lookup table to be used by the mapper
108 """
109
110 # Declared because they are needed by the setArrows method.
111 self.data_collector = data_collector
112 self.vtk_glyph = vtk.vtkGlyph3D()
113
114 Arrows.setArrows(self)
115 # "Cut" is used to distinguish cutting from clipping.
116 Plane.__init__(self, scene, data_collector,
117 self.vtk_glyph.GetOutput(), transform, lut, "Cut")
118
119 from arrows import Arrows
120 from plane import Plane
121
122 class ArrowsOnClip(Arrows, Plane):
123 """
124 Class that shows a vector field by arrows on a clip.
125 """
126
127 def __init__(self, scene, data_collector, transform, lut = None):
128 """
129 @type scene: L{Scene <scene.Scene>} object
130 @param scene: Scene in which components are to be added to
131 @type data_collector: L{DataCollector <datacollector.DataCollector>}
132 object
133 @param data_collector: Source of data for visualization
134 @type transform: L{Transform <geo.Transform>} object
135 @param transform: Orientation of the plane
136 @type lut: L{BlueToRed <colormap.BlueToRed>} or
137 L{RedToBlue <colormap.RedToBlue>} object
138 @param lut: Lookup table to be used by the mapper
139 """
140
141 # Declared because they are needed by the setArrows method.
142 self.data_collector = data_collector
143 self.vtk_glyph = vtk.vtkGlyph3D()
144
145 Arrows.setArrows(self)
146 # "Clip" is used to distinguish clipping from cutting.
147 Plane.__init__(self, scene, data_collector,
148 self.vtk_glyph.GetOutput(), transform, lut, "Clip")
149

  ViewVC Help
Powered by ViewVC 1.1.26