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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 996 - (hide annotations)
Mon Feb 26 03:43:13 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 3914 byte(s)
Updated the drivers. Setting the active scalar/vector/tensor is now done in the DataCollector. i.e. 
dc = DataCollector(...)
dc.setFileName(...)
dc.setActiveScalar(...)

The use of setActiveScalar / setActiveVector / setActiveTensor have to be done after the setFileName.
1 jongui 943 """
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 jongui 946 from constant import Viewport, Color, Lut, ColorMode
10 jongui 943 from streamlinemodule import StreamLineModule
11     from tube import Tube
12     from point import PointSource
13     from outline import Outline
14    
15 jongui 949 # NOTE: DataSetMapper, Actor3D, PointSource, StreamLineModule and Tube were
16     # inherited to allow access to their public methods from the driver.
17 jongui 943 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 jongui 996 # If no lut is specified, the color scheme will be used.
26     def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
27     lut = Lut.COLOR, color_mode = ColorMode.VECTOR, outline = True):
28 jongui 943 """
29     @type scene: L{Scene <scene.Scene>} object
30     @param scene: Scene in which objects are to be rendered on
31     @type data_collector: L{DataCollector <datacollector.DataCollector>}
32     object
33     @param data_collector: Deal with source of data for visualisation
34     @type viewport: L{Viewport <constant.Viewport>} constant
35     @param viewport: Viewport in which the object is to be rendered on
36     @type lut : L{Lut <constant.Lut>} constant
37     @param lut: Lookup table color scheme
38 jongui 949 @type color_mode: L{ColorMode <constant.ColorMode>} constant
39     @param color_mode: Type of color mode
40 jongui 943 @type outline: Boolean
41     @param outline: Places an outline around the domain surface
42     """
43    
44     # NOTE: Actor3D is inherited and there are two instances declared here.
45     # As a result, when methods from Actor3D is invoked from the driver,
46     # only the methods associated with the latest instance (which in this
47     # case is the Actor3D for the Tube) can be executed. Actor3D
48     # methods associated with Outline cannot be invoked from the driver.
49     # They can only be called within here, which is why Outline must be
50     # place before Tube as there is unlikely to be any changes
51     # made to the Outline's Actor3D.
52    
53     # ----- Outline -----
54    
55     if(outline == True):
56     outline = Outline(data_collector._getOutput())
57     DataSetMapper.__init__(self, outline._getOutput())
58    
59     Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
60     # Default outline color is black.
61     Actor3D.setColor(self, Color.BLACK)
62     # Default line width is 1.
63     Actor3D._setLineWidth(self, 1)
64     scene._addActor3D(viewport, Actor3D._getActor3D(self))
65    
66     # ----- Streamline -----
67    
68     # NOTE: Lookup table color mapping (color or grey scale) MUST be set
69     # before DataSetMapper. If it is done after DataSetMapper, no effect
70     # will take place.
71     if(lut == Lut.COLOR): # Colored lookup table.
72     lookup_table = LookupTable()
73     lookup_table._setTableValue()
74     elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.
75     lookup_table = LookupTable()
76     lookup_table._setLookupTableToGreyScale()
77    
78     PointSource.__init__(self, data_collector._getOutput())
79     StreamLineModule.__init__(self, data_collector._getOutput(),
80     PointSource._getOutput(self))
81    
82     Tube.__init__(self, StreamLineModule._getOutput(self))
83     DataSetMapper.__init__(self, Tube._getOutput(self),
84     lookup_table._getLookupTable())
85    
86 jongui 946 if(color_mode == ColorMode.VECTOR): # Color velocity by vector.
87 jongui 992 DataSetMapper._setScalarVisibilityOn(self)
88     StreamLineModule._setSpeedScalarsOn(self)
89 jongui 946 DataSetMapper._setScalarRange(self,
90     data_collector._getVectorRange())
91     elif(color_mode == ColorMode.SCALAR): # Color velocity by scalar.
92 jongui 992 DataSetMapper._setScalarVisibilityOn(self)
93     StreamLineModule._setSpeedScalarsOff(self)
94 jongui 946 DataSetMapper._setScalarRange(self,
95     data_collector._getScalarRange())
96 jongui 949
97 jongui 943 Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))
98     scene._addActor3D(viewport, Actor3D._getActor3D(self))
99    

  ViewVC Help
Powered by ViewVC 1.1.26