nksr-wrapper / examples /chunked_reconstruction.py
bdck's picture
Upload examples/chunked_reconstruction.py
e73a251 verified
"""
Large-scale / out-of-core reconstruction example.
When your point cloud has millions of points (e.g. a full building or
outdoor LiDAR scan), NKSR supports chunking: the scene is split into
overlapping blocks, each reconstructed independently, and then fused
into a single implicit field.
"""
from pathlib import Path
from nksr_wrapper import NKSRMeshReconstructor, load_point_cloud, save_mesh
ply_path = Path("assets/large_scene.ply")
points, normals = load_point_cloud(ply_path)
recon = NKSRMeshReconstructor(
device="cuda:0",
config="ks",
chunk_tmp_device="cpu", # offload finished chunks to CPU RAM
)
mesh = recon.reconstruct(
points=points,
normals=normals,
chunk_size=50.0, # each chunk is a 50-unit cube
overlap_ratio=0.05, # 5 % overlap for smooth transitions
approx_kernel_grad=True, # faster gradient approximation
solver_tol=1e-4, # slightly looser tolerance — huge scenes
mise_iter=1,
)
save_mesh("large_scene_mesh.ply", mesh.vertices, mesh.faces)
print(f"Reconstructed {len(mesh.vertices):,} vertices, {len(mesh.faces):,} faces")