From bd215e41de68898e52706629a4e462291b58d988 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Mon, 10 Feb 2025 14:21:28 +0100 Subject: [PATCH] fix(test): PointCloud unit tests --- src/Source/Potree2Source.js | 4 ++++ src/Source/PotreeSource.js | 4 ++++ test/unit/entwine.js | 17 +++++++++-------- test/unit/potree.js | 1 + test/unit/potree2.js | 14 ++++++++------ test/unit/potree2layerparsing.js | 4 ++++ test/unit/potreelayerparsing.js | 16 ++++++++++++---- 7 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Source/Potree2Source.js b/src/Source/Potree2Source.js index 75e8cd8836..9bcd3988b7 100644 --- a/src/Source/Potree2Source.js +++ b/src/Source/Potree2Source.js @@ -151,6 +151,10 @@ class Potree2Source extends Source { if (!source.file) { throw new Error('New Potree2Source: file is required'); } + if (!source.crs) { + // with better data and the spec this might be removed + throw new Error('New PotreeSource: crs is required'); + } super(source); this.file = source.file; diff --git a/src/Source/PotreeSource.js b/src/Source/PotreeSource.js index 0796f8484a..4229c50d9c 100644 --- a/src/Source/PotreeSource.js +++ b/src/Source/PotreeSource.js @@ -63,6 +63,10 @@ class PotreeSource extends Source { if (!source.file) { throw new Error('New PotreeSource: file is required'); } + if (!source.crs) { + // with better data and the spec this might be removed + throw new Error('New PotreeSource: crs is required'); + } super(source); this.file = source.file; diff --git a/test/unit/entwine.js b/test/unit/entwine.js index 43fc24237e..a85baeec79 100644 --- a/test/unit/entwine.js +++ b/test/unit/entwine.js @@ -1,13 +1,14 @@ import assert from 'assert'; +import { Vector3 } from 'three'; import View from 'Core/View'; import GlobeView from 'Core/Prefab/GlobeView'; import Coordinates from 'Core/Geographic/Coordinates'; import EntwinePointTileSource from 'Source/EntwinePointTileSource'; import EntwinePointTileLayer from 'Layer/EntwinePointTileLayer'; import EntwinePointTileNode from 'Core/EntwinePointTileNode'; -import LASParser from 'Parser/LASParser'; import sinon from 'sinon'; import Fetcher from 'Provider/Fetcher'; +import LASParser from 'Parser/LASParser'; import Renderer from './bootstrap'; import eptFile from '../data/entwine/ept.json'; @@ -78,18 +79,16 @@ describe('Entwine Point Tile', function () { }); }); - describe('Layer', function () { + describe('Entwine Point Tile Layer', function () { let renderer; - let placement; let view; let layer; let context; before(function (done) { renderer = new Renderer(); - placement = { coord: new Coordinates('EPSG:4326', 0, 0), range: 250 }; - view = new GlobeView(renderer.domElement, placement, { renderer }); - layer = new EntwinePointTileLayer('test', { source }, view); + view = new GlobeView(renderer.domElement, {}, { renderer }); + layer = new EntwinePointTileLayer('test', { source }); context = { camera: view.camera, @@ -117,8 +116,10 @@ describe('Entwine Point Tile', function () { }); it('tries to update on the root and succeeds', function (done) { + const lookAt = new Vector3(); + const coord = new Coordinates(view.referenceCrs).setFromVector3(layer.root.bbox.getCenter(lookAt)); view.controls.lookAtCoordinate({ - coord: source.center, + coord, range: 250, }, false) .then(() => { @@ -135,7 +136,7 @@ describe('Entwine Point Tile', function () { }); }); - describe('Node', function () { + describe('Entwine Point Tile Node', function () { let root; before(function () { const layer = { source: { url: 'http://server.geo', extension: 'laz' } }; diff --git a/test/unit/potree.js b/test/unit/potree.js index b744b603a7..8357520388 100644 --- a/test/unit/potree.js +++ b/test/unit/potree.js @@ -60,6 +60,7 @@ describe('Potree', function () { const source = new PotreeSource({ file: fileName, url: baseurl, + crs: 'EPSG:4978', }); // Configure Point Cloud layer diff --git a/test/unit/potree2.js b/test/unit/potree2.js index ff1b48a0c7..906558c293 100644 --- a/test/unit/potree2.js +++ b/test/unit/potree2.js @@ -17,16 +17,18 @@ describe('Potree2', function () { before(function () { renderer = new Renderer(); - viewer = new View('EPSG:3946', renderer.domElement, { renderer }); + viewer = new View('EPSG:4978', renderer.domElement, { renderer }); viewer.camera.camera3D.position.copy(new Vector3(0, 0, 10)); // Configure Point Cloud layer + const source = new Potree2Source({ + file: 'metadata.json', + url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/potree2.0/lion', + networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + crs: 'EPSG:4978', + }); potreeLayer = new Potree2Layer('lion', { - source: new Potree2Source({ - file: 'metadata.json', - url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/potree2.0/lion', - networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, - }), + source, crs: viewer.referenceCrs, }); diff --git a/test/unit/potree2layerparsing.js b/test/unit/potree2layerparsing.js index 9f1dc423fc..6cf06f8bd0 100644 --- a/test/unit/potree2layerparsing.js +++ b/test/unit/potree2layerparsing.js @@ -50,6 +50,7 @@ describe('Potree2 Provider', function () { file: 'metadata.json', url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/potree2.0/lion', networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + crs: 'EPSG:4978', metadata, }); @@ -65,6 +66,7 @@ describe('Potree2 Provider', function () { file: 'metadata.json', url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/potree2.0/lion', networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + crs: 'EPSG:4978', metadata: { version: '2.0', name: 'lion', @@ -132,6 +134,7 @@ describe('Potree2 Provider', function () { file: 'metadata.json', url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/potree2.0/lion', networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + crs: 'EPSG:4978', metadata: { version: '2.0', name: 'lion', @@ -199,6 +202,7 @@ describe('Potree2 Provider', function () { file: 'metadata.json', url: 'https://raw.githubusercontent.com/iTowns/iTowns2-sample-data/master/pointclouds/potree2.0/lion', networkOptions: process.env.HTTPS_PROXY ? { agent: new HttpsProxyAgent(process.env.HTTPS_PROXY) } : {}, + crs: 'EPSG:4978', metadata: { version: '2.0', name: 'lion', diff --git a/test/unit/potreelayerparsing.js b/test/unit/potreelayerparsing.js index 0f1207edb2..c4db8bcc02 100644 --- a/test/unit/potreelayerparsing.js +++ b/test/unit/potreelayerparsing.js @@ -42,7 +42,8 @@ describe('Potree Provider', function () { it('cloud with no normal information', function _it(done) { // No normals const cloud = { - boundingBox: { lx: 0, ly: 1, ux: 2, uy: 3 }, + boundingBox: { lx: 10, ly: 20, ux: 30, uy: 40 }, + tightBoundingBox: { lx: 1, ly: 2, ux: 3, uy: 4 }, scale: 1.0, pointAttributes: ['POSITION', 'RGB'], octreeDir: 'data', @@ -51,6 +52,7 @@ describe('Potree Provider', function () { const source = new PotreeSource({ file: fileName, url: baseurl, + crs: 'EPSG:4978', cloud, }); @@ -66,7 +68,8 @@ describe('Potree Provider', function () { it('cloud with normals as vector', function _it(done) { // // // // normals as vector const cloud = { - boundingBox: { lx: 0, ly: 1, ux: 2, uy: 3 }, + boundingBox: { lx: 10, ly: 20, ux: 30, uy: 40 }, + tightBoundingBox: { lx: 1, ly: 2, ux: 3, uy: 4 }, scale: 1.0, pointAttributes: ['POSITION', 'NORMAL', 'CLASSIFICATION'], octreeDir: 'data', @@ -75,6 +78,7 @@ describe('Potree Provider', function () { const source = new PotreeSource({ file: fileName, url: baseurl, + crs: 'EPSG:4978', cloud, }); @@ -91,7 +95,8 @@ describe('Potree Provider', function () { it('cloud with spheremapped normals', function _it(done) { // // spheremapped normals const cloud = { - boundingBox: { lx: 0, ly: 1, ux: 2, uy: 3 }, + boundingBox: { lx: 10, ly: 20, ux: 30, uy: 40 }, + tightBoundingBox: { lx: 1, ly: 2, ux: 3, uy: 4 }, scale: 1.0, pointAttributes: ['POSITION', 'COLOR_PACKED', 'NORMAL_SPHEREMAPPED'], octreeDir: 'data', @@ -99,6 +104,7 @@ describe('Potree Provider', function () { const source = new PotreeSource({ file: fileName, url: baseurl, + crs: 'EPSG:4978', cloud, }); const layer = new PotreeLayer('pointsCloud3', { source, crs: view.referenceCrs }); @@ -115,7 +121,8 @@ describe('Potree Provider', function () { it('cloud with oct16 normals', function _it(done) { // // // oct16 normals const cloud = { - boundingBox: { lx: 0, ly: 1, ux: 2, uy: 3 }, + boundingBox: { lx: 10, ly: 20, ux: 30, uy: 40 }, + tightBoundingBox: { lx: 1, ly: 2, ux: 3, uy: 4 }, scale: 1.0, pointAttributes: ['POSITION', 'COLOR_PACKED', 'CLASSIFICATION', 'NORMAL_OCT16'], octreeDir: 'data', @@ -124,6 +131,7 @@ describe('Potree Provider', function () { file: fileName, url: baseurl, cloud, + crs: 'EPSG:4978', }); const layer = new PotreeLayer('pointsCloud4', { source, crs: view.referenceCrs }); View.prototype.addLayer.call(view, layer);