/[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 840 - (show annotations)
Wed Sep 6 07:52:12 2006 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 2000 byte(s)
Added arrowsOnPlane and mapOnPlane. 

1 """
2 @author: John Ngui
3 @author: Lutz Gross
4 """
5
6 import vtk
7 from common import *
8
9 class Arrows(Common):
10 """
11 Class that shows a vector field by arrows.
12 """
13
14 def __init__(self, scene, data_collector):
15 """
16 @type scene: L{OpenScene <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 """
22
23 Common.__init__(self, scene, data_collector)
24 self.vtk_glyph = None
25 self.setArrows()
26
27 Common.setMapper(self, "self.vtk_glyph.GetOutput()")
28 Common.setActor(self)
29 Common.addActor(self)
30
31 def setArrows(self):
32 """
33 Set up the glyph and use arrows as the source.
34 """
35
36 vtk_arrows = vtk.vtkArrowSource()
37
38 self.vtk_glyph = vtk.vtkGlyph3D()
39 self.vtk_glyph.SetInput(self.data_collector.getReader().GetOutput())
40 self.vtk_glyph.SetSource(vtk_arrows.GetOutput())
41 self.vtk_glyph.SetVectorModeToUseVector() # Default vector mode
42 self.vtk_glyph.SetScaleModeToScaleByVector() # Default scale mode
43 self.setColorMode("Scalar") # Default color mode
44 self.setScaleFactor(0.2) # Default scale factor
45
46 def setScaleFactor(self, scale_factor):
47 """
48 Set the scale factor for the arrows.
49
50 @type scale_factor: Number
51 @param scale_factor: Scale factor
52 """
53
54 self.vtk_glyph.SetScaleFactor(scale_factor)
55
56 def setColorMode(self, color_mode):
57 """
58 Set the color mode for the arrows.
59
60 @type color_mode: String
61 @param color_mode: Color mode for the arrows (I{Scalar or Vector})
62 """
63
64 eval("self.vtk_glyph.SetColorModeToColorBy%s()" % color_mode)
65
66
67 from arrows import Arrows
68 from plane import Plane
69
70 class ArrowsOnPlane(Arrows, Plane):
71 """
72 shows a vector field by arrows on a plane
73 """
74
75 def __init__(self, scene, data_collector):
76 Common.__init__(self, scene, data_collector)
77 self.vtk_glyph = None
78 self.setArrows()
79
80 Plane.__init__(self, scene, data_collector,
81 "self.vtk_glyph.GetOutput()")
82

  ViewVC Help
Powered by ViewVC 1.1.26