Skip to content

Instantly share code, notes, and snippets.

@chrisj
Created February 1, 2024 17:04
Show Gist options
  • Save chrisj/328828d13480627961166beb16cfcd18 to your computer and use it in GitHub Desktop.
Save chrisj/328828d13480627961166beb16cfcd18 to your computer and use it in GitHub Desktop.
positionToMultiscaleChunks(position: Float32Array) {
const { rank, spatiallyIndexedSources } = this;
const tempLower = new Float32Array(rank);
const tempUpper = new Float32Array(rank);
const tempChunk = new Float32Array(rank);
for (const source of spatiallyIndexedSources) {
matrix.transformPoint(
tempLower,
source.multiscaleToChunkTransform,
rank + 1,
position,
rank,
);
tempUpper.set(tempLower);
let totalChunks = 1;
for (let i = 0; i < rank; ++i) {
const a = tempLower[i];
const b = tempUpper[i];
const lower = Math.min(a, b);
const upper = Math.max(a, b);
// In the case that the point lies directly on a boundary, ensure it is included in both
// chunks, since we don't know how the datasource handles this case.
tempLower[i] = Math.ceil(lower - 1);
tempUpper[i] = Math.floor(upper + 1);
totalChunks *= tempUpper[i] - tempLower[i];
}
const { chunks } = source;
for (let chunkIndex = 0; chunkIndex < totalChunks; ++chunkIndex) {
let remainder = chunkIndex;
for (let i = 0; i < rank; ++i) {
const lower = tempLower[i];
const upper = tempUpper[i];
const size = upper - lower;
const x = (tempChunk[i] = remainder % size);
remainder = (remainder - x) / size;
}
const chunk = chunks.get(tempChunk.join());
if (chunk !== undefined) {
console.log(
"we got a chunk",
chunk.chunkGridPosition,
source.spec.chunkDataSize,
);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment