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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1197 - (hide annotations)
Mon Jun 18 02:08:34 2007 UTC (13 years, 10 months ago) by jongui
File MIME type: text/x-python
File size: 5061 byte(s)
Update the way movies are generated. Please refer to the examples. 

The user can now either specify the image range(first and last images inclusive):
mov.imageRange(input_directory = PYVISI_EXAMPLE_IMAGES_PATH,
        first_image = IMAGE_NAME + "000938.jpg",
		last_image = IMAGE_NAME + "000948.jpg")
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))

or the user can specify a list of images:

lst = ['image1.jpg', 'image5.jpg', 'image7.jpg]
mov.imageList(input_directory = PYVISI_EXAMPLE_IMAGES_PATH, image_list = lst)
mov.makeMovie(os.path.join(PYVISI_EXAMPLE_IMAGES_PATH, "movie.mpg"))


1 ksteube 1147 """
2 jongui 1197 @var __author__: name of author
3     @var __copyright__: copyrights
4     @var __license__: licence agreement
5     @var __url__: url entry point on documentation
6     @var __version__: version
7     @var __date__: date of the version
8 ksteube 1147 """
9    
10 jongui 1197 __author__="John Ngui, john.ngui@uq.edu.au"
11     __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
12     http://www.access.edu.au
13     Primary Business: Queensland, Australia"""
14     __license__="""Licensed under the Open Software License version 3.0
15     http://www.opensource.org/licenses/osl-3.0.php"""
16     __url__="http://www.iservo.edu.au/esys"
17     __version__="$Revision$"
18     __date__="$Date$"
19    
20    
21 ksteube 1147 import vtk
22    
23     class Transform:
24     """
25     Class that defines the orientation of planes.
26    
27     @attention: There is a difference between performing rotation first
28     followed by translation, and performing translation first followed
29     by rotation.
30    
31     @attention: VTK's coordinate system and translation is NOT 100% accurate.
32     Consequently, performing maximum rotation and translation can potentially
33     yield incorrect results. For instance, rotating a XY plane along the x-axis
34     90 degrees may NOT produce any results (as it is possible that the XY
35     plane has just fallen outside the visible range). However, rotating the
36     XY plane 89.9 degrees instead should produce the correct resutls.
37     """
38    
39     def __init__(self):
40     """
41     Initialise the transform object.
42     """
43    
44     # NOTE: VTK's coordinates are not 100% accurate. The origin is not
45     # exaclty (0,0,0) and the normal is not exactly (0, 0, 1). There is a
46     # slight variance. As a result, a slight alteration has to be done
47     # in order for the plane to be displayed correctly. Otherwise, the
48     # plane may just fall outside the bounding box and nothing
49     # is displayed.
50     self.__OFFSET_VARIANCE = 0.0000000001
51     self.__vtk_transform = vtk.vtkTransform()
52    
53     def translate(self, x_offset, y_offset, z_offset):
54     """
55     Translate the rendered object along the x, y and z-axes.
56    
57     @type x_offset: Number
58     @param x_offset: Amount to translate along the x-axis
59     @type y_offset: Number
60     @param y_offset: Amount to translate along the y-axis
61     @type z_offset: Number
62     @param z_offset: Amount to translate along the z-axis
63     """
64    
65     self.__vtk_transform.Translate(-x_offset, -y_offset, -z_offset)
66    
67     def rotateX(self, angle):
68     """
69     Rotate the plane along the x-axis.
70    
71     @type angle: Number
72     @param angle: Angle to rotate the plane
73     """
74    
75     self.__vtk_transform.RotateX(-angle)
76    
77     def rotateY(self, angle):
78     """
79     Rotate the plane along the y-axis.
80    
81     @type angle: Number
82     @param angle: Angle to rotate the plane
83     """
84    
85     self.__vtk_transform.RotateY(angle)
86    
87     def rotateZ(self, angle):
88     """
89     Rotate the plane along the z-axis.
90    
91     @type angle: Number
92     @param angle: Angle to rotate the plane
93     """
94    
95     self.__vtk_transform.RotateZ(angle)
96    
97     def setPlaneToXY(self, offset = 0):
98     """
99     Set the plane orthogonal to the z-axis.
100    
101     @type offset: Number
102     @param offset: Amount to translate along the z-axis
103     """
104    
105     self.translate(0, 0, offset + self.__OFFSET_VARIANCE)
106    
107     def setPlaneToYZ(self, offset = 0):
108     """
109     Set the plane orthogonal to the x-axis.
110    
111     @type offset: Number
112     @param offset: Amount to translate along the x-axis
113     """
114    
115     # NOTE: rotateY must come first before translate. Otherwise,
116     # the output may be incorrect.
117     self.rotateY(90)
118     self.translate(offset, 0, 0)
119    
120     def setPlaneToXZ(self, offset = 0):
121     """
122     Set the plane orthogonal to the y-axis.
123    
124     @type offset: Number
125     @param offset: Amount to translate along the y-axis
126     """
127    
128     # rotateX must come first before translate. Otherwise, it won't work.
129     self.rotateX(90)
130     self.translate(0, offset, 0)
131    
132     def _getTransform(self):
133     """
134     Return the transform instance.
135    
136     @rtype: vtkTransform
137     @return: Transform instance that is used to specify the orientation
138     of the plane
139     """
140    
141     return self.__vtk_transform
142    
143    
144     ###############################################################################
145    
146    
147     class TransformFilter:
148     """
149     Class that defines a transform poly data filter.
150     """
151    
152 jongui 1148 def __init__(self):
153 ksteube 1147 """
154     Initialise the transoform poly data filter.
155 jongui 1148 """
156 ksteube 1147
157 jongui 1148 self.__vtk_transform_filter = vtk.vtkTransformPolyDataFilter()
158    
159     def _setupTransformFilter(self, plane_source, transform):
160     """
161     Setup the transform filter.
162    
163 ksteube 1147 @type plane_source: vtkPolyData
164     @param plane_source: Polygonal data
165     @type transform: L{Transform <transform.Transform>} object
166     @param transform: Specifies the orientation of the plane source
167     """
168    
169     self.__plane_source = plane_source
170     self.__transform = transform
171    
172 jongui 1148 self.__setInput()
173     self.__setTransform()
174 ksteube 1147
175 jongui 1148 def __setInput(self):
176 ksteube 1147 """
177     Set the input for the transform poly data filter.
178     """
179    
180     self.__vtk_transform_filter.SetInput(self.__plane_source)
181    
182 jongui 1148 def __setTransform(self):
183 ksteube 1147 """
184     Set the transformation of the plane source.
185     """
186    
187     self.__vtk_transform_filter.SetTransform(self.__transform)
188    
189 jongui 1148 def _getTransformFilterOutput(self):
190 ksteube 1147 """
191     Return the output of the transform poly data filter.
192     """
193    
194     return self.__vtk_transform_filter.GetOutput()
195    
196    
197    
198    
199    
200    

  ViewVC Help
Powered by ViewVC 1.1.26