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

Method get_ray_intersection

pointersect/inference/structures.py:3460–3546  ·  view source on GitHub ↗

Intersect the mesh with rays to get ground truth Args: ray: (b, *m_shape) Returns: ray_rgbs: (b, *m_shape, 3) ray_ts: (b, *m_shape) surface_normals_w: (b, *m_sha

(
            self,
            ray: Ray,
            device: torch.device = torch.device('cpu'),
    )

Source from the content-addressed store, hash-verified

3458 )
3459
3460 def get_ray_intersection(
3461 self,
3462 ray: Ray,
3463 device: torch.device = torch.device('cpu'),
3464 ):
3465 """
3466 Intersect the mesh with rays to get ground truth
3467
3468 Args:
3469 ray:
3470 (b, *m_shape)
3471
3472 Returns:
3473 ray_rgbs:
3474 (b, *m_shape, 3)
3475 ray_ts:
3476 (b, *m_shape)
3477 surface_normals_w:
3478 (b, *m_shape, 3) in the world coordinate
3479 hit_map:
3480 (b, *m_shape) 1: hit, 0: miss
3481 """
3482
3483 torch_dtype = ray.origins_w.dtype
3484 b, *m_shape, _ = ray.origins_w.shape
3485 rays = torch.cat(
3486 (
3487 ray.origins_w,
3488 ray.directions_w,
3489 ), dim=-1) # (b, *m, 6)
3490 rays = rays.detach().cpu().float().numpy()
3491
3492 # cast the rays, get the intersections
3493 raycast_results = self.scene.cast_rays(rays)
3494 t_hits = raycast_results['t_hit'].numpy() # (b, *m), inf if not hit the mesh
3495 hit_map = 1 - np.isinf(t_hits) # (b, *m) 1 if hit a surface, 0 otherwise
3496
3497 # render rgb of the ray
3498 if self.mesh.has_textures():
3499 ray_rgbs = render.interp_texture_map_from_ray_tracing_results(
3500 mesh=self.mesh,
3501 raycast_results=raycast_results,
3502 texture_maps=[skimage.img_as_float(np.array(img)).astype(np.float32) for img in self.mesh.textures],
3503 merge_textures=True, # combine results from multiple textures.
3504 )[0]
3505 else:
3506 ray_rgbs = np.ones((b, *m_shape, 3), dtype=np.float32)
3507
3508 # note that primitive_normals is the normal of the triangle face
3509 # we can use uv map to interpolate vertex normal
3510 # interpolate surface normal using uv map to get better normal estimation
3511 if self.mesh.has_vertex_normals():
3512 surface_normals = render.interp_surface_normal_from_ray_tracing_results(
3513 mesh=self.mesh,
3514 raycast_results=raycast_results,
3515 ) # (b, *m, 3)
3516 else:
3517 surface_normals = raycast_results['primitive_normals'].numpy() # (b, *m, 3)

Callers 4

get_rgbd_imageMethod · 0.95
_rasterize_renderingMethod · 0.95
sample_point_cloudMethod · 0.95
__getitem__Method · 0.80

Calls 4

deviceMethod · 0.80
catMethod · 0.45
detachMethod · 0.45
toMethod · 0.45

Tested by

no test coverage detected