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

Diff of /trunk/pyvisi/py_src/ellipsoid.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1147 by ksteube, Wed May 16 06:39:11 2007 UTC revision 1197 by jongui, Mon Jun 18 02:08:34 2007 UTC
# Line 1  Line 1 
1  """  """
2  @author: John NGUI  @var __author__: name of author
3    @var __copyright__: copyrights
4    @var __license__: licence agreement
5    @var __url__: url entry point on documentation
6    @var __version__: version
7    @var __date__: date of the version
8  """  """
9    
10    __author__="John Ngui, john.ngui@uq.edu.au"
11    __copyright__="""  Copyright (c) 2006 by ACcESS MNRF
12                        http://www.access.edu.au
13                    Primary Business: Queensland, Australia"""
14    __license__="""Licensed under the Open Software License version 3.0
15                 http://www.opensource.org/licenses/osl-3.0.php"""
16    __url__="http://www.iservo.edu.au/esys"
17    __version__="$Revision$"
18    __date__="$Date$"
19    
20    
21  import vtk  import vtk
22  from mapper import DataSetMapper  from mapper import DataSetMapper
23  from lookuptable import LookupTable  from lookuptable import LookupTable
24  from actor import Actor3D  from actor import Actor3D
25  from constant import Viewport, Color, Lut, VizType, ColorMode  from constant import Viewport, Color, Lut, ColorMode
26  from sphere import Sphere  from sphere import Sphere
27  from normals import Normals  from normals import Normals
28  from glyph import  TensorGlyph  from glyph import  TensorGlyph
# Line 53  class Ellipsoid(DataSetMapper, Actor3D, Line 69  class Ellipsoid(DataSetMapper, Actor3D,
69          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
70          """          """
71    
72          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
73          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
74          # only the methods associated with the latest instance (which in this          self.__lut = lut
75          # case is the Actor3D for the Ellipsoid) can be executed. Actor3D          self.__cell_to_point = cell_to_point
76          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
77          # They can only be called within here, which is why Outline must be  
78          # place before Ellipsoid as there is unlikely to be any changes          # Keeps track whether Ellipsoid has been modified.
79          # made to the Outline's Actor3D.          self.__modified = True      
80            MaskPoints.__init__(self)
81          # ----- Outline -----          Sphere.__init__(self)
82            TensorGlyph.__init__(self)
83          if(outline == True):          Normals.__init__(self)
84              outline = Outline(data_collector._getOutput())          DataSetMapper.__init__(self)
85              DataSetMapper.__init__(self, outline._getOutput())          Actor3D.__init__(self)
86            scene._addVisualizationModules(self)
87    
88            # ----- Outline -----
89    
90            # NOTE: Changes cannot be made to the Outline's properties from the
91            # driver.
92            if(self.__outline == True):
93                outline = Outline(self.__data_collector._getDataCollectorOutput())
94                mapper = DataSetMapper()
95                mapper._setupDataSetMapper(outline._getOutlineOutput())
96    
97              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
98                actor3D._setupActor3D(mapper._getDataSetMapper())
99              # Default outline color is black.              # Default outline color is black.
100              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
101    
102              # Default line width is 1.              # Default line width is 1.
103              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
104              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
105    
106          # ----- Ellipsoid -----          # ----- Ellipsoid -----
107    
108          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
109          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
110          # will take place.          # will take place.
111          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
112              lookup_table = LookupTable()              lookup_table = LookupTable()
113              lookup_table._setTableValue()              lookup_table._setTableValue()
114          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
115              lookup_table = LookupTable()              lookup_table = LookupTable()
116              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
117    
118          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
119              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
120              MaskPoints.__init__(self, c2p._getOutput())                      self.__data_collector._getDataCollectorOutput())
121          elif(cell_to_point == False): # No conversion happens.                self._setupMaskPoints(c2p._getCellToPointOutput())
122              MaskPoints.__init__(self, data_collector._getOutput())          elif(self.__cell_to_point == False): # No conversion happens.  
123                self._setupMaskPoints(
124                        self.__data_collector._getDataCollectorOutput())
125    
126            self._setupTensorGlyph(self._getMaskPointsOutput(),
127                    self._getSphereOutput())
128            self._setupNormals(self._getTensorGlyphOutput())
129    
130          Sphere.__init__(self)          self._setupDataSetMapper(self._getNormalsOutput(),
         TensorGlyph.__init__(self, MaskPoints._getOutput(self),  
                 Sphere._getOutput(self))  
         Normals.__init__(self, TensorGlyph._getOutput(self))  
   
         DataSetMapper.__init__(self, Normals._getOutput(self),  
131                  lookup_table._getLookupTable())                  lookup_table._getLookupTable())
         DataSetMapper._setScalarRange(self, data_collector._getScalarRange())  
132    
133          data_collector._paramForUpdatingMultipleSources(VizType.ELLIPSOID,          self._setupActor3D(self._getDataSetMapper())
134                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))          scene._addActor3D(self.__viewport, self._getActor3D())
135    
136        def _isModified(self):  
137            """
138            Return whether the Ellipsoid or DataCollector has been modified.
139    
140            @rtype: Boolean
141            @return: True or False
142            """
143    
144            return self.__modified or self.__data_collector._isModified()
145    
146        def _render(self, scene):
147            """
148            Render the ellipsoids.
149    
150            @type scene: L{Scene <scene.Scene>} object
151            @param scene: Scene in which objects are to be rendered on
152            """
153    
154          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          if (self._isModified() == True):
155          scene._addActor3D(viewport, Actor3D._getActor3D(self))              if(self.__data_collector._isScalarSet() == True):
156                    self.__data_collector._setActiveScalar()
157                if(self.__data_collector._isTensorSet() == True):
158                    self.__data_collector._setActiveTensor()
159    
160                # self._isScalarRangeSet checks whether the scalar range has been
161                # specified by the user. If it has, then the scalar range
162                # read from the source will be ignored.
163                if(not(self._isScalarRangeSet())):
164                    self._setScalarRange(self.__data_collector._getScalarRange())
165                self.__modified = False
166    
167    
168  ###############################################################################  ###############################################################################
# Line 156  class EllipsoidOnPlaneCut(DataSetMapper, Line 211  class EllipsoidOnPlaneCut(DataSetMapper,
211          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
212          """          """
213    
214          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
215          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
216          # only the methods associated with the latest instance (which in this          self.__lut = lut
217          # case is the Actor3D for the Ellipsoid) can be executed. Actor3D          self.__cell_to_point = cell_to_point
218          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
219          # They can only be called within here, which is why Outline must be  
220          # place before Ellipsoid as there is unlikely to be any changes          # Keeps track whether EllipsoidOnPlaneCut has been modified.
221          # made to the Outline's Actor3D.          self.__modified = True      
222            Transform.__init__(self)
223            Plane.__init__(self)
224            Cutter.__init__(self)
225            MaskPoints.__init__(self)
226            Sphere.__init__(self)
227            TensorGlyph.__init__(self)
228            Normals.__init__(self)
229            DataSetMapper.__init__(self)
230            Actor3D.__init__(self)
231            scene._addVisualizationModules(self)
232    
233          # ----- Outline -----          # ----- Outline -----
234    
235          if(outline == True):          # NOTE: Changes cannot be made to the Outline's properties from the
236              outline = Outline(data_collector._getOutput())          # driver.
237              DataSetMapper.__init__(self, outline._getOutput())          if(self.__outline == True):
238                outline = Outline(self.__data_collector._getDataCollectorOutput())
239                mapper = DataSetMapper()
240                mapper._setupDataSetMapper(outline._getOutlineOutput())
241    
242              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
243                actor3D._setupActor3D(mapper._getDataSetMapper())
244              # Default outline color is black.              # Default outline color is black.
245              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
246    
247              # Default line width is 1.              # Default line width is 1.
248              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
249              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
250    
251          # ----- Ellipsoid on a cut plane -----          # ----- Ellipsoid on a cut plane -----
252    
253          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
254          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
255          # will take place.          # will take place.
256          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
257              lookup_table = LookupTable()              lookup_table = LookupTable()
258              lookup_table._setTableValue()              lookup_table._setTableValue()
259          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
260              lookup_table = LookupTable()              lookup_table = LookupTable()
261              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
262    
263          Transform.__init__(self)              self._setupPlane(self._getTransform())
         Plane.__init__(self, Transform._getTransform(self))  
264    
265          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
266              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
267              Cutter.__init__(self, c2p._getOutput(), Plane._getPlane(self))                        self.__data_collector._getDataCollectorOutput())
268          elif(cell_to_point == False): # No conversion happens.                self._setupCutter(c2p._getCellToPointOutput(), self._getPlane())    
269              Cutter.__init__(self, data_collector._getOutput(),          elif(self.__cell_to_point == False): # No conversion happens.  
270                      Plane._getPlane(self))                self._setupCutter(self.__data_collector._getDataCollectorOutput(),
271                        self._getPlane())  
272    
273            self._setupMaskPoints(self._getCutterOutput())
274    
275            self._setupTensorGlyph(self._getMaskPointsOutput(),
276                    self._getSphereOutput())
277            self._setupNormals(self._getTensorGlyphOutput())
278    
279          MaskPoints.__init__(self, Cutter._getOutput(self))          self._setupDataSetMapper(self._getNormalsOutput(),
280          Sphere.__init__(self)                  lookup_table._getLookupTable())
281    
282          TensorGlyph.__init__(self, MaskPoints._getOutput(self),          self._setupActor3D(self._getDataSetMapper())
283                  Sphere._getOutput(self))          scene._addActor3D(self.__viewport, self._getActor3D())
         Normals.__init__(self, TensorGlyph._getOutput(self))  
284    
285          DataSetMapper.__init__(self, Normals._getOutput(self),      def _isModified(self):  
286                  lookup_table._getLookupTable())          """
287          DataSetMapper._setScalarRange(self, data_collector._getScalarRange())          Return whether the EllipsoidOnPlaneCut or DataCollector has been
288            modified.
289    
290          data_collector._paramForUpdatingMultipleSources(VizType.ELLIPSOID,          @rtype: Boolean
291                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))          @return: True or False
292            """
293    
294            return self.__modified or self.__data_collector._isModified()
295    
296        def _render(self, scene):
297            """
298            Render the ellipsoids cut using a plane.
299    
300            @type scene: L{Scene <scene.Scene>} object
301            @param scene: Scene in which objects are to be rendered on
302            """
303    
304          Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))          if (self._isModified() == True):
305          scene._addActor3D(viewport, Actor3D._getActor3D(self))              if(self.__data_collector._isScalarSet() == True):
306                    self.__data_collector._setActiveScalar()
307                if(self.__data_collector._isTensorSet() == True):
308                    self.__data_collector._setActiveTensor()
309    
310                # self._isScalarRangeSet checks whether the scalar range has been
311                # specified by the user. If it has, then the scalar range
312                # read from the source will be ignored.
313                if(not(self._isScalarRangeSet())):
314                    self._setScalarRange(self.__data_collector._getScalarRange())
315                self.__modified = False
316    
317    
318  ###############################################################################  ###############################################################################
# Line 263  class EllipsoidOnPlaneClip(DataSetMapper Line 359  class EllipsoidOnPlaneClip(DataSetMapper
359          @param outline: Places an outline around the domain surface          @param outline: Places an outline around the domain surface
360          """          """
361    
362          # NOTE: Actor3D is inherited and there are two instances declared here.          self.__data_collector = data_collector
363          # As a result, when methods from Actor3D is invoked from the driver,          self.__viewport = viewport
364          # only the methods associated with the latest instance (which in this          self.__lut = lut
365          # case is the Actor3D for the Ellipsoid) can be executed. Actor3D          self.__cell_to_point = cell_to_point
366          # methods associated with Outline cannot be invoked from the driver.          self.__outline = outline
367          # They can only be called within here, which is why Outline must be  
368          # place before Ellipsoid as there is unlikely to be any changes          # Keeps track whether EllipsoidOnPlaneClip has been modified.
369          # made to the Outline's Actor3D.          self.__modified = True      
370            Transform.__init__(self)
371            Plane.__init__(self)
372            Clipper.__init__(self)
373            MaskPoints.__init__(self)
374            Sphere.__init__(self)
375            TensorGlyph.__init__(self)
376            Normals.__init__(self)
377            DataSetMapper.__init__(self)
378            Actor3D.__init__(self)
379            scene._addVisualizationModules(self)
380    
381          # ----- Outline -----          # ----- Outline -----
382    
383          if(outline == True):          # NOTE: Changes cannot be made to the Outline's properties from the
384              outline = Outline(data_collector._getOutput())          # driver.
385              DataSetMapper.__init__(self, outline._getOutput())          if(self.__outline == True):
386                outline = Outline(self.__data_collector._getDataCollectorOutput())
387                mapper = DataSetMapper()
388                mapper._setupDataSetMapper(outline._getOutlineOutput())
389    
390              Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))              actor3D = Actor3D()
391                actor3D._setupActor3D(mapper._getDataSetMapper())
392              # Default outline color is black.              # Default outline color is black.
393              Actor3D.setColor(self, Color.BLACK)              actor3D.setColor(Color.BLACK)
394    
395              # Default line width is 1.              # Default line width is 1.
396              Actor3D._setLineWidth(self, 1)              actor3D._setLineWidth(1)
397              scene._addActor3D(viewport, Actor3D._getActor3D(self))              scene._addActor3D(self.__viewport, actor3D._getActor3D())
398    
399          # ----- Ellipsoid on a clipped plane -----          # ----- Ellipsoid on a clipped plane -----
400    
401          # NOTE: Lookup table color mapping (color or grey scale) MUST be set          # NOTE: Lookup table color mapping (color or grey scale) MUST be set
402          # before DataSetMapper. If it is done after DataSetMapper, no effect          # before DataSetMapper. If it is done after DataSetMapper, no effect
403          # will take place.          # will take place.
404          if(lut == Lut.COLOR): # Colored lookup table.          if(self.__lut == Lut.COLOR): # Colored lookup table.
405              lookup_table = LookupTable()              lookup_table = LookupTable()
406              lookup_table._setTableValue()              lookup_table._setTableValue()
407          elif(lut == Lut.GREY_SCALE): # Grey scaled lookup table.          elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
408              lookup_table = LookupTable()              lookup_table = LookupTable()
409              lookup_table._setLookupTableToGreyScale()              lookup_table._setLookupTableToGreyScale()
410    
411          Transform.__init__(self)              self._setupPlane(self._getTransform())
         Plane.__init__(self, Transform._getTransform(self))  
412    
413          if(cell_to_point == True): # Converts cell data to point data.          if(self.__cell_to_point == True): # Converts cell data to point data.
414              c2p = CellDataToPointData(data_collector._getOutput())              c2p = CellDataToPointData(
415              MaskPoints.__init__(self, c2p._getOutput())                      self.__data_collector._getDataCollectorOutput())
416          elif(cell_to_point == False): # No conversion happens.                self._setupMaskPoints(c2p._getCellToPointOutput())
417              MaskPoints.__init__(self, data_collector._getOutput())          elif(self.__cell_to_point == False): # No conversion happens.  
418                self._setupMaskPoints(
419                        self.__data_collector._getDataCollectorOutput())
420    
421          # NOTE: TensorGlyph must come before Clipper. Otherwise clipping          # NOTE: TensorGlyph must come before Clipper. Otherwise clipping
422          # may not work correctly.          # may not work correctly.
423          Sphere.__init__(self)          self._setupTensorGlyph(self._getMaskPointsOutput(),
424          TensorGlyph.__init__(self, MaskPoints._getOutput(self),                  self._getSphereOutput())
425                  Sphere._getOutput(self))          self._setupNormals(self._getTensorGlyphOutput())
         Normals.__init__(self, TensorGlyph._getOutput(self))  
426    
427          # NOTE: Clipper must come after TensorGlyph. Otherwise clipping          # NOTE: Clipper must come after TensorGlyph. Otherwise clipping
428          # may not work correctly.          # may not work correctly.
429          Clipper.__init__(self, Normals._getOutput(self),          self._setupClipper(self._getNormalsOutput(),
430                  Plane._getPlane(self))                    self._getPlane())  
431          Clipper._setClipFunction(self)          self._setClipFunction()
432    
433          DataSetMapper.__init__(self, Clipper._getOutput(self),          self._setupDataSetMapper(self._getClipperOutput(),
434              lookup_table._getLookupTable())                  lookup_table._getLookupTable())
435          DataSetMapper._setScalarRange(self, data_collector._getScalarRange())  
436            self._setupActor3D(self._getDataSetMapper())
437            scene._addActor3D(self.__viewport, self._getActor3D())
438    
439        def _isModified(self):  
440            """
441            Return whether the EllipsoidOnPlaneClip or DataCollector has been
442            modified.
443    
444            @rtype: Boolean
445            @return: True or False
446            """
447    
448            return self.__modified or self.__data_collector._isModified()
449    
450        def _render(self, scene):
451            """
452            Render the ellipsoids clip using a plane.
453    
454            @type scene: L{Scene <scene.Scene>} object
455            @param scene: Scene in which objects are to be rendered on
456            """
457    
458          data_collector._paramForUpdatingMultipleSources(VizType.ELLIPSOID,          if (self._isModified() == True):
459                  ColorMode.SCALAR, DataSetMapper._getDataSetMapper(self))              if(self.__data_collector._isScalarSet() == True):
460                    self.__data_collector._setActiveScalar()
461                if(self.__data_collector._isTensorSet() == True):
462                    self.__data_collector._setActiveTensor()
463    
464                # self._isScalarRangeSet checks whether the scalar range has been
465                # specified by the user. If it has, then the scalar range
466                # read from the source will be ignored.
467                if(not(self._isScalarRangeSet())):
468                    self._setScalarRange(self.__data_collector._getScalarRange())
469                self.__modified = False
470    
         Actor3D.__init__(self, DataSetMapper._getDataSetMapper(self))  
         scene._addActor3D(viewport, Actor3D._getActor3D(self))  
471    

Legend:
Removed from v.1147  
changed lines
  Added in v.1197

  ViewVC Help
Powered by ViewVC 1.1.26