MCPcopy
hub / github.com/TencentARC/Pixal3D / transform_mesh

Function transform_mesh

data_toolkit/utils.py:496–539  ·  view source on GitHub ↗

Apply multi-view transform to mesh vertices based on camera transform matrix.

(mesh_v, frame)

Source from the content-addressed store, hash-verified

494
495
496def transform_mesh(mesh_v, frame):
497 """
498 Apply multi-view transform to mesh vertices based on camera transform matrix.
499 """
500 device = mesh_v.device
501 c2w_orig = torch.tensor(frame['transform_matrix'], dtype=torch.float32, device=device)
502
503 # Old and new camera matrices
504 radius = c2w_orig[:3, 3].norm().item()
505 c2w_new = get_new_camera_matrix(radius=radius, yaw=-90/180.0*math.pi, pitch=0.0,
506 dtype=torch.float32, device=device)
507 w2c_orig = torch.inverse(c2w_orig)
508
509 # Initial and final axis alignment matrices
510 R_init = torch.tensor([
511 [1.0, 0.0, 0.0, 0.0],
512 [0.0, 0.0, -1.0, 0.0],
513 [0.0, 1.0, 0.0, 0.0],
514 [0.0, 0.0, 0.0, 1.0]
515 ], dtype=torch.float32, device=device)
516
517 R_back = torch.tensor([
518 [1.0, 0.0, 0.0, 0.0],
519 [0.0, 0.0, 1.0, 0.0],
520 [0.0, -1.0, 0.0, 0.0],
521 [0.0, 0.0, 0.0, 1.0]
522 ], dtype=torch.float32, device=device)
523
524 R_ply = torch.tensor([
525 [1.0, 0.0, 0.0, 0.0],
526 [0.0, 0.0, 1.0, 0.0],
527 [0.0, -1.0, 0.0, 0.0],
528 [0.0, 0.0, 0.0, 1.0]
529 ], dtype=torch.float32, device=device)
530
531 T_cam = c2w_new @ w2c_orig @ R_ply
532 T_final = R_back @ T_cam @ R_init
533
534 # Apply transform
535 mesh_v = mesh_v.reshape(-1, 3)
536 verts_h = torch.cat([mesh_v, torch.ones((mesh_v.shape[0], 1), dtype=torch.float32, device=device)], dim=1)
537 verts_trans = (T_final @ verts_h.T).T[:, :3]
538
539 return verts_trans
540
541
542def sphere_normalize_torch(vertices):

Callers 1

_dual_grid_mesh_viewFunction · 0.90

Calls 2

get_new_camera_matrixFunction · 0.85
reshapeMethod · 0.45

Tested by

no test coverage detected