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

Function rectify_points

plib/utils.py:928–1033  ·  view source on GitHub ↗

Given n points associated with each of the m rays (each row in points), rotate and translate the coordinate so that - ray direction becomes (0,0,1) - ray origin becomes (0,0,0) - if translate is True, the coordinate origin is chosen so that the t to the closest projection is 1

(
        points: torch.Tensor,
        ray_origins: torch.Tensor,
        ray_directions: torch.Tensor,
        translate: bool = False,
        randomize_translate: bool = False,
        ts: torch.Tensor = None,
        t_min: float = 0.,
        t_max: float = 1e6,
)

Source from the content-addressed store, hash-verified

926
927
928def rectify_points(
929 points: torch.Tensor,
930 ray_origins: torch.Tensor,
931 ray_directions: torch.Tensor,
932 translate: bool = False,
933 randomize_translate: bool = False,
934 ts: torch.Tensor = None,
935 t_min: float = 0.,
936 t_max: float = 1e6,
937):
938 """
939 Given n points associated with each of the m rays (each row in points),
940 rotate and translate the coordinate so that
941 - ray direction becomes (0,0,1)
942 - ray origin becomes (0,0,0)
943 - if translate is True, the coordinate origin is chosen so that the t to the closest projection is 1
944
945 Args:
946 points:
947 (*, m, n, 3) xyz
948 ray_origins:
949 (*, m, 3)
950 ray_directions:
951 (*, m, 3)
952 translate:
953 whether to translate the coord so that the closest point's projection on the
954 ray has t = 0 for all t > 0.
955 randomize_translate:
956 only used when translate is true.
957 If randomize_translate = true, tt will be one random distance between 0 and closest point
958 ts:
959 (*, m, n) the projection length each points on the ray
960 should be given only if translate is True.
961
962 Returns:
963 points_n:
964 (*, m, n, 3) the transformed points
965 Rs_w2n:
966 (*, m, 3, 3) the rotation matrix that transform the world coord to the rectified coord
967 translation_w2n:
968 (*, m, 3, 1) the translation vector that transform the world coord to the rectified coord
969 tt:
970 (*, m) the t that we subtract from the input ts
971 """
972 timing_info = dict()
973 stime_total = timer()
974 stime_frame = timer()
975 y = torch.zeros_like(ray_directions) # (*, m, 3)
976 y[..., 1] = 1. # try to use the current y-axis as the y-axis
977 Rs_n2w = rigid_motion.construct_coord_frame(
978 z=ray_directions,
979 y=y,
980 ) # (*, m, 3, 3) the column in the 3*3 matrix is the axis coord with unit norm
981 # Rs_n2w = torch.randn(*(ray_directions.shape[:-1]), 3, 3, device=ray_directions.device)
982 # it can be thought of as the transform matrix from the new coord to the world coord
983 timing_info['create_R_n2w_in_rectify'] = timer() - stime_frame
984
985 stime_ts = timer()

Callers

nothing calls this directly

Calls 1

cloneMethod · 0.45

Tested by

no test coverage detected