Published
Edited
Jun 18, 2020
1 fork
Importers
34 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
coords = { // decode Morton indices into 3D coords
const coords = [];
for (const c of mortonIndices) {
const x = compact1By2(c >> 0);
const y = compact1By2(c >> 1);
const z = compact1By2(c >> 2);
coords.push({x, y, z});
}
return coords;
}
Insert cell
// convert [0, 1, 2, ...] sequence of Hilbert values into Morton indices
mortonIndices = new Uint32Array(side ** 3).map((v, i) => transformCurve(i, order, hilbertToMortonTable))
Insert cell
// convert a Hilbert value into a Morton index using a lookup table
transformCurve = (index, bits, lookupTable) => {
let out = 0;
for (let i = 3 * (bits - 1), transform = 0; i >= 0; i -= 3) {
transform = lookupTable[transform | ((index >> i) & 7)];
out = (out << 3) | (transform & 7);
transform &= ~7;
}
return out;
}
Insert cell
// lookup table for converting a Hilbert value to a Morton index
hilbertToMortonTable = Uint8Array.of(
48, 33, 35, 26, 30, 79, 77, 44,
78, 68, 64, 50, 51, 25, 29, 63,
27, 87, 86, 74, 72, 52, 53, 89,
83, 18, 16, 1, 5, 60, 62, 15,
0, 52, 53, 57, 59, 87, 86, 66,
61, 95, 91, 81, 80, 2, 6, 76,
32, 2, 6, 12, 13, 95, 91, 17,
93, 41, 40, 36, 38, 10, 11, 31,
14, 79, 77, 92, 88, 33, 35, 82,
70, 10, 11, 23, 21, 41, 40, 4,
19, 25, 29, 47, 46, 68, 64, 34,
45, 60, 62, 71, 67, 18, 16, 49
)
Insert cell
// extract every 3rd bit from a number to decode a component of a Morton index
compact1By2 = (x) => { // https://fgiesen.wordpress.com/2009/12/13/decoding-morton-codes/
x &= 0x09249249;
x = (x ^ (x >> 2)) & 0x030c30c3;
x = (x ^ (x >> 4)) & 0x0300f00f;
x = (x ^ (x >> 8)) & 0xff0000ff;
x = (x ^ (x >> 16)) & 0x000003ff;
return x;
}
Insert cell
Insert cell
Insert cell
Zdog = require('zdog')
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more