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
283 284 285 | |
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
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 | |
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
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 | |
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
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
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
394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
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
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 | |
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
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 | |
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.
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
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
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
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |