junaid-simamdigital commited on
Commit
837e903
·
verified ·
1 Parent(s): 5d0e532

Upload simam3d_core.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. simam3d_core.py +44 -0
simam3d_core.py CHANGED
@@ -258,3 +258,47 @@ def write_confidence_ply(
258
  *point, *color, float(score), int(source_view)
259
  )
260
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
258
  *point, *color, float(score), int(source_view)
259
  )
260
  )
261
+
262
+
263
+ def write_gaussian_ply(
264
+ path: str | Path,
265
+ points: np.ndarray,
266
+ colors: np.ndarray,
267
+ weights: np.ndarray | None = None,
268
+ source_views: np.ndarray | None = None,
269
+ ) -> None:
270
+ """Write a confidence-initialized 3DGS PLY with evidence fields."""
271
+ points = np.asarray(points, dtype=np.float32)
272
+ colors = np.asarray(colors, dtype=np.uint8)[..., :3]
273
+ if points.ndim != 2 or points.shape[1] != 3 or colors.shape != (len(points), 3):
274
+ raise ValueError("points and colors must contain matching Nx3 arrays")
275
+ opacity, log_scale = gaussian_initialization(weights, len(points))
276
+ if weights is None or len(weights) != len(points):
277
+ exported_confidence = np.ones(len(points), dtype=np.float32)
278
+ else:
279
+ exported_confidence = np.clip(np.asarray(weights, dtype=np.float32), 0.0, 1.0)
280
+ if source_views is None or len(source_views) != len(points):
281
+ source_views = np.full(len(points), -1, dtype=np.int32)
282
+ else:
283
+ source_views = np.asarray(source_views, dtype=np.int32)
284
+ dc = (colors.astype(np.float32) / 255.0 - 0.5) / 0.2820947918
285
+ header = [
286
+ "ply", "format ascii 1.0", f"element vertex {len(points)}",
287
+ "property float x", "property float y", "property float z",
288
+ "property float nx", "property float ny", "property float nz",
289
+ "property float f_dc_0", "property float f_dc_1", "property float f_dc_2",
290
+ "property float opacity", "property float scale_0", "property float scale_1",
291
+ "property float scale_2", "property float rot_0", "property float rot_1",
292
+ "property float rot_2", "property float rot_3",
293
+ "property float confidence", "property int source_view", "end_header",
294
+ ]
295
+ with Path(path).open("w", encoding="utf-8") as handle:
296
+ handle.write("\n".join(header) + "\n")
297
+ for point, color, alpha, scale, score, source_view in zip(
298
+ points, dc, opacity, log_scale, exported_confidence, source_views
299
+ ):
300
+ handle.write(
301
+ "{:.7g} {:.7g} {:.7g} 0 0 0 {:.7g} {:.7g} {:.7g} {:.7g} {:.7g} {:.7g} {:.7g} 1 0 0 0 {:.7g} {}\n".format(
302
+ *point, *color, alpha, scale, scale, scale, float(score), int(source_view)
303
+ )
304
+ )