@@ -58,7 +58,7 @@ def open(self):
5858 self .offset_y = self .config .get ('offset_y' , 0 )
5959 self .log .info ('Configured offsets x: {}, y: {}' .format (self .offset_x , self .offset_y ))
6060
61- # Note that get_camera_offset must be called before updating the values of self.width and self.height.
61+ # Note that transform_offset() must be called before updating the values of self.width and self.height.
6262
6363 self .gain = self .config .get ('gain' , 0 )
6464 self .exposure_time = self .config .get ('exposure_time' , 1000 )
@@ -138,23 +138,22 @@ def acquisition_loop(self):
138138 self .testbed .simulator .end_camera_acquisition (camera_name = self .id )
139139 self .is_acquiring .submit_data (np .array ([0 ], dtype = 'int8' ))
140140
141- def get_camera_offset (self , x , y , inverse = False ): # TODO: Find better name for this function.
142- #TODO: Check docstrings in general now that this can do invserse transformations.
141+ def transform_offset (self , x , y , inverse = False ):
143142 """Convert relative camera offsets given by the user to absolute offsets in camera coordinates.
144143
145144 The forward transformation is done by performing the following procedure:
146145 1.) Translate the origin to the center of the ROI.
147- 2.) if rot90 is True, rotate 90 degrees counter-clockwise about the center of the ROI
148- 3.) Translate the origin back to the upper left fo the ROI .
149- 4.) If flip_x is True, reflect in x .
150- 5.) If flip_y is True, reflect in y .
146+ 2.) If rot90 is True, rotate 90 degrees counter-clockwise about the center of the ROI.
147+ 3.) If flip_x is True, reflect in x .
148+ 4.) If flip_y is True, reflect in y .
149+ 5.) Translate the origin back to the upper left fo the ROI .
151150
152151 Parameters
153152 ----------
154153 x: float
155- The x-offset coordinate in the user coordinate system
154+ The x-offset coordinate in the user coordinate system.
156155 y: float
157- The y-offset coordinate in the user coordinate system
156+ The y-offset coordinate in the user coordinate system.
158157 inverse: bool, optional
159158 If True, the transformation is performed in reverse, i.e. from camera coordinates to user coordinates.
160159 Defaults to False.
@@ -165,11 +164,11 @@ def get_camera_offset(self, x, y, inverse=False): # TODO: Find better name for
165164 The transformed x and y coordinates for their location in camera array coordinates. If there is no rotation
166165 or flip in x or y, then this returns the same x, y values that are input.
167166 """
168- # Define the translation matrix T to get to the center of the ROI.
169- T = np .zeros ((3 , 3 ))
170- np .fill_diagonal (T , 1 )
171- T [0 ][- 1 ] = - self .width / 2
172- T [1 ][- 1 ] = - self .height / 2
167+ # Define the translation matrix T_center to get to the center of the ROI.
168+ T_center = np .zeros ((3 , 3 ))
169+ np .fill_diagonal (T_center , 1 )
170+ T_center [0 ][- 1 ] = - self .width / 2
171+ T_center [1 ][- 1 ] = - self .height / 2
173172
174173 # Initialize rotation matrix R.
175174 R = np .zeros ((3 , 3 ))
@@ -208,13 +207,14 @@ def get_camera_offset(self, x, y, inverse=False): # TODO: Find better name for
208207 T_back [0 ][- 1 ] = self .width / 2
209208 T_back [1 ][- 1 ] = self .height / 2
210209
211- # Perform the dot product. First flip in x to establish top left origin, then translate to ROI center, rotate,
212- # translate back to origin, flip in x, and finally flip in y. #TODO: Is this comment correct?
210+ # Perform the dot product.
211+ # Translate to ROI center, rotate, flip in x then in y,
212+ # and finally translate back to origin.
213213 coords = [x , y , 1 ]
214- new_coords = np .linalg .multi_dot ([T_back , Y , X , R , T , coords ])
214+ new_coords = np .linalg .multi_dot ([T_back , Y , X , R , T_center , coords ])
215215
216216 if inverse :
217- new_coords = np .linalg .multi_dot ([T , Y , X , R ( - 1 ) , T_back , coords ]) # TODO: Make this real Python
217+ new_coords = np .linalg .multi_dot ([T_center , Y , X , R . T , T_back , coords ])
218218
219219 return new_coords [0 ], new_coords [1 ]
220220
@@ -267,27 +267,27 @@ def offset_x(self):
267267 camera_offset_x = self .get_roi_offset_x ()
268268 camera_offset_y = self .get_roi_offset_y ()
269269
270- offset_x , _ = self .get_camera_offset (camera_offset_x , camera_offset_y , inverse = True )
270+ offset_x , _ = self .transform_offset (camera_offset_x , camera_offset_y , inverse = True )
271271
272272 return offset_x
273273
274274 @offset_x .setter
275275 def offset_x (self , offset_x , offset_y ):
276- camera_offset_x , _ = self .get_camera_offset (offset_x , offset_y )
276+ camera_offset_x , _ = self .transform_offset (offset_x , offset_y )
277277 self .set_roi_offset_x (camera_offset_x )
278278
279279 @property
280280 def offset_y (self ):
281281 camera_offset_x = self .get_roi_offset_x ()
282282 camera_offset_y = self .get_roi_offset_y ()
283283
284- _ , offset_y = self .get_camera_offset (camera_offset_x , camera_offset_y , inverse = True )
284+ _ , offset_y = self .transform_offset (camera_offset_x , camera_offset_y , inverse = True )
285285
286286 return offset_y
287287
288288 @offset_y .setter
289289 def offset_y (self , offset_x , offset_y ):
290- _ , camera_offset_y = self .get_camera_offset (offset_x , offset_y )
290+ _ , camera_offset_y = self .transform_offset (offset_x , offset_y )
291291 self .set_roi_offset_y (camera_offset_y )
292292
293293 @property
0 commit comments