Given camera poses, return the rasterized RGBD images. Args: camera: (b, q) already on device render_normal_w: whether to ray trace to get surface normal in world coordinate render_method: 'rasteri
(
self,
camera: Camera,
render_normal_w: bool = True,
device: torch.device = torch.device('cpu'),
camera_for_normal: T.Optional[Camera] = None,
)
| 3360 | raise NotImplementedError |
| 3361 | |
| 3362 | def _rasterize_rendering( |
| 3363 | self, |
| 3364 | camera: Camera, |
| 3365 | render_normal_w: bool = True, |
| 3366 | device: torch.device = torch.device('cpu'), |
| 3367 | camera_for_normal: T.Optional[Camera] = None, |
| 3368 | ) -> RGBDImage: |
| 3369 | """ |
| 3370 | Given camera poses, return the rasterized RGBD images. |
| 3371 | |
| 3372 | Args: |
| 3373 | camera: |
| 3374 | (b, q) already on device |
| 3375 | render_normal_w: |
| 3376 | whether to ray trace to get surface normal in world coordinate |
| 3377 | render_method: |
| 3378 | 'rasterization': use o3d rasterization (may have anti-aliasing applied) |
| 3379 | 'ray_cast': use ray_casting to sample rgb |
| 3380 | camera_for_normal: |
| 3381 | (b, q) camera for computing normal (in case intrinsic is negative at (2,2)) |
| 3382 | |
| 3383 | Returns: |
| 3384 | rgbdimage: (b, q) on device |
| 3385 | """ |
| 3386 | |
| 3387 | intrinsic = camera.intrinsic.detach().cpu().numpy() # (b, q, 3, 3) |
| 3388 | H_c2w = camera.H_c2w.detach().cpu().numpy() # (b, q, 4, 4) |
| 3389 | b, q = H_c2w.shape[0], H_c2w.shape[1] |
| 3390 | assert H_c2w.shape[2] == 4 |
| 3391 | assert H_c2w.shape[3] == 4 |
| 3392 | |
| 3393 | # convert (b, q) dimensino to list |
| 3394 | intrinsic_list = [] |
| 3395 | H_c2w_list = [] |
| 3396 | for i in range(b): |
| 3397 | for j in range(q): |
| 3398 | intrinsic_list.append(intrinsic[i, j]) |
| 3399 | H_c2w_list.append(H_c2w[i, j]) |
| 3400 | |
| 3401 | extrinsic_matrices = [rigid_motion.RigidMotion.invert_homogeneous_matrix(H) for H in H_c2w_list] |
| 3402 | |
| 3403 | out_dict = render.rasterize( |
| 3404 | meshes=[self.mesh], |
| 3405 | intrinsic_matrix=intrinsic_list, |
| 3406 | extrinsic_matrices=extrinsic_matrices, |
| 3407 | width_px=camera.width_px, |
| 3408 | height_px=camera.height_px, |
| 3409 | get_point_cloud=False, |
| 3410 | dtype=sample_utils.get_np_dtype(camera.H_c2w.dtype), |
| 3411 | ) |
| 3412 | # out_dict contains |
| 3413 | # imgs: a list of (h, w, 3) rgb |
| 3414 | # z_maps: a list of (h, w) z of the scene points in the camera coordinate |
| 3415 | # hit_maps: a list of (h, w) true: valid |
| 3416 | # using imgs, cam_pose, intrinsics, and z_maps, we can generate point cloud |
| 3417 | |
| 3418 | imgs = out_dict['imgs'] # list of (h, w, 3) |
| 3419 | z_maps = out_dict['z_maps'] # list of (h, w) |
no test coverage detected