From 86f4f0157fbb0e90330d0d53524257b2f7a722a7 Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Wed, 28 Jun 2017 12:32:28 +0200 Subject: [PATCH] compute mean for each node --- src/PointCloudOctree.js | 15 +++++++++--- src/loader/BinaryLoader.js | 4 +--- src/loader/LasLazLoader.js | 16 ++++++------- src/workers/BinaryDecoderWorker.js | 26 ++++++++++++++++----- src/workers/GreyhoundBinaryDecoderWorker.js | 12 ++++++---- src/workers/LASDecoderWorker.js | 17 +++++++++++--- 6 files changed, 61 insertions(+), 29 deletions(-) diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index 9befd523..a3d3bf4e 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -132,11 +132,20 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree{ material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), node.pcIndex); } } - - - }; + //{ // DEBUG + // let sg = new THREE.SphereGeometry(1, 16, 16); + // let sm = new THREE.MeshNormalMaterial(); + // let s = new THREE.Mesh(sg, sm); + // s.scale.set(5, 5, 5); + // s.position.copy(geometryNode.mean) + // .add(this.position) + // .add(geometryNode.boundingBox.min); + // + // viewer.scene.scene.add(s); + //} + node.geometryNode = geometryNode; node.sceneNode = sceneNode; node.pointcloud = this; diff --git a/src/loader/BinaryLoader.js b/src/loader/BinaryLoader.js index 4a72c4c6..ccde135e 100644 --- a/src/loader/BinaryLoader.js +++ b/src/loader/BinaryLoader.js @@ -101,10 +101,8 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){ } geometry.boundingBox = node.boundingBox; - //geometry.boundingBox = tightBoundingBox; node.geometry = geometry; - //node.boundingBox = tightBoundingBox; - //node.position.copy(node.boundingBox.min); + node.mean = new THREE.Vector3(...data.mean); node.tightBoundingBox = tightBoundingBox; node.loaded = true; node.loading = false; diff --git a/src/loader/LasLazLoader.js b/src/loader/LasLazLoader.js index 9b22c338..6abc20a9 100644 --- a/src/loader/LasLazLoader.js +++ b/src/loader/LasLazLoader.js @@ -174,14 +174,12 @@ Potree.LasLazBatcher = class LasLazBatcher{ //let indices = new ArrayBuffer(numPoints*4); //let iIndices = new Uint32Array(indices); - let box = new THREE.Box3(); - - let fPositions = new Float32Array(positions); - for(let i = 0; i < numPoints; i++){ - //iIndices[i] = i; - - box.expandByPoint(new THREE.Vector3(fPositions[3*i+0], fPositions[3*i+1], fPositions[3*i+2])); - } + //let box = new THREE.Box3(); + // + //let fPositions = new Float32Array(positions); + //for(let i = 0; i < numPoints; i++){ + // box.expandByPoint(new THREE.Vector3(fPositions[3*i+0], fPositions[3*i+1], fPositions[3*i+2])); + //} geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3)); geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3, true)); @@ -190,7 +188,6 @@ Potree.LasLazBatcher = class LasLazBatcher{ geometry.addAttribute('returnNumber', new THREE.BufferAttribute(returnNumbers, 1)); geometry.addAttribute('numberOfReturns', new THREE.BufferAttribute(numberOfReturns, 1)); geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(pointSourceIDs, 1)); - //geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 1)); geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(numPoints*3), 3)); let indicesAttribute = new THREE.Uint8BufferAttribute(e.data.indices, 4); @@ -209,6 +206,7 @@ Potree.LasLazBatcher = class LasLazBatcher{ this.node.loaded = true; this.node.loading = false; this.node.pcoGeometry.numNodesLoading--; + this.node.mean = new THREE.Vector3(...e.data.mean); Potree.workerPool.returnWorker(workerPath, worker); }; diff --git a/src/workers/BinaryDecoderWorker.js b/src/workers/BinaryDecoderWorker.js index 5712d925..96d6083c 100644 --- a/src/workers/BinaryDecoderWorker.js +++ b/src/workers/BinaryDecoderWorker.js @@ -50,6 +50,8 @@ onmessage = function(event){ let tightBoxMax = [ Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY ]; let attributeBuffers = {}; + + let mean = [0, 0, 0]; let offset = 0; for(let i = 0; i < pointAttributes.attributes.length; i++){ @@ -62,15 +64,26 @@ onmessage = function(event){ let startPos = new Date().getTime(); for(let j = 0; j < numPoints; j++){ + + let x, y, z; + if(version.newerThan("1.3")){ - positions[3*j+0] = (cv.getUint32(offset + j*pointAttributes.byteSize+0, true) * scale); - positions[3*j+1] = (cv.getUint32(offset + j*pointAttributes.byteSize+4, true) * scale); - positions[3*j+2] = (cv.getUint32(offset + j*pointAttributes.byteSize+8, true) * scale); + x = (cv.getUint32(offset + j*pointAttributes.byteSize+0, true) * scale); + y = (cv.getUint32(offset + j*pointAttributes.byteSize+4, true) * scale); + z = (cv.getUint32(offset + j*pointAttributes.byteSize+8, true) * scale); }else{ - positions[3*j+0] = cv.getFloat32(j*pointAttributes.byteSize+0, true) + nodeOffset[0]; - positions[3*j+1] = cv.getFloat32(j*pointAttributes.byteSize+4, true) + nodeOffset[1]; - positions[3*j+2] = cv.getFloat32(j*pointAttributes.byteSize+8, true) + nodeOffset[2]; + x = cv.getFloat32(j*pointAttributes.byteSize+0, true) + nodeOffset[0]; + y = cv.getFloat32(j*pointAttributes.byteSize+4, true) + nodeOffset[1]; + z = cv.getFloat32(j*pointAttributes.byteSize+8, true) + nodeOffset[2]; } + + positions[3*j+0] = x; + positions[3*j+1] = y; + positions[3*j+2] = z; + + mean[0] += x / numPoints; + mean[1] += y / numPoints; + mean[2] += z / numPoints; tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3*j+0]); tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3*j+1]); @@ -224,6 +237,7 @@ onmessage = function(event){ } let message = { + mean: mean, attributeBuffers: attributeBuffers, tightBoundingBox: { min: tightBoxMin, max: tightBoxMax }, indices: indices diff --git a/src/workers/GreyhoundBinaryDecoderWorker.js b/src/workers/GreyhoundBinaryDecoderWorker.js index 4458cdaa..f631780b 100644 --- a/src/workers/GreyhoundBinaryDecoderWorker.js +++ b/src/workers/GreyhoundBinaryDecoderWorker.js @@ -98,6 +98,8 @@ onmessage = function(event){ var attributeBuffers = {}; var offset = 0; var pointSize = pointAttributes.byteSize; + + let mean = [0, 0, 0]; var logged = 0; @@ -121,11 +123,10 @@ onmessage = function(event){ positions[3*j+0] = x; positions[3*j+1] = y; positions[3*j+2] = z; - - //if(j < 2){ - // console.log("u:" + ux + ", " + uy + ", " + uz); - // console.log("f:" + x + ", " + y + ", " + z); - //} + + mean[0] += x / numPoints; + mean[1] += y / numPoints; + mean[2] += z / numPoints; tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3*j+0]); tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3*j+1]); @@ -271,6 +272,7 @@ onmessage = function(event){ } var message = { + mean: mean, attributeBuffers: attributeBuffers, tightBoundingBox: { min: tightBoxMin, max: tightBoxMax }, indices: indices diff --git a/src/workers/LASDecoderWorker.js b/src/workers/LASDecoderWorker.js index 5081b1b0..7f0db977 100644 --- a/src/workers/LASDecoderWorker.js +++ b/src/workers/LASDecoderWorker.js @@ -90,6 +90,8 @@ onmessage = function(event){ max: [ Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY ] }; + let mean = [0, 0, 0]; + // temp arrays seem to be significantly faster than DataViews // at the moment: http://jsperf.com/dataview-vs-temporary-float64array @@ -114,9 +116,17 @@ onmessage = function(event){ tempUint8[3] = bufferView[i*pointSize+11]; var z = tempInt32[0]; - positions[3*i+0] = x * scale[0] + offset[0] - event.data.mins[0]; - positions[3*i+1] = y * scale[1] + offset[1] - event.data.mins[1]; - positions[3*i+2] = z * scale[2] + offset[2] - event.data.mins[2]; + x = x * scale[0] + offset[0] - event.data.mins[0]; + y = y * scale[1] + offset[1] - event.data.mins[1]; + z = z * scale[2] + offset[2] - event.data.mins[2]; + + positions[3*i+0] = x; + positions[3*i+1] = y; + positions[3*i+2] = z; + + mean[0] += x / numPoints; + mean[1] += y / numPoints; + mean[2] += z / numPoints; tightBoundingBox.min[0] = Math.min(tightBoundingBox.min[0], positions[3*i+0]); tightBoundingBox.min[1] = Math.min(tightBoundingBox.min[1], positions[3*i+1]); @@ -176,6 +186,7 @@ onmessage = function(event){ } var message = { + mean: mean, position: pBuff, color: cBuff, intensity: iBuff,