Quilt geometry¶
quiltwright.quilt
¶
Quilt geometry, assembly, and save.
Renderer-agnostic half of quilt production: tiling grid, device presets, view offsets, the assembler every backend feeds, and the Looking Glass filename convention. numpy and pillow only -- importing this module must not load VTK.
Typical usage::
from quiltwright.quilt import QUILT_PRESETS, assemble_quilt, save_quilt
spec = QUILT_PRESETS["portrait"]
save_quilt(assemble_quilt(views, spec), "torus", spec)
Re-exported from :mod:quiltwright.lfd for one release, so
from quiltwright.lfd import QuiltSpec keeps working.
Part of Quiltwright -- https://github.com/Flux-Frontiers/quiltwright Author: Eric G. Suchanek, PhD
HasLens
¶
Bases: Protocol
fov and focal_distance -- all the depth budget reads.
A typing :class:~typing.Protocol, not a runtime base class.
:class:QuiltCamera satisfies this, as does a tiny namespace with those
two attributes (see :class:~quiltwright.lfd._Lens) so a depth report
does not have to construct a throwaway camera.
QuiltCamera
¶
Bases: Protocol
Look-at camera that can feed a quilt sweep.
:class:~quiltwright.povray.PovCamera and
:class:~quiltwright.cycles.CyclesCamera both satisfy this. Named
QuiltCamera rather than CameraFrame so it does not collide with
kg_utils.viz3d.layout.CameraFrame in the growth engine.
Handedness is the camera's own: POV-Ray is left-handed, Cycles and VTK
are right-handed. :meth:basis returns (forward, right, up) in
that convention. Callers that emit a renderer-specific frustum convert
:func:window_shear into the units that renderer takes.
Every :class:QuiltCamera is also a :class:HasLens.
focal_distance
property
¶
Distance from the eye to the look-at point, in scene units.
basis()
¶
Orthonormal (forward, right, up) in this camera's handedness.
Source code in src/quiltwright/quilt.py
342 343 344 | |
QuiltSpec(columns, rows, quilt_width, quilt_height, aspect, view_cone=35.0)
dataclass
¶
Geometry of a quilt: tiling grid, total pixel size, and view cone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
int
|
Number of view tiles per quilt row. |
required |
rows
|
int
|
Number of view tiles per quilt column. |
required |
quilt_width
|
int
|
Total quilt width in pixels. |
required |
quilt_height
|
int
|
Total quilt height in pixels. |
required |
aspect
|
float
|
Aspect ratio (width / height) of a single view, which matches the target display's aspect. Embedded in the quilt filename so Looking Glass software can configure playback correctly. |
required |
view_cone
|
float
|
Total horizontal sweep of the camera in degrees. Looking Glass documents 35° as the standard rendering cone (the physical display cone is wider, ~40-58° depending on model; rendering slightly narrower adds apparent depth). |
35.0
|
n_views
property
¶
Total number of views in the quilt.
tile_height
property
¶
Height of a single view tile in pixels.
tile_width
property
¶
Width of a single view tile in pixels.
filename(stem, ext='png')
¶
Quilt filename with the metadata suffix Looking Glass software parses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stem
|
str
|
Base name without extension (e.g. |
required |
ext
|
str
|
File extension without the dot. |
'png'
|
Returns:
| Type | Description |
|---|---|
str
|
e.g. |
Source code in src/quiltwright/quilt.py
95 96 97 98 99 100 101 102 | |
scaled(factor)
¶
Same view grid at a fraction of the pixel size.
Casting at full preset size is rarely what you want: rendering costs about a second, but the wait is Bridge loading the resulting PNG, and that scales with its area. Halving the linear size quarters it.
The scaled dimensions are rounded down to a multiple of the tile grid, which is the part that is easy to get wrong: scale naively and the quilt no longer divides evenly into tiles, so every view lands on a fractional pixel boundary and the whole light field smears.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
float
|
Linear scale factor, e.g. |
required |
Returns:
| Type | Description |
|---|---|
QuiltSpec
|
A new :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If factor is not positive, or scales the quilt below one pixel per tile. |
Source code in src/quiltwright/quilt.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
still(height=1100)
¶
The same view, once, as a flat image at this device's aspect.
A one-tile "quilt" is the cheapest way to check framing, lighting and
materials before paying for the whole sweep, and it is what the
gallery images are: :func:view_offsets returns a single zero offset
at n_views == 1, so the render is the centre view and nothing
else. The width follows :attr:aspect rather than being fixed, so
the still is framed like the panel it is standing in for -- a still
of a landscape device is a landscape image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Image height in pixels. |
1100
|
Returns:
| Type | Description |
|---|---|
QuiltSpec
|
A new 1x1 :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If height is not positive. |
Source code in src/quiltwright/quilt.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
tile_origin(view_index)
¶
Pixel (x, y) of a view's top-left corner within the quilt image.
Quilt convention: view 0 at the bottom-left, advancing
left-to-right then bottom-to-top. The returned y is measured
from the image top (numpy/PIL row order).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
view_index
|
int
|
View number in |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
|
Source code in src/quiltwright/quilt.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
with_grid(columns, rows)
¶
Same quilt at a different view-grid density.
Total quilt pixels stay fixed, so more views means fewer pixels per view: the device's lenticular optics interpolate between views, so extra views give smoother look-around at the cost of per-view sharpness. The official presets are the factory-calibrated balance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
int
|
New number of tile columns. |
required |
rows
|
int
|
New number of tile rows. |
required |
Returns:
| Type | Description |
|---|---|
QuiltSpec
|
A new :class: |
Source code in src/quiltwright/quilt.py
104 105 106 107 108 109 110 111 112 113 114 115 116 | |
assemble_quilt(views, spec)
¶
Tile per-view images into a single quilt image.
This is the renderer-agnostic half of quilt production: it takes views
that some backend already rendered -- VTK via :func:render_quilt, a
ray-tracer via :mod:quiltwright.povray -- and lays them out in quilt
order. Views are consumed lazily, so a backend can stream them without
holding all n_views frames in memory at once.
Views whose pixel size differs from the tile size are resampled, which is what makes anamorphic quilts (tile pixel aspect != view aspect, e.g. the 27" presets) come out correctly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
Iterable[ndarray]
|
Iterable of |
required |
spec
|
QuiltSpec
|
Quilt specification (grid, size, aspect). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of views does not match |
Source code in src/quiltwright/quilt.py
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 | |
focal_distance_for_range(near, far)
¶
Focal distance that balances disparity between the nearest and farthest content -- their harmonic mean.
Disparity grows with |1 - Z/depth|, which is asymmetric in depth:
placing the focal plane at the arithmetic midpoint leaves the near
content far worse off than the far content. Equalising the two,
Z/near - 1 = 1 - Z/far, gives Z = 2/(1/near + 1/far).
With far at infinity this reduces to 2 * near.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
near
|
float
|
Distance to the nearest content, in scene units. |
required |
far
|
float
|
Distance to the farthest content; may be |
required |
Returns:
| Type | Description |
|---|---|
float
|
Focal distance to aim the camera at. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If near is not positive or exceeds far. |
Source code in src/quiltwright/quilt.py
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 | |
litiholo_names(spec, *, mode='HPO')
¶
Filenames LitiHolo's own capture tool gives a sweep, in view order.
The printer consumes a numbered sequence, so the names carry the view
ordering and nothing else may. Matching the vendor tool's convention
costs nothing and removes one variable from a first print: its
captureHPOSequence() writes render-{W}x{H}-HPO-01.jpg through
-23.jpg, one-indexed and zero-padded to two digits, leftmost
camera first. Quiltwright's own view000.png ordering is the same
sweep under a different name, which is exactly the kind of difference
that is invisible until a plate comes back mirrored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
QuiltSpec
|
Sweep specification; supplies the view count and the capture size that appears in the name. |
required |
mode
|
str
|
|
'HPO'
|
Returns:
| Type | Description |
|---|---|
list[str]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If mode is not |
Source code in src/quiltwright/quilt.py
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 | |
pack_litiholo_sweep(views, dest, spec, *, zip_output=False, jpeg_quality=95)
¶
Re-encode a rendered sweep into what the LitiHolo tool hands the printer.
The renderer-agnostic delivery step, the same role :func:assemble_quilt
plays for a panel: take views some backend already rendered -- POV-Ray
via :func:~quiltwright.povray.render_pov_views, anything else that
writes ordered frames -- and emit JPEGs named and ordered the way the
vendor's own tool emits them (see :func:litiholo_names).
Nothing here changes the geometry, which is set at render time and is
the part that actually decides whether a plate comes out right; render
with geometry="toe-in" if you are matching the tool rather than the
specification sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
views
|
Iterable[str | Path]
|
Rendered view images, in view order, view 0 leftmost. Any format pillow reads; each is converted to RGB, so a transparent background flattens to black -- which is the background the tool's own capture offers and the one a hologram wants. |
required |
dest
|
str | Path
|
Output directory; created if absent. |
required |
spec
|
QuiltSpec
|
Sweep specification. Its view count must match views, and its tile size names the files. |
required |
zip_output
|
bool
|
Also write |
False
|
jpeg_quality
|
int
|
Pillow JPEG quality, 1-95. The vendor tool takes whatever its browser's canvas encoder gives it; 95 is pillow's practical ceiling and errs toward not adding artefacts of our own to an image that is about to be sliced into hogels. |
95
|
Returns:
| Type | Description |
|---|---|
list[Path]
|
The JPEG paths written, in view order. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of views does not match spec. |
Source code in src/quiltwright/quilt.py
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 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 | |
resolve_view_cone(spec, view_cone)
¶
Apply an explicit view cone, or cap the device's native one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
QuiltSpec
|
Quilt specification carrying the device's native cone. |
required |
view_cone
|
float | None
|
Cone asked for explicitly, in degrees; |
required |
Returns:
| Type | Description |
|---|---|
tuple[QuiltSpec, float | None]
|
|
Source code in src/quiltwright/quilt.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
save_quilt(quilt, stem, spec)
¶
Write a quilt to PNG using the Looking Glass filename convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quilt
|
ndarray
|
RGB array from :func: |
required |
stem
|
str | Path
|
Output path without the quilt suffix or extension.
Any |
required |
spec
|
QuiltSpec
|
Quilt specification (encodes the suffix metadata). |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The path written, e.g. |
Source code in src/quiltwright/quilt.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
sweep_extent(spec, focal_distance)
¶
Half-width of the lateral eye travel the quilt's view sweep needs.
The outermost views sit focal_distance * tan(cone/2) to either side
of the centre view -- the largest magnitude in :func:view_offsets, in
closed form. For an object on a turntable that space is empty; inside a
room it is furniture and walls, so compare it against a measured
:class:~quiltwright.povray.Clearance before committing to a render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
QuiltSpec
|
Quilt specification (supplies the view cone). |
required |
focal_distance
|
float
|
Camera-to-focal-plane distance, in scene units. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Half the total eye sweep, in scene units. |
Source code in src/quiltwright/quilt.py
479 480 481 482 483 484 485 486 487 488 489 490 491 492 | |
sweep_spec(n_views, view_cone, tile_width, tile_height)
¶
Geometry for a plain ordered view sweep rather than a tiled quilt.
A quilt's view count is columns * rows, so a rectangular grid cannot
express a prime count. A single row can express any count at all, which
is what consumers that want the views as separate frames -- hologram
printers, lenticular interlacers -- actually ask for. The camera sweep is
identical either way; only the packing differs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_views
|
int
|
Number of views in the sweep. |
required |
view_cone
|
float
|
Total horizontal camera sweep in degrees. |
required |
tile_width
|
int
|
Pixel width of one view. |
required |
tile_height
|
int
|
Pixel height of one view. |
required |
Returns:
| Type | Description |
|---|---|
QuiltSpec
|
A single-row :class: |
Source code in src/quiltwright/quilt.py
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 | |
view_angles(spec)
¶
Signed angle of every view about the focal point, in degrees.
The sweep's angular sampling, independent of how a backend realises it.
An off-axis sweep converts these to lateral eye offsets with
:func:view_offsets; a toe-in sweep
(:func:~quiltwright.povray.toe_in_cameras) swings the eye around the
focal point by these angles directly. Both sample the same angles, so
the sampling interval quoted in a depth budget means the same thing
either way.
Ordered to match quilt view order: view 0 is the leftmost camera, so
angles run from -view_cone/2 to +view_cone/2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
QuiltSpec
|
Quilt or sweep specification (view count + cone angle). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape |
Source code in src/quiltwright/quilt.py
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
view_disparity(spec, fov, focal_distance, depth)
¶
Pixel shift of a feature between adjacent quilt views.
This is the number that decides whether a hologram fuses. A lenticular display blends neighbouring views optically, so content that moves only a pixel or two between them reads as solid depth, while larger shifts read as ghosting or a visible stack of copies. Rendered scenes that "look fine" flat routinely blow this budget.
Derived from the off-axis projection: a point at depth along the view
axis lands at image coordinate (D/aspect)(x/depth + s(1/Z - 1/depth))
for eye offset s, so the shift across the whole cone is
[tan(cone/2)/tan(fov/2)] * (1 - Z/depth) * tile_height pixels, which
divided between n_views - 1 gaps gives this. The aspect ratio
cancels. Verified against ray-traced renders to within 0.5%.
Two consequences worth internalising: content at the focal plane has zero disparity, and a narrower FOV increases disparity, because it magnifies the scene and the parallax along with it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
QuiltSpec
|
Quilt specification (view count + cone angle + tile size). |
required |
fov
|
float
|
Vertical field of view in degrees. |
required |
focal_distance
|
float
|
Camera-to-focal-plane distance, in scene units. |
required |
depth
|
float
|
Distance of the content of interest from the camera, in
scene units. Use |
required |
Returns:
| Type | Description |
|---|---|
float
|
Adjacent-view shift in pixels. Roughly 4-5 px is the practical ceiling; beyond ~8 px expect visible ghosting on hard edges. |
Source code in src/quiltwright/quilt.py
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 | |
view_offsets(spec, distance)
¶
Horizontal camera offsets (world units) for every view in the quilt.
Cameras sweep a total angle of spec.view_cone centred on the base
camera position, at constant distance from the focal plane. Offsets are
ordered to match quilt view order: view 0 is the leftmost camera.
The eye travels along a straight line perpendicular to the view axis,
which is what an off-axis sweep wants -- the image planes stay parallel
and the frustum shear does the rest. A toe-in sweep moves the eye along
a circular arc instead; see :func:~quiltwright.povray.toe_in_cameras.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
QuiltSpec
|
Quilt specification (view count + cone angle). |
required |
distance
|
float
|
Distance from camera to the focal plane. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Array of shape |
Source code in src/quiltwright/quilt.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
window_shear(offset, focal_distance, fov, aspect)
¶
Dimensionless horizontal window shift that pins the look-at point.
The eye has translated offset along the camera's right vector. This is the shear that slides the frustum window back so the original look-at point stays centred -- the off-axis projection, never a toe-in.
VTK's SetWindowCenter takes this value directly (units of half the
image width). Blender's shift_x is this value divided by 2
(fractions of the full frame width). POV-Ray slides the image-plane
centre by window_shear * (aspect / 2) along right, which is
-offset * D / Z for image-plane distance D.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
offset
|
float
|
Lateral eye offset along the camera's right vector, in
scene units, from :func: |
required |
focal_distance
|
float
|
Camera-to-focal-plane distance, in scene units. |
required |
fov
|
float
|
Vertical field of view in degrees. |
required |
aspect
|
float
|
Width / height of the rendered view. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The dimensionless window centre. Zero at the centre view; negative when the eye has moved right. |
Source code in src/quiltwright/quilt.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |