1 |
""" |
2 |
@author: John NGUI |
3 |
""" |
4 |
|
5 |
import vtk |
6 |
from mapper import DataSetMapper |
7 |
from lookuptable import LookupTable |
8 |
from actor import Actor3D |
9 |
from constant import Viewport, Color, Lut, ColorMode |
10 |
from streamlinemodule import StreamLineModule |
11 |
from tube import Tube |
12 |
from point import PointSource |
13 |
from outline import Outline |
14 |
|
15 |
# NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were |
16 |
# inherited to allow access to their public methods from the driver. |
17 |
class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube): |
18 |
|
19 |
""" |
20 |
Class that show a vector field using streamline. |
21 |
""" |
22 |
|
23 |
# The SOUTH_WEST default viewport is used when there is only one viewport. |
24 |
# This saves the user from specifying the viewport when there is only one. |
25 |
# If no vector field is specified, the first encountered in the file will |
26 |
# be loaded automatically. If no lut is specified, the color scheme will |
27 |
# be used. |
28 |
def __init__(self, scene, data_collector, scalar = None, vector = None, |
29 |
viewport = Viewport.SOUTH_WEST, lut = Lut.COLOR, |
30 |
color_mode = ColorMode.VECTOR, outline = True): |
31 |
""" |
32 |
@type scene: L{Scene <scene.Scene>} object |
33 |
@param scene: Scene in which objects are to be rendered on |
34 |
@type data_collector: L{DataCollector <datacollector.DataCollector>} |
35 |
object |
36 |
@param data_collector: Deal with source of data for visualisation |
37 |
@type vector: String |
38 |
@param vector: Vector field to load from the source file |
39 |
@type scalar: String |
40 |
@param scalar: Scalar field to load from the source file |
41 |
@type viewport: L{Viewport <constant.Viewport>} constant |
42 |
@param viewport: Viewport in which the object is to be rendered on |
43 |
@type lut : L{Lut <constant.Lut>} constant |
44 |
@param lut: Lookup table color scheme |
45 |
@type color_mode: L{ColorMode <constant.ColorMode>} constant |
46 |
@param color_mode: Type of color mode |
47 |
@type outline: Boolean |
48 |
@param outline: Places an outline around the domain surface |
49 |
""" |
50 |
|
51 |
# NOTE: Actor3D is inherited and there are two instances declared here. |
52 |
# As a result, when methods from Actor3D is invoked from the driver, |
53 |
# only the methods associated with the latest instance (which in this |
54 |
# case is the Actor3D for the Tube) can be executed. Actor3D |
55 |
# methods associated with Outline cannot be invoked from the driver. |
56 |
# They can only be called within here, which is why Outline must be |
57 |
# place before Tube as there is unlikely to be any changes |
58 |
# made to the Outline's Actor3D. |
59 |
|
60 |
# ----- Outline ----- |
61 |
|
62 |
if(outline == True): |
63 |
outline = Outline(data_collector._getOutput()) |
64 |
DataSetMapper.__init__(self, outline._getOutput()) |
65 |
|
66 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
67 |
# Default outline color is black. |
68 |
Actor3D.setColor(self, Color.BLACK) |
69 |
# Default line width is 1. |
70 |
Actor3D._setLineWidth(self, 1) |
71 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
72 |
|
73 |
# ----- Streamline ----- |
74 |
|
75 |
if(vector != None): |
76 |
print "vector" |
77 |
data_collector._setActiveVector(vector) |
78 |
elif(scalar != None): |
79 |
print "scalar" |
80 |
data_collector._setActiveScalar(scalar) |
81 |
|
82 |
# NOTE: Lookup table color mapping (color or grey scale) MUST be set |
83 |
# before DataSetMapper. If it is done after DataSetMapper, no effect |
84 |
# will take place. |
85 |
if(lut == Lut.COLOR): # Colored lookup table. |
86 |
lookup_table = LookupTable() |
87 |
lookup_table._setTableValue() |
88 |
elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table. |
89 |
lookup_table = LookupTable() |
90 |
lookup_table._setLookupTableToGreyScale() |
91 |
|
92 |
PointSource.__init__(self, data_collector._getOutput()) |
93 |
StreamLineModule.__init__(self, data_collector._getOutput(), |
94 |
PointSource._getOutput(self)) |
95 |
|
96 |
Tube.__init__(self, StreamLineModule._getOutput(self)) |
97 |
DataSetMapper.__init__(self, Tube._getOutput(self), |
98 |
lookup_table._getLookupTable()) |
99 |
|
100 |
if(color_mode == ColorMode.VECTOR): # Color velocity by vector. |
101 |
print "vectro mode" |
102 |
DataSetMapper._setScalarRange(self, |
103 |
data_collector._getVectorRange()) |
104 |
elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar. |
105 |
print "scalar mode" |
106 |
DataSetMapper._setScalarRange(self, |
107 |
data_collector._getScalarRange()) |
108 |
|
109 |
Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self)) |
110 |
scene._addActor3D(viewport, Actor3D._getActor3D(self)) |
111 |
|