fixed hierarchy loading bug

This commit is contained in:
mschuetz 2015-02-26 18:24:41 +01:00
parent 0da016d4ea
commit 99f1925ba5
2 changed files with 109 additions and 128 deletions

View File

@ -12,6 +12,7 @@ Potree.PointCloudOctreeGeometry = function(){
this.numNodesLoading = 0;
this.nodes = null;
this.pointAttributes = null;
this.hierarchyPartDepth = 6;
}
Potree.PointCloudOctreeGeometryNode = function(name, pcoGeometry, boundingBox){
@ -34,49 +35,128 @@ Potree.PointCloudOctreeGeometryNode.prototype.addChild = function(child){
Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
if(this.loading === true || this.pcoGeometry.numNodesLoading > 1){
return;
}else{
this.loading = true;
}
this.loading = true;
if(Potree.PointCloudOctree.lru.numPoints + this.numPoints >= Potree.pointLoadLimit){
Potree.PointCloudOctree.disposeLeastRecentlyUsed(this.numPoints);
}
this.pcoGeometry.numNodesLoading++;
if((this.level % this.pcoGeometry.hierarchyPartDepth) === 0){
this.loadHierachyThenPoints();
}else{
this.loadPoints();
}
}
Potree.PointCloudOctreeGeometryNode.prototype.loadPoints = function(){
this.pcoGeometry.loader.load(this);
}
};
Potree.BinaryNodeLoader = function(){
}
Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function(){
Potree.BinaryNodeLoader.load = function(node, extension, callback){
var url = node.pcoGeometry.octreeDir + "/" + node.name;
if(extension !== undefined && extension.length > 0){
url += "." + extension;
}
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
var buffer = xhr.response;
callback(node, buffer);
} else {
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
var node = this;
// load hierarchy
var callback = function(node, hbuffer){
var count = hbuffer.byteLength / 5;
var view = new DataView(hbuffer);
var stack = [];
var children = view.getUint8(0);
var numPoints = view.getUint32(1, true);
stack.push({children: children, numPoints: numPoints, name: node.name});
var decoded = [];
var offset = 5;
while(stack.length > 0){
var snode = stack.shift();
var mask = 1;
for(var i = 0; i < 8; i++){
if((snode.children & mask) !== 0){
var childIndex = i;
var childName = snode.name + i;
var childChildren = view.getUint8(offset);
var childNumPoints = view.getUint32(offset + 1, true);
stack.push({children: childChildren, numPoints: childNumPoints, name: childName});
decoded.push({children: childChildren, numPoints: childNumPoints, name: childName});
offset += 5;
}
mask = mask * 2;
}
if(offset === hbuffer.byteLength){
break;
}
}
//console.log(decoded);
var nodes = {};
nodes[node.name] = node;
var pco = node.pcoGeometry;
for( var i = 0; i < decoded.length; i++){
var name = decoded[i].name;
var numPoints = decoded[i].numPoints;
var index = parseInt(name.charAt(name.length-1));
var parentName = name.substring(0, name.length-1);
var parentNode = nodes[parentName];
var level = name.length-1;
var boundingBox = POCLoader.createChildAABB(parentNode.boundingBox, index);
var currentNode = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
currentNode.level = level;
currentNode.numPoints = numPoints;
parentNode.addChild(currentNode);
nodes[name] = currentNode;
}
node.loadPoints();
};
try{
xhr.send(null);
}catch(e){
console.log("fehler beim laden der punktwolke: " + e);
if((node.level % node.pcoGeometry.hierarchyPartDepth) === 0){
var hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
var xhr = new XMLHttpRequest();
xhr.open('GET', hurl, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
var hbuffer = xhr.response;
callback(node, hbuffer);
} else {
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
}
}
};
try{
xhr.send(null);
}catch(e){
console.log("fehler beim laden der punktwolke: " + e);
}
}
}
};
Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){

View File

@ -15,18 +15,17 @@ Potree.BinaryLoader.prototype.newerVersion = function(version){
};
Potree.BinaryLoader.prototype.load = function(node){
if(node.loaded){
return;
}
var scope = this;
var url = node.pcoGeometry.octreeDir + "/" + node.name;
if(this.version.newerThan("1.3")){
url += ".bin";
}
var scope = this;
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
@ -46,104 +45,6 @@ Potree.BinaryLoader.prototype.load = function(node){
}catch(e){
console.log("fehler beim laden der punktwolke: " + e);
}
this.loadHierarchy(node);
};
Potree.BinaryLoader.prototype.loadHierarchy = function(node){
// load hierarchy
var callback = function(node, hbuffer){
var count = hbuffer.byteLength / 5;
var view = new DataView(hbuffer);
var stack = [];
var children = view.getUint8(0);
var numPoints = view.getUint32(1, true);
stack.push({children: children, numPoints: numPoints, name: node.name});
var decoded = [];
var offset = 5;
while(stack.length > 0){
var snode = stack.shift();
var mask = 1;
for(var i = 0; i < 8; i++){
if((snode.children & mask) !== 0){
var childIndex = i;
var childName = snode.name + i;
var childChildren = view.getUint8(offset);
var childNumPoints = view.getUint32(offset + 1, true);
stack.push({children: childChildren, numPoints: childNumPoints, name: childName});
decoded.push({children: childChildren, numPoints: childNumPoints, name: childName});
offset += 5;
}
mask = mask * 2;
}
if(offset === hbuffer.byteLength){
break;
}
}
console.log(decoded);
var nodes = {};
nodes[node.name] = node;
var pco = node.pcoGeometry;
for( var i = 0; i < decoded.length; i++){
var name = decoded[i].name;
var numPoints = decoded[i].numPoints;
var index = parseInt(name.charAt(name.length-1));
var parentName = name.substring(0, name.length-1);
var parentNode = nodes[parentName];
var level = name.length-1;
var boundingBox = POCLoader.createChildAABB(parentNode.boundingBox, index);
var node = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
node.level = level;
node.numPoints = numPoints;
parentNode.addChild(node);
nodes[name] = node;
}
};
if((node.level % 5) === 0){
var hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
var xhr = new XMLHttpRequest();
xhr.open('GET', hurl, true);
xhr.responseType = 'arraybuffer';
xhr.overrideMimeType('text/plain; charset=x-user-defined');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) {
var hbuffer = xhr.response;
callback(node, hbuffer);
} else {
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
}
}
};
try{
xhr.send(null);
}catch(e){
console.log("fehler beim laden der punktwolke: " + e);
}
}
};
Potree.BinaryLoader.prototype.parse = function(node, buffer){