Rawal Khirodkar commited on
Commit
1a446df
·
1 Parent(s): 83279a5

Pointmap: replace slow poisson-disk sphere sampling with instant Fibonacci sphere

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -144,13 +144,25 @@ def _foreground_mask(image_pil: Image.Image, target_h: int, target_w: int) -> np
144
  # -----------------------------------------------------------------------------
145
  # Point cloud export
146
 
147
- def _camera_marker(radius: float = 0.04, n_points: int = 600,
148
  color=(0.20, 0.55, 0.96)) -> o3d.geometry.PointCloud:
149
- """Small uniformly-blue sphere at the world origin marking the camera."""
150
- sphere = o3d.geometry.TriangleMesh.create_sphere(radius=radius, resolution=24)
151
- sphere.translate((0.0, 0.0, 0.0))
152
- pc = sphere.sample_points_poisson_disk(number_of_points=n_points)
153
- pc.colors = o3d.utility.Vector3dVector(np.tile(color, (len(pc.points), 1)))
 
 
 
 
 
 
 
 
 
 
 
 
154
  return pc
155
 
156
 
 
144
  # -----------------------------------------------------------------------------
145
  # Point cloud export
146
 
147
+ def _camera_marker(radius: float = 0.04, n_points: int = 800,
148
  color=(0.20, 0.55, 0.96)) -> o3d.geometry.PointCloud:
149
+ """Small uniformly-blue sphere at the world origin marking the camera.
150
+
151
+ Manual Fibonacci-sphere sampling — instant, vs Open3D's poisson-disk which
152
+ can take seconds per call.
153
+ """
154
+ rng = np.random.default_rng(0)
155
+ i = np.arange(n_points)
156
+ phi = np.arccos(1 - 2 * (i + 0.5) / n_points) # latitude
157
+ theta = np.pi * (1 + 5 ** 0.5) * (i + 0.5) # golden-angle longitude
158
+ pts = np.stack([
159
+ radius * np.sin(phi) * np.cos(theta),
160
+ radius * np.sin(phi) * np.sin(theta),
161
+ radius * np.cos(phi),
162
+ ], axis=1)
163
+ pc = o3d.geometry.PointCloud()
164
+ pc.points = o3d.utility.Vector3dVector(pts.astype(np.float64))
165
+ pc.colors = o3d.utility.Vector3dVector(np.tile(color, (n_points, 1)).astype(np.float64))
166
  return pc
167
 
168