MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / project_gl

Function project_gl

eval_code/recons/models/moge/utils3d/numpy/transforms.py:547–579  ·  view source on GitHub ↗

Project 3D points to 2D following the OpenGL convention (except for row major matrice) Args: points (np.ndarray): [..., N, 3] or [..., N, 4] 3D points to project, if the last dimension is 4, the points are assumed to be in homogeneous coordinates model (np.ndar

(
        points: np.ndarray,
        model: np.ndarray = None,
        view: np.ndarray = None,
        perspective: np.ndarray = None
    )

Source from the content-addressed store, hash-verified

545
546@batched(2,2,2,2)
547def project_gl(
548 points: np.ndarray,
549 model: np.ndarray = None,
550 view: np.ndarray = None,
551 perspective: np.ndarray = None
552 ) -> Tuple[np.ndarray, np.ndarray]:
553 """
554 Project 3D points to 2D following the OpenGL convention (except for row major matrice)
555
556 Args:
557 points (np.ndarray): [..., N, 3] or [..., N, 4] 3D points to project, if the last
558 dimension is 4, the points are assumed to be in homogeneous coordinates
559 model (np.ndarray): [..., 4, 4] model matrix
560 view (np.ndarray): [..., 4, 4] view matrix
561 perspective (np.ndarray): [..., 4, 4] perspective matrix
562
563 Returns:
564 scr_coord (np.ndarray): [..., N, 3] screen space coordinates, value ranging in [0, 1].
565 The origin (0., 0., 0.) is corresponding to the left & bottom & nearest
566 linear_depth (np.ndarray): [..., N] linear depth
567 """
568 assert perspective is not None, "perspective matrix is required"
569 if points.shape[-1] == 3:
570 points = np.concatenate([points, np.ones_like(points[..., :1])], axis=-1)
571 if model is not None:
572 points = points @ model.swapaxes(-1, -2)
573 if view is not None:
574 points = points @ view.swapaxes(-1, -2)
575 clip_coord = points @ perspective.swapaxes(-1, -2)
576 ndc_coord = clip_coord[..., :3] / clip_coord[..., 3:]
577 scr_coord = ndc_coord * 0.5 + 0.5
578 linear_depth = clip_coord[..., 3]
579 return scr_coord, linear_depth
580
581
582@batched(2,2,2)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected