Geometry¶
Voxel boxes, subvolume sample templates, shape functions and iDVC-style point grids. See Correlation method.
zvdvc.geometry.box¶
Integer voxel boxes, half-open, in array order (z, y, x).
- class zvdvc.geometry.box.Box(lo: 'Int3', hi: 'Int3')[source]¶
Bases:
object- grow(margin)[source]¶
Expand by
marginvoxels on every side (rounded outward). A 3-tuple margin is(z, y, x).
- shift_xyz(offset_xyz)[source]¶
Translate by a displacement given in point order
(x, y, z), rounded outward.
zvdvc.geometry.templates¶
Subvolume sample templates.
As in CCPi, samples are not voxel-centred and their number is independent of subvolume size. Interpolation supplies values at arbitrary positions.
Unlike CCPi, which builds a FloatingCloud per point, zvDVC builds one
template per run and shares it across all points. On the GPU the template
offsets sit in constant/shared memory, so a batch is described by its centres
and parameters alone and per-point sample coordinates are never stored.
cube: ak x k x kgrid withk = ceil(n_samples ** (1/3)), spanning[-r*aspect, +r*aspect]per axis (CCPiSearchrounds the count up the same way).sphere:n_samplespoints uniform inside the ellipsoid of radiusr*aspect, by rejection from the bounding cube with a seeded Mersenne Twister. CCPi does the same withstd::mt19937. The streams differ, so parity with CCPi is statistical (docs/MVP_PLAN.md, M1).
Offsets are stored in z, y, x order (the cube is built that way; sphere samples are sorted). A kernel’s neighbouring threads take neighbouring samples, so this order keeps their volume reads in the same cache lines: 6.8x faster sums on the GPU on real data, and the same sums up to rounding.
- class zvdvc.geometry.templates.Template(offsets: 'np.ndarray', spec: 'SubvolumeSpec')[source]¶
Bases:
object- Parameters:
offsets (ndarray)
spec (SubvolumeSpec)
- spec: SubvolumeSpec¶
- zvdvc.geometry.templates.cube_side(n_samples)[source]¶
Smallest
kwithk**3 >= n_samples(exact in integers;ceil(n ** (1/3))is not).
- zvdvc.geometry.templates.make_template(spec)[source]¶
- Parameters:
spec (SubvolumeSpec)
- Return type:
zvdvc.geometry.warp¶
Shape functions: 3, 6 and 12 degrees of freedom, in CCPi’s parameterisation.
Parameter vector (CCPi SearchParams), angles in radians, strain dimensionless:
index 0 1 2 3 4 5 6 7 8 9 10 11
name u v w phi the psi exx eyy ezz exy eyz exz
A template offset d around centre c maps to
x’ = c + t + (I + E) R d
where t = (u, v, w), R is CCPi’s roll-pitch-yaw matrix
(SearchParams::set_param_vect) and E is the symmetric strain tensor.
This matches FloatingCloud::affine_to: translate, then rotate_ptvect
(d -> R d), then strain_ptvect (d' -> d' + E d'), both relative to
the moved reference point. ndof = 3 gives R = I, E = 0; ndof = 6
gives E = 0.
The forward-additive solver (CCPi parity) needs dx'/dp at the current
p. That is nonlinear in the angles and is computed analytically per point
and iteration: 3 x ndof values per sample, cheap next to interpolation. The
inverse-compositional solver (M5) needs only dx'/dp at p = 0,
precomputed once per run from the template.
- zvdvc.geometry.warp.rotation_matrix(angles)[source]¶
(B, 3) -> (B, 3, 3), CCPi roll-pitch-yaw.
angles = (phi, the, psi): yaw about z, pitch about y, roll about x, composed asR = Rx(psi) Ry(the) Rz(phi)(the aerospace 3-2-1 direction-cosine matrix).
- zvdvc.geometry.warp.strain_tensor(strains)[source]¶
(B, 6)
(exx, eyy, ezz, exy, eyz, exz)-> (B, 3, 3) symmetric.
- zvdvc.geometry.warp.warp(centres, params, offsets)[source]¶
(B, 3), (B, ndof), (M, 3) -> (B, M, 3) warped sample positions.
- zvdvc.geometry.warp.warp_linear_jacobians(params)[source]¶
dx'/dp_k = A_k dfor the non-translation parameters: (B, ndof) -> (B, ndof - 3, 3, 3).Translations have
dx'/dt = I. Solvers contractA_kwith the image gradient and the template, so the (B, M, 3, ndof) array ofwarp_jacobian()is never formed.
- zvdvc.geometry.warp.warp_jacobian(params, offsets)[source]¶
dx'/dp: (B, ndof), (M, 3) -> (B, M, 3, ndof). Forward-additive solver.
zvdvc.geometry.pointgrid¶
Point-cloud generation, following iDVC’s Point Cloud panel.
iDVC places points on a regular lattice inside a mask. The spacing comes from
subvolume size and overlap, with an optional lattice rotation. The mask can
optionally be eroded so whole subvolumes stay inside it. zvDVC does the same
in chunks, so a 4096^3 mask never has to be in memory at once, and writes the
result straight into a zarr-vectors store
(zvdvc.io.pointcloud.write_pointcloud_store()).
- zvdvc.geometry.pointgrid.lattice_spacing(subvolume, overlap)[source]¶
Point spacing (x, y, z) for a given fractional overlap, as iDVC computes it.
Neighbouring subvolumes overlap by
overlapof their extent along each axis, so the spacing issize * aspect * (1 - overlap).
- zvdvc.geometry.pointgrid.grid_in_mask(shape_zyx, spacing_xyz, *, mask=None, rotation_deg=(0.0, 0.0, 0.0), erode_radius=0.0, origin_xyz=None)[source]¶
Lattice points (N, 3) inside
mask(a (z, y, x) array or a zarr array read slab by slab).The lattice passes through
origin_xyz(default: the volume centre) and is rotated about it. Points are kept if they lie inside the volume and, with a mask, if the nearest mask voxel is set and (erode_radius > 0) at leasterode_radiusvoxels from the nearest unset voxel. Points come out sorted by (z, y, x).