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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 973 - (show annotations)
Thu Feb 15 04:06:23 2007 UTC (12 years, 8 months ago) by jongui
File MIME type: text/x-python
File size: 4165 byte(s)
Corrected a bug related to the scalar and vector range in the velocity module.
1 """
2 @author: John NGUI
3 """
4
5 import vtk
6 from constant import Source
7
8 class DataCollector:
9 """
10 Class that defines a data collector which dealrs with the source
11 of data for the visualisation.
12 """
13
14 def __init__(self, source = Source.XML):
15 """
16 Initialise the data collector.
17
18 @type source: L{Source <constant.Source>} constant
19 @param source: Source data type
20 """
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 Set the source file name to read.
28
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
36 # 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 Specify the scalar field to load from the source file.
43
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 Specify the vector field to load from the source file.
53
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 Specify the tensor field to load from the source file.
63
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 @rtype: Two column tuple containing numbers
75 @return: Scalar range
76 """
77
78 #self._getOutput().GetPointData().SetActiveScalars("temp")
79 return self._getOutput().GetPointData().GetScalars().GetRange(-1)
80
81 def _getVectorRange(self):
82 """
83 Return the vector range.
84
85 @rtype: Two column tuple containing numbers
86 @return: Vector range
87 """
88
89 vector_range = self._getOutput().GetPointData().GetVectors().GetRange(-1)
90
91 # NOTE: Generally GetRange(-1) returns the correct vector range.
92 # However, there are certain data sets where GetRange(-1) seems
93 # to return incorrect mimimum vector although the maximum vector is
94 # correct. As a result, the mimimum vector has been hard coded to 0.0
95 # to accommodate those incorrect cases.
96
97 return (0.0, vector_range[1])
98
99 def _getTensorRange(self):
100 """
101 Return the tensor range.
102
103 @rtype: Two column table
104 @return: Tensor range
105 """
106
107 return self._getOutput().GetPointData().GetTensors().GetRange()
108
109 def _getOutput(self):
110 """
111 Return the output of the data collector.
112
113 @rtype: vtkUnstructuredGrid
114 @return: Unstructured grid
115 """
116
117 return self.__output
118
119
120 ###############################################################################
121
122
123 from constant import ImageFormat
124
125 class ImageReader:
126 """
127 Class that defines an image reader.
128 """
129
130 def __init__(self, format):
131 """
132 Initialise the image reader.
133
134 @type format: String
135 @param format: Format of the image
136 """
137
138 self.__format = format
139 self.__vtk_image_reader = self.getImageReader()
140
141 def getImageReader(self):
142 """
143 Return the appropriate image reader based on the supplied image
144 format.
145
146 @rtype: vtkImageReader2 (i.e. vtkJPEGReader, etc)
147 @return: Image reader
148 """
149
150 if(self.__format == ImageFormat.JPG):
151 return vtk.vtkJPEGReader()
152 elif(self.__format == ImageFormat.BMP):
153 return vtk.vtkBMPReader()
154 elif(self.__format == ImageFormat.PNM):
155 return vtk.vtkPNMReader()
156 elif(self.__format == ImageFormat.PNG):
157 return vtk.vtkPNGReader()
158 elif(self.__format == ImageFormat.TIF):
159 return vtk.vtkTIFFReader()
160
161 def setFileName(self, file_name):
162 """
163 Set the image file name.
164
165 @type file_name: String
166 @param file_name: Image file name to be read
167 """
168
169 self.__vtk_image_reader.SetFileName(file_name)
170
171 def _getOutput(self):
172 """
173 Return the output of the image reader.
174
175 @rtype: vtkImageData
176 @return Image data
177 """
178
179 return self.__vtk_image_reader.GetOutput()
180

  ViewVC Help
Powered by ViewVC 1.1.26