registration
triwarp.registration
Point cloud registration: Procrustes analysis and ICP.
procrustes
procrustes(
a: array[vec3],
b: array[vec3],
weights: array[float32] | None = None,
reflection: bool = True,
translation: bool = True,
scale: bool = True,
return_cost: Literal[True] = True,
) -> tuple[wp.array[wp.mat44], wp.array[wp.vec3], float]
procrustes(
a: array[vec3],
b: array[vec3],
weights: array[float32] | None = None,
reflection: bool = True,
translation: bool = True,
scale: bool = True,
return_cost: Literal[False] = False,
) -> wp.array[wp.mat44]
procrustes(
a: array[vec3],
b: array[vec3],
weights: array[float32] | None = None,
reflection: bool = True,
translation: bool = True,
scale: bool = True,
return_cost: bool = True,
) -> (
tuple[wp.array[wp.mat44], wp.array[wp.vec3], float]
| wp.array[wp.mat44]
)
procrustes(
a: array[vec3],
b: array[vec3],
weights: array[float32] | None = None,
reflection: bool = True,
translation: bool = True,
scale: bool = True,
return_cost: bool = True,
) -> (
tuple[wp.array[wp.mat44], wp.array[wp.vec3], float]
| wp.array[wp.mat44]
)
Find the optimal transform mapping point cloud a onto b.
Warp port of trimesh.registration.procrustes. Accepts and returns
GPU-resident arrays; no NumPy in the hot path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
array[vec3]
|
Corresponding point clouds, shape |
required |
b
|
array[vec3]
|
Corresponding point clouds, shape |
required |
weights
|
array[float32] | None
|
Per-point weights, shape |
None
|
reflection
|
bool
|
Allow reflections in the rotation component. |
True
|
translation
|
bool
|
Allow translation. |
True
|
scale
|
bool
|
Allow uniform scaling. |
True
|
return_cost
|
bool
|
When |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
matrix |
tuple[array[mat44], array[vec3], float] | array[mat44]
|
|
transformed |
tuple[array[mat44], array[vec3], float] | array[mat44]
|
|
cost |
tuple[array[mat44], array[vec3], float] | array[mat44]
|
Weighted sum of squared distances between transformed and b.
Only returned when |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Notes
Latency-bound at every size that matters: the fit is two kernel launches (four with
return_cost), one allocation for the packed moment accumulator and one readback, so the
cost is nearly flat in n. Callers in a loop should use the workspace form — see
icp, which allocates once outside its iteration.
The returned matrix is column-vector, which is the transpose of pytorch3d's.
pytorch3d.ops.corresponding_points_alignment solves the row-vector form s X R + T = Y,
so its R is this matrix's linear block divided by the scale and transposed.
Source code in triwarp/registration.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
icp
icp(
a: array[vec3],
target_vertices: array[vec3],
target_faces: array[int32] | None = None,
*,
initial: array[mat44] | mat44 | None = None,
max_iterations: int = 20,
threshold: float = 1e-05,
max_distance: float | None = None,
reflection: bool = False,
translation: bool = True,
scale: bool = False,
) -> tuple[wp.array[wp.mat44], wp.array[wp.vec3], float]
Point-to-point iterative closest point registration.
Aligns the source cloud a onto a target mesh or point cloud by repeatedly
matching each source point to its nearest target counterpart and solving the
resulting correspondence with procrustes.
Following the pytorch3d formulation, every iteration re-aligns the
original a to the current correspondences, so the returned transform is a
single map from a to the target (no incremental-composition drift). Only a
rough initial alignment is required for a good result.
Warp port combining trimesh.registration.icp and
pytorch3d.ops.iterative_closest_point. Correspondence search runs on the
GPU via closest_point_on_mesh
(mesh target) or query_nearest
(point-cloud target); the alignment is the GPU tiled SVD of
procrustes.
Its R is the transpose of the linear block returned here, because it solves the
row-vector form s X R + T = Y; the converged transform is what is comparable, not the
iteration count, since relative_rmse_thr is its own stopping rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
array[vec3]
|
Source point cloud, shape |
required |
target_vertices
|
array[vec3]
|
Target vertex positions, shape |
required |
target_faces
|
array[int32] | None
|
Flat |
None
|
initial
|
array[mat44] | mat44 | None
|
Initial transform seeding the first correspondence search, as a |
None
|
max_iterations
|
int
|
Maximum number of ICP iterations. |
20
|
threshold
|
float
|
Stop when the cost decreases by less than this between iterations. |
1e-05
|
max_distance
|
float | None
|
Reject correspondences farther than this (weight |
None
|
reflection
|
bool
|
Forwarded to |
False
|
translation
|
bool
|
Forwarded to |
False
|
scale
|
bool
|
Forwarded to |
False
|
Returns:
| Type | Description |
|---|---|
matrix
|
|
transformed
|
|
cost
|
Weighted mean squared correspondence distance at the final iteration. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Source code in triwarp/registration.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
icp_point_to_plane
icp_point_to_plane(
a: array[vec3],
target_vertices: array[vec3],
target_faces: array[int32] | None = None,
*,
target_normals: array[vec3] | None = None,
initial: array[mat44] | mat44 | None = None,
max_iterations: int = 20,
threshold: float = 1e-06,
max_distance: float | None = None,
robust_kernel: Literal[
"none", "huber", "tukey"
] = "none",
robust_scale: float | None = None,
damping: float = 1e-06,
) -> tuple[wp.array[wp.mat44], wp.array[wp.vec3], float]
Point-to-plane iterative closest point registration with optional robust loss.
Minimizes the squared distance from each transformed source point to the
tangent plane of its target correspondence, which converges faster than the
point-to-point metric on smooth surfaces. Each iteration linearizes the
residual, assembles the 6x6 Gauss-Newton system on the GPU, solves it, and
composes the incremental rigid step into the running transform.
Warp port of the libigl iterative_closest_point (rigid, point-to-plane)
and Open3D's robust TransformationEstimationPointToPlane. An optional
Huber or Tukey M-estimator down-weights outlier correspondences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
array[vec3]
|
Source point cloud, shape |
required |
target_vertices
|
array[vec3]
|
Target vertex positions, shape |
required |
target_faces
|
array[int32] | None
|
Flat |
None
|
target_normals
|
array[vec3] | None
|
Per-vertex unit normals for a point-cloud target, shape |
None
|
initial
|
array[mat44] | mat44 | None
|
Initial transform, as a |
None
|
max_iterations
|
int
|
Maximum number of ICP iterations. |
20
|
threshold
|
float
|
Stop when the cost decreases by less than this between iterations. |
1e-06
|
max_distance
|
float | None
|
Reject correspondences farther than this. No rejection when |
None
|
robust_kernel
|
Literal['none', 'huber', 'tukey']
|
M-estimator applied to residuals: |
'none'
|
robust_scale
|
float | None
|
Tuning constant of the robust kernel (Huber |
None
|
damping
|
float
|
Relative Levenberg damping added to the normal-equations diagonal (scaled by its mean magnitude) for conditioning on planar/degenerate targets. |
1e-06
|
Returns:
| Type | Description |
|---|---|
matrix
|
|
transformed
|
|
cost
|
Robust-weighted sum of squared point-to-plane residuals at the final iteration. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
Source code in triwarp/registration.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | |