some progress on large coordinate support and support for las, laz and binary

This commit is contained in:
mschuetz 2014-08-11 13:29:59 +02:00
parent fa84d82722
commit 48e44bd65b
7 changed files with 128 additions and 123 deletions

View File

@ -36,6 +36,7 @@ Potree.PointCloudOctree = function(geometry, material){
this.LODDistance = 20;
this.LODFalloff = 1.3;
this.LOD = 4;
this.showBoundingBox = false;
var rootProxy = new Potree.PointCloudOctreeProxyNode(this.pcoGeometry.root);
@ -49,6 +50,7 @@ Potree.PointCloudOctree.prototype.update = function(camera){
this.numVisiblePoints = 0;
// create frustum in object space
camera.updateMatrixWorld();
var frustum = new THREE.Frustum();
var viewI = camera.matrixWorldInverse;
var world = this.matrixWorld;
@ -61,23 +63,68 @@ Potree.PointCloudOctree.prototype.update = function(camera){
var worldI = new THREE.Matrix4().getInverse(world);
var camMatrixObject = new THREE.Matrix4().multiply(worldI).multiply(view);
var camObjPos = new THREE.Vector3().setFromMatrixPosition( camMatrixObject );
var ray = new THREE.Ray(camera.position, new THREE.Vector3( 0, 0, -1 ).applyQuaternion( camera.quaternion ) );
//var ray = new THREE.Ray(camera.position, new THREE.Vector3( 0, -1, 0 ) );
// check visibility
var stack = [];
stack.push(this);
while(stack.length > 0){
var object = stack.shift();
if(object instanceof THREE.Mesh || object instanceof THREE.Line ){
object.visible = true;
continue;
}
var box = object.boundingBox;
var tbox = Potree.utils.computeTransformedBoundingBox(box, this.matrixWorld);
var distance = box.center().distanceTo(camObjPos);
var radius = box.size().length() * 0.5;
var visible = true;
visible = visible && frustum.intersectsBox(box);
if(object.level > 3){
visible = visible && Math.pow(radius, 0.8) / distance > (1 / this.LOD);
visible = visible && (this.numVisiblePoints + object.numPoints < Potree.pointLoadLimit);
visible = visible && (this.numVisibleNodes <= this.maxVisibleNodes);
visible = visible && (this.numVisiblePoints <= this.maxVisiblePoints);
if(object.level > 0){
{ // distance to camera method
visible = visible && Math.pow(radius, 0.8) / distance > (1 / this.LOD);
visible = visible && (this.numVisiblePoints + object.numPoints < Potree.pointLoadLimit);
visible = visible && (this.numVisibleNodes <= this.maxVisibleNodes);
visible = visible && (this.numVisiblePoints <= this.maxVisiblePoints);
}
//{ // distance to view ray method
// var br = tbox.size().length() / 2;
// var distanceToPoint = ray.distanceToPoint(tbox.center());
// //var m = tbox.size().length() / distanceToPoint;
// var m = (br - distanceToPoint) / br;
// m = Math.max(m+1, 1);
// m = Math.pow(m, 5);
//
// //visible = visible && (distanceToPoint < tbox.size().length());
//
// visible = visible && m * Math.pow(radius, 0.8) / distance > (1 / this.LOD);
// visible = visible && (this.numVisiblePoints + object.numPoints < Potree.pointLoadLimit);
// visible = visible && (this.numVisibleNodes <= this.maxVisibleNodes);
// visible = visible && (this.numVisiblePoints <= this.maxVisiblePoints);
// //visible = visible || (distanceToPoint < tbox.size().length() / 2);
//
// //document.getElementById("lblMessage").innerHTML = distanceToPoint;
// //if(distanceToPoint < tbox.size().length()){
// // if(object.centerSphere !== undefined){
// // object.centerSphere.material.color.r = 0;
// // object.centerSphere.material.color.b = 1;
// // }
// //}else{
// // if(object.centerSphere !== undefined){
// // object.centerSphere.material.color.r = 1;
// // object.centerSphere.material.color.b = 0;
// // }
// //}
//}
}else{
visible = true;
}
@ -90,15 +137,26 @@ Potree.PointCloudOctree.prototype.update = function(camera){
}
}
//visible = visible && (object.level <= 4);
//visible = (object.level <= 4);
//visible = object.level === 0 || object.name === "r" || object.name === "r4" || object.name === "r44" || object.name === "r442" || object.name === "r4420" || object.name === "r44200";
object.visible = visible;
if(!visible){
this.hideDescendants(object);
continue;
}else if(visible && this.showBoundingBox && object instanceof THREE.PointCloud){
if(object.boundingBoxNode === undefined && object.boundingBox !== undefined){
var boxHelper = new THREE.BoxHelper(object);
object.add(boxHelper);
object.boundingBoxNode = boxHelper;
}
//var boxHelper = new THREE.BoxHelper(node);
//node.add(boxHelper);
//node.boxHelper = boxHelper;
}else if(!this.showBoundingBox){
if(object.boundingBoxNode !== undefined){
//object.boundingBoxNode.visible = false;
object.remove(object.boundingBoxNode);
object.boundingBoxNode = undefined;
}
}
if(object instanceof THREE.PointCloud){
@ -131,6 +189,19 @@ Potree.PointCloudOctree.prototype.replaceProxy = function(proxy){
parent.remove(proxy);
parent.add(node);
//var centerGeometry = new THREE.SphereGeometry();
//var material = new THREE.MeshBasicMaterial({color: 'red'});
//var centerNode = new THREE.Mesh(centerGeometry, material);
//centerNode.position = node.boundingBox.center();
//var scale = 10/(node.level+1);
//centerNode.scale.set(scale, scale, scale);
//node.add(centerNode);
//node.centerSphere = centerNode;
//
//var boxHelper = new THREE.BoxHelper(node);
//node.add(boxHelper);
//node.boxHelper = boxHelper;
for(var i = 0; i < 8; i++){
if(geometryNode.children[i] !== undefined){
var child = geometryNode.children[i];

View File

@ -69,12 +69,12 @@ Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
var uiView = new Uint8Array(buffer);
for(var i = 0; i < numPoints; i++){
positions[3*i] = fView[4*i];
positions[3*i+1] = fView[4*i+1];
positions[3*i+2] = fView[4*i+2];
positions[3*i+0] = fView[4*i+0] + node.pcoGeometry.offset.x;
positions[3*i+1] = fView[4*i+1] + node.pcoGeometry.offset.y;
positions[3*i+2] = fView[4*i+2] + node.pcoGeometry.offset.z;
color.setRGB(uiView[16*i+12], uiView[16*i+13], uiView[16*i+14]);
colors[3*i] = color.r /255;
colors[3*i+0] = color.r / 255;
colors[3*i+1] = color.g / 255;
colors[3*i+2] = color.b / 255;
}
@ -90,7 +90,6 @@ Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
nodesLoadTimes[url].end = new Date().getTime();
var time = nodesLoadTimes[url].end - nodesLoadTimes[url].start;
//console.log("loadTime[" + url.replace(/^.*[\\\/]/, '') + "]: " + time + "ms");
};
nodesLoadTimes[url] = {};
@ -129,7 +128,6 @@ Potree.BinaryNodeLoader.load = function(node, callback){
Potree.LasLazBatcher = function(node, url){
this.push = function(lasBuffer){
//var ww = Potree.LasLazBatcher.decoderWorkers.pop();
var ww = Potree.workers.lasdecoder.getWorker();
ww.onmessage = function(e){
var geometry = new THREE.BufferGeometry();
@ -138,9 +136,6 @@ Potree.LasLazBatcher = function(node, url){
var endsWith = function(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
//if(!endsWith(url, "r44200.las")){
// numPoints = Math.min(numPoints, 100);
//}
var positions = e.data.position;
var colors = e.data.color;
@ -150,9 +145,9 @@ Potree.LasLazBatcher = function(node, url){
var fPositions = new Float32Array(positions);
for(var i = 0; i < numPoints; i++){
//fPositions[3*i+0] -= node.pcoGeometry.boundingBox.min.x;
//fPositions[3*i+1] -= node.pcoGeometry.boundingBox.min.y;
//fPositions[3*i+2] -= node.pcoGeometry.boundingBox.min.z;
fPositions[3*i+0] += node.pcoGeometry.offset.x;
fPositions[3*i+1] += node.pcoGeometry.offset.y;
fPositions[3*i+2] += node.pcoGeometry.offset.z;
box.expandByPoint(new THREE.Vector3(fPositions[3*i+0], fPositions[3*i+1], fPositions[3*i+2]));
}
@ -160,7 +155,6 @@ Potree.LasLazBatcher = function(node, url){
geometry.addAttribute('position', new THREE.Float32Attribute(positions, 3));
geometry.addAttribute('color', new THREE.Float32Attribute(colors, 3));
geometry.addAttribute('intensity', new THREE.Float32Attribute(intensities, 1));
//geometry.boundingBox = node.boundingBox;
geometry.boundingBox = box;
node.geometry = geometry;
@ -171,9 +165,6 @@ Potree.LasLazBatcher = function(node, url){
nodesLoadTimes[url].end = new Date().getTime();
var time = nodesLoadTimes[url].end - nodesLoadTimes[url].start;
//console.log("loadTime[" + url.replace(/^.*[\\\/]/, '') + "]: " + time + "ms");
//Potree.LasLazBatcher.decoderWorkers.push(ww);
Potree.workers.lasdecoder.returnWorker(ww);
};
@ -191,47 +182,7 @@ Potree.LasLazBatcher = function(node, url){
}
};
//Potree.LasLazBatcher.decoderWorkers = [];
//
//for(var i = 0; i < 5; i++){
// var ww = new Worker("../src/workers/LASDecoderWorker.js");
// Potree.LasLazBatcher.decoderWorkers.push(ww);
//}
Potree.PointCloudOctreeGeometryNode.prototype.bufferLoaded = function(buffer){
var geometry = new THREE.BufferGeometry();
var numPoints = buffer.byteLength / 16;
var positions = new Float32Array(numPoints*3);
var colors = new Float32Array(numPoints*3);
var color = new THREE.Color();
var fView = new Float32Array(buffer);
var uiView = new Uint8Array(buffer);
for(var i = 0; i < numPoints; i++){
positions[3*i] = fView[4*i];
positions[3*i+1] = fView[4*i+1];
positions[3*i+2] = fView[4*i+2];
color.setRGB(uiView[16*i+12], uiView[16*i+13], uiView[16*i+14]);
colors[3*i] = color.r /255;
colors[3*i+1] = color.g / 255;
colors[3*i+2] = color.b / 255;
}
geometry.addAttribute('position', new THREE.Float32Attribute(positions, 3));
geometry.addAttribute('color', new THREE.Float32Attribute(colors, 3));
geometry.boundingBox = this.boundingBox;
this.geometry = geometry;
this.loaded = true;
this.loading = false;
this.pcoGeometry.numNodesLoading--;
}
Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){
delete this.geometry;
this.loaded = false;
//console.log("dispose: " + this.name);
}

View File

@ -17,7 +17,10 @@ function POCLoader(){
* @param url
* @param loadingFinishedListener executed after loading the binary has been finished
*/
POCLoader.load = function load(url) {
POCLoader.load = function load(url, params) {
var parameters = params || {};
var toOrigin = parameters.toOrigin || false;
try{
var pco = new Potree.PointCloudOctreeGeometry();
pco.url = url;
@ -35,19 +38,25 @@ POCLoader.load = function load(url) {
pco.spacing = fMno.spacing;
pco.pointAttributes = fMno.pointAttributes;
var min = new THREE.Vector3(fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz);
var max = new THREE.Vector3(fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz);
var boundingBox = new THREE.Box3(min, max);
var offset = new THREE.Vector3(0,0,0);
if(toOrigin){
offset.set(-min.x, -min.y, -min.z);
boundingBox.min.add(offset);
boundingBox.max.add(offset);
}
pco.boundingBox = boundingBox;
pco.offset = offset;
var nodes = {};
{ // load root
var name = "r";
var min = new THREE.Vector3(fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz);
var max = new THREE.Vector3(fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz);
var boundingBox = new THREE.Box3(min, max);
pco.boundingBox = boundingBox;
var box = boundingBox.clone();
box.min.sub(boundingBox.min);
box.max.sub(boundingBox.min);
var root = new Potree.PointCloudOctreeGeometryNode(name, pco, box);
var root = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
root.level = 0;
root.numPoints = fMno.hierarchy[0][1];
pco.root = root;

View File

@ -45,8 +45,7 @@ Potree.PointCloudHeightMaterial.vs_points = [
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); ",
" vec4 world = modelMatrix * vec4( position, 1.0 ); ",
" float w = (world.y - uMin) / (uMax-uMin); ",
" w = clamp(w-0.1, 0.0, 1.0); ",
" //vColor = 0.2*vec3(0.788, 0.64, 0.16) * (1.0-w) + vec3(0.67, 0.62, 0.53) * w; ",
" w = clamp(w-0.1, 0.2, 1.0); ",
" vColor = vec3(1.0, 0.0, 0.0) * (w) ; ",
" ",
" gl_PointSize = size * 1.0 / length( mvPosition.xyz ); ",

View File

@ -1,36 +1,48 @@
Potree.PointCloudIntensityMaterial = function(){
Potree.PointCloudIntensityMaterial = function(parameters){
var attributes = {
intensity: { type: "f", value: [] }
};
var uniforms = {
color: { type: "c", value: new THREE.Color( 0xffffff ) },
size: { type: "f", value: 2500 }
size: { type: "f", value: 1 }
};
var pointSize = parameters.size || 1.0;
this.setValues({
uniforms: uniforms,
attributes: attributes,
vertexShader: Potree.PointCloudIntensityMaterial.vs_points.join("\n"),
fragmentShader: Potree.PointCloudIntensityMaterial.fs_points_rgb.join("\n"),
vertexColors: THREE.VertexColors,
alphaTest: 0.9,
size: pointSize,
alphaTest: 0.9
});
};
Potree.PointCloudIntensityMaterial.prototype = new THREE.ShaderMaterial();
Object.defineProperty(Potree.PointCloudIntensityMaterial.prototype, "size", {
get: function(){
return this.uniforms.size.value;
},
set: function(value){
this.uniforms.size.value = value;
}
});
Potree.PointCloudIntensityMaterial.vs_points = [
"attribute float intensity; ",
"uniform float size; ",
"varying vec3 vColor; ",
" ",
"void main() { ",
" vColor = vec3(1.0, 1.0, 1.0) * (intensity / 500.0); ",
" vColor = vec3(1.0, 1.0, 1.0) * (intensity / 400.0); ",
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); ",
" ",
" gl_PointSize = size * 1.0 / length( mvPosition.xyz ); ",
" //gl_PointSize = size * 1.0 / length( mvPosition.xyz ); ",
" gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ",
" gl_PointSize = max(2.0, gl_PointSize); ",
" gl_Position = projectionMatrix * mvPosition; ",
"} "];

View File

@ -24,7 +24,7 @@ Potree.PointCloudRGBMaterial.vs_points = [
"varying vec3 vColor; ",
" ",
"void main() { ",
" vColor = color / 65000.0; ",
" vColor = color; ",
" vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); ",
" ",
" gl_PointSize = size * 1.0 / length( mvPosition.xyz ); ",

View File

@ -135,9 +135,9 @@ onmessage = function(event){
tempUint8[1] = bufferView[i*pointSize+25];
var b = tempUint16[0];
colors[3*i+0] = r;
colors[3*i+1] = g;
colors[3*i+2] = b;
colors[3*i+0] = r / 65536;
colors[3*i+1] = g / 65536;
colors[3*i+2] = b / 65536;
}
}
@ -155,40 +155,3 @@ onmessage = function(event){
postMessage(message, transferables);
}
//onmessage = function(event){
// var buffer = event.data.buffer;
// var numPoints = event.data.numPoints;
// var pointSize = event.data.pointSize;
// var pointFormatID = event.data.pointFormatID;
// var scale = event.data.scale;
// var offset = event.data.offset;
// var mins = event.data.mins;
// var maxs = event.data.maxs;
//
// var decoder = new LASDecoder(buffer, pointFormatID, pointSize, numPoints, scale, offset);
//
// var pBuff = new ArrayBuffer(numPoints*3*4);
// var cBuff = new ArrayBuffer(numPoints*3*4);
// var iBuff = new ArrayBuffer(numPoints*4);
// var positions = new Float32Array(pBuff);
// var colors = new Float32Array(cBuff);
// var intensities = new Float32Array(iBuff);
//
// for(var i = 0; i < numPoints; i++){
// var p = decoder.getPoint(i);
//
// positions[3*i] = p.position[0] * decoder.scale[0] + decoder.offset[0] - mins[0];
// positions[3*i+1] = p.position[1] * decoder.scale[1] + decoder.offset[1] - mins[1];
// positions[3*i+2] = p.position[2] * decoder.scale[2] + decoder.offset[2] - mins[2];
//
// colors[3*i] = p.color[0] /255;
// colors[3*i+1] = p.color[1] / 255;
// colors[3*i+2] = p.color[2] / 255;
//
// intensities[i] = p.intensity;
// }
//
// var message = {position: pBuff, color: cBuff, intensity: iBuff};
// postMessage(message, [message.position, message.color, message.intensity]);
//}