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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 949 - (hide annotations)
Fri Feb 2 05:33:05 2007 UTC (13 years, 6 months ago) by jongui
File MIME type: text/x-python
File size: 4102 byte(s)
Fixed some more bugs and added more epydocs. Testing remains outstanding.
1 jongui 943 """
2     @author: John NGUI
3     """
4    
5     import vtk
6     from constant import Source
7    
8     class DataCollector:
9     """
10 jongui 947 Class that defines a data collector which dealrs with the source
11     of data for the visualisation.
12 jongui 943 """
13    
14     def __init__(self, source = Source.XML):
15     """
16     Initialise the data collector.
17    
18     @type source: L{Source <constant.Source>} constant
19 jongui 947 @param source: Source data type
20 jongui 943 """
21    
22     if(source == Source.XML): # Source is an XML file.
23     self.__vtk_xml_reader = vtk.vtkXMLUnstructuredGridReader()
24    
25     def setFileName(self, file_name):
26     """
27 jongui 947 Set the source file name to read.
28 jongui 943
29     @type file_name: String
30     @param file_name: Name of the file to read
31     """
32    
33     self.__vtk_xml_reader.SetFileName(file_name)
34     self.__output = self.__vtk_xml_reader.GetOutput()
35 jongui 947
36 jongui 943 # NOTE: Update must be called after SetFileName to make the reader
37     # up to date. Otherwise, some output values may be incorrect.
38     self.__vtk_xml_reader.Update()
39    
40     def _setActiveScalar(self, scalar):
41     """
42 jongui 947 Specify the scalar field to load from the source file.
43 jongui 943
44     @type scalar: String
45     @param scalar: Scalar field to load from the file.
46     """
47    
48     self._getOutput().GetPointData().SetActiveScalars(scalar)
49    
50     def _setActiveVector(self, vector):
51     """
52 jongui 947 Specify the vector field to load from the source file.
53 jongui 943
54     @type vector: String
55     @param vector: Vector field to load from the file.
56     """
57    
58     self._getOutput().GetPointData().SetActiveVectors(vector)
59    
60     def _setActiveTensor(self, tensor):
61     """
62 jongui 947 Specify the tensor field to load from the source file.
63 jongui 943
64     @type tensor: String
65     @param tensor: Tensor field to load from the file.
66     """
67    
68     self._getOutput().GetPointData().SetActiveTensors(tensor)
69    
70     def _getScalarRange(self):
71     """
72     Return the scalar range.
73    
74 jongui 949 @rtype: Two column tuple containing numbers
75 jongui 943 @return: Scalar range
76     """
77    
78     return self._getOutput().GetPointData().GetScalars().GetRange(-1)
79    
80     def _getVectorRange(self):
81     """
82     Return the vector range.
83    
84 jongui 949 @rtype: Two column tuple containing numbers
85 jongui 943 @return: Vector range
86     """
87    
88 jongui 948 vector_range = self._getOutput().GetPointData().GetVectors().GetRange(-1)
89 jongui 943
90     # NOTE: Generally GetRange(-1) returns the correct vector range.
91     # However, there are certain data sets where GetRange(-1) seems
92     # to return incorrect mimimum vector although the maximum vector is
93     # correct. As a result, the mimimum vector has been hard coded to 0.0
94     # to accommodate those incorrect cases.
95     return (0.0, vector_range[1])
96    
97     def _getTensorRange(self):
98     """
99     Return the tensor range.
100    
101     @rtype: Two column table
102     @return: Tensor range
103     """
104    
105     return self._getOutput().GetPointData().GetTensors().GetRange()
106    
107     def _getOutput(self):
108     """
109     Return the output of the data collector.
110    
111     @rtype: vtkUnstructuredGrid
112     @return: Unstructured grid
113     """
114    
115     return self.__output
116    
117    
118 jongui 947 ###############################################################################
119    
120    
121 jongui 943 from constant import ImageFormat
122    
123     class ImageReader:
124     """
125     Class that defines an image reader.
126     """
127    
128     def __init__(self, format):
129     """
130     Initialise the image reader.
131    
132     @type format: String
133     @param format: Format of the image
134     """
135    
136     self.__format = format
137     self.__vtk_image_reader = self.getImageReader()
138    
139     def getImageReader(self):
140     """
141 jongui 947 Return the appropriate image reader based on the supplied image
142 jongui 943 format.
143    
144     @rtype: vtkImageReader2 (i.e. vtkJPEGReader, etc)
145     @return: Image reader
146     """
147    
148     if(self.__format == ImageFormat.JPG):
149     return vtk.vtkJPEGReader()
150     elif(self.__format == ImageFormat.BMP):
151     return vtk.vtkBMPReader()
152     elif(self.__format == ImageFormat.PNM):
153     return vtk.vtkPNMReader()
154     elif(self.__format == ImageFormat.PNG):
155     return vtk.vtkPNGReader()
156     elif(self.__format == ImageFormat.TIF):
157     return vtk.vtkTIFFReader()
158    
159     def setFileName(self, file_name):
160     """
161     Set the image file name.
162    
163     @type file_name: String
164 jongui 947 @param file_name: Image file name to be read
165 jongui 943 """
166    
167     self.__vtk_image_reader.SetFileName(file_name)
168    
169     def _getOutput(self):
170     """
171 jongui 947 Return the output of the image reader.
172 jongui 943
173     @rtype: vtkImageData
174     @return Image data
175     """
176    
177     return self.__vtk_image_reader.GetOutput()
178    

  ViewVC Help
Powered by ViewVC 1.1.26