visibility
triwarp.visibility
How far the surface is from a point.
Outward until nothing is hit (ambient_occlusion,
volumetric_obscurance); inward until it is hit again
(shape_diameter,
thickness); or in every direction at once, which is the radius at
which the surface first appears
(max_tangent_sphere).
All five take (mesh: wp.Mesh, points, *, normals=None, ...) -- a prebuilt BVH and a set of
positions to measure at -- which is what separates this module from
triwarp.proximity, where the queries take raw (vertices, faces) and ask
where the surface is rather than how far away.
The two outward fields integrate the same bundle of rays over the outward hemisphere at each point,
weighted by Lambert's cosine law, and differ only in what a blocked ray costs: ambient occlusion
charges a hit its full weight however far away it is, obscurance discounts it by
exp(-tau * distance) so that only nearby geometry darkens a point. Ambient occlusion is the
tau -> 0 limit, which is why they share a kernel. Neither is normalized against a scene, so both
are comparable across meshes and resolutions, and on a convex closed surface no ray can return
and every point reads exactly 0 -- the cheapest available sanity check on a result.
The three inward measures differ in how much evidence they take.
thickness is a dispatcher over the other two: one inward ray, or
one tangent sphere. shape_diameter fires a whole cone and
takes an outlier-trimmed mean, which is what makes it stable enough for skeleton extraction and part
segmentation. max_tangent_sphere uses no rays at all: it
shrinks a sphere until nothing but the surface touches it, so it answers the question for a volume
rather than along a direction, and it is the reason this module's name is a loose fit for one of its
five members.
RayWeight
module-attribute
RayWeight = Literal['cosine', 'uniform']
Weighting of a ray; see ambient_occlusion.
ambient_occlusion
ambient_occlusion(
mesh: Mesh,
points: array[vec3],
*,
normals: array[vec3] | None = None,
n_rays: int = 64,
weight: RayWeight = "cosine",
max_t: float | None = None,
) -> wp.array[wp.float32]
Fraction of the outward hemisphere at each point that is blocked by the mesh itself.
A Fibonacci hemisphere lattice is rotated into each point's tangent frame and every direction is
traced against the mesh; the result is the weighted share of directions that hit something. This
is MeshLab's compute_scalar_ambient_occlusion and libigl's igl::ambient_occlusion, which
differ from each other exactly in the weight argument below.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
Triangle mesh with a built BVH ( |
required |
points
|
array[vec3]
|
|
required |
normals
|
array[vec3] | None
|
|
None
|
n_rays
|
int
|
Directions per point. Error falls as |
64
|
weight
|
RayWeight
|
How a direction is weighted in the integral:
|
'cosine'
|
max_t
|
float | None
|
Maximum ray length. Anything beyond it does not occlude. When |
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
volumetric_obscurance
triwarp.visibility.shape_diameter
triwarp.sample.sample_fibonacci_hemisphere
Notes
MeshLab reports the complement of this (higher is more exposed) and leaves it unnormalized —
its number is roughly (1 - occlusion) * n_rays / 4 for a cosine-weighted bundle over
n_rays whole-sphere directions. Its direction set is also its own, so the two agree in
distribution and in ranking rather than value by value.
Source code in triwarp/visibility.py
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 143 | |
volumetric_obscurance
volumetric_obscurance(
mesh: Mesh,
points: array[vec3],
*,
normals: array[vec3] | None = None,
n_rays: int = 64,
tau: float = 0.1,
weight: RayWeight = "cosine",
max_t: float | None = None,
) -> wp.array[wp.float32]
Distance-attenuated ambient occlusion: an occluder at range t counts exp(-tau * t).
Iones et al.'s obscurance, and MeshLab's compute_scalar_by_volumetric_obscurance. It exists
because binary ambient_occlusion treats a wall across
the room like a crevice wall a millimetre away, which darkens the interior of any closed room
uniformly and hides exactly the small-scale detail the field is usually wanted for. Attenuating
by distance keeps the response local.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
Triangle mesh with a built BVH ( |
required |
points
|
array[vec3]
|
|
required |
normals
|
array[vec3] | None
|
|
None
|
n_rays
|
int
|
Directions per point. |
64
|
tau
|
float
|
Attenuation rate, in inverse length units of the mesh — so it is not scale-invariant,
and a mesh scaled by |
0.1
|
weight
|
RayWeight
|
Ray weighting, as in |
'cosine'
|
max_t
|
float | None
|
Maximum ray length. |
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
Source code in triwarp/visibility.py
146 147 148 149 150 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 | |
shape_diameter
shape_diameter(
mesh: Mesh,
points: array[vec3],
*,
normals: array[vec3] | None = None,
n_rays: int = 64,
cone_angle: float = math.pi / 3.0,
trim: float = 1.0,
max_t: float | None = None,
) -> wp.array[wp.float32]
Shape diameter function: local thickness of the volume, from an inward cone of rays.
Shapira et al.'s SDF and MeshLab's compute_scalar_by_shape_diameter_function_per_vertex. A
cone of n_rays rays is fired into the volume about -normal, each is traced to the far
side, and the result is the cosine-weighted mean of those distances after discarding the
outliers — the rays that escaped through a nearby opening or crossed the entire model, which
would otherwise dominate the average near any concavity.
This is the many-ray generalization of
thickness(method="ray"): at n_rays=1 with a vanishing
cone_angle the bundle collapses to the inward normal and the two agree to float32. The extra
rays are what make it stable — a single ray through a thin sliver of geometry reads a thickness
the neighbourhood does not have — and the reason it is the quantity used for skeleton extraction
and part segmentation rather than the one-ray version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
Triangle mesh with a built BVH ( |
required |
points
|
array[vec3]
|
|
required |
normals
|
array[vec3] | None
|
|
None
|
n_rays
|
int
|
Rays per point. MeshLab's default is |
64
|
cone_angle
|
float
|
Half-angle of the cone in radians, measured from the inward normal. The default
|
pi / 3.0
|
trim
|
float
|
Keep only rays whose distance is within |
1.0
|
max_t
|
float | None
|
Maximum ray length. When |
None
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
thickness
max_tangent_sphere
triwarp.visibility.ambient_occlusion
triwarp.sample.sample_fibonacci_cone
Notes
MeshLab's cone_amplitude parameter is a no-op in the 2025.07 build — its output is
byte-identical at 90 and 120 degrees — and its trimming rule is not the one documented
in the paper, so its values differ from these by a roughly constant factor on a given mesh.
Compare against it by rank rather than by value; the exactly-checkable statements are the
reduction to thickness at n_rays=1 and the analytic
2 R on a sphere.
Source code in triwarp/visibility.py
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 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 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
thickness
thickness(
mesh: Mesh,
points: array[vec3],
*,
exterior: bool = False,
normals: array[vec3] | None = None,
method: Literal["max_sphere", "ray"] = "max_sphere",
) -> wp.array[wp.float32]
Local thickness of the volume at each point, by one inward ray or one tangent sphere.
A dispatcher over the module's other two inward measures, and the cheapest of the three: it
takes a single piece of evidence per point where
shape_diameter fires a whole cone and trims the outliers.
method="max_sphere" returns twice the radius of
max_tangent_sphere, which answers the question for a
volume rather than along a direction; method="ray" returns
longest_ray along -normals (or +normals with
exterior=True), which is one ray and therefore reads whatever thin sliver of geometry it
happens to cross.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
Triangle mesh with a built BVH ( |
required |
points
|
array[vec3]
|
|
required |
exterior
|
bool
|
When |
False
|
normals
|
array[vec3] | None
|
|
None
|
method
|
Literal['max_sphere', 'ray']
|
|
'max_sphere'
|
Returns:
| Type | Description |
|---|---|
array[float32]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
See Also
max_tangent_sphere
shape_diameter
The stable many-ray generalization of method="ray".
longest_ray
Source code in triwarp/visibility.py
389 390 391 392 393 394 395 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 | |
max_tangent_sphere
max_tangent_sphere(
mesh: Mesh,
points: array[vec3],
*,
inwards: bool = True,
normals: array[vec3] | None = None,
threshold: float = 1e-06,
max_iter: int = 100,
) -> tuple[wp.array[wp.vec3], wp.array[wp.float32]]
Find the center and radius of the sphere tangent to the mesh at each point.
Implements the shrinking-sphere algorithm (Inui et al. 2016): iteratively
finds the largest sphere tangent to the mesh at points with no
non-tangential intersections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Mesh
|
Warp mesh (BVH built by caller). |
required |
points
|
array[vec3]
|
|
required |
inwards
|
bool
|
If |
True
|
normals
|
array[vec3] | None
|
|
None
|
threshold
|
float
|
Convergence threshold as a fraction of the mesh's own bounding-box diagonal, not the (possibly larger) box enclosing the query points too -- a query far outside the mesh should not loosen how tightly the sphere converges. |
1e-06
|
max_iter
|
int
|
Maximum number of shrink iterations. |
100
|
Returns:
| Type | Description |
|---|---|
centers
|
|
radii
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
RuntimeError
|
If |
Source code in triwarp/visibility.py
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 | |