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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (11 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 2620 byte(s)
Don't panic.
Updating copyright stamps

1 ksteube 1809
2     ########################################################
3     #
4 jfenwick 2881 # Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1809 # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7     #
8     # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11     #
12     ########################################################
13    
14 jfenwick 2881 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 ksteube 1809 Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18     __license__="""Licensed under the Open Software License version 3.0
19     http://www.opensource.org/licenses/osl-3.0.php"""
20 jfenwick 2344 __url__="https://launchpad.net/escript-finley"
21 ksteube 1809
22 ksteube 1147 """
23 jfenwick 2625 :var __author__: name of author
24     :var __copyright__: copyrights
25     :var __license__: licence agreement
26     :var __url__: url entry point on documentation
27     :var __version__: version
28     :var __date__: date of the version
29 ksteube 1147 """
30    
31 jongui 1197 __author__="John Ngui, john.ngui@uq.edu.au"
32    
33 ksteube 1147 from constant import ImageFormat
34 gross 2313 from esys.escript import getMPISizeWorld
35 gross 2365 if getMPISizeWorld()==1: import vtk
36 ksteube 1147
37     class ImageReader:
38     """
39     Class that defines an image reader. An image reader is used to read
40     data from an image in a variety of formats.
41     """
42    
43     def __init__(self, format):
44     """
45     Initialise the image reader.
46    
47 jfenwick 2625 :type format: `ImageFormat` constant
48     :param format: Format of the image
49 ksteube 1147 """
50 gross 2313 if getMPISizeWorld()>1:
51     raise ValueError,"pyvisi.ImageReader is not running on more than one processor."
52 ksteube 1147 self.__format = format
53     self.__vtk_image_reader = self.__getImageReader()
54    
55     def __getImageReader(self):
56     """
57     Return the corresponding image reader based on the supplied image
58     format.
59    
60 jfenwick 2625 :rtype: vtkImageReader2 (i.e. vtkJPEGReader, etc)
61     :return: Image reader
62 ksteube 1147 """
63    
64     if(self.__format == ImageFormat.JPG):
65     return vtk.vtkJPEGReader()
66     elif(self.__format == ImageFormat.BMP):
67     return vtk.vtkBMPReader()
68     elif(self.__format == ImageFormat.PNM):
69     return vtk.vtkPNMReader()
70     elif(self.__format == ImageFormat.PNG):
71     return vtk.vtkPNGReader()
72     elif(self.__format == ImageFormat.TIF):
73     return vtk.vtkTIFFReader()
74    
75     def setImageName(self, image_name):
76     """
77     Set the image file name to be read.
78    
79 jfenwick 2625 :type image_name: String
80     :param image_name: Image name from which image data is to be read
81 ksteube 1147 """
82    
83     self.__vtk_image_reader.SetFileName(image_name)
84    
85 jongui 1148 def _getImageReaderOutput(self):
86 ksteube 1147 """
87     Return the output of the image reader.
88    
89 jfenwick 2625 :rtype: vtkImageData
90     :return: Image data
91 ksteube 1147 """
92    
93     return self.__vtk_image_reader.GetOutput()
94    

  ViewVC Help
Powered by ViewVC 1.1.26