text stringlengths 0 1.47k |
|---|
device=axis.device, |
dtype=torch.float64, |
) |
eye = torch.eye(3, device=axis.device, dtype=torch.float64) |
return eye + math.sin(rad) * K + (1.0 - math.cos(rad)) * (K @ K) |
def _rotation_constrained_probe( |
src_full: torch.Tensor, |
tgt_full: torch.Tensor, |
T: torch.Tensor, |
*, |
with_scale: bool, |
probe_deg: float = 10.0, |
n_src: int = 2048, |
n_tgt: int = 1024, |
) -> float: |
"""Quantify how strongly the surviving overlap constrains rotation (0 = flat/ambiguous). |
At the converged pose, the target→source overlap residual is at a minimum. If the surviving |
geometry actually constrains rotation, perturbing the rotation by ``±probe_deg`` about ANY axis |
(around the overlap centroid) raises that residual; if the region is rotationally ambiguous (a |
symmetric / featureless crop), some perturbation leaves the residual essentially unchanged. |
We return the SMALLEST residual increase over a set of probe axes, a *sensitivity* score: |
sensitivity = min_axis ( resid(R rotated by probe_deg) - resid(R rotated by 1deg) ) / scale |
Subtracting the residual under a TINY (1deg) rotation removes the surface-*resampling* floor: on |
a discretely-sampled cloud even an in-place re-sampling of the same surface (a rotation that maps |
the shape onto itself, e.g. a sphere) costs ~one point-spacing of residual. A genuinely |
constrained object's residual keeps climbing far past that floor at ``probe_deg``; an ambiguous |
one stays near the floor for some axis, so its score is ~0. The rise is normalised by the |
target's RMS radius (a dimensionless object-relative score). Cheap: a handful of cdist passes, |
CPU-friendly. |
Args: |
src_full / tgt_full: full source / (partial) target clouds (float32). |
T: converged 4×4 source→target transform. |
with_scale: Sim(3) if True. |
probe_deg: perturbation magnitude (degrees). |
n_src / n_tgt: strided subsample sizes. |
Returns: |
``sensitivity`` (>= 0). Larger = better-constrained rotation; near 0 = ambiguous. |
""" |
dev = T.device |
src = _stride_subsample(src_full, n_src).double() |
tgt = _stride_subsample(tgt_full, n_tgt).double() |
if src.shape[0] < 3 or tgt.shape[0] < 3: |
return 0.0 |
block = T[:3, :3].double() |
t = T[:3, 3].double() |
s = float(torch.linalg.det(block).abs().clamp_min(1e-18) ** (1.0 / 3.0)) if with_scale else 1.0 |
R = block / s if with_scale else block |
def overlap_resid(Rm: torch.Tensor, tm: torch.Tensor) -> float: |
TA = src @ Rm.transpose(-1, -2) * s + tm # (Ns, 3) |
d = torch.cdist(tgt, TA).min(dim=1).values # each observed target -> nearest source |
# trimmed mean (drop occlusion-boundary tail) for a stable residual |
k = max(3, int(0.85 * d.shape[0])) |
return float(d.topk(k, largest=False).values.mean().item()) |
# Normalise the residual rise by the TARGET's characteristic size (RMS radius), so the score is |
# a dimensionless "how far did the twist move the overlap, relative to the object scale". |
scale_ref = float((tgt - tgt.mean(dim=0)).norm(dim=1).pow(2).mean().sqrt().clamp_min(1e-9).item()) |
# overlap centroid (rotate about it so translation re-solves cleanly) |
TA0 = src @ R.transpose(-1, -2) * s + t |
nn = torch.cdist(tgt, TA0).argmin(dim=1) |
pivot = TA0[nn].mean(dim=0) # centroid of the matched (overlap) source region |
axes = torch.tensor( |
[[1.0, 0, 0], [0, 1.0, 0], [0, 0, 1.0], [1.0, 1.0, 0], [1.0, 0, 1.0], [0, 1.0, 1.0]], |
device=dev, |
dtype=torch.float64, |
) |
def probe_resid(ax: torch.Tensor, sgn: float, deg: float) -> float: |
dR = _axis_angle_R(ax / ax.norm(), sgn * math.radians(deg)) |
Rm = dR @ R |
tm = t + (pivot - dR @ pivot) # keep the overlap centroid fixed under the probe rotation |
return overlap_resid(Rm, tm) |
sensitivities = [] |
for ax in axes: |
for sgn in (1.0, -1.0): |
floor = probe_resid(ax, sgn, 1.0) # resampling floor in this rotation direction |
far = probe_resid(ax, sgn, probe_deg) # residual at the full probe angle |
sensitivities.append((far - floor) / scale_ref) |
return float(max(0.0, min(sensitivities))) |
# ── scale-robust seed (Open3D FPFH+RANSAC, optional) + splatreg refine ────────── |
def _cloud_voxel(pts: torch.Tensor, mult: float = 1.5) -> float: |
"""Scale-adaptive FPFH voxel from the cloud's POINT SPACING (median nearest-neighbour distance). |
The object-scale FPFH defaults (``inlier_tol`` ~2 cm, descriptor radii tuned for a 14 cm test |
object) are wrong by 1-2 orders of magnitude on metre-scale indoor scans, that is why the |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.