def test_single_intersection(self): q = [0,0,0] v = [1,0,0] w = [1,0,0,2] p = [2,0,0] assert_allclose(normalize(line_plane_intersection(q, v, w)), normalize(p))
def test_pixel_generation(self): unnormalized_pixel_rays = np.transpose( [[[0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1]], [[0, 1, 1], [1, 1, 1], [2, 1, 1], [3, 1, 1]], [[0, 2, 1], [1, 2, 1], [2, 2, 1], [3, 2, 1]]], (1, 0, 2)) assert_allclose(pixel_rays(self.oe), normalize(unnormalized_pixel_rays), rtol=self.rtol)
def pixel_rays(optical_equipment): """ Function: pixel_rays Creates an array of the rays for a piece of optical equipment with a given resolution Parameters: equipment - *<OpticalEquipment>* The piece of optical equipment to calculate the pixel rays for Returns: *ndarray* of the pixel rays for the piece of optical equipment. Will have shape (height, width, 3), where height is the resolution height and width is the resolution width. The last dimension holds the ray. Rays are in the optical equipment frame """ res = optical_equipment.resolution # get grid of the locations of the pixels distorted_points = np.transpose(np.mgrid[0:res[0], 0:res[1]], (1, 2, 0)) grid_shape = distorted_points.shape # convert to a list of points to pass to undistortPoints distorted_points_list = distorted_points.reshape(-1, 1, 2) # undistort the pixel locations points_list = cv2.undistortPoints(distorted_points_list.astype(np.float32), optical_equipment.intrinsic_matrix, optical_equipment.distortion) # turn it back into a grid points = points_list.reshape(grid_shape) # convert to rays by appending 1 as z axis rays = np.concatenate((points, np.ones(res + (1,))), axis=2) # normalize return normalize(rays, axis=2)
def test_horz_planes(self): assert_allclose(normalize(np.around(self.horz_planes, decimals=10)), normalize(np.around(self.exp_horz_planes, decimals=10)), rtol=self.rtol, atol=self.atol)