lightweightmr / example /make_sphere.py
bdck's picture
Upload example/make_sphere.py
3196e80 verified
raw
history blame
1.18 kB
"""
Generate a simple synthetic point cloud (sphere + noise) for quick testing.
Run this first if you don't have a scan handy.
python example/make_sphere.py
"""
import numpy as np
import os
# Make 3000 points on a unit sphere + small noise
n = 3000
phi = np.random.uniform(0, 2 * np.pi, n)
cos_theta = np.random.uniform(-1, 1, n)
sin_theta = np.sqrt(1 - cos_theta ** 2)
x = sin_theta * np.cos(phi)
y = sin_theta * np.sin(phi)
z = cos_theta
pts = np.stack([x, y, z], axis=1)
pts += np.random.normal(0, 0.01, pts.shape) # tiny noise
os.makedirs("example", exist_ok=True)
# Save as simple XYZ
np.savetxt("example/sphere.xyz", pts, fmt="%.6f")
# Save as ASCII PLY
n_verts = len(pts)
header = f"""ply
format ascii 1.0
element vertex {n_verts}
property float x
property float y
property float z
end_header
"""
with open("example/sphere.ply", "w") as f:
f.write(header)
for v in pts:
f.write(f"{v[0]:.6f} {v[1]:.6f} {v[2]:.6f}\n")
print("Created example/sphere.ply (and example/sphere.xyz)")
print(f" {n_verts} points on a noisy unit sphere")
print("\nNext, run:")
print(" python -m lightweightmr -i example/sphere.ply -o example/sphere_mesh.ply --device cpu")