Upload example/make_sphere.py
Browse files- example/make_sphere.py +46 -0
example/make_sphere.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Generate a simple synthetic point cloud (sphere + noise) for quick testing.
|
| 3 |
+
Run this first if you don't have a scan handy.
|
| 4 |
+
|
| 5 |
+
python example/make_sphere.py
|
| 6 |
+
"""
|
| 7 |
+
import numpy as np
|
| 8 |
+
import os
|
| 9 |
+
|
| 10 |
+
# Make 3000 points on a unit sphere + small noise
|
| 11 |
+
n = 3000
|
| 12 |
+
phi = np.random.uniform(0, 2 * np.pi, n)
|
| 13 |
+
cos_theta = np.random.uniform(-1, 1, n)
|
| 14 |
+
sin_theta = np.sqrt(1 - cos_theta ** 2)
|
| 15 |
+
|
| 16 |
+
x = sin_theta * np.cos(phi)
|
| 17 |
+
y = sin_theta * np.sin(phi)
|
| 18 |
+
z = cos_theta
|
| 19 |
+
|
| 20 |
+
pts = np.stack([x, y, z], axis=1)
|
| 21 |
+
pts += np.random.normal(0, 0.01, pts.shape) # tiny noise
|
| 22 |
+
|
| 23 |
+
os.makedirs("example", exist_ok=True)
|
| 24 |
+
|
| 25 |
+
# Save as simple XYZ
|
| 26 |
+
np.savetxt("example/sphere.xyz", pts, fmt="%.6f")
|
| 27 |
+
|
| 28 |
+
# Save as ASCII PLY
|
| 29 |
+
n_verts = len(pts)
|
| 30 |
+
header = f"""ply
|
| 31 |
+
format ascii 1.0
|
| 32 |
+
element vertex {n_verts}
|
| 33 |
+
property float x
|
| 34 |
+
property float y
|
| 35 |
+
property float z
|
| 36 |
+
end_header
|
| 37 |
+
"""
|
| 38 |
+
with open("example/sphere.ply", "w") as f:
|
| 39 |
+
f.write(header)
|
| 40 |
+
for v in pts:
|
| 41 |
+
f.write(f"{v[0]:.6f} {v[1]:.6f} {v[2]:.6f}\n")
|
| 42 |
+
|
| 43 |
+
print("Created example/sphere.ply (and example/sphere.xyz)")
|
| 44 |
+
print(f" {n_verts} points on a noisy unit sphere")
|
| 45 |
+
print("\nNext, run:")
|
| 46 |
+
print(" python -m lightweightmr -i example/sphere.ply -o example/sphere_mesh.ply --device cpu")
|