trying difference encoding
This commit is contained in:
parent
0200236da3
commit
759091a598
49
src/BitReader.js
Normal file
49
src/BitReader.js
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
/**
|
||||
* Reads unsigned integers encoded in a variable amount of bits from the buffer.
|
||||
* Bits are aligned into 32bit unsigned integers.
|
||||
* for example, given 3 integers:
|
||||
* x: 123 encoded in 11 bits, binary: 00001111011
|
||||
* y: 7945 encoded in 17 bits, binary: 00001111100001001
|
||||
* z: 12 encoded in 6 bits, binary: 001100
|
||||
*
|
||||
* | --- 32 bits --- || --- 32 bits --- |
|
||||
* |................................||................................|
|
||||
* |00001111011000011111000010010011||00
|
||||
* | x || y || z |
|
||||
*
|
||||
* z does not fit fully into the first 32 bit integer.
|
||||
* The first 4 bits of z are stored at the end of the first 32 bit integer
|
||||
* and the remaining 2 bits at the next 32 bit integer.
|
||||
*
|
||||
*/
|
||||
BitReader = function(buf){
|
||||
|
||||
var buffer = new Uint32Array(buf);
|
||||
var bitOffset = 0;
|
||||
|
||||
this.read = function(bits){
|
||||
var result;
|
||||
|
||||
if((bitOffset % 32) + bits <= 32){
|
||||
var val = buffer[Math.floor(bitOffset / 32)];
|
||||
var leftGap = bitOffset % 32;
|
||||
var rightGap = 32 - (leftGap + bits);
|
||||
|
||||
result = (val << leftGap) >>> (leftGap + rightGap);
|
||||
}else{
|
||||
var val = buffer[Math.floor(bitOffset / 32)];
|
||||
var leftGap = bitOffset % 32;
|
||||
var rightGap = (leftGap + bits) - 32;
|
||||
|
||||
result = (val << leftGap) >>> (leftGap - rightGap)
|
||||
|
||||
val = buffer[Math.floor(bitOffset / 32)+1];
|
||||
result = result | val >>> (32 - rightGap);
|
||||
}
|
||||
|
||||
bitOffset += bits;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -70,8 +70,8 @@ Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
|
||||
// check visibility
|
||||
// TODO min and max points
|
||||
var minPoints = 1*1000*1000;
|
||||
var maxPoints = 5*1000*1000;
|
||||
//var minPoints = 1*1000*1000;
|
||||
//var maxPoints = 5*1000*1000;
|
||||
var stack = [];
|
||||
stack.push(this);
|
||||
while(stack.length > 0){
|
||||
@ -91,15 +91,15 @@ Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
visible = visible && frustum.intersectsBox(box);
|
||||
if(object.level > 0){
|
||||
|
||||
if(this.numVisiblePoints > minPoints && this.numVisiblePoints < maxPoints){
|
||||
//if(this.numVisiblePoints > minPoints && this.numVisiblePoints < maxPoints){
|
||||
// cull detail nodes based in distance to camera
|
||||
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);
|
||||
}else if(this.numVisiblePoints > maxPoints){
|
||||
visible = false;
|
||||
}
|
||||
//}else if(this.numVisiblePoints > maxPoints){
|
||||
// visible = false;
|
||||
//}
|
||||
}else{
|
||||
//visible = true;
|
||||
}
|
||||
@ -152,13 +152,18 @@ Potree.PointCloudOctree.prototype.update = function(camera){
|
||||
for(var i = 0; i < object.children.length; i++){
|
||||
stack.push(object.children[i]);
|
||||
}
|
||||
|
||||
//console.log(object.name);
|
||||
}
|
||||
|
||||
if(this.loadQueue.length > 0){
|
||||
if(this.loadQueue.length >= 2){
|
||||
this.loadQueue.sort(function(a,b){return b.lod - a.lod});
|
||||
}
|
||||
this.loadQueue[0].node.geometryNode.load();
|
||||
|
||||
for(var i = 0; i < Math.min(5, this.loadQueue.length); i++){
|
||||
this.loadQueue[i].node.geometryNode.load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,6 +188,16 @@ Potree.PointCloudOctree.prototype.replaceProxy = function(proxy){
|
||||
var child = geometryNode.children[i];
|
||||
var childProxy = new Potree.PointCloudOctreeProxyNode(child);
|
||||
node.add(childProxy);
|
||||
|
||||
//for(var j = 0; j < 8; j++){
|
||||
// if(child.children[j] !== undefined){
|
||||
// var cchild = child.children[j];
|
||||
// var cchildProxy = new Potree.PointCloudOctreeProxyNode(cchild);
|
||||
// childProxy.add(cchildProxy);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
|
||||
@ -51,7 +51,86 @@ Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
|
||||
nodesLoadTimes[url] = {};
|
||||
nodesLoadTimes[url].start = new Date().getTime();
|
||||
LasLazLoader.load(url, new Potree.LasLazBatcher(this, url));
|
||||
}else {
|
||||
} else if ( pointAttributes === "POT"){
|
||||
|
||||
var callback = function(node, buffer){
|
||||
var dv = new DataView(buffer, 0, 4);
|
||||
var headerSize = dv.getUint32(0, true);
|
||||
var pointOffset = 4 + headerSize;
|
||||
|
||||
var headerBuffer = buffer.slice(4, 4 + headerSize);
|
||||
var header = String.fromCharCode.apply(null, new Uint8Array(headerBuffer));
|
||||
header = JSON.parse(header);
|
||||
console.log(header);
|
||||
|
||||
var pScale = header.attributes[0].scale;
|
||||
var pOffset = header.attributes[0].offset;
|
||||
var pEncoding = header.attributes[0].encoding;
|
||||
|
||||
var scale = new THREE.Vector3(pScale[0], pScale[1], pScale[2]);
|
||||
var offset = new THREE.Vector3(pOffset[0], pOffset[1], pOffset[2]);
|
||||
var min = pEncoding.min;
|
||||
var max = pEncoding.max;
|
||||
var bits = pEncoding.bits;
|
||||
|
||||
var pointBuffer = buffer.slice(pointOffset, pointOffset + buffer.byteLength - pointOffset);
|
||||
var br = new BitReader(pointBuffer);
|
||||
|
||||
var X = br.read(32);
|
||||
var Y = br.read(32);
|
||||
var Z = br.read(32);
|
||||
|
||||
var r = br.read(8);
|
||||
var g = br.read(8);
|
||||
var b = br.read(8);
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = header.pointcount;
|
||||
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
var color = new THREE.Color();
|
||||
|
||||
for(var i = 0; i < header.pointcount - 1; i++){
|
||||
|
||||
dx = br.read(bits[0]) + min[0];
|
||||
dy = br.read(bits[1]) + min[1];
|
||||
dz = br.read(bits[2]) + min[2];
|
||||
|
||||
X = X + dx;
|
||||
Y = Y + dy;
|
||||
Z = Z + dz;
|
||||
|
||||
x = X * scale.x + offset.x;
|
||||
y = Y * scale.y + offset.y;
|
||||
z = Z * scale.z + offset.z;
|
||||
|
||||
r = br.read(8);
|
||||
g = br.read(8);
|
||||
b = br.read(8);
|
||||
|
||||
positions[3*i+0] = x;// + node.pcoGeometry.offset.x;
|
||||
positions[3*i+1] = y;// + node.pcoGeometry.offset.y;
|
||||
positions[3*i+2] = z;// + node.pcoGeometry.offset.z;
|
||||
|
||||
colors[3*i+0] = r / 255;
|
||||
colors[3*i+1] = g / 255;
|
||||
colors[3*i+2] = b / 255;
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
|
||||
geometry.boundingBox = node.boundingBox;
|
||||
node.geometry = geometry;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
node.pcoGeometry.numNodesLoading--;
|
||||
|
||||
};
|
||||
|
||||
Potree.BinaryNodeLoader.load(this, "pot", callback);
|
||||
|
||||
} else {
|
||||
// load binary node files
|
||||
|
||||
var url = this.pcoGeometry.octreeDir + "/" + this.name;
|
||||
@ -94,7 +173,7 @@ Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
|
||||
|
||||
nodesLoadTimes[url] = {};
|
||||
nodesLoadTimes[url].start = new Date().getTime();
|
||||
Potree.BinaryNodeLoader.load(this, callback);
|
||||
Potree.BinaryNodeLoader.load(this, "", callback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,8 +181,8 @@ Potree.BinaryNodeLoader = function(){
|
||||
|
||||
}
|
||||
|
||||
Potree.BinaryNodeLoader.load = function(node, callback){
|
||||
var url = node.pcoGeometry.octreeDir + "/" + node.name;
|
||||
Potree.BinaryNodeLoader.load = function(node, extension, callback){
|
||||
var url = node.pcoGeometry.octreeDir + "/" + node.name + "." + extension;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user