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

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

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

revision 1077 by jongui, Wed Apr 4 13:31:39 2007 UTC revision 1078 by jongui, Thu Apr 5 06:18:47 2007 UTC
# Line 12  except ImportError: Line 12  except ImportError:
12    
13  class DataCollector:  class DataCollector:
14      """      """
15      Class that defines a data collector which deals with the source      Class that defines a data collector. A data collector is used to read
16      of data for the visualisation.      data from an XML file or from an escript object directly.
17    
18      @attention: One DataCollector instance can only be used to specify one      @attention: One DataCollector instance can only be used to specify one
19      scalar, vector and tensor attribute from a source at any one time. If a      scalar, vector and tensor attribute from a source at any one time. If a
20      second scalar, vector or tensor attribute needs to be specified from the      second scalar, vector or tensor attribute needs to be specified from the
21      same source, a second DataCollector instance must be created.      same source, a second DataCollector instance must be created.
22    
23      @attention: When a series of XML files / ESCRIPT objects are read      @attention: When a series of XML files or escript objects are read
24      (using 'setFileName' in a for-loop), the 'setActiveScalar' /      (using 'setFileName' or 'setData' in a for-loop), the 'setActiveScalar' /
25      'setActiveVector' / 'setActiveTensor' have to be called after loading each      'setActiveVector' / 'setActiveTensor' have to be called for each new file
26      new file (if a specific field needs to be loaded) as all active fields      (provided a specific field needs to be loaded) as all active fields
27      specified for the previous file goes back to the default once a new file      specified from the previous file goes back to the default once a new file
28      is read.      is read.
29      """      """
30    
# Line 44  class DataCollector: Line 44  class DataCollector:
44          # Source is a escript data object using a temp file in the background.          # Source is a escript data object using a temp file in the background.
45          elif (self.__source == Source.ESCRIPT):          elif (self.__source == Source.ESCRIPT):
46              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()
47              # Create a temporary .xml file and retrieves its path.              # Create a temporary .xml file and retrieve its path.
48              self.__tmp_file = tempfile.mkstemp(suffix=".xml")[1]              self.__tmp_file = tempfile.mkstemp(suffix=".xml")[1]
             #self.__vtk_xml_reader.SetFileName(self.__tmp_file)  
49    
50      def __del__(self):      def __del__(self):
51          """          """
# Line 58  class DataCollector: Line 57  class DataCollector:
57    
58      def setFileName(self, file_name):      def setFileName(self, file_name):
59          """          """
60          Set the source file name to read.          Set the XML file name to read.
61    
62          @type file_name: String          @type file_name: String
63          @param file_name: Name of the file to read          @param file_name: Name of the file to read
# Line 68  class DataCollector: Line 67  class DataCollector:
67              self.__vtk_xml_reader.SetFileName(file_name)              self.__vtk_xml_reader.SetFileName(file_name)
68    
69              # Update must be called after SetFileName to make the reader              # Update must be called after SetFileName to make the reader
70              # up to date. Otherwise, some output values may be incorrect.              # up-to-date. Otherwise, some output values may be incorrect.
71              self.__vtk_xml_reader.Update()              self.__vtk_xml_reader.Update()
72              self.__output = self.__vtk_xml_reader.GetOutput()              self.__output = self.__vtk_xml_reader.GetOutput()
73              self.__get_attribute_lists()              self.__get_attribute_lists()
# Line 78  class DataCollector: Line 77  class DataCollector:
77              # instantiated. Therefore, the range of the mapper can only be              # instantiated. Therefore, the range of the mapper can only be
78              # updated after the first file/source has been read.              # updated after the first file/source has been read.
79              if(self.__count > 0):              if(self.__count > 0):
80                  self._updateRange(None)                  self._updateRange()
81    
82              self.__count+=1              self.__count+=1
83    
# Line 91  class DataCollector: Line 90  class DataCollector:
90          Create data using the <name>=<data> pairing. Assumption is made          Create data using the <name>=<data> pairing. Assumption is made
91          that the data will be given in the appropriate format.          that the data will be given in the appropriate format.
92    
93          @bug: Reading source data directly from an ESCRIPT object is NOT          @bug: Reading source data directly from an escript object is NOT
94          work properly and should NOT be used.          work properly. Therefore this method should NOT be used at this
95            stage.
96          """          """
97    
98          if self.__source == Source.ESCRIPT:          if self.__source == Source.ESCRIPT:
# Line 102  class DataCollector: Line 102  class DataCollector:
102              # setFileName. If Modified is not called, only the first file              # setFileName. If Modified is not called, only the first file
103              # will always be displayed. The reason Modified is used is              # will always be displayed. The reason Modified is used is
104              # because the same temporary file name is always used              # because the same temporary file name is always used
105              # (old file is overwritten). Modified MUST NOT be used in              # (previous file is overwritten). Modified MUST NOT be used in
106              # setFileName, it can cause incorrect output such as map.              # setFileName, it can cause incorrect output such as map.
107              self.__vtk_xml_reader.Modified()              self.__vtk_xml_reader.Modified()
108              # Update must be called after Modified. If Update is called before              # Update must be called after Modified. If Update is called before
# Line 127  class DataCollector: Line 127  class DataCollector:
127          # or cell data. If not available, program exits.          # or cell data. If not available, program exits.
128    
129          # NOTE: This check is similar to the check used in _getScalarRange          # NOTE: This check is similar to the check used in _getScalarRange
130          # but is used only when a scalar attribute has been specified.          # but this is used only when a scalar attribute has been specified.
131          if scalar in self.__point_attribute['scalars']:          if scalar in self.__point_attribute['scalars']:
132              self._getOutput().GetPointData().SetActiveScalars(scalar)              self._getOutput().GetPointData().SetActiveScalars(scalar)
133          elif scalar in self.__cell_attribute['scalars']:          elif scalar in self.__cell_attribute['scalars']:
# Line 148  class DataCollector: Line 148  class DataCollector:
148          # or cell data. If not available, program exits.          # or cell data. If not available, program exits.
149    
150          # NOTE: This check is similar to the check used in _getVectorRange          # NOTE: This check is similar to the check used in _getVectorRange
151          # but is used only when a vector attribute has been specified.          # but this is used only when a vector attribute has been specified.
152          if vector in self.__point_attribute['vectors']:          if vector in self.__point_attribute['vectors']:
153              self._getOutput().GetPointData().SetActiveVectors(vector)              self._getOutput().GetPointData().SetActiveVectors(vector)
154          elif vector in self.__cell_attribute['vectors']:          elif vector in self.__cell_attribute['vectors']:
# Line 169  class DataCollector: Line 169  class DataCollector:
169          # or cell data. If not available, program exits.          # or cell data. If not available, program exits.
170    
171          # NOTE: This check is similar to the check used in _getTensorRange          # NOTE: This check is similar to the check used in _getTensorRange
172          # but is used only when a tensor attribute has been specified.          # but this is used only when a tensor attribute has been specified.
173          if tensor in self.__point_attribute['tensors']:          if tensor in self.__point_attribute['tensors']:
174              self._getOutput().GetPointData().SetActiveTensors(tensor)              self._getOutput().GetPointData().SetActiveTensors(tensor)
175          elif tensor in self.__cell_attribute['tensors']:          elif tensor in self.__cell_attribute['tensors']:
# Line 179  class DataCollector: Line 179  class DataCollector:
179              sys.exit(0)              sys.exit(0)
180    
181      # 'object' is set to 'None' because some types of visualization have      # 'object' is set to 'None' because some types of visualization have
182      # two different ranges that need to be updated while others only have one.      # two ranges that needs to be updated while others only have one.
183      def _paramForUpdatingMultipleSources(self, viz_type, color_mode, mapper,      def _paramForUpdatingMultipleSources(self, viz_type, color_mode, mapper,
184              object = None):              object = None):
185          """          """
186          Parameters required to update the necessary range when two or more          Parameters required to update the necessary data when two or more
187          files are read.          files or escript objects are read.
188    
189          @type viz_type: : L{VizType <constant.VizType>} constant          @type viz_type: : L{VizType <constant.VizType>} constant
190          @param viz_type: Type if visualization (i.e. Map, Velocity, etc)          @param viz_type: Type if visualization
191          @type color_mode: L{ColorMode <constant.ColorMode>} constant          @type color_mode: L{ColorMode <constant.ColorMode>} constant
192          @param color_mode: Type of color mode          @param color_mode: Type of color mode
193          @type mapper: vtkDataSetMapper          @type mapper: vtkDataSetMapper
194          @param mapper: Mapped data          @param mapper: Mapped data
195          @type object: vtkPolyDataAlgorith (i.e. vtkContourFilter, vtkGlyph3D, \          @type object: vtkPolyDataAlgorithm (i.e. vtkContourFilter, vtkGlyph3D, \
196                  etc)                  etc)
197          @param object: Poly data          @param object: Polygonal data
198          """          """
199    
200          self.__viz_type = viz_type          self.__viz_type = viz_type
# Line 202  class DataCollector: Line 202  class DataCollector:
202          self.__mapper = mapper          self.__mapper = mapper
203          self.__object = object          self.__object = object
204    
205      def _updateRange(self, range):      def _updateRange(self):
206          """          """
207          Update the necessary range when two or more sources are read in.          Update the necessary range(s) when two or more files or escript objects
208            are read.
209          """          """
210    
211          if self.__viz_type == VizType.MAP or \          if self.__viz_type == VizType.MAP or \
# Line 232  class DataCollector: Line 233  class DataCollector:
233    
234      def __get_array_type(self, arr):      def __get_array_type(self, arr):
235          """          """
236          Return if the array type is a scalar, vector or tensor by looking          Return whether an array type is scalar, vector or tensor by looking
237          at the number of components in the array.          at the number of components in the array.
238    
239          @type arr: vtkDataArray          @type arr: vtkDataArray
240          @param arr: An array from the source.          @param arr: An array from the source.
241          @rtype: String          @rtype: String
242          @return: Array type ('scalar', vector', 'tensor')          @return: Array type ('scalar', vector' or 'tensor')
243          """          """
244    
245          # Number of components in an array.          # Number of components in an array.
# Line 297  class DataCollector: Line 298  class DataCollector:
298          # If not available, program exits.          # If not available, program exits.
299    
300          # NOTE: This check is similar to the check used in _setActiveScalar          # NOTE: This check is similar to the check used in _setActiveScalar
301          # but is used only when no scalar attribute has been specified.          # but this is used only when no scalar attribute has been specified.
302          if(len(self.__point_attribute['scalars']) != 0):          if(len(self.__point_attribute['scalars']) != 0):
303              return self._getOutput().GetPointData().GetScalars().GetRange(-1)              return self._getOutput().GetPointData().GetScalars().GetRange(-1)
304          elif(len(self.__cell_attribute['scalars']) != 0):          elif(len(self.__cell_attribute['scalars']) != 0):
# Line 318  class DataCollector: Line 319  class DataCollector:
319          # If not available, program exits.          # If not available, program exits.
320    
321          # NOTE: This check is similar to the check used in _setActiveVector          # NOTE: This check is similar to the check used in _setActiveVector
322          # but is used only when no vector attribute has been specified.          # but this is used only when no vector attribute has been specified.
323    
324          # NOTE: Generally GetRange(-1) returns the correct vector range.          # NOTE: Generally GetRange(-1) returns the correct vector range.
325          # However, there are certain data sets where GetRange(-1) seems          # However, there are certain data sets where GetRange(-1) seems
326          # to return incorrect mimimum vector although the maximum vector is          # to return incorrect mimimum vector although the maximum vector is
327          # correct. As a result, the mimimum vector has been hard coded to 0.0          # correct. As a result, the mimimum vector has been hard coded to 0.0
328          # to accommodate the incorrect cases.          # to accommodate for the incorrect cases.
329          if(len(self.__point_attribute['vectors']) != 0):          if(len(self.__point_attribute['vectors']) != 0):
330              vector_range = \              vector_range = \
331                      self._getOutput().GetPointData().GetVectors().GetRange(-1)                      self._getOutput().GetPointData().GetVectors().GetRange(-1)
# Line 341  class DataCollector: Line 342  class DataCollector:
342          """          """
343          Return the tensor range.          Return the tensor range.
344    
345          @rtype: Two column table          @rtype: Two column tuple containing numbers
346          @return: Tensor range          @return: Tensor range
347          """          """
348    
# Line 349  class DataCollector: Line 350  class DataCollector:
350          # If not available, program exits.          # If not available, program exits.
351    
352          # NOTE: This check is similar to the check used in _setActiveTensor          # NOTE: This check is similar to the check used in _setActiveTensor
353          # but is used only when no tensor attribute has been specified.          # but this is used only when no tensor attribute has been specified.
354          if(len(self.__point_attribute['tensors']) != 0):          if(len(self.__point_attribute['tensors']) != 0):
355              return self._getOutput().GetPointData().GetTensors().GetRange(-1)              return self._getOutput().GetPointData().GetTensors().GetRange(-1)
356          elif(len(self.__cell_attribute['tensors']) != 0):          elif(len(self.__cell_attribute['tensors']) != 0):

Legend:
Removed from v.1077  
changed lines
  Added in v.1078

  ViewVC Help
Powered by ViewVC 1.1.26