ordito.metrics
Chamfer and Hausdorff distances between point clouds and meshes.
All metrics are fully GPU-resident: they compose the nearest-neighbor and
point-to-surface primitives in proximity with the tiled reductions
in reduce, and never move per-element data to the host.
Chamfer distances reduce plain Euclidean distances by default, the usual definition of the
metric. squared=True squares each distance before reducing instead, which is the pytorch3d
convention (pytorch3d.loss.chamfer_distance) and the one to pass when comparing against it.
Hausdorff distances follow libigl's igl::hausdorff and reduce the
(already Euclidean) per-element distances with a maximum, so no squaring or final square root is
needed.
One place the convention does not carry over, because the two libraries answer different
questions: pytorch3d.loss.point_mesh_face_distance sums point-to-triangle with
face-to-point, where
chamfer_points_to_mesh's backward direction is
mesh-vertex to nearest query. The forward halves agree, but the whole scalars differ by
construction and are not comparable.
Two families of geometry are supported and can be mixed:
points_to_points-- both sides are point clouds (nearest neighbor viaquery_nearest).points_to_mesh-- a point cloud versus a triangle mesh (point-to-surface viaclosest_point_on_meshone way, mesh-vertex nearest neighbor the other way).mesh_to_mesh-- both sides are triangle meshes (vertex-to-surface both directions).
Referenced by 4 places
API Reference API reference › Find a function by task · typing › empty_1d · energies · energies › edge_length_loss
Functions:
| Name | Description |
|---|---|
chamfer_points_to_points |
Chamfer distance between two point clouds. |
chamfer_points_to_mesh |
Chamfer distance between a point cloud and a triangle mesh. |
chamfer_mesh_to_mesh |
Chamfer distance between two triangle meshes (vertex-to-surface). |
chamfer_points_to_points_loss |
Differentiable Chamfer loss between two point clouds. |
chamfer_points_to_mesh_loss |
Differentiable Chamfer loss between a point cloud and a triangle mesh. |
chamfer_mesh_to_mesh_loss |
Differentiable Chamfer loss between two triangle meshes (vertex-to-surface). |
hausdorff_points_to_points |
Hausdorff distance between two point clouds. |
hausdorff_points_to_mesh |
Hausdorff distance between a point cloud and a triangle mesh. |
hausdorff_mesh_to_mesh |
Hausdorff distance between two triangle meshes. |
chamfer_points_to_points
chamfer_points_to_points(
x: array[vec3],
y: array[vec3],
*,
point_reduction: _PointReduction = ...,
single_directional: bool = ...,
squared: bool = ...,
) -> float
chamfer_points_to_points(
x: array[vec3],
y: array[vec3],
*,
point_reduction: None,
single_directional: Literal[True],
squared: bool = ...,
) -> odt.Array1dFloat32
chamfer_points_to_points(
x: array[vec3],
y: array[vec3],
*,
point_reduction: None,
single_directional: Literal[False] = ...,
squared: bool = ...,
) -> tuple[odt.Array1dFloat32, odt.Array1dFloat32]
chamfer_points_to_points(
x: array[vec3],
y: array[vec3],
*,
point_reduction: None,
single_directional: bool,
squared: bool = ...,
) -> _UnreducedChamfer
chamfer_points_to_points(
x: array[vec3],
y: array[vec3],
*,
point_reduction: _PointReduction | None = "mean",
single_directional: bool = False,
squared: bool = False,
) -> float | _UnreducedChamfer
Chamfer distance between two point clouds.
For each point in x the Euclidean distance to its nearest neighbor in y is
accumulated (and symmetrically for y into x unless single_directional).
pytorch3d.loss.chamfer_distance is this call with squared=True; its
single_directional keyword maps onto this one exactly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array[vec3]
|
|
required |
y
|
array[vec3]
|
|
required |
point_reduction
|
_PointReduction | None
|
How to reduce the per-point distances of each direction:
|
'mean'
|
single_directional
|
bool
|
If |
False
|
squared
|
bool
|
Square each distance before reducing, as |
False
|
Returns:
| Type | Description |
|---|---|
float or array[float32] or tuple
|
The reduced Chamfer distance as a Python |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Examples:
The x -> y distances are [0, 1] and the y -> x ones [0, 3]; the symmetric value
is the sum of the two means:
import warp as wp
import ordito as od
x = wp.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], dtype=wp.vec3)
y = wp.array([[0.0, 0.0, 0.0], [0.0, 0.0, 3.0]], dtype=wp.vec3)
print(od.metrics.chamfer_points_to_points(x, y)) # 2.0
print(od.metrics.chamfer_points_to_points(x, y, single_directional=True)) # 0.5
print(od.metrics.chamfer_points_to_points(x, y, squared=True)) # 5.0
forward, backward = od.metrics.chamfer_points_to_points(x, y, point_reduction=None)
print(forward.numpy().tolist(), backward.numpy().tolist()) # [0.0, 1.0] [0.0, 3.0]
Referenced by 5 places
API Reference metrics › chamfer_mesh_to_mesh · metrics › chamfer_points_to_mesh · metrics › chamfer_points_to_points_loss
Migrating from another library Migrating from PyTorch3D › Neighbours and distances · Migrating from PyTorch3D › What's different, not just renamed
Source code in ordito/metrics.py
151 152 153 154 155 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 | |
chamfer_points_to_mesh
chamfer_points_to_mesh(
points: array[vec3],
vertices: array[vec3],
faces: array[int32],
*,
point_reduction: _PointReduction = ...,
single_directional: bool = ...,
squared: bool = ...,
mesh: Mesh | None = ...,
) -> float
chamfer_points_to_mesh(
points: array[vec3],
vertices: array[vec3],
faces: array[int32],
*,
point_reduction: None,
single_directional: Literal[True],
squared: bool = ...,
mesh: Mesh | None = ...,
) -> odt.Array1dFloat32
chamfer_points_to_mesh(
points: array[vec3],
vertices: array[vec3],
faces: array[int32],
*,
point_reduction: None,
single_directional: Literal[False] = ...,
squared: bool = ...,
mesh: Mesh | None = ...,
) -> tuple[odt.Array1dFloat32, odt.Array1dFloat32]
chamfer_points_to_mesh(
points: array[vec3],
vertices: array[vec3],
faces: array[int32],
*,
point_reduction: None,
single_directional: bool,
squared: bool = ...,
mesh: Mesh | None = ...,
) -> _UnreducedChamfer
chamfer_points_to_mesh(
points: array[vec3],
vertices: array[vec3],
faces: array[int32],
*,
point_reduction: _PointReduction | None = "mean",
single_directional: bool = False,
squared: bool = False,
mesh: Mesh | None = None,
) -> float | _UnreducedChamfer
Chamfer distance between a point cloud and a triangle mesh.
The forward term is the distance from each point to the mesh surface
(exact, via closest_point_on_mesh);
the backward term is the distance from each mesh vertex to its nearest
point in the cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
array[vec3]
|
|
required |
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
point_reduction
|
_PointReduction | None
|
|
'mean'
|
single_directional
|
bool
|
If |
False
|
squared
|
bool
|
Square each distance before reducing, as |
False
|
mesh
|
Mesh | None
|
A |
None
|
Returns:
| Type | Description |
|---|---|
float or array[float32] or tuple
|
Same layout as |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Examples:
A point 1.0 outside a unit cube and one at its centre, 0.5 from every face. The backward
term adds the mean distance from the cube's corners to the cloud, sqrt(3) / 2:
import warp as wp
import ordito as od
vertices, faces = od.creation.box()
points = wp.array([[1.5, 0.0, 0.0], [0.0, 0.0, 0.0]], dtype=wp.vec3)
forward = od.metrics.chamfer_points_to_mesh(points, vertices, faces, single_directional=True)
print(forward) # 0.75
print(f"{od.metrics.chamfer_points_to_mesh(points, vertices, faces):.4f}") # 1.6160
Referenced by 6 places
API Reference metrics · metrics › chamfer_mesh_to_mesh · metrics › chamfer_points_to_mesh_loss · metrics › chamfer_points_to_points
Examples Spatial queries › Chamfer and Hausdorff distances
Migrating from another library Migrating from PyTorch3D › Neighbours and distances
Source code in ordito/metrics.py
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
chamfer_mesh_to_mesh
chamfer_mesh_to_mesh(
vertices_a: array[vec3],
faces_a: array[int32],
vertices_b: array[vec3],
faces_b: array[int32],
*,
point_reduction: _PointReduction = ...,
single_directional: bool = ...,
squared: bool = ...,
mesh_a: Mesh | None = ...,
mesh_b: Mesh | None = ...,
) -> float
chamfer_mesh_to_mesh(
vertices_a: array[vec3],
faces_a: array[int32],
vertices_b: array[vec3],
faces_b: array[int32],
*,
point_reduction: None,
single_directional: Literal[True],
squared: bool = ...,
mesh_a: Mesh | None = ...,
mesh_b: Mesh | None = ...,
) -> odt.Array1dFloat32
chamfer_mesh_to_mesh(
vertices_a: array[vec3],
faces_a: array[int32],
vertices_b: array[vec3],
faces_b: array[int32],
*,
point_reduction: None,
single_directional: Literal[False] = ...,
squared: bool = ...,
mesh_a: Mesh | None = ...,
mesh_b: Mesh | None = ...,
) -> tuple[odt.Array1dFloat32, odt.Array1dFloat32]
chamfer_mesh_to_mesh(
vertices_a: array[vec3],
faces_a: array[int32],
vertices_b: array[vec3],
faces_b: array[int32],
*,
point_reduction: None,
single_directional: bool,
squared: bool = ...,
mesh_a: Mesh | None = ...,
mesh_b: Mesh | None = ...,
) -> _UnreducedChamfer
chamfer_mesh_to_mesh(
vertices_a: array[vec3],
faces_a: array[int32],
vertices_b: array[vec3],
faces_b: array[int32],
*,
point_reduction: _PointReduction | None = "mean",
single_directional: bool = False,
squared: bool = False,
mesh_a: Mesh | None = None,
mesh_b: Mesh | None = None,
) -> float | _UnreducedChamfer
Chamfer distance between two triangle meshes (vertex-to-surface).
The forward term is the distance from each vertex of mesh A to the
surface of mesh B; the backward term is the reverse. This mirrors the
vertex-based approach of libigl while accumulating (mean/sum) instead of maximizing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices_a
|
array[vec3]
|
|
required |
faces_a
|
array[vec3]
|
|
required |
vertices_b
|
array[vec3]
|
|
required |
faces_b
|
array[vec3]
|
|
required |
point_reduction
|
_PointReduction | None
|
|
'mean'
|
single_directional
|
bool
|
If |
False
|
squared
|
bool
|
Square each distance before reducing, as |
False
|
mesh_a
|
Mesh | None
|
|
None
|
mesh_b
|
Mesh | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
float or array[float32] or tuple
|
Same layout as |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Examples:
A unit cube inside a cube of side 2: each inner corner is 0.5 from the outer surface, each
outer corner sqrt(3) / 2 from the inner one:
import ordito as od
vertices_a, faces_a = od.creation.box()
vertices_b, faces_b = od.creation.box(extents=(2.0, 2.0, 2.0))
forward = od.metrics.chamfer_mesh_to_mesh(
vertices_a, faces_a, vertices_b, faces_b, single_directional=True
)
print(forward) # 0.5
symmetric = od.metrics.chamfer_mesh_to_mesh(vertices_a, faces_a, vertices_b, faces_b)
print(f"{symmetric:.4f}") # 1.3660
Referenced by 6 places
API Reference API reference › Find a function by task · metrics › chamfer_mesh_to_mesh_loss · metrics › chamfer_points_to_mesh · metrics › chamfer_points_to_points · metrics › hausdorff_mesh_to_mesh
Examples Spatial queries › Chamfer and Hausdorff distances
Source code in ordito/metrics.py
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 | |
chamfer_points_to_points_loss
chamfer_points_to_points_loss(
x: array[vec3],
y: array[vec3],
*,
tape: Tape | None = None,
point_reduction: _DiffReduction = "mean",
single_directional: bool = False,
squared: bool = False,
) -> wp.array[wp.float32]
Differentiable Chamfer loss between two point clouds.
Squared-distance analogue of
chamfer_points_to_points that returns
a length-1 wp.float32 device array instead of a host float, so the loss can be
back-propagated to x and y through a caller-owned wp.Tape.
The nearest-neighbor assignment (via
query_nearest) is computed
outside tape and held constant during the backward pass, matching pytorch3d's
chamfer_distance gradient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array[vec3]
|
|
required |
y
|
array[vec3]
|
|
required |
tape
|
Tape | None
|
Caller-owned |
None
|
point_reduction
|
_DiffReduction
|
|
'mean'
|
single_directional
|
bool
|
If |
False
|
squared
|
bool
|
Square each distance before reducing, as |
False
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Examples:
The point (1, 0, 0) is 1 from its nearest neighbour at the origin, so the mean loss is
0.5 and its gradient pushes it towards the origin with weight 1 / 2:
import warp as wp
import ordito as od
x = wp.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], dtype=wp.vec3, requires_grad=True)
y = wp.array([[0.0, 0.0, 0.0], [1.0, 0.0, 2.0]], dtype=wp.vec3)
tape = wp.Tape()
loss = od.metrics.chamfer_points_to_points_loss(x, y, tape=tape, single_directional=True)
tape.backward(loss=loss)
print(loss.numpy()) # [0.5]
print(x.grad.numpy()[1]) # [0.5 0. 0. ]
Referenced by 4 places
API Reference config · metrics › chamfer_mesh_to_mesh_loss · metrics › chamfer_points_to_mesh_loss
Migrating from another library Migrating from PyTorch3D › Neighbours and distances
Source code in ordito/metrics.py
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 | |
chamfer_points_to_mesh_loss
chamfer_points_to_mesh_loss(
points: array[vec3],
vertices: array[vec3],
faces: array[int32],
*,
tape: Tape | None = None,
point_reduction: _DiffReduction = "mean",
single_directional: bool = False,
squared: bool = False,
mesh: Mesh | None = None,
) -> wp.array[wp.float32]
Differentiable Chamfer loss between a point cloud and a triangle mesh.
Squared-distance analogue of
chamfer_points_to_mesh. The forward term
is the exact point-to-surface distance (closest triangle held constant during
backprop); the backward term is the distance from each mesh vertex to its
nearest point in the cloud. Gradients flow to points and vertices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
array[vec3]
|
|
required |
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
tape
|
Tape | None
|
Caller-owned |
None
|
point_reduction
|
_DiffReduction
|
|
'mean'
|
single_directional
|
bool
|
If |
False
|
squared
|
bool
|
Square each distance before reducing, as |
False
|
mesh
|
Mesh | None
|
A |
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Examples:
A point 1.0 outside the x = 0.5 face of a unit cube; the gradient of its distance points
away from the face:
import warp as wp
import ordito as od
vertices, faces = od.creation.box()
points = wp.array([[1.5, 0.1, 0.2]], dtype=wp.vec3, requires_grad=True)
tape = wp.Tape()
loss = od.metrics.chamfer_points_to_mesh_loss(
points, vertices, faces, tape=tape, single_directional=True
)
tape.backward(loss=loss)
print(loss.numpy()) # [1.]
print(points.grad.numpy()[0]) # [1. 0. 0.]
Referenced by 4 places
API Reference config · metrics › chamfer_mesh_to_mesh_loss · metrics › chamfer_points_to_points_loss
Migrating from another library Migrating from PyTorch3D › Neighbours and distances
Source code in ordito/metrics.py
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 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 | |
chamfer_mesh_to_mesh_loss
chamfer_mesh_to_mesh_loss(
vertices_a: array[vec3],
faces_a: array[int32],
vertices_b: array[vec3],
faces_b: array[int32],
*,
tape: Tape | None = None,
point_reduction: _DiffReduction = "mean",
single_directional: bool = False,
squared: bool = False,
mesh_a: Mesh | None = None,
mesh_b: Mesh | None = None,
) -> wp.array[wp.float32]
Differentiable Chamfer loss between two triangle meshes (vertex-to-surface).
Squared-distance analogue of
chamfer_mesh_to_mesh. The forward term is
the distance from each vertex of mesh A to the surface of mesh B (with
the closest triangle held constant during backprop); the backward term is the reverse.
Gradients flow to both meshes' vertices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices_a
|
array[vec3]
|
|
required |
faces_a
|
array[vec3]
|
|
required |
vertices_b
|
array[vec3]
|
|
required |
faces_b
|
array[vec3]
|
|
required |
tape
|
Tape | None
|
Caller-owned |
None
|
point_reduction
|
_DiffReduction
|
|
'mean'
|
single_directional
|
bool
|
If |
False
|
squared
|
bool
|
Square each distance before reducing, as |
False
|
mesh_a
|
Mesh | None
|
|
None
|
mesh_b
|
Mesh | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
ValueError
|
If |
Examples:
A unit cube under a slab whose bottom face is the plane z = 1: the cube's top corners are
0.5 from it and the bottom ones 1.5, a mean of 1, and every corner is pulled up with
weight 1 / 8:
import warp as wp
import ordito as od
vertices_a, faces_a = od.creation.box()
vertices_b, faces_b = od.creation.box(bounds=[[-2.0, -2.0, 1.0], [2.0, 2.0, 2.0]])
vertices_a.requires_grad = True
tape = wp.Tape()
loss = od.metrics.chamfer_mesh_to_mesh_loss(
vertices_a, faces_a, vertices_b, faces_b, tape=tape, single_directional=True
)
tape.backward(loss=loss)
print(loss.numpy()) # [1.]
print(set(vertices_a.grad.numpy()[:, 2].tolist())) # {-0.125}
Referenced by 3 places
API Reference config · metrics › chamfer_points_to_mesh_loss · metrics › chamfer_points_to_points_loss
Source code in ordito/metrics.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 | |
hausdorff_points_to_points
hausdorff_points_to_points(
x: array[vec3],
y: array[vec3],
*,
single_directional: bool = False,
) -> float
Hausdorff distance between two point clouds.
The directed distance d(x, y) = max_i min_j ||x_i - y_j|| is computed (and
symmetrized with d(y, x) unless single_directional). Equivalent to
symmetrizing scipy.spatial.distance.directed_hausdorff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array[vec3]
|
|
required |
y
|
array[vec3]
|
|
required |
single_directional
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
float
|
The (symmetric or directed) Hausdorff distance. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Examples:
Every point of x is within 1 of y, but (3, 0, 0) is 2 from x:
import warp as wp
import ordito as od
x = wp.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0]], dtype=wp.vec3)
y = wp.array([[0.0, 0.0, 0.0], [3.0, 0.0, 0.0]], dtype=wp.vec3)
print(od.metrics.hausdorff_points_to_points(x, y)) # 2.0
print(od.metrics.hausdorff_points_to_points(x, y, single_directional=True)) # 1.0
Referenced by 1 place
API Reference metrics › hausdorff_points_to_mesh
Source code in ordito/metrics.py
882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 | |
hausdorff_points_to_mesh
hausdorff_points_to_mesh(
points: array[vec3],
vertices: array[vec3],
faces: array[int32],
*,
single_directional: bool = False,
mesh: Mesh | None = None,
) -> float
Hausdorff distance between a point cloud and a triangle mesh.
The forward distance is the maximum over points of the distance to the mesh surface; the backward distance is the maximum over mesh vertices of the distance to the nearest point in the cloud.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
array[vec3]
|
|
required |
vertices
|
array[vec3]
|
|
required |
faces
|
array[int32]
|
|
required |
single_directional
|
bool
|
If |
False
|
mesh
|
Mesh | None
|
A |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The (symmetric or directed) Hausdorff distance. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Examples:
A point 1.0 outside a unit cube and one at its centre. The farthest cube corner from the
cloud is sqrt(3) / 2 from the centre point, so the symmetric value is still 1:
import warp as wp
import ordito as od
vertices, faces = od.creation.box()
points = wp.array([[1.5, 0.0, 0.0], [0.0, 0.0, 0.0]], dtype=wp.vec3)
directed = od.metrics.hausdorff_points_to_mesh(points, vertices, faces, single_directional=True)
print(directed) # 1.0
print(f"{od.metrics.hausdorff_points_to_mesh(points, vertices, faces):.4f}") # 1.0000
Referenced by 2 places
API Reference metrics › hausdorff_mesh_to_mesh · metrics › hausdorff_points_to_points
Source code in ordito/metrics.py
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | |
hausdorff_mesh_to_mesh
hausdorff_mesh_to_mesh(
vertices_a: array[vec3],
faces_a: array[int32],
vertices_b: array[vec3],
faces_b: array[int32],
*,
single_directional: bool = False,
mesh_a: Mesh | None = None,
mesh_b: Mesh | None = None,
) -> float
Hausdorff distance between two triangle meshes.
Direct port of libigl's igl::hausdorff (vertex-based overload): the distance
from every vertex of one mesh to the surface of the other is computed in both
directions and the overall maximum is returned. This equals
sqrt(max(d_ba, d_ab)) in libigl, where d_* are squared distances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices_a
|
array[vec3]
|
|
required |
faces_a
|
array[vec3]
|
|
required |
vertices_b
|
array[vec3]
|
|
required |
faces_b
|
array[vec3]
|
|
required |
single_directional
|
bool
|
If |
False
|
mesh_a
|
Mesh | None
|
|
None
|
mesh_b
|
Mesh | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
float
|
The (symmetric or directed) Hausdorff distance. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If |
Examples:
A unit cube inside a cube of side 2: the inner corners are 0.5 from the outer surface, the
outer corners sqrt(3) / 2 from the inner one:
import ordito as od
vertices_a, faces_a = od.creation.box()
vertices_b, faces_b = od.creation.box(extents=(2.0, 2.0, 2.0))
directed = od.metrics.hausdorff_mesh_to_mesh(
vertices_a, faces_a, vertices_b, faces_b, single_directional=True
)
print(directed) # 0.5
symmetric = od.metrics.hausdorff_mesh_to_mesh(vertices_a, faces_a, vertices_b, faces_b)
print(f"{symmetric:.4f}") # 0.8660
Referenced by 5 places
API Reference API reference › Find a function by task · metrics › chamfer_mesh_to_mesh · metrics › hausdorff_points_to_mesh · metrics › hausdorff_points_to_points
Examples Spatial queries › Chamfer and Hausdorff distances
Source code in ordito/metrics.py
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 | |