@@ -138,10 +138,11 @@ 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 ):
142- """Convert relative camera offsets given by the user to absolute offsets in camera array coordinates.
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.
143+ """Convert relative camera offsets given by the user to absolute offsets in camera coordinates.
143144
144- This is done by performing the following procedure:
145+ The forward transformation is done by performing the following procedure:
145146 1.) Translate the origin to the center of the ROI.
146147 2.) if rot90 is True, rotate 90 degrees counter-clockwise about the center of the ROI
147148 3.) Translate the origin back to the upper left fo the ROI.
@@ -151,9 +152,13 @@ def get_camera_offset(self, x, y):
151152 Parameters
152153 ----------
153154 x: float
154- The x-offset coordinate
155+ The x-offset coordinate in the user coordinate system
155156 y: float
156- The y-offset coordinate
157+ The y-offset coordinate in the user coordinate system
158+ inverse: bool, optional
159+ If True, the transformation is performed in reverse, i.e. from camera coordinates to user coordinates.
160+ Defaults to False.
161+
157162 Returns
158163 -------
159164 new_x, new_y: float, float
@@ -204,10 +209,13 @@ def get_camera_offset(self, x, y):
204209 T_back [1 ][- 1 ] = self .height / 2
205210
206211 # Perform the dot product. First flip in x to establish top left origin, then translate to ROI center, rotate,
207- # translate back to origin, flip in x, and finally flip in y.
212+ # translate back to origin, flip in x, and finally flip in y. #TODO: Is this comment correct?
208213 coords = [x , y , 1 ]
209214 new_coords = np .linalg .multi_dot ([T_back , Y , X , R , T , coords ])
210215
216+ if inverse :
217+ new_coords = np .linalg .multi_dot ([T , Y , X , R (- 1 ), T_back , coords ]) # TODO: Make this real Python
218+
211219 return new_coords [0 ], new_coords [1 ]
212220
213221 def rot_flip_image (self , img ):
@@ -259,7 +267,7 @@ def offset_x(self):
259267 camera_offset_x = self .get_roi_offset_x ()
260268 camera_offset_y = self .get_roi_offset_y ()
261269
262- offset_x , _ = self .get_user_offset (camera_offset_x , camera_offset_y ) # TODO: ROI transformation here.
270+ offset_x , _ = self .get_camera_offset (camera_offset_x , camera_offset_y , inverse = True )
263271
264272 return offset_x
265273
@@ -273,7 +281,7 @@ def offset_y(self):
273281 camera_offset_x = self .get_roi_offset_x ()
274282 camera_offset_y = self .get_roi_offset_y ()
275283
276- _ , offset_y = self .get_user_offset (camera_offset_x , camera_offset_y ) # TODO: ROI transformation here.
284+ _ , offset_y = self .get_camera_offset (camera_offset_x , camera_offset_y , inverse = True )
277285
278286 return offset_y
279287
0 commit comments