text stringlengths 0 1.47k |
|---|
) -> torch.Tensor: |
"""Rank ALL ``seeds`` by a cheap fully-batched target→source point-to-point trimmed ICP. |
This is a *coarse, fast* basin pre-selector, it runs every super-Fibonacci seed at once |
(vectorised closed-form Umeyama steps via :func:`splatreg.align._batched_umeyama`, chunked over |
seeds) so we never pay the per-seed Python-loop / 6×6-solve cost of the point-to-plane refiner on |
thousands of candidates. Point-to-point can't reach the exact subset pose on a one-sided crop |
(that's what the pivoted point-to-plane refine is for), but its trimmed target→source overlap |
residual reliably *ranks* seeds so the true basin is among the top few, the expensive refine then |
only runs on those. Returns the converged rotations ``(B, 3, 3)`` ordered best-overlap first. |
""" |
Ns, Nt = src.shape[0], tgt.shape[0] |
sc = src.mean(0) |
tc = tgt.mean(0) |
keep_k = max(6, int(round(trim * Nt))) |
score_chunks: list[torch.Tensor] = [] |
R_chunks: list[torch.Tensor] = [] |
src0 = (src - sc).to(torch.float32) |
tgtf = tgt.to(torch.float32) |
for lo in range(0, seeds.shape[0], seed_batch): |
Rb = seeds[lo : lo + seed_batch].to(torch.float32) |
b = Rb.shape[0] |
# transformed full source per seed (B, Ns, 3): rotate about source centroid, place at target. |
X = torch.bmm(src0.unsqueeze(0).expand(b, Ns, 3), Rb.transpose(1, 2)) + tc.to(torch.float32) |
Y = tgtf.unsqueeze(0).expand(b, Nt, 3).contiguous() |
# track the cumulative rotation applied to the source (starts at the seed Rb) |
Rcur = Rb.clone() |
for _ in range(int(iters)): |
d, idx = _batched_nn(Y, X) # each target -> nearest transformed source |
thr = torch.kthvalue(d, keep_k, dim=1, keepdim=True).values |
wmask = (d <= thr).to(X.dtype) |
Xm = torch.gather(X, 1, idx.unsqueeze(-1).expand(b, Nt, 3)) # matched src per target |
s_i, R_i, t_i = _batched_umeyama(Xm, Y, wmask, with_scale=False) |
X = torch.bmm(X, R_i.transpose(1, 2)) + t_i[:, None, :] |
Rcur = torch.bmm(R_i, Rcur) |
d, _ = _batched_nn(Y, X) |
k = max(3, int(0.9 * Nt)) |
score_chunks.append(torch.sort(d, dim=1).values[:, :k].sqrt().mean(dim=1)) |
R_chunks.append(Rcur) |
scores = torch.cat(score_chunks, dim=0) |
Rall = torch.cat(R_chunks, dim=0) |
order = torch.argsort(scores) |
return Rall[order].to(torch.float64) |
def _overlap_basin_sweep( |
src_full: torch.Tensor, |
tgt_full: torch.Tensor, |
*, |
with_scale: bool, |
n_rot: int = 2048, |
icp_iters: int = 12, |
trim: float = 0.7, |
topk: int = 200, |
refine_iters: int = 150, |
refine_trim: float = 0.8, |
n_src: int = 1400, |
n_tgt: int = 800, |
) -> torch.Tensor: |
"""Overlap-aware **point-to-plane** super-Fibonacci basin sweep, the partial-overlap recoverer. |
The FPFH path lands a wrong rotation on smooth splat surfaces (the descriptors are near-flat off |
the disambiguating lobe), so the coarse init falls into a wrong basin and the ambiguity detector |
then (correctly) flags it. This sweep replaces that coarse init with a geometry-only search that |
is robust to a one-sided crop: |
1. Seed SO(3) with a deterministic super-Fibonacci covering (``n_rot`` rotations); for each seed |
centroid-align the source to the target and run a short overlap-aware *point-to-plane* trimmed |
ICP (:func:`_point_to_plane_overlap_icp`). Point-to-plane (not point-to-point) is essential: |
it lets the partial target slide along the smooth source surface to its true tangential |
position, so the correct basin converges to residual ~0 while wrong basins stay at ~0.005. |
2. Keep the ``topk`` lowest-residual converged seeds and re-refine each with a longer, |
tighter-trim point-to-plane ICP, then pick the winner by the SYMMETRIC overlap residual (see |
step 3). On MODERATE crops (keep≈60 %) the true basin's coarse seed ranks DEEP in the cheap |
prefilter (the cropped one-directional residual barely separates it from the 170-ish mirror), |
so a shallow ``topk`` drops it before the precise refine ever sees it; the true basin also needs |
enough refine iterations to fully descend. ``topk=200`` + ``refine_iters=150`` keeps the true |
seed in the pool and lets it converge, this is what lifts keep60 from 1/3 to 3/3 solved, |
while staying GPU-affordable (the prefilter is fully batched; only ``topk`` seeds are refined). |
3. Return the lowest-residual transform. When the crop genuinely deletes the rotation- |
disambiguating geometry (heavy crops), no seed reaches a low residual, the caller's ambiguity |
gate then honestly flags it instead of returning a confident wrong pose. |
Deterministic (closed-form seeds + strided subsample, no RNG). ``with_scale`` is accepted for |
signature parity but the partial-overlap sweep estimates a rigid pose (scale is recovered by the |
downstream FPFH/Umeyama path when needed); the test geometry is metric-consistent so this does |
not affect recovery. |
Returns the best 4×4 source→target transform. |
""" |
del with_scale # rigid sweep; scale parity handled upstream |
dev, dtype = src_full.device, src_full.dtype |
src = _stride_subsample(src_full, n_src).double() |
tgt = _stride_subsample(tgt_full, n_tgt).double() |
eye4 = torch.eye(4, device=dev, dtype=dtype) |
if src.shape[0] < 6 or tgt.shape[0] < 6: |
return eye4 |
# Per-source-point normals (reuse the FPFH normal estimator for a consistent surface estimate). |
sidx = _knn_indices(src.to(torch.float32), _FS_KNN_NORMAL) |
snrm = _estimate_normals(src.to(torch.float32), sidx).double() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.