Add offset and scaling based on new Greyhound API.

This commit is contained in:
Connor Manning 2016-02-29 23:48:13 +01:00
parent 6abe9c4a85
commit c43f8e8e1c
13 changed files with 193 additions and 114 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -72,9 +72,10 @@
viewer.setDescription(""); viewer.setDescription("");
//viewer.setMinNodeSize(5); //viewer.setMinNodeSize(5);
// Since this parameter to addPointCloud starts with the string 'greyhound:', it // Since this parameter to addPointCloud starts with the string
// is recognised as a greyhound server URL // 'greyhound://', it is recognised as a greyhound server URL.
viewer.addPointCloud("greyhound:http://dev.greyhound.io/resource/autzen/"); viewer.addPointCloud(
"greyhound://http://localhost:8080/resource/autzen-calc/");
viewer.loadGUI(); viewer.loadGUI();

View File

@ -1,7 +1,8 @@
var nodesLoadTimes = {}; var nodesLoadTimes = {};
var baseLoaded = false; var baseLoaded = false;
Potree.PointCloudGreyhoundGeometryNode = function(name, pcoGeometry, boundingBox){ Potree.PointCloudGreyhoundGeometryNode = function(
name, pcoGeometry, boundingBox, scale, offset){
this.id = Potree.PointCloudGreyhoundGeometryNode.IDCount++; this.id = Potree.PointCloudGreyhoundGeometryNode.IDCount++;
this.name = name; this.name = name;
this.index = parseInt(name.charAt(name.length-1)); this.index = parseInt(name.charAt(name.length-1));
@ -9,6 +10,8 @@ Potree.PointCloudGreyhoundGeometryNode = function(name, pcoGeometry, boundingBox
this.geometry = null; this.geometry = null;
this.boundingBox = boundingBox; this.boundingBox = boundingBox;
this.boundingSphere = boundingBox.getBoundingSphere(); this.boundingSphere = boundingBox.getBoundingSphere();
this.scale = scale;
this.offset = offset;
this.children = {}; this.children = {};
this.numPoints = 0; this.numPoints = 0;
this.level = null; this.level = null;
@ -52,10 +55,6 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.getChildren = function(){
return children; return children;
}; };
Potree.PointCloudGreyhoundGeometryNode.prototype.getBoundingBox = function(){
return this.boundingBox;
};
Potree.PointCloudGreyhoundGeometryNode.prototype.getURL = function(){ Potree.PointCloudGreyhoundGeometryNode.prototype.getURL = function(){
//Determine what schema to ask the greyhound server for. //Determine what schema to ask the greyhound server for.
var material = viewer.getMaterial(); var material = viewer.getMaterial();
@ -119,20 +118,28 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.getURL = function(){
}.bind(this)); }.bind(this));
var bb = this.boundingBox; var bb = this.boundingBox;
var offset = this.pcoGeometry.offset; var offset = this.offset;
var boundsString = (bb.min.x) + ',' + (bb.min.y) + ',' + (bb.min.z) + ',' + (bb.max.x) + ',' + (bb.max.y) + ',' + (bb.max.z); var scale = this.pcoGeometry.scale;
var boundsString =
(bb.min.x * scale + offset.x) + ',' +
(bb.min.y * scale + offset.y) + ',' +
(bb.min.z * scale + offset.z) + ',' +
(bb.max.x * scale + offset.x) + ',' +
(bb.max.y * scale + offset.y) + ',' +
(bb.max.z * scale + offset.z);
var offsetString = offset.x + ',' + offset.y + ',' + offset.z;
var url = ''+this.pcoGeometry.serverURL + var url = ''+this.pcoGeometry.serverURL +
'read?depthBegin=' + 'read?depthBegin=' +
(baseLoaded ? (this.level + this.pcoGeometry.baseDepth) : 0) + (baseLoaded ? (this.level + this.pcoGeometry.baseDepth) : 0) +
'&depthEnd=' + (this.level + this.pcoGeometry.baseDepth + 1) + '&depthEnd=' + (this.level + this.pcoGeometry.baseDepth + 1) +
'&bounds=[' + boundsString + ']' + '&bounds=[' + boundsString + ']' +
'&schema='+JSON.stringify(schema); '&schema=' + JSON.stringify(schema) +
// Ideally, we would want to be able to ask for a scale and an offset as well. '&scale=' + scale +
// Once that is possible in Greyhound, this will need to be changed. '&offset=[' + offsetString + ']';// +
//+'&scale=' +this.pcoGeometry.scale, //'&compress=true';
//+'&offset=' +this.pcoGeometry.scale;
if (!baseLoaded) { if (!baseLoaded) {
baseLoaded = true; baseLoaded = true;
@ -266,7 +273,7 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct
parentNode.boundingBox, index); parentNode.boundingBox, index);
var currentNode = new Potree.PointCloudGreyhoundGeometryNode( var currentNode = new Potree.PointCloudGreyhoundGeometryNode(
name, pgg, boundingBox); name, pgg, boundingBox, node.scale, node.offset);
currentNode.level = level; currentNode.level = level;
currentNode.numPoints = numPoints; currentNode.numPoints = numPoints;
@ -279,11 +286,21 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct
}; };
if((node.level % node.pcoGeometry.hierarchyStepSize) === 0){ if((node.level % node.pcoGeometry.hierarchyStepSize) === 0){
var depthBegin = node.level + node.pcoGeometry.baseDepth; var depthBegin = node.level + node.pcoGeometry.baseDepth;
var depthEnd = depthBegin + node.pcoGeometry.hierarchyStepSize + 1; var depthEnd = depthBegin + node.pcoGeometry.hierarchyStepSize + 1;
var bb = this.boundingBox; var bb = this.boundingBox;
var offset = node.pcoGeometry.offset; var scale = this.pcoGeometry.scale;
var boundsString = (bb.min.x) + ',' + (bb.min.y) + ',' + (bb.min.z) + ',' + (bb.max.x) + ',' + (bb.max.y) + ',' + (bb.max.z);
// Going back into Greyhound-space, i.e. the space of the actual points
// in the dataset. Add the offset to get there.
var offset = node.offset;
var boundsString =
(bb.min.x * scale + offset.x) + ',' +
(bb.min.y * scale + offset.y) + ',' +
(bb.min.z * scale + offset.z) + ',' +
(bb.max.x * scale + offset.x) + ',' +
(bb.max.y * scale + offset.y) + ',' +
(bb.max.z * scale + offset.z);
var hurl = ''+this.pcoGeometry.serverURL + 'hierarchy?bounds=[' + boundsString + ']' + '&depthBegin=' + depthBegin + '&depthEnd=' + depthEnd; var hurl = ''+this.pcoGeometry.serverURL + 'hierarchy?bounds=[' + boundsString + ']' + '&depthBegin=' + depthBegin + '&depthEnd=' + depthEnd;
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
@ -292,10 +309,10 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === 4) { if (xhr.readyState === 4) {
if (xhr.status === 200 || xhr.status === 0) { if (xhr.status === 200 || xhr.status === 0) {
var greyhoundHierarchy = JSON.parse(xhr.responseText); var greyhoundHierarchy = JSON.parse(xhr.responseText);
callback(node, greyhoundHierarchy); callback(node, greyhoundHierarchy);
} else { } else {
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url); console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
} }
} }
}; };

View File

@ -46,7 +46,7 @@ Potree.GreyhoundBinaryLoader.prototype.parse = function(node, buffer){
var numPoints = (buffer.byteLength - NUM_POINTS_BYTE_SIZE) / node.pcoGeometry.pointAttributes.byteSize; var numPoints = (buffer.byteLength - NUM_POINTS_BYTE_SIZE) / node.pcoGeometry.pointAttributes.byteSize;
var pointAttributes = node.pcoGeometry.pointAttributes; var pointAttributes = node.pcoGeometry.pointAttributes;
node.numPoints = numPoints; node.numPoints = numPoints;
var ww = Potree.workers.greyhoundBinaryDecoder.getWorker(); var ww = Potree.workers.greyhoundBinaryDecoder.getWorker();

View File

@ -1,5 +1,3 @@
/** /**
* @class Loads greyhound metadata and returns a PointcloudOctree * @class Loads greyhound metadata and returns a PointcloudOctree
* *
@ -22,14 +20,14 @@ Potree.GreyhoundLoader.loadInfoJSON = function load(url, callback) {
* @param loadingFinishedListener executed after loading the binary has been finished * @param loadingFinishedListener executed after loading the binary has been finished
*/ */
Potree.GreyhoundLoader.load = function load(url, callback) { Potree.GreyhoundLoader.load = function load(url, callback) {
var HIERARCHY_STEP_SIZE = 3; var HIERARCHY_STEP_SIZE = 5;
var SCALE = 1; var SCALE = .01;
try{ try{
// We assume everything ater the string 'greyhound:' is the server url // We assume everything ater the string 'greyhound://' is the server url
var serverURL = url.split('greyhound:')[1]; var serverURL = url.split('greyhound://')[1];
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('GET', serverURL+'info', true); xhr.open('GET', serverURL + 'info', true);
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if(xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)){ if(xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)){
@ -70,19 +68,31 @@ Potree.GreyhoundLoader.load = function load(url, callback) {
"size": 2, "size": 2,
"type": "unsigned" "type": "unsigned"
}], }],
"srs": "PROJCS[\"NAD_1983_HARN_Lambert_Conformal_Conic\",GEOGCS[\"GCS_North_American_1983_HARN\",DATUM[\"NAD83_High_Accuracy_Regional_Network\",SPHEROID[\"GRS_1980\",6378137,298.257222101,AUTHORITY[\"EPSG\",\"7019\"]],AUTHORITY[\"EPSG\",\"6152\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",43],PARAMETER[\"standard_parallel_2\",45.5],PARAMETER[\"latitude_of_origin\",41.75],PARAMETER[\"central_meridian\",-120.5],PARAMETER[\"false_easting\",1312335.958005249],PARAMETER[\"false_northing\",0],UNIT[\"foot\",0.3048,AUTHORITY[\"EPSG\",\"9002\"]]]", "srs": "<omitted for brevity>",
"type": "octree" "type": "octree"
} }
*/ */
var greyhoundInfo = JSON.parse(xhr.responseText); var greyhoundInfo = JSON.parse(xhr.responseText);
var version = new Potree.Version('1.4'); var version = new Potree.Version('1.4');
var bounds = greyhoundInfo.bounds; var globalBounds = greyhoundInfo.bounds;
// Center around the origin.
var offset = [
globalBounds[0] + (globalBounds[3] - globalBounds[0]) / 2,
globalBounds[1] + (globalBounds[4] - globalBounds[1]) / 2,
globalBounds[2] + (globalBounds[5] - globalBounds[2]) / 2
];
var localBounds = globalBounds.map(function(v, i) {
return (v - offset[i % 3]) / SCALE;
});
var baseDepth = Math.max(8, greyhoundInfo.baseDepth); var baseDepth = Math.max(8, greyhoundInfo.baseDepth);
var pgg = new Potree.PointCloudGreyhoundGeometry(); var pgg = new Potree.PointCloudGreyhoundGeometry();
pgg.serverURL = serverURL; pgg.serverURL = serverURL;
pgg.spacing = (bounds[3]-bounds[0])/2^baseDepth; pgg.spacing = (localBounds[3]-localBounds[0])/2^baseDepth;
pgg.baseDepth = baseDepth; pgg.baseDepth = baseDepth;
pgg.hierarchyStepSize = HIERARCHY_STEP_SIZE; pgg.hierarchyStepSize = HIERARCHY_STEP_SIZE;
@ -126,17 +136,22 @@ Potree.GreyhoundLoader.load = function load(url, callback) {
} }
pgg.pointAttributes = new Potree.PointAttributes(attributes); pgg.pointAttributes = new Potree.PointAttributes(attributes);
var min = new THREE.Vector3(bounds[0], bounds[1], bounds[2]); var min = new THREE.Vector3(
var max = new THREE.Vector3(bounds[3], bounds[4], bounds[5]); localBounds[0], localBounds[1], localBounds[2]);
var max = new THREE.Vector3(
localBounds[3], localBounds[4], localBounds[5]);
var offset = new THREE.Vector3(offset[0], offset[1], offset[2]);
var boundingBox = new THREE.Box3(min, max); var boundingBox = new THREE.Box3(min, max);
var tightBoundingBox = boundingBox.clone(); var tightBoundingBox = boundingBox.clone();
var nodeOffset = new THREE.Vector3(0,0,0); // var nodeOffset = new THREE.Vector3(0,0,0);
var globalOffset = new THREE.Vector3(0,0,0); // var globalOffset = new THREE.Vector3(0,0,0);
var extent = {'x': max.x - min.x, 'y': max.y - min.y, 'z': max.z - min.z}; var extent = {
'x': max.x - min.x,
globalOffset.set(min.x, min.y, min.z); 'y': max.y - min.y,
'z': max.z - min.z
};
pgg.projection = greyhoundInfo.srs; pgg.projection = greyhoundInfo.srs;
pgg.boundingBox = boundingBox; pgg.boundingBox = boundingBox;
@ -146,18 +161,20 @@ Potree.GreyhoundLoader.load = function load(url, callback) {
// Ideally, we would want to be able to ask for a scale and an offset as well. // Ideally, we would want to be able to ask for a scale and an offset as well.
// Once that is possible in Greyhound, this will need to be changed. // Once that is possible in Greyhound, this will need to be changed.
pgg.bbOffset = globalOffset; pgg.bbOffset = new THREE.Vector3(0,0,0);
pgg.offset = nodeOffset; pgg.offset = new THREE.Vector3(0,0,0);
pgg.scale = SCALE; //greyhoundInfo.scale; pgg.scale = SCALE; //greyhoundInfo.scale;
pgg.loader = new Potree.GreyhoundBinaryLoader(version, boundingBox, pgg.scale); pgg.loader = new Potree.GreyhoundBinaryLoader(
version, boundingBox, pgg.scale);
var nodes = {}; var nodes = {};
{ // load root { // load root
var name = "r"; var name = "r";
var root = new Potree.PointCloudGreyhoundGeometryNode(name, pgg, boundingBox); var root = new Potree.PointCloudGreyhoundGeometryNode(
name, pgg, boundingBox, pgg.scale, offset);
root.level = 0; root.level = 0;
root.hasChildren = true; root.hasChildren = true;
root.numPoints = greyhoundInfo.numPoints; root.numPoints = greyhoundInfo.numPoints;

View File

@ -168,7 +168,7 @@ Potree.Viewer = function(domElement, args){
// load pointcloud // load pointcloud
if(!path){ if(!path){
}else if(path.indexOf("greyhound:") === 0){ }else if(path.indexOf("greyhound://") === 0){
// We check if the path string starts with 'greyhound:', if so we assume it's a greyhound server URL. // We check if the path string starts with 'greyhound:', if so we assume it's a greyhound server URL.
Potree.GreyhoundLoader.load(path, function(geometry) { Potree.GreyhoundLoader.load(path, function(geometry) {
if(!geometry){ if(!geometry){

View File

@ -30,27 +30,37 @@ function CustomView(buffer) {
}; };
} }
function networkToNative(val) {
return ((val & 0x00FF) << 24) |
((val & 0xFF00) << 8) |
((val >> 8) & 0xFF00) |
((val >> 24) & 0x00FF);
}
Potree = {}; Potree = {};
onmessage = function(event){ onmessage = function(event){
var NUM_POINTS_BYTE_SIZE = 4; var NUM_POINTS_BYTES = 4;
var buffer = event.data.buffer; var buffer = event.data.buffer;
var pointAttributes = event.data.pointAttributes; var pointAttributes = event.data.pointAttributes;
var numPoints = (buffer.byteLength - NUM_POINTS_BYTE_SIZE) / pointAttributes.byteSize;
var view = new DataView(buffer, buffer.byteLength - NUM_POINTS_BYTES, NUM_POINTS_BYTES);
var numPoints = networkToNative(view.getUint32(0));
buffer = buffer.slice(0, buffer.byteLength - NUM_POINTS_BYTES);
// TODO Decompress buffer here.
var cv = new CustomView(buffer); var cv = new CustomView(buffer);
var version = new Potree.Version(event.data.version); var version = new Potree.Version(event.data.version);
var min = event.data.min; var min = event.data.min;
var max = event.data.max; var max = event.data.max;
var nodeOffset = event.data.offset; var nodeOffset = event.data.offset;
var bbOffset = event.data.bbOffset;
var scale = event.data.scale; var scale = event.data.scale;
var tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]; var tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];
var tightBoxMax = [ Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY ]; var tightBoxMax = [ Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY ];
var extent = {'x': max[0] - min[0], 'y': max[1] - min[1], 'z': max[2] - min[2]};
var attributeBuffers = {}; var attributeBuffers = {};
var offset = 0; var offset = 0;
@ -64,9 +74,9 @@ onmessage = function(event){
var positions = new Float32Array(buff); var positions = new Float32Array(buff);
for (var j = 0; j < numPoints; j++) { for (var j = 0; j < numPoints; j++) {
positions[3*j+0] = (cv.getUint32(offset + j*pointAttributes.byteSize+0) - nodeOffset[0]); positions[3*j+0] = (cv.getUint32(offset + j*pointAttributes.byteSize+0) /*- nodeOffset[0]*/);
positions[3*j+1] = (cv.getUint32(offset + j*pointAttributes.byteSize+4) - nodeOffset[1]); positions[3*j+1] = (cv.getUint32(offset + j*pointAttributes.byteSize+4) /*- nodeOffset[1]*/);
positions[3*j+2] = (cv.getUint32(offset + j*pointAttributes.byteSize+8) - nodeOffset[2]); positions[3*j+2] = (cv.getUint32(offset + j*pointAttributes.byteSize+8) /*- nodeOffset[2]*/);
tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3*j+0]); tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3*j+0]);
tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3*j+1]); tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3*j+1]);