twanghcmut's picture
download
raw
1.74 kB
import numpy as np
def triangulate(view, stride=3, max_edge=0.08, exclude=None):
if stride < 1 or max_edge <= 0:
raise ValueError("stride and max_edge must be positive")
points = view["pts3d"][::stride, ::stride]
mask = view["mask"].copy()
if exclude is not None:
if exclude.shape != mask.shape:
raise ValueError("Exclusion mask must match the pointmap")
mask &= ~exclude
mask = mask[::stride, ::stride]
height, width = mask.shape
grid = np.arange(height * width).reshape(height, width)
a, b, c, d = (
grid[:-1, :-1].ravel(),
grid[:-1, 1:].ravel(),
grid[1:, :-1].ravel(),
grid[1:, 1:].ravel(),
)
faces = np.concatenate((np.column_stack((a, c, b)), np.column_stack((b, c, d))))
vertices = points.reshape(-1, 3)
valid = mask.ravel()[faces].all(axis=1)
faces = faces[valid]
edges = vertices[faces] - vertices[faces[:, [1, 2, 0]]]
faces = faces[(np.linalg.norm(edges, axis=-1) < max_edge).all(axis=1)]
if not len(faces):
raise ValueError("No valid surface triangles")
used, remapped = np.unique(faces, return_inverse=True)
yy, xx = np.meshgrid(
np.arange(height) * stride, np.arange(width) * stride, indexing="ij"
)
original_height, original_width = view["mask"].shape
uv = np.column_stack(
(xx.ravel() / (original_width - 1), yy.ravel() / (original_height - 1))
)
return vertices[used], remapped.reshape(-1, 3), uv[used]
def anchor_transform(predicted_camera, reference_camera):
return np.asarray(reference_camera) @ np.linalg.inv(predicted_camera)
def transform_points(points, transform):
return points @ transform[:3, :3].T + transform[:3, 3]

Xet Storage Details

Size:
1.74 kB
·
Xet hash:
341487062f58306be9bb2dec1f98ba27df812a0c95884083772ca018e23312e2

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.