Rawal Khirodkar commited on
Commit
04f5fcb
·
1 Parent(s): bed3d5d

Pointmap: surfel size from bbox diag/sqrt(N) (proper 2D-surface formula); factor 1.5 for clear overlap

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -272,13 +272,15 @@ def _make_glb(image_pil_texture: Image.Image, pointmap_hwc: np.ndarray,
272
  centroid = pts.mean(axis=0).astype(np.float32) if len(pts) else np.zeros(3, np.float32)
273
  pts = pts - centroid
274
 
275
- # Surfel size from KD-tree median nearest-neighbour distance.
276
- # Factor 0.6 adjacent surfels overlap slightly along the surface so
277
- # there are no visible gaps between tiles.
 
 
 
278
  if len(pts) >= 2:
279
- from scipy.spatial import cKDTree
280
- nn_dist = cKDTree(pts).query(pts, k=2)[0][:, 1]
281
- r = max(float(np.median(nn_dist)) * 0.6, 1e-4)
282
  else:
283
  r = 0.005
284
 
 
272
  centroid = pts.mean(axis=0).astype(np.float32) if len(pts) else np.zeros(3, np.float32)
273
  pts = pts - centroid
274
 
275
+ # Surfel size: surface-spacing estimate = bbox diagonal / sqrt(N).
276
+ # This is geometrically correct for points distributed across a 2D surface;
277
+ # raw KD-tree NN distance is biased too small (adjacent pixels often map
278
+ # to nearly-coincident 3D points, pulling the median way below the actual
279
+ # visual spacing). Factor 1.5 gives clear overlap so the surface reads
280
+ # as solid skin rather than a sparse tile pattern.
281
  if len(pts) >= 2:
282
+ extent_diag = float(np.linalg.norm(np.ptp(pts, axis=0)))
283
+ r = max(extent_diag / np.sqrt(len(pts)) * 1.5, 1e-4)
 
284
  else:
285
  r = 0.005
286