File size: 1,184 Bytes
3196e80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
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")