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 |
""" |
22 |
|
23 |
Common.__init__(self, scene, data_collector) |
24 |
self.vtk_glyph = vtk.vtkGlyph3D() |
25 |
self.setArrows() |
26 |
|
27 |
Common.setMapperInput(self, self.vtk_glyph.GetOutput(), lut) |
28 |
Common.setActorInput(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.SetInput(self.data_collector.getReader().GetOutput()) |
39 |
self.vtk_glyph.SetSource(vtk_arrows.GetOutput()) |
40 |
self.setVectorMode("Vector") |
41 |
self.setScaleMode("Vector") |
42 |
self.setColorMode("Scalar") |
43 |
self.setScaleFactor(0.3) |
44 |
|
45 |
def setVectorMode(self, vector_mode): |
46 |
eval("self.vtk_glyph.SetVectorModeToUse%s" % vector_mode) |
47 |
|
48 |
def setScaleMode(self, scale_mode): |
49 |
eval("self.vtk_glyph.SetScaleModeToScaleBy%s" % scale_mode) |
50 |
|
51 |
def setScaleFactor(self, scale_factor): |
52 |
""" |
53 |
Set the scale factor for the arrows. |
54 |
|
55 |
@type scale_factor: Number |
56 |
@param scale_factor: Scale factor |
57 |
""" |
58 |
|
59 |
self.vtk_glyph.SetScaleFactor(scale_factor) |
60 |
|
61 |
def setColorMode(self, color_mode): |
62 |
""" |
63 |
Set the color mode for the arrows. |
64 |
|
65 |
@type color_mode: String |
66 |
@param color_mode: Color mode for the arrows (I{Scalar or Vector}) |
67 |
""" |
68 |
|
69 |
eval("self.vtk_glyph.SetColorModeToColorBy%s()" % color_mode) |
70 |
|
71 |
|
72 |
from arrows import Arrows |
73 |
from plane import Plane |
74 |
|
75 |
class ArrowsOnPlane(Arrows, Plane): |
76 |
""" |
77 |
Class that shows a vector field by arrows on a given plane. |
78 |
""" |
79 |
|
80 |
def __init__(self, scene, data_collector, lut = None): |
81 |
""" |
82 |
@type scene: L{Scene <scene.Scene>} object |
83 |
@param scene: Scene in which components are to be added to |
84 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
85 |
object |
86 |
|
87 |
@param data_collector: Source of data for visualization |
88 |
""" |
89 |
|
90 |
self.data_collector = data_collector |
91 |
self.vtk_glyph = vtk.vtkGlyph3D() |
92 |
Arrows.setArrows(self) |
93 |
|
94 |
Plane.__init__(self, scene, data_collector, |
95 |
self.vtk_glyph.GetOutput(), lut) |
96 |
|