vol_encode: Carry a field into 8 bits

View source: R/encode.R

vol_encodeR Documentation

Carry a field into 8 bits

Description

Quantises the field to the 254 codes an 8-bit texture channel can carry, through a monotone transfer, and measures the error the quantisation costs against the values it started from.

Usage

vol_encode(field, transfer = c("auto", "sqrt", "linear"))

Arguments

field

A vol_field.

transfer

Name of the transfer: "sqrt", "linear", or "auto", which takes the square root for a non-negative field and the linear ramp for any other.

Details

Carry a field into 8 bits

Eight bits per cell is what makes the payload small enough to travel inside a page, and the transfer decides where those bits are spent. With v the value, v_{lo} and v_{hi} its extremes and N = 254 the codes available, the square-root transfer writes

c = 1 + \mathrm{round}\!\left((N-1)\, \frac{\sqrt{v} - \sqrt{v_{lo}}}{\sqrt{v_{hi}} - \sqrt{v_{lo}}}\right),

and the renderer inverts it by squaring. A strongly skewed positive field is served far better by that than by a linear ramp, because the linear ramp spends most of its codes on a tail that holds few cells.

The error is reported and not assumed. For the case study the root mean square error is 0.27 and the worst single cell 1.66 degrees Celsius days, against a field that reaches 580, and the plotted colour bands are 2.5 wide, so the quantisation is well inside the resolution of the picture.

Code 0 is reserved for a missing cell, so the codes that carry data are 1 to 254. The renderer tests the companion mask before it reads a value, so a missing cell contributes nothing to the ray. A constant field takes code 1 everywhere and decodes to the constant to within rounding.

Value

A list of class vol_encoding with codes, an integer array of the same shape as the field holding 0 for a missing cell and 1 to 254 otherwise; transfer, the record the manifest carries; and error, the absolute error at every cell that carries a value.

See Also

vol_field() for the input, vol_resample() for the step before, vol_payload() for the step after, print.vol_encoding(), summary.vol_encoding() and plot.vol_encoding() for the methods that report the error.

Examples

data(med_mhw)
e <- vol_encode(vol_resample(med_mhw))
e
summary(e)
plot(e)
plot(e, type = "depth")

volumr documentation built on Dec. 2, 2026, 5:07 p.m.