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

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

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

revision 1210 by jongui, Wed Jun 20 05:01:30 2007 UTC revision 1211 by jongui, Wed Jul 4 05:16:46 2007 UTC
# Line 508  class MapOnScalarClip(DataSetMapper, Act Line 508  class MapOnScalarClip(DataSetMapper, Act
508                      self.__data_collector._getDataCollectorOutput())                      self.__data_collector._getDataCollectorOutput())
509              # None is used because a plane is not required when a scalar              # None is used because a plane is not required when a scalar
510              # value is used to perform the clipping.              # value is used to perform the clipping.
511              self._setupClipper(c2p._getDataCollectorOutput(), None)              self._setupClipper(c2p._getCellToPointOutput(), None)
512          elif(self.__cell_to_point == False): # No conversion happens.          elif(self.__cell_to_point == False): # No conversion happens.
513              self._setupClipper(              self._setupClipper(
514                      self.__data_collector._getDataCollectorOutput(),None)                      self.__data_collector._getDataCollectorOutput(),None)
# Line 548  class MapOnScalarClip(DataSetMapper, Act Line 548  class MapOnScalarClip(DataSetMapper, Act
548              self.__modified = False              self.__modified = False
549    
550    
551    ##############################################################################
552    
553    
554    from rotation import Rotation
555    from geometry import Geometry
556    
557    # NOTE: DataSetMapper, Actor3D, Clipper and Rotation were inherited
558    # to allow access to their public methods from the driver.
559    class MapOnScalarClipWithRotation(DataSetMapper, Actor3D, Clipper, Rotation):
560        """
561        This class works in a similar way to L{Map <map.Map>}, except that it
562        shows a 2D scalar field clipped using a scalar value and subsequently
563        rotated around the z-axis to create a  3D looking effect. This class should
564        only be used with 2D data sets and NOT 3D.
565        """
566    
567        # The SOUTH_WEST default viewport is used when there is only one viewport.
568        # This saves the user from specifying the viewport when there is only one.
569        # If no lut is specified, the color scheme will be used.
570        def __init__(self, scene, data_collector, viewport = Viewport.SOUTH_WEST,
571                lut = Lut.COLOR, cell_to_point = False):
572            """
573            Initialise the MapOnScalarClipWithRotation.
574    
575            @attention: The source can either be point or cell data. If the
576            source is cell data, a conversion to point data may or may not be
577            required, in order for the object to be rendered correctly.
578            If a conversion is needed, the 'cell_to_point' flag must be set to
579            'True', otherwise 'False' (which is the default). On occasions, an
580            inaccurate object may be rendered from cell data even after conversion.
581    
582            @type scene: L{Scene <scene.Scene>} object
583            @param scene: Scene in which objects are to be rendered on
584            @type data_collector: L{DataCollector <datacollector.DataCollector>}
585                    object
586            @param data_collector: Deal with source of data for visualisation
587            @type viewport: L{Viewport <constant.Viewport>} constant
588            @param viewport: Viewport in which objects are to be rendered on
589            @type lut : L{Lut <constant.Lut>} constant
590            @param lut: Lookup table color scheme
591            @type cell_to_point: Boolean
592            @param cell_to_point: Converts cell data to point data (by averaging)
593            """
594    
595            self.__data_collector = data_collector
596            self.__viewport = viewport
597            self.__lut = lut
598            self.__cell_to_point = cell_to_point
599            
600            # Keeps track whether MapOnScalarClipWithRotation has been modified.
601            self.__modified = True
602            Clipper.__init__(self)
603            Rotation.__init__(self)
604            DataSetMapper.__init__(self)
605            Actor3D.__init__(self)
606            scene._addVisualizationModules(self)
607    
608        def _isModified(self):  
609            """
610            Return whether the MapOnScalarClipWithRotation or DataCollector has
611            been modified.
612    
613            @rtype: Boolean
614            @return: True or False
615            """
616    
617            return self.__modified or self.__data_collector._isModified()
618    
619        def _render(self, scene):
620            """
621            Render the surface map clip using scalar data and subsequently rotated.
622    
623            @type scene: L{Scene <scene.Scene>} object
624            @param scene: Scene in which objects are to be rendered on
625            """
626    
627            # This entire 'if' section had to be moved from the __init__ method
628            # due to the use of 'GetPoints().GetNumberOfPoints()'. A source
629            # (i.e. xml file) must be
630            # supplied before 'GetPoints().GetNumberOfPoints()' is able to return
631            # the correct value
632            # when executed. This is to accommodate for lazy evaluation.
633            if (self._isModified() == True):
634    
635                # Swaps the points from the y-axis to the z-axis and vice-versa.
636                # This is needed as VTK is only able to perform rotation along
637                # the z-axis.
638                output = self.__data_collector._getDataCollectorOutput()
639                num_points = output.GetPoints().GetNumberOfPoints()
640                for i in range (num_points):
641                    point = output.GetPoints().GetPoint(i)
642                    output.GetPoints().SetPoint(i, point[0], point[2], point[1])
643    
644                # --- Map clipped using a scalar value and subsequently rotated ---
645    
646                # NOTE: Lookup table color mapping (color or grey scale) MUST be set
647                # before DataSetMapper. If it is done after DataSetMapper, no effect
648                # will take place.
649                if(self.__lut == Lut.COLOR): # Colored lookup table.
650                    lookup_table = LookupTable()
651                    lookup_table._setTableValue()
652                elif(self.__lut == Lut.GREY_SCALE): # Grey scaled lookup table.
653                    lookup_table = LookupTable()
654                    lookup_table._setLookupTableToGreyScale()
655    
656                if(self.__cell_to_point == True): #Converts cell data to point data.
657                    c2p = CellDataToPointData(output)
658                    # None is used because a plane is not required when a scalar
659                    # value is used to perform the clipping.
660                    self._setupClipper(c2p._getCellToPointOutput(), None)
661                elif(self.__cell_to_point == False): # No conversion happens.
662                    self._setupClipper(output, None)
663    
664                geometry = Geometry(self._getClipperOutput())  
665                
666                self._setupRotationExtrusionFilter(geometry._getGeometryOutput())
667                self._setupDataSetMapper(self._getRotationOutput(),
668                        lookup_table._getLookupTable())
669    
670                self._setupActor3D(self._getDataSetMapper())
671                scene._addActor3D(self.__viewport, self._getActor3D())
672    
673                if(self.__data_collector._isScalarSet() == True):
674                    self.__data_collector._setActiveScalar()
675                # self._isScalarRangeSet checks whether the scalar range has been
676                # specified by the user. If it has, then the scalar range
677                # read from the source will be ignored.
678                if(not(self._isScalarRangeSet())):
679                    self._setScalarRange(self.__data_collector._getScalarRange())
680    
681                self.__modified = False
682    
683    
684    

Legend:
Removed from v.1210  
changed lines
  Added in v.1211

  ViewVC Help
Powered by ViewVC 1.1.26