text
stringlengths
0
1.47k
except Exception:
return None
import numpy as _np
try:
sp = o3d.geometry.PointCloud()
sp.points = o3d.utility.Vector3dVector(src.detach().cpu().to(torch.float64).numpy())
tp = o3d.geometry.PointCloud()
tp.points = o3d.utility.Vector3dVector(tgt.detach().cpu().to(torch.float64).numpy())
tp.estimate_normals(o3d.geometry.KDTreeSearchParamHybrid(radius=voxel * 2.0, max_nn=30))
res = o3d.pipelines.registration.registration_icp(
sp,
tp,
voxel * 2.0,
T0.detach().cpu().to(torch.float64).numpy(),
o3d.pipelines.registration.TransformationEstimationPointToPlane(),
o3d.pipelines.registration.ICPConvergenceCriteria(max_iteration=int(iters)),
)
return torch.tensor(_np.asarray(res.transformation), dtype=torch.float64)
except Exception:
return None
@torch.no_grad()
def robust_feature_align(
target: Gaussians,
source: Gaussians,
*,
transform: str = "se3",
voxel: float | None = None,
refine_iters: int = 30,
rng_seed: int = 42,
) -> tuple[torch.Tensor, dict]:
"""Scale-robust registrar: Open3D FPFH+RANSAC seed + splatreg overlap-aware refine (+ Sim(3)).
The object-tuned :func:`feature_align` seed collapses on metre-scale indoor scans (its FPFH radii
and 2 cm inlier tolerance are object-scale), which is why pure-splatreg ``init="fast"`` only hits
~13 % RR on 3DMatch while Open3D's scale-correct FPFH+RANSAC hits ~77 %. This path takes the best
of both: it borrows Open3D's *robust correspondence/seed* (auto-scaled voxel + radii) and then
runs splatreg's own overlap-aware trimmed ICP (:func:`_overlap_icp_polish`, target→source so a
partial overlap can't drag the fit) on top, adding refine accuracy and, for ``transform="sim3"``,
a recovered scale Open3D's rigid RANSAC never estimates.
When Open3D is absent it falls back to the pure-splatreg :func:`feature_align` (with the same
scale-adaptive ``voxel`` mapped into its ``inlier_tol``), so the function always returns a pose.
Args:
target / source: reference / to-align splats (only ``.means`` read).
transform: ``"se3"`` (rigid) or ``"sim3"`` (estimate scale in the refine).
voxel: downsample/feature scale (m); ``None`` → auto from the cloud bbox.
refine_iters: splatreg overlap-ICP polish iterations on top of the seed.
Returns:
``(T_4x4, info)``, estimated 4×4 (source→target, source device/dtype) and an ``info`` dict
(``voxel``, ``n_corr``, ``used_open3d`` and ``confidence``).
"""
if transform not in ("se3", "sim3"):
raise ValueError(f"transform must be 'se3' or 'sim3', got {transform!r}")
with_scale = transform == "sim3"
dev = source.means.device
dtype = source.means.dtype
src_full = source.means.to(torch.float32)
tgt_full = target.means.to(device=dev, dtype=torch.float32)
info = {"voxel": 0.0, "n_corr": 0, "used_open3d": False, "confidence": 0.0}
if src_full.shape[0] < 4 or tgt_full.shape[0] < 4:
return torch.eye(4, device=dev, dtype=dtype), info
if voxel is None:
# Derive from each cloud's point spacing; use the finer so detail survives the downsample.
voxel = min(_cloud_voxel(src_full), _cloud_voxel(tgt_full))
info["voxel"] = float(voxel)
T_seed, n_corr = _open3d_fpfh_ransac_seed(src_full, tgt_full, voxel, rng_seed=rng_seed)
if T_seed is not None:
info["used_open3d"] = True
info["n_corr"] = int(n_corr)
T0 = T_seed.to(device=dev, dtype=dtype)
# SE(3): Open3D point-to-plane ICP refine (scale-correct, standard) — tightens the seed at
# room scale without the object-tuned overlap ICP's low-overlap wander. For Sim(3) we need a
# scale DoF Open3D's rigid ICP can't give, so we use splatreg's overlap-aware Sim(3) ICP.
if not with_scale:
T_o3d = _open3d_icp_refine(src_full, tgt_full, T0, voxel, iters=refine_iters)
T_ref = T_o3d.to(device=dev, dtype=dtype) if T_o3d is not None else T0
else:
T_ref = _overlap_icp_polish(
src_full,
tgt_full,
T0,
with_scale=True,
iters=refine_iters,
n_src=min(4000, src_full.shape[0]),
n_tgt=min(2000, tgt_full.shape[0]),
)
# Accept the refine only if it does not worsen the overlap fit (a degenerate ICP can wander).
# NOTE: gate on the scale-blind one-directional residual BEFORE any scale-only correction, so
# the rotation/translation winner is chosen on the same footing the polish was tuned for.
r0 = _overlap_residual_norm(src_full, tgt_full, T0, with_scale=with_scale)
r1 = _overlap_residual_norm(src_full, tgt_full, T_ref, with_scale=with_scale)