Skip to content

Commit

Permalink
TO REMOVE: COPC support
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Jul 13, 2023
1 parent f7a0d42 commit 8f3a645
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 11 deletions.
68 changes: 57 additions & 11 deletions src/Core/CopcNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import * as THREE from 'three';
import { Hierarchy } from 'copc';
import PointCloudNode from 'Core/PointCloudNode';

const size = new THREE.Vector3();
const position = new THREE.Vector3();
const translation = new THREE.Vector3();

class CopcNode extends PointCloudNode {
/**
* Constructs a new instance of a COPC Octree node
Expand Down Expand Up @@ -50,18 +54,64 @@ class CopcNode extends PointCloudNode {
});
}

createChildAABB(node) {
// factor to apply, based on the depth difference (can be > 1)
const f = 2 ** (node.depth - this.depth);

// size of the child node bbox (Vector3), based on the size of the
// parent node, and divided by the factor
this.bbox.getSize(size).divideScalar(f);

// initialize the child node bbox at the location of the parent node bbox
node.bbox.min.copy(this.bbox.min);

// position of the parent node, if it was at the same depth than the
// child, found by multiplying the tree position by the factor
position.copy(this).multiplyScalar(f);

// difference in position between the two nodes, at child depth, and
// scale it using the size
translation.subVectors(node, position).multiply(size);

// apply the translation to the child node bbox
node.bbox.min.add(translation);

// use the size computed above to set the max
node.bbox.max.copy(node.bbox.min).add(size);
}

async loadOctree() {
const buffer = await this.fetch(this.entryOffset, this.entryLength);
const subtree = await Hierarchy.parse(new Uint8Array(buffer));
const hierarchy = await Hierarchy.parse(new Uint8Array(buffer));

const node = subtree.nodes[this.id];
const node = hierarchy.nodes[this.id];
if (!node) {
return Promise.reject('[CopcNode]: entry not found in hierarchy');
}

this.numPoints = node.pointCount;
this.entryOffset = node.pointDataOffset;
this.entryLength = node.pointDataLength;

const stack = [];
stack.push(this);

while (stack.length) {
const node = stack.shift();
const depth = node.depth + 1;
const x = node.x * 2;
const y = node.y * 2;
const z = node.z * 2;

node.findAndCreateChild(depth, x, y, z, hierarchy, stack);
node.findAndCreateChild(depth, x + 1, y, z, hierarchy, stack);
node.findAndCreateChild(depth, x, y + 1, z, hierarchy, stack);
node.findAndCreateChild(depth, x + 1, y + 1, z, hierarchy, stack);
node.findAndCreateChild(depth, x, y, z + 1, hierarchy, stack);
node.findAndCreateChild(depth, x + 1, y, z + 1, hierarchy, stack);
node.findAndCreateChild(depth, x, y + 1, z + 1, hierarchy, stack);
node.findAndCreateChild(depth, x + 1, y + 1, z + 1, hierarchy, stack);
}
}

/**
Expand All @@ -71,9 +121,9 @@ class CopcNode extends PointCloudNode {
* @param {number} y
* @param {number} z
* @param {Hierarchy.Subtree} hierarchy
* @returns {CopcNode | undefined}
* @param {CopcNode[]} stack
*/
findAndCreateChild(depth, x, y, z, hierarchy) {
findAndCreateChild(depth, x, y, z, hierarchy, stack) {
const id = `${this.depth}-${this.x}-${this.y}-${this.z}`;

let pointCount;
Expand All @@ -93,7 +143,7 @@ class CopcNode extends PointCloudNode {
byteSize = page.pageLength;
}

return new CopcNode(
const child = new CopcNode(
depth,
x,
y,
Expand All @@ -103,27 +153,23 @@ class CopcNode extends PointCloudNode {
this.layer,
pointCount,
);
this.add(child);
stack.push(child);
}

async load() {
console.log('[load]: check if octree loaded');
if (!this.octreeIsLoaded) {
await this.loadOctree();
}

console.log('[load]: octree is loaded');
const buffer = await this.fetch(this.entryOffset, this.entryLength);
console.log('[load]: buffer is fetched');
console.log(buffer);
const geometry = await this.layer.source.parse(buffer, {
out: this.layer,
in: {
...this.layer.source,
pointCount: this.numPoints,
},
});
console.log('[load]: geometry is parsed');
console.log(geometry);

return geometry;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Layer/CopcLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class CopcLayer extends PointCloudLayer {
return this.root.loadOctree().then(resolve);
});
}

get spacing() {
return this.source.info.spacing;
}
}

export default CopcLayer;

0 comments on commit 8f3a645

Please sign in to comment.