MCPcopy Index your code
hub / github.com/apple/ml-pointersect / sample_point_cloud

Method sample_point_cloud

pointersect/inference/structures.py:3548–3653  ·  view source on GitHub ↗

Sample the mesh to create a point cloud Args: num_points: number of point to sample method: 'poisson_disk' 'uniform_camera' Returns: point_cloud: (1, num_points) rgbd_image: (1,

(
            self,
            num_points: int,
            method: str = 'poisson_disk',
            device: torch.device = torch.device('cpu'),
            width_px: int = 10,
            height_px: int = 10,
            fov: float = 60.,  # degree
            dtype: np.dtype = np.float32,
    )

Source from the content-addressed store, hash-verified

3546 )
3547
3548 def sample_point_cloud(
3549 self,
3550 num_points: int,
3551 method: str = 'poisson_disk',
3552 device: torch.device = torch.device('cpu'),
3553 width_px: int = 10,
3554 height_px: int = 10,
3555 fov: float = 60., # degree
3556 dtype: np.dtype = np.float32,
3557 ) -> T.Dict[str, T.Any]:
3558 """
3559 Sample the mesh to create a point cloud
3560 Args:
3561 num_points:
3562 number of point to sample
3563 method:
3564 'poisson_disk'
3565 'uniform_camera'
3566
3567 Returns:
3568 point_cloud: (1, num_points)
3569 rgbd_image: (1, num_img)
3570 camera: (1, num_img)
3571
3572 """
3573 if dtype in {np.float32, float}:
3574 torch_dtype = torch.float32
3575 elif dtype == np.float64:
3576 torch_dtype = torch.float64
3577 else:
3578 raise NotImplementedError
3579
3580 if method == 'poisson_disk':
3581 o3d_pcd = self.mesh.sample_points_poisson_disk(int(num_points))
3582 # create rays to get uv and texture -> color of points
3583 xyz_w = np.array(o3d_pcd.points, dtype=dtype) # (n, 3)
3584 ray_ends = torch.from_numpy(xyz_w).to(dtype=torch_dtype, device=device).unsqueeze(0) # (1, n, 3)
3585 ray_directions = torch.ones_like(ray_ends) # (1, n, 3)
3586 ray_ts = torch.ones(1, ray_ends.size(1), dtype=torch_dtype, device=device) * 1.0e-5 # (1, n)
3587 ray_origins = ray_ends - ray_directions * ray_ts.unsqueeze(-1)
3588 ray = Ray(
3589 origins_w=ray_origins,
3590 directions_w=ray_directions,
3591 )
3592 out_dict = self.get_ray_intersection(
3593 ray=ray,
3594 device=device,
3595 )
3596 xyz_w = ray_origins + out_dict['ray_ts'].unsqueeze(-1) * ray_directions
3597 idxs = (out_dict['hit_map'].squeeze(0) > 0.5) # (n,)
3598
3599 point_cloud = PointCloud(
3600 xyz_w=xyz_w[:, idxs], # (1, n, 3)
3601 rgb=out_dict['ray_rgbs'][:, idxs], # (1, n, 3)
3602 normal_w=out_dict['surface_normals_w'][:, idxs], # (1, n, 3)
3603 )
3604 rgbd_image = None
3605 camera = None

Callers 1

render_meshFunction · 0.95

Calls 10

get_ray_intersectionMethod · 0.95
get_rgbd_imageMethod · 0.95
RayClass · 0.85
PointCloudClass · 0.85
CameraTrajectoryClass · 0.85
deviceMethod · 0.80
sizeMethod · 0.80
get_cameraMethod · 0.80
get_pcdMethod · 0.80
toMethod · 0.45

Tested by

no test coverage detected