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

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

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

revision 845 by jongui, Fri Sep 8 07:13:01 2006 UTC revision 846 by jongui, Mon Sep 11 07:40:09 2006 UTC
# Line 1  Line 1 
1    """
2    @author: John Ngui
3    @author: Lutz Gross
4    """
5    
6  import vtk  import vtk
7  from common import *  from common import *
8    
9  class Image(Common):  class Image(Common):
10        """
11        Class that displays an image.
12        """
13    
14      def __init__(self, scene, format):      def __init__(self, scene, format):
15            """
16            @type scene: L{Scene <scene.Scene>} object
17            @param scene: Scene in which components are to be added to
18            @type format: String
19            @param format: Format of the image (i.e. jpg)
20            """
21    
22          Common.__init__(self, scene)          Common.__init__(self, scene)
23          self.vtk_image_reader = self.determineReader(format)          self.vtk_image_reader = self.determineReader(format)
24          self.vtk_texture = None          self.vtk_texture = None
25          self.vtk_plane = None          self.vtk_plane = None
26    
27      def determineReader(self, format):      def determineReader(self, format):
28            """
29            Determines the image format and returns the corresponding image reader.
30    
31            @type format: String
32            @param format: Format of the image (i.e. jpg)
33            @rtype: vtkImageReader2 (i.e. vtkJPEGReader)
34            @return: VTK image reader
35            """
36    
37          if(format == "jpg"):          if(format == "jpg"):
38              return vtk.vtkJPEGReader()                return vtk.vtkJPEGReader()  
39          elif(format == "bmp"):          elif(format == "bmp"):
40              return vtk.vtkBMPReader()              return vtk.vtkBMPReader()
41    
42      def setFileName(self, file_name):      def setFileName(self, file_name):
43            """
44            Set the file name, and setup the mapper as well as the actor.  
45            
46            @type file_name: String
47            @param file_name: Image file name
48            """
49    
50          self.vtk_image_reader.SetFileName(file_name)          self.vtk_image_reader.SetFileName(file_name)
51    
52          self.setTexture()          self.setTexture()
# Line 23  class Image(Common): Line 54  class Image(Common):
54    
55          Common.setMapper(self, "self.vtk_plane.GetOutput()")          Common.setMapper(self, "self.vtk_plane.GetOutput()")
56          Common.setActor(self)          Common.setActor(self)
57          Common.setTexture(self.vtk_texture)          Common.setTexture(self, self.vtk_texture)
58          Common.addActor(self)          Common.addActor(self)
59    
60      def setTexture(self):      def setTexture(self):
61            """
62            Set the texture map.    
63            """
64    
65          self.vtk_texture = vtk.vtkTexture()          self.vtk_texture = vtk.vtkTexture()
66          self.vtk_texture.SetInput(self.vtk_image_reader.GetOutput())              self.vtk_texture.SetInput(self.vtk_image_reader.GetOutput())    
67    
68      def setPlane(self):      def setPlane(self):
69            """
70            Set the texture coordinates (generated from the plane), which controls
71            the positioning of the texture on a surface.
72            """
73    
74          self.vtk_plane = vtk.vtkPlaneSource()          self.vtk_plane = vtk.vtkPlaneSource()
75                    
           
           
           
           
           
76    
77    

Legend:
Removed from v.845  
changed lines
  Added in v.846

  ViewVC Help
Powered by ViewVC 1.1.26