/[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 946 - (show annotations)
Wed Jan 31 03:08:04 2007 UTC (12 years, 7 months ago) by jongui
File MIME type: text/x-python
File size: 3780 byte(s)
added colouring option to use either scalar data or vector data.
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 class StreamLine(DataSetMapper, Actor3D, PointSource, StreamLineModule, Tube):
16
17 """
18 Class that show a vector field using streamline.
19 """
20
21 # The SOUTH_WEST default viewport is used when there is only one viewport.
22 # This saves the user from specifying the viewport when there is only one.
23 # If no vector field is specified, the first encountered in the file will
24 # be loaded automatically. If no lut is specified, the color scheme will
25 # be used.
26 def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
27 lut = Lut.COLOR, outline = True, color_mode = ColorMode.VECTOR):
28
29 """
30 @type scene: L{Scene <scene.Scene>} object
31 @param scene: Scene in which objects are to be rendered on
32 @type data_collector: L{DataCollector <datacollector.DataCollector>}
33 object
34 @param data_collector: Deal with source of data for visualisation
35 @type tensor: String
36 @param tensor: Tensor field to load from the source file
37 @type viewport: L{Viewport <constant.Viewport>} constant
38 @param viewport: Viewport in which the object is to be rendered on
39 @type lut : L{Lut <constant.Lut>} constant
40 @param lut: Lookup table color scheme
41 @type outline: Boolean
42 @param outline: Places an outline around the domain surface
43 """
44
45 # NOTE: Actor3D is inherited and there are two instances declared here.
46 # As a result, when methods from Actor3D is invoked from the driver,
47 # only the methods associated with the latest instance (which in this
48 # case is the Actor3D for the Tube) can be executed. Actor3D
49 # methods associated with Outline cannot be invoked from the driver.
50 # They can only be called within here, which is why Outline must be
51 # place before Tube as there is unlikely to be any changes
52 # made to the Outline's Actor3D.
53
54 # ----- Outline -----
55
56 if(outline == True):
57 outline = Outline(data_collector._getOutput())
58 DataSetMapper.__init__(self, outline._getOutput())
59
60 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
61 # Default outline color is black.
62 Actor3D.setColor(self, Color.BLACK)
63 # Default line width is 1.
64 Actor3D._setLineWidth(self, 1)
65 scene._addActor3D(viewport, Actor3D._getActor3D(self))
66
67
68 # ----- Streamline -----
69
70
71
72 # NOTE: Lookup table color mapping (color or grey scale) MUST be set
73 # before DataSetMapper. If it is done after DataSetMapper, no effect
74 # will take place.
75 if(lut == Lut.COLOR): # Colored lookup table.
76 lookup_table = LookupTable()
77 lookup_table._setTableValue()
78 elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
79 lookup_table = LookupTable()
80 lookup_table._setLookupTableToGreyScale()
81
82 PointSource.__init__(self, data_collector._getOutput())
83 StreamLineModule.__init__(self, data_collector._getOutput(),
84 PointSource._getOutput(self))
85
86 Tube.__init__(self, StreamLineModule._getOutput(self))
87
88 DataSetMapper.__init__(self, Tube._getOutput(self),
89 lookup_table._getLookupTable())
90
91 #DataSetMapper._setScalarRange(self, data_collector._getScalarRange())
92
93 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
94 DataSetMapper._setScalarRange(self,
95 data_collector._getVectorRange())
96 print "vector"
97 elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
98 DataSetMapper._setScalarRange(self,
99 data_collector._getScalarRange())
100 print "scalar"
101 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
102 scene._addActor3D(viewport, Actor3D._getActor3D(self))
103

  ViewVC Help
Powered by ViewVC 1.1.26