| 29 | |
| 30 | |
| 31 | class PointCloud: |
| 32 | def __init__( |
| 33 | self, |
| 34 | xyz_w: torch.Tensor, # (b, n, 3) |
| 35 | rgb: T.Optional[torch.Tensor] = None, # (b, n, 3) |
| 36 | normal_w: T.Optional[torch.Tensor] = None, # (b, n, 3) vertex normal in world coordinate |
| 37 | captured_z_direction_w: T.Optional[torch.Tensor] = None, |
| 38 | # (b, n, 3) # (z axis of the camera in world coordinate) |
| 39 | captured_dps: T.Optional[torch.Tensor] = None, # (b, n, 1) distance per sample |
| 40 | captured_dps_u_w: T.Optional[torch.Tensor] = None, |
| 41 | # (b, n, 3) distance per sample in camera x direction in the word coord |
| 42 | captured_dps_v_w: T.Optional[torch.Tensor] = None, |
| 43 | # (b, n, 3) distance per sample in camera y direction in the word coord |
| 44 | captured_view_direction_w: T.Optional[torch.Tensor] = None, |
| 45 | # (b, n, 3) # unit vector pointing from capturing camera pinhole to the point |
| 46 | valid_mask: T.Optional[torch.Tensor] = None, # (b, n, 1) |
| 47 | included_point_at_inf: bool = False, # whether n==0 represents point at inf |
| 48 | feature: T.Optional[torch.Tensor] = None, # (b, n, f) |
| 49 | img_idxs: T.Optional[torch.Tensor] = None, # (b, n, 1) linear index of qhw in the original rgbd image |
| 50 | ): |
| 51 | self.xyz_w = xyz_w |
| 52 | self.rgb = rgb |
| 53 | self.normal_w = normal_w |
| 54 | self.captured_z_direction_w = captured_z_direction_w |
| 55 | self.captured_view_direction_w = captured_view_direction_w |
| 56 | self.captured_dps = captured_dps |
| 57 | self.captured_dps_u_w = captured_dps_u_w |
| 58 | self.captured_dps_v_w = captured_dps_v_w |
| 59 | self.valid_mask = valid_mask |
| 60 | self.feature = feature |
| 61 | self.img_idxs = img_idxs |
| 62 | |
| 63 | self.attr_names = [ |
| 64 | 'xyz_w', 'rgb', 'captured_z_direction_w', 'captured_view_direction_w', |
| 65 | 'captured_dps', 'captured_dps_u_w', 'captured_dps_v_w', 'normal_w', |
| 66 | 'valid_mask', 'feature', 'img_idxs', |
| 67 | ] |
| 68 | |
| 69 | self.included_point_at_inf = included_point_at_inf |
| 70 | self.check_dim() |
| 71 | |
| 72 | @staticmethod |
| 73 | def from_o3d_pcd( |
| 74 | o3d_pcd: o3d.geometry.PointCloud, |
| 75 | ) -> 'PointCloud': |
| 76 | """ |
| 77 | Return a point cloud object from o3d_pcd |
| 78 | Args: |
| 79 | o3d_pcd: |
| 80 | (n,) |
| 81 | Returns: |
| 82 | (b=1, n) |
| 83 | """ |
| 84 | xyz_w = torch.from_numpy(np.array(o3d_pcd.points)).float().unsqueeze(0) # (1, n, 3) |
| 85 | if o3d_pcd.has_normals(): |
| 86 | normals = torch.from_numpy(np.array(o3d_pcd.normals)).float().unsqueeze(0) # (1, n, 3) |
| 87 | else: |
| 88 | normals = None |
no outgoing calls
no test coverage detected