Skip to content

Commit

Permalink
virutal nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
akhileshh committed Jan 27, 2025
1 parent 2969124 commit efb0944
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
4 changes: 0 additions & 4 deletions src/datasource/graphene/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ function decodeMultiscaleManifestChunk(chunk: GrapheneMultiscaleManifestChunk, r
clipLowerBound: vec3.clone(response.clipLowerBound),
clipUpperBound: vec3.clone(response.clipUpperBound),
};
console.log("original chunkShape", chunk.manifest.chunkShape.join());
chunk.manifest.chunkShape[0] /= 8;
chunk.manifest.chunkShape[1] /= 8;
chunk.manifest.chunkShape[2] /= 40;
chunk.fragmentIds = response.fragments;
chunk.manifest.clipLowerBound.fill(0);
chunk.manifest.clipUpperBound.fill(10000000);
Expand Down
2 changes: 1 addition & 1 deletion src/mesh/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ export class MultiscaleMeshLayer extends PerspectiveViewRenderLayer<ThreeDimensi
manifest;
if (DEBUG_MULTISCALE_FRAGMENTS) {
try {
validateOctree(octree);
validateOctree(octree, /*allowDuplicateChildren=*/ true);
} catch (e) {
console.log(`invalid octree for object=${objectId}: ${e.message}`);
}
Expand Down
37 changes: 22 additions & 15 deletions src/mesh/multiscale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function getDesiredMultiscaleMeshChunks(
const gridX = octree[rowOffset];
const gridY = octree[rowOffset + 1];
const gridZ = octree[rowOffset + 2];
const childBegin = octree[rowOffset + 3];
const childBeginAndVirtual = octree[rowOffset + 3];
const childEndAndEmpty = octree[rowOffset + 4];
let xLower = gridX * size * chunkShape[0] + chunkGridSpatialOrigin[0];
let yLower = gridY * size * chunkShape[1] + chunkGridSpatialOrigin[1];
Expand Down Expand Up @@ -202,16 +202,19 @@ export function getDesiredMultiscaleMeshChunks(
const pixelSize = minW / scaleFactor;

if (priorLodScale === 0 || pixelSize * detailCutoff < priorLodScale) {
const lodScale = lodScales[lod];
let lodScale = lodScales[lod];
if (lodScale !== 0) {
callback(lod, row, lodScale / pixelSize, childEndAndEmpty >>> 31);
const virtual = childBeginAndVirtual >>> 31;
if (virtual) {
lodScale = 0;
}
const empty = childEndAndEmpty >>> 31;
callback(lod, row, lodScale / pixelSize, empty | virtual);
}

if (
lod > 0 &&
(lodScale === 0 || pixelSize * detailCutoff < lodScale)
) {
if (lod > 0 && (lodScale === 0 || pixelSize * detailCutoff < lodScale)) {
const nextPriorLodScale = lodScale === 0 ? priorLodScale : lodScale;
const childBegin = (childBeginAndVirtual & 0x7fffffff) >>> 0;
const childEnd = (childEndAndEmpty & 0x7fffffff) >>> 0;
for (let childRow = childBegin; childRow < childEnd; ++childRow) {
handleChunk(lod - 1, childRow, nextPriorLodScale);
Expand Down Expand Up @@ -349,40 +352,44 @@ export function getMultiscaleChunksToDraw(
emitChunksUpTo(0, 0);
}

export function validateOctree(octree: Uint32Array) {
export function validateOctree(octree: Uint32Array, allowDuplicateChildren: boolean = false) {
if (octree.length % 5 !== 0) {
throw new Error("Invalid length");
}
const numNodes = octree.length / 5;
const seenNodes = new Set<number>();
function exploreNode(node: number) {
if (seenNodes.has(node)) {
throw new Error("Previously seen node");
throw new Error(`Previously seen node: ${node}`);
}
seenNodes.add(node);
if (node < 0 || node >= numNodes) {
throw new Error("Invalid node reference");
throw new Error(`Invalid node reference: ${node}`);
}
const x = octree[node * 5];
const y = octree[node * 5 + 1];
const z = octree[node * 5 + 2];
const beginChild = octree[node * 5 + 3];
const endChild = octree[node * 5 + 4];
const beginChild = (octree[node * 5 + 3] & 0x7fffffff) >>> 0;
const endChild = (octree[node * 5 + 4] & 0x7fffffff) >>> 0;
if (
beginChild < 0 ||
endChild < 0 ||
endChild < beginChild ||
endChild > numNodes ||
beginChild + 8 < endChild
(!allowDuplicateChildren && beginChild + 8 < endChild)
) {
throw new Error("Invalid child references");
throw new Error(
`Invalid child references: node ${node} specifies beginChild=${beginChild}, endChild=${endChild}`,
);
}
for (let child = beginChild; child < endChild; ++child) {
const childX = octree[child * 5];
const childY = octree[child * 5 + 1];
const childZ = octree[child * 5 + 2];
if (childX >>> 1 !== x || childY >>> 1 !== y || childZ >>> 1 !== z) {
throw new Error("invalid child");
throw new Error(
`invalid child position: parent=${node} child=${child} childX=${childX} childY=${childY} childZ=${childZ} parentX=${x} parentY=${y} parentZ=${z}`,
);
}
exploreNode(child);
}
Expand Down

0 comments on commit efb0944

Please sign in to comment.