MCPcopy Create free account
hub / github.com/apple/ml-pointersect / baseline_pcd_ray_intersection

Function baseline_pcd_ray_intersection

plib/utils.py:1917–2030  ·  view source on GitHub ↗

Baseline point cloud-ray intersection. Algorithm: 1. poisson surface reconstruction from point cloud to create a mesh 2. ray tracing using the mesh to get surface normal Returns: mesh: est_ts_w: (m, h, w) distance on the ray direction to the interse

(
        points_w: np.ndarray,  # (n, 3)
        cam_poses: np.ndarray,  # (m, 4, 4) target camera pose, cam to world
        intrinsics: np.ndarray,  # (m, 3, 3)  intrinsic matrix of the camrea
        width_px: int,
        height_px: int,
        k: int,
        method: str = 'alpha',  # 'poisson', 'alpha', 'ball'
        poisson_depth: int = 9,
        alpha: float = 0.01,
        ball_radii: T.List[float] = (0.005, 0.01, 0.02, 0.04),
        points_rgb: np.ndarray = None,  # (n, 3)
)

Source from the content-addressed store, hash-verified

1915
1916
1917def baseline_pcd_ray_intersection(
1918 points_w: np.ndarray, # (n, 3)
1919 cam_poses: np.ndarray, # (m, 4, 4) target camera pose, cam to world
1920 intrinsics: np.ndarray, # (m, 3, 3) intrinsic matrix of the camrea
1921 width_px: int,
1922 height_px: int,
1923 k: int,
1924 method: str = 'alpha', # 'poisson', 'alpha', 'ball'
1925 poisson_depth: int = 9,
1926 alpha: float = 0.01,
1927 ball_radii: T.List[float] = (0.005, 0.01, 0.02, 0.04),
1928 points_rgb: np.ndarray = None, # (n, 3)
1929):
1930 """
1931 Baseline point cloud-ray intersection.
1932
1933 Algorithm:
1934 1. poisson surface reconstruction from point cloud to create a mesh
1935 2. ray tracing using the mesh to get surface normal
1936
1937 Returns:
1938 mesh:
1939 est_ts_w:
1940 (m, h, w) distance on the ray direction to the intersection point
1941 est_surface_normals_w:
1942 (m, h, w, 3) surface normal at the intersection point, in the world coordinate
1943 est_hits:
1944 (m, h, w) whether the ray intersect with a surface
1945 """
1946
1947 # create pcd
1948 pcd = o3d.geometry.PointCloud()
1949 pcd.points = o3d.utility.Vector3dVector(points_w)
1950 # if points_rgb is not None:
1951 # pcd.rgbs = o3d.utility.Vector3dVector(points_rgb)
1952
1953 # estimate normal at each vertex
1954 pcd.estimate_normals()
1955 pcd.orient_normals_consistent_tangent_plane(k=k)
1956
1957 # create mesh from pcd
1958 if method == 'poisson':
1959 with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
1960 mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd, depth=poisson_depth)
1961 elif method == 'alpha':
1962 tetra_mesh, pt_map = o3d.geometry.TetraMesh.create_from_point_cloud(pcd)
1963 mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_alpha_shape(
1964 pcd, alpha, tetra_mesh, pt_map)
1965 elif method == 'ball':
1966 mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_ball_pivoting(
1967 pcd, o3d.utility.DoubleVector(ball_radii)
1968 )
1969 else:
1970 raise NotImplementedError
1971
1972 # create ray tracing scene
1973 mesh_t = o3d.t.geometry.TriangleMesh.from_legacy(mesh)
1974 scene = o3d.t.geometry.RaycastingScene()

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected