/[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 975 by jongui, Thu Feb 15 04:06:23 2007 UTC revision 976 by gross, Thu Feb 15 23:57:02 2007 UTC
# Line 3  Line 3 
3  """  """
4    
5  import vtk  import vtk
6    import tempfile, os
7  from constant import Source  from constant import Source
8    try:
9      import esys.escript
10    except ImportError:
11      print "Warning: importing esys.escript failed."
12    
13  class DataCollector:  class DataCollector:
14      """      """
# Line 18  class DataCollector: Line 23  class DataCollector:
23          @type source: L{Source <constant.Source>} constant          @type source: L{Source <constant.Source>} constant
24          @param source: Source data type          @param source: Source data type
25          """          """
26                    
27                    self.__source=source
28          if(source == Source.XML): # Source is an XML file.          if(source == Source.XML): # Source is an XML file.
29              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()              self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()
30                    # this is a temporary solution using a file:
31                    if (source == Source.ESCRIPT):
32                             self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()
33                             self.__tmp_file=tempfile.mkstemp(suffix=".xml")[1]
34                             self.__vtk_xml_reader.SetFileName(self.__tmp_file)
35                             self.__output = self.__vtk_xml_reader.GetOutput()
36            def __del__(self):
37                   """
38                   clean up
39                   """
40                   if (self.__source == Source.ESCRIPT):
41                       if os.access(self.__tmp_file,os.F_OK): os.unlink(self.__tmp_file)
42    
43    
44      def setFileName(self, file_name):      def setFileName(self, file_name):
45          """          """
# Line 29  class DataCollector: Line 48  class DataCollector:
48          @type file_name: String          @type file_name: String
49          @param file_name: Name of the file to read          @param file_name: Name of the file to read
50          """          """
51                    if self.__source == Source.XML:
52          self.__vtk_xml_reader.SetFileName(file_name)             self.__vtk_xml_reader.SetFileName(file_name)
53          self.__output = self.__vtk_xml_reader.GetOutput()             self.__output = self.__vtk_xml_reader.GetOutput()
54    
55          # NOTE: Update must be called after SetFileName to make the reader             # NOTE: Update must be called after SetFileName to make the reader
56          # up to date. Otherwise, some output values may be incorrect.             # up to date. Otherwise, some output values may be incorrect.
57          self.__vtk_xml_reader.Update()             self.__vtk_xml_reader.Update()
58                    else:
59                       raise ValueError("source type %s does not support setFileName"%self.__source)
60    
61            def setData(self,**args):
62                    """
63                    sets the data using. <name>=<data> sets the data tagged by <name> to the object <data>. It is expected
64                    that the data are given in an appropriate source type.
65                    """
66                    if self.__source == Source.ESCRIPT:
67                       esys.escript.saveVTK(self.__tmp_file,**args)
68                       self.__vtk_xml_reader.Update()
69                    else:
70                       raise ValueError("source type %s does not support setData"%self.__source)
71    
72      def _setActiveScalar(self, scalar):      def _setActiveScalar(self, scalar):
73          """          """
# Line 86  class DataCollector: Line 118  class DataCollector:
118          @return: Vector range          @return: Vector range
119          """          """
120    
121                    print self._getOutput().GetPointData().GetVectors()
122          vector_range = self._getOutput().GetPointData().GetVectors().GetRange(-1)          vector_range = self._getOutput().GetPointData().GetVectors().GetRange(-1)
123    
124          # NOTE: Generally GetRange(-1) returns the correct vector range.          # NOTE: Generally GetRange(-1) returns the correct vector range.

Legend:
Removed from v.975  
changed lines
  Added in v.976

  ViewVC Help
Powered by ViewVC 1.1.26