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

Function compute_point_ray_distance

plib/utils.py:409–444  ·  view source on GitHub ↗

Compute the distance between each point to each ray. Args: points: (*, n, 3) ray_origins: (*, m, 3) ray_directions: (*, m, 3) Returns: dists: (*, m, n) distance between each point to each ray projections: (*,

(
        points: torch.Tensor,
        ray_origins: torch.Tensor,
        ray_directions: torch.Tensor,
)

Source from the content-addressed store, hash-verified

407
408
409def compute_point_ray_distance(
410 points: torch.Tensor,
411 ray_origins: torch.Tensor,
412 ray_directions: torch.Tensor,
413) -> T.Dict[str, T.Any]:
414 """
415 Compute the distance between each point to each ray.
416
417 Args:
418 points:
419 (*, n, 3)
420 ray_origins:
421 (*, m, 3)
422 ray_directions:
423 (*, m, 3)
424
425 Returns:
426 dists: (*, m, n) distance between each point to each ray
427 projections: (*, m, n, 3) the projected points on the ray
428 ts: (*, m, n) length on ray (can be negative)
429 """
430
431 points = points.unsqueeze(-3) # (*, 1, n, 3)
432 ray_origins = ray_origins.unsqueeze(-2) # (*, m, 1, 3)
433 ray_directions = ray_directions.unsqueeze(-2) # (*, m, 1, 3)
434 dv = points - ray_origins # (*, m, n, 3)
435
436 ts = (dv * ray_directions).sum(dim=-1, keepdim=True) # (*, m, n, 1) projected length on ray (can be negative)
437 projections = ray_origins + ts * ray_directions # (*, m, n, 3)
438 dists = torch.linalg.norm(points - projections, ord=2, dim=-1) # (*, m, n)
439
440 return dict(
441 dists=dists, # (*, m, n)
442 projections=projections, # (*, m, n, 3)
443 ts=ts.squeeze(-1), # (*, m, n)
444 )
445
446
447def get_k_neighbor_points_in_chunks(

Callers 3

get_k_neighbor_pointsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected