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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 994 - (show annotations)
Fri Feb 23 07:00:54 2007 UTC (12 years, 2 months ago) by jongui
File MIME type: text/x-python
File size: 4351 byte(s)
Modified the way setActiveScalar, setActiveVector and setActiveTensor are specified. It appears that the attributes have to be set each time a new file is read.
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 # data_collector._setActiveVector(vector)
77 #elif(scalar != None):
78 # data_collector._setActiveScalar(scalar)
79
80 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
81 # before DataSetMapper. If it is done after DataSetMapper, no effect
82 # will take place.
83 if(lut == Lut.COLOR): # Colored lookup table.
84 lookup_table = LookupTable()
85 lookup_table._setTableValue()
86 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
87 lookup_table = LookupTable()
88 lookup_table._setLookupTableToGreyScale()
89
90 PointSource.__init__(self, data_collector._getOutput())
91 StreamLineModule.__init__(self, data_collector._getOutput(),
92 PointSource._getOutput(self))
93
94 Tube.__init__(self, StreamLineModule._getOutput(self))
95 DataSetMapper.__init__(self, Tube._getOutput(self),
96 lookup_table._getLookupTable())
97
98 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
99 DataSetMapper._setScalarVisibilityOn(self)
100 StreamLineModule._setSpeedScalarsOn(self)
101 DataSetMapper._setScalarRange(self,
102 data_collector._getVectorRange())
103 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
104 DataSetMapper._setScalarVisibilityOn(self)
105 StreamLineModule._setSpeedScalarsOff(self)
106 DataSetMapper._setScalarRange(self,
107 data_collector._getScalarRange())
108
109 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
110 scene._addActor3D(viewport, Actor3D._getActor3D(self))
111

  ViewVC Help
Powered by ViewVC 1.1.26