Skip to content

Commit

Permalink
refactor(potree1and2): change linked with multisource
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Sep 6, 2024
1 parent 4aa157e commit 07a6df8
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 148 deletions.
13 changes: 9 additions & 4 deletions examples/potree2_25d_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@
var lookAt = new itowns.THREE.Vector3();
var size = new itowns.THREE.Vector3();

potreeLayer.root.bbox.getSize(size);
potreeLayer.root.bbox.getCenter(lookAt);
const bboxes = potreeLayer.root.map(root => root.bbox);
let bbox = bboxes[0];
for (let i = 1; i < bboxes.length; i++) {
bbox = bbox.union(bboxes[i]);
}
bbox.getSize(size);
bbox.getCenter(lookAt);

debug.PointCloudDebug.initTools(view, potreeLayer, debugGui);

view.camera.camera3D.far = 2.0 * size.length();

ratio = size.x / size.z;
position = potreeLayer.root.bbox.min.clone().add(
position = bbox.min.clone().add(
size.multiply({ x: 0, y: 0, z: ratio * 0.5 }));
lookAt.z = potreeLayer.root.bbox.min.z;
lookAt.z = bbox.min.z;
placeCamera(position, lookAt);
controls.moveSpeed = size.length() / 3;

Expand Down
13 changes: 9 additions & 4 deletions examples/potree_25d_map.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,22 @@
var lookAt = new itowns.THREE.Vector3();
var size = new itowns.THREE.Vector3();

potreeLayer.root.bbox.getSize(size);
potreeLayer.root.bbox.getCenter(lookAt);
const bboxes = potreeLayer.root.map(root => root.bbox);
let bbox = bboxes[0];
for (let i = 1; i < bboxes.length; i++) {
bbox = bbox.union(bboxes[i]);
}
bbox.getSize(size);
bbox.getCenter(lookAt);

debug.PointCloudDebug.initTools(view, potreeLayer, debugGui);

view.camera3D.far = 2.0 * size.length();

ratio = size.x / size.z;
position = potreeLayer.root.bbox.min.clone().add(
position = bbox.min.clone().add(
size.multiply({ x: 0, y: 0, z: ratio * 0.5 }));
lookAt.z = potreeLayer.root.bbox.min.z;
lookAt.z = bbox.min.z;
placeCamera(position, lookAt);
controls.moveSpeed = size.length() / 3;

Expand Down
67 changes: 34 additions & 33 deletions src/Layer/Potree2Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,39 +150,40 @@ class Potree2Layer extends PointCloudLayer {

const resolve = this.addInitializationStep();

this.source.whenReady.then((metadata) => {
this.scale = new THREE.Vector3(1, 1, 1);
this.metadata = metadata;
this.pointAttributes = parseAttributes(metadata.attributes);
this.spacing = metadata.spacing;

const normal = Array.isArray(this.pointAttributes.attributes) &&
this.pointAttributes.attributes.find(elem => elem.name.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal.name] = 1;
}

const min = new THREE.Vector3(...metadata.boundingBox.min);
const max = new THREE.Vector3(...metadata.boundingBox.max);
const boundingBox = new THREE.Box3(min, max);

const root = new Potree2Node(0, 0, this);

root.bbox = boundingBox;
root.boundingSphere = boundingBox.getBoundingSphere(new THREE.Sphere());

root.id = 'r';
root.depth = 0;
root.nodeType = 2;
root.hierarchyByteOffset = 0n;
root.hierarchyByteSize = BigInt(metadata.hierarchy.firstChunkSize);

root.byteOffset = 0;

this.root = root;

return this.root.loadOctree().then(resolve);
});
this.root = [];
this.source.whenReady
.then((metadata) => {
this.scale = new THREE.Vector3(1, 1, 1);
this.metadata = metadata;
this.pointAttributes = parseAttributes(metadata.attributes);
this.spacing = metadata.spacing;

const normal = Array.isArray(this.pointAttributes.attributes) &&
this.pointAttributes.attributes.find(elem => elem.name.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal.name] = 1;
}

const min = new THREE.Vector3(...metadata.boundingBox.min);
const max = new THREE.Vector3(...metadata.boundingBox.max);
const boundingBox = new THREE.Box3(min, max);

const root = new Potree2Node(0, 0, this);
root.bbox = boundingBox;
root.boundingSphere = boundingBox.getBoundingSphere(new THREE.Sphere());

root.id = 'r';
root.depth = 0;
root.nodeType = 2;
root.hierarchyByteOffset = 0n;
root.hierarchyByteSize = BigInt(metadata.hierarchy.firstChunkSize);

root.byteOffset = 0;

this.root.push(root);

return root.loadOctree().then(resolve);
});
}
}

Expand Down
34 changes: 19 additions & 15 deletions src/Layer/PotreeLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,29 @@ class PotreeLayer extends PointCloudLayer {

const resolve = this.addInitializationStep();

this.source.whenReady.then((cloud) => {
this.scale = new THREE.Vector3().addScalar(cloud.scale);
this.spacing = cloud.spacing;
this.hierarchyStepSize = cloud.hierarchyStepSize;
this.root = [];
this.source.whenReady
.then((cloud) => {
this.scale = new THREE.Vector3().addScalar(cloud.scale);
this.spacing = cloud.spacing;
this.hierarchyStepSize = cloud.hierarchyStepSize;

const normal = Array.isArray(cloud.pointAttributes) &&
cloud.pointAttributes.find(elem => elem.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal] = 1;
}
const normal = Array.isArray(cloud.pointAttributes) &&
cloud.pointAttributes.find(elem => elem.startsWith('NORMAL'));
if (normal) {
this.material.defines[normal] = 1;
}

this.supportsProgressiveDisplay = (this.source.extension === 'cin');
this.supportsProgressiveDisplay = (this.source.extension === 'cin');

this.root = new PotreeNode(0, 0, this);
this.root.bbox.min.set(cloud.boundingBox.lx, cloud.boundingBox.ly, cloud.boundingBox.lz);
this.root.bbox.max.set(cloud.boundingBox.ux, cloud.boundingBox.uy, cloud.boundingBox.uz);
const root = new PotreeNode(0, 0, this);
root.bbox.min.set(cloud.boundingBox.lx, cloud.boundingBox.ly, cloud.boundingBox.lz);
root.bbox.max.set(cloud.boundingBox.ux, cloud.boundingBox.uy, cloud.boundingBox.uz);

return this.root.loadOctree().then(resolve);
});
this.root.push(root);

return root.loadOctree().then(resolve);
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/potree.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Potree', function () {
View.prototype.addLayer.call(viewer, potreeLayer)
.then((layer) => {
context.camera.camera3D.updateMatrixWorld();
assert.equal(layer.root.children.length, 6);
assert.equal(layer.root[0].children.length, 6);
layer.bboxes.visible = true;
done();
}).catch(done);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/potree2.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Potree2', function () {
View.prototype.addLayer.call(viewer, potreeLayer)
.then((layer) => {
context.camera.camera3D.updateMatrixWorld();
assert.equal(layer.root.children.length, 6);
assert.equal(layer.root[0].children.length, 6);
layer.bboxes.visible = true;
done();
}).catch(done);
Expand Down
92 changes: 47 additions & 45 deletions test/unit/potree2layerprocessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,76 +9,78 @@ describe('preUpdate Potree2Layer', function () {
source: { baseurl: 'server.geo' },
hierarchyStepSize: 1,
};
layer.root = new Potree2Node(4000, 0, layer);
layer.root.bbox.setFromArray([1000, 1000, 1000, 0, 0, 0]);
const root = new Potree2Node(4000, 0, layer);
root.bbox.setFromArray([1000, 1000, 1000, 0, 0, 0]);

layer.root.add(new Potree2Node(3000, 0, layer), 1, layer.root);
layer.root.children[0].obj = { layer, isPoints: true };
layer.root.add(new Potree2Node(3000, 0, layer), 2, layer.root);
layer.root.children[1].obj = { layer, isPoints: true };
layer.root.add(new Potree2Node(3000, 0, layer), 3, layer.root);
layer.root.children[2].obj = { layer, isPoints: true };
root.add(new Potree2Node(3000, 0, layer), 1, root);
root.children[0].obj = { layer, isPoints: true };
root.add(new Potree2Node(3000, 0, layer), 2, root);
root.children[1].obj = { layer, isPoints: true };
root.add(new Potree2Node(3000, 0, layer), 3, root);
root.children[2].obj = { layer, isPoints: true };

layer.root.children[0].add(new Potree2Node(2000, 0, layer), 1, layer.root);
layer.root.children[0].children[0].obj = { layer, isPoints: true };
layer.root.children[0].add(new Potree2Node(2000, 0, layer), 2, layer.root);
layer.root.children[0].children[1].obj = { layer, isPoints: true };
layer.root.children[1].add(new Potree2Node(2000, 0, layer), 1, layer.root);
layer.root.children[1].children[0].obj = { layer, isPoints: true };
layer.root.children[2].add(new Potree2Node(2000, 0, layer), 2, layer.root);
layer.root.children[2].children[0].obj = { layer, isPoints: true };
layer.root.children[2].add(new Potree2Node(2000, 0, layer), 3, layer.root);
layer.root.children[2].children[1].obj = { layer, isPoints: true };
root.children[0].add(new Potree2Node(2000, 0, layer), 1, root);
root.children[0].children[0].obj = { layer, isPoints: true };
root.children[0].add(new Potree2Node(2000, 0, layer), 2, root);
root.children[0].children[1].obj = { layer, isPoints: true };
root.children[1].add(new Potree2Node(2000, 0, layer), 1, root);
root.children[1].children[0].obj = { layer, isPoints: true };
root.children[2].add(new Potree2Node(2000, 0, layer), 2, root);
root.children[2].children[0].obj = { layer, isPoints: true };
root.children[2].add(new Potree2Node(2000, 0, layer), 3, root);
root.children[2].children[1].obj = { layer, isPoints: true };

layer.root.children[0].children[0].add(new Potree2Node(1000, 0, layer), 1, layer.root);
layer.root.children[0].children[0].children[0].obj = { layer, isPoints: true };
layer.root.children[0].children[0].add(new Potree2Node(1000, 0, layer), 5, layer.root);
layer.root.children[0].children[0].children[1].obj = { layer, isPoints: true };
layer.root.children[0].children[1].add(new Potree2Node(1000, 0, layer), 4, layer.root);
layer.root.children[0].children[1].children[0].obj = { layer, isPoints: true };
layer.root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 1, layer.root);
layer.root.children[2].children[1].children[0].obj = { layer, isPoints: true };
layer.root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 2, layer.root);
layer.root.children[2].children[1].children[1].obj = { layer, isPoints: true };
layer.root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 3, layer.root);
layer.root.children[2].children[1].children[2].obj = { layer, isPoints: true };
layer.root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 4, layer.root);
layer.root.children[2].children[1].children[3].obj = { layer, isPoints: true };
root.children[0].children[0].add(new Potree2Node(1000, 0, layer), 1, root);
root.children[0].children[0].children[0].obj = { layer, isPoints: true };
root.children[0].children[0].add(new Potree2Node(1000, 0, layer), 5, root);
root.children[0].children[0].children[1].obj = { layer, isPoints: true };
root.children[0].children[1].add(new Potree2Node(1000, 0, layer), 4, root);
root.children[0].children[1].children[0].obj = { layer, isPoints: true };
root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 1, root);
root.children[2].children[1].children[0].obj = { layer, isPoints: true };
root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 2, root);
root.children[2].children[1].children[1].obj = { layer, isPoints: true };
root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 3, root);
root.children[2].children[1].children[2].obj = { layer, isPoints: true };
root.children[2].children[1].add(new Potree2Node(1000, 0, layer), 4, root);
root.children[2].children[1].children[3].obj = { layer, isPoints: true };

layer.root = [root];

it('should return root if no change source', () => {
const sources = new Set();
assert.deepStrictEqual(
layer.root,
layer.root[0],
Potree2Layer.prototype.preUpdate.call(layer, context, sources)[0]);
});

it('should return root if no common ancestors', () => {
const sources = new Set();
sources.add(layer.root.children[0].children[0]);
sources.add(layer.root.children[2].children[1]);
sources.add(layer.root[0].children[0].children[0]);
sources.add(layer.root[0].children[2].children[1]);
assert.deepStrictEqual(
layer.root,
layer.root[0],
Potree2Layer.prototype.preUpdate.call(layer, context, sources)[0]);
});

it('should return common ancestor', () => {
const sources = new Set();
sources.add(layer.root.children[2].children[0]);
sources.add(layer.root.children[2].children[1]);
sources.add(layer.root.children[2].children[1].children[2]);
sources.add(layer.root.children[2].children[1].children[3]);
sources.add(layer.root[0].children[2].children[0]);
sources.add(layer.root[0].children[2].children[1]);
sources.add(layer.root[0].children[2].children[1].children[2]);
sources.add(layer.root[0].children[2].children[1].children[3]);
assert.deepStrictEqual(
layer.root.children[2],
layer.root[0].children[2],
Potree2Layer.prototype.preUpdate.call(layer, context, sources)[0]);
});

it('should not search ancestors if layer are different root if no common ancestors', () => {
const sources = new Set();
sources.add(layer.root.children[2].children[0]);
sources.add(layer.root.children[2].children[1].children[3]);
layer.root.children[2].children[1].children[3].obj = { layer: {}, isPoints: true };
sources.add(layer.root[0].children[2].children[0]);
sources.add(layer.root[0].children[2].children[1].children[3]);
layer.root[0].children[2].children[1].children[3].obj = { layer: {}, isPoints: true };
assert.deepStrictEqual(
layer.root.children[2].children[0],
layer.root[0].children[2].children[0],
Potree2Layer.prototype.preUpdate.call(layer, context, sources)[0]);
});
});
Loading

0 comments on commit 07a6df8

Please sign in to comment.