Add offset and scaling based on new Greyhound API.
This commit is contained in:
parent
6abe9c4a85
commit
c43f8e8e1c
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
14
build/potree/potree.min.js
vendored
14
build/potree/potree.min.js
vendored
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
@ -72,9 +72,10 @@
|
||||
viewer.setDescription("");
|
||||
//viewer.setMinNodeSize(5);
|
||||
|
||||
// Since this parameter to addPointCloud starts with the string 'greyhound:', it
|
||||
// is recognised as a greyhound server URL
|
||||
viewer.addPointCloud("greyhound:http://dev.greyhound.io/resource/autzen/");
|
||||
// Since this parameter to addPointCloud starts with the string
|
||||
// 'greyhound://', it is recognised as a greyhound server URL.
|
||||
viewer.addPointCloud(
|
||||
"greyhound://http://localhost:8080/resource/autzen-calc/");
|
||||
|
||||
viewer.loadGUI();
|
||||
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
var nodesLoadTimes = {};
|
||||
var baseLoaded = false;
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode = function(name, pcoGeometry, boundingBox){
|
||||
Potree.PointCloudGreyhoundGeometryNode = function(
|
||||
name, pcoGeometry, boundingBox, scale, offset){
|
||||
this.id = Potree.PointCloudGreyhoundGeometryNode.IDCount++;
|
||||
this.name = name;
|
||||
this.index = parseInt(name.charAt(name.length-1));
|
||||
@ -9,6 +10,8 @@ Potree.PointCloudGreyhoundGeometryNode = function(name, pcoGeometry, boundingBox
|
||||
this.geometry = null;
|
||||
this.boundingBox = boundingBox;
|
||||
this.boundingSphere = boundingBox.getBoundingSphere();
|
||||
this.scale = scale;
|
||||
this.offset = offset;
|
||||
this.children = {};
|
||||
this.numPoints = 0;
|
||||
this.level = null;
|
||||
@ -52,10 +55,6 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.getChildren = function(){
|
||||
return children;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getBoundingBox = function(){
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getURL = function(){
|
||||
//Determine what schema to ask the greyhound server for.
|
||||
var material = viewer.getMaterial();
|
||||
@ -119,20 +118,28 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.getURL = function(){
|
||||
}.bind(this));
|
||||
|
||||
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 +
|
||||
'read?depthBegin=' +
|
||||
(baseLoaded ? (this.level + this.pcoGeometry.baseDepth) : 0) +
|
||||
'&depthEnd=' + (this.level + this.pcoGeometry.baseDepth + 1) +
|
||||
'&bounds=[' + boundsString + ']' +
|
||||
'&schema='+JSON.stringify(schema);
|
||||
// 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.
|
||||
//+'&scale=' +this.pcoGeometry.scale,
|
||||
//+'&offset=' +this.pcoGeometry.scale;
|
||||
'&schema=' + JSON.stringify(schema) +
|
||||
'&scale=' + scale +
|
||||
'&offset=[' + offsetString + ']';// +
|
||||
//'&compress=true';
|
||||
|
||||
if (!baseLoaded) {
|
||||
baseLoaded = true;
|
||||
@ -266,7 +273,7 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct
|
||||
parentNode.boundingBox, index);
|
||||
|
||||
var currentNode = new Potree.PointCloudGreyhoundGeometryNode(
|
||||
name, pgg, boundingBox);
|
||||
name, pgg, boundingBox, node.scale, node.offset);
|
||||
|
||||
currentNode.level = level;
|
||||
currentNode.numPoints = numPoints;
|
||||
@ -279,11 +286,21 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct
|
||||
|
||||
};
|
||||
if((node.level % node.pcoGeometry.hierarchyStepSize) === 0){
|
||||
var depthBegin = node.level + node.pcoGeometry.baseDepth;
|
||||
var depthEnd = depthBegin + node.pcoGeometry.hierarchyStepSize + 1;
|
||||
var bb = this.boundingBox;
|
||||
var offset = node.pcoGeometry.offset;
|
||||
var boundsString = (bb.min.x) + ',' + (bb.min.y) + ',' + (bb.min.z) + ',' + (bb.max.x) + ',' + (bb.max.y) + ',' + (bb.max.z);
|
||||
var depthBegin = node.level + node.pcoGeometry.baseDepth;
|
||||
var depthEnd = depthBegin + node.pcoGeometry.hierarchyStepSize + 1;
|
||||
var bb = this.boundingBox;
|
||||
var scale = this.pcoGeometry.scale;
|
||||
|
||||
// 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 xhr = new XMLHttpRequest();
|
||||
@ -292,10 +309,10 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = funct
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
var greyhoundHierarchy = JSON.parse(xhr.responseText);
|
||||
callback(node, greyhoundHierarchy);
|
||||
var greyhoundHierarchy = JSON.parse(xhr.responseText);
|
||||
callback(node, greyhoundHierarchy);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -46,7 +46,7 @@ Potree.GreyhoundBinaryLoader.prototype.parse = function(node, buffer){
|
||||
var numPoints = (buffer.byteLength - NUM_POINTS_BYTE_SIZE) / node.pcoGeometry.pointAttributes.byteSize;
|
||||
var pointAttributes = node.pcoGeometry.pointAttributes;
|
||||
|
||||
node.numPoints = numPoints;
|
||||
node.numPoints = numPoints;
|
||||
|
||||
|
||||
var ww = Potree.workers.greyhoundBinaryDecoder.getWorker();
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
Potree.GreyhoundLoader.load = function load(url, callback) {
|
||||
var HIERARCHY_STEP_SIZE = 3;
|
||||
var SCALE = 1;
|
||||
var HIERARCHY_STEP_SIZE = 5;
|
||||
var SCALE = .01;
|
||||
|
||||
try{
|
||||
// We assume everything ater the string 'greyhound:' is the server url
|
||||
var serverURL = url.split('greyhound:')[1];
|
||||
// We assume everything ater the string 'greyhound://' is the server url
|
||||
var serverURL = url.split('greyhound://')[1];
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', serverURL+'info', true);
|
||||
xhr.open('GET', serverURL + 'info', true);
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if(xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)){
|
||||
@ -70,19 +68,31 @@ Potree.GreyhoundLoader.load = function load(url, callback) {
|
||||
"size": 2,
|
||||
"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"
|
||||
}
|
||||
*/
|
||||
var greyhoundInfo = JSON.parse(xhr.responseText);
|
||||
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 pgg = new Potree.PointCloudGreyhoundGeometry();
|
||||
pgg.serverURL = serverURL;
|
||||
pgg.spacing = (bounds[3]-bounds[0])/2^baseDepth;
|
||||
pgg.spacing = (localBounds[3]-localBounds[0])/2^baseDepth;
|
||||
pgg.baseDepth = baseDepth;
|
||||
pgg.hierarchyStepSize = HIERARCHY_STEP_SIZE;
|
||||
|
||||
@ -126,17 +136,22 @@ Potree.GreyhoundLoader.load = function load(url, callback) {
|
||||
}
|
||||
pgg.pointAttributes = new Potree.PointAttributes(attributes);
|
||||
|
||||
var min = new THREE.Vector3(bounds[0], bounds[1], bounds[2]);
|
||||
var max = new THREE.Vector3(bounds[3], bounds[4], bounds[5]);
|
||||
var min = new THREE.Vector3(
|
||||
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 tightBoundingBox = boundingBox.clone();
|
||||
|
||||
var nodeOffset = new THREE.Vector3(0,0,0);
|
||||
var globalOffset = new THREE.Vector3(0,0,0);
|
||||
// var nodeOffset = 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};
|
||||
|
||||
globalOffset.set(min.x, min.y, min.z);
|
||||
var extent = {
|
||||
'x': max.x - min.x,
|
||||
'y': max.y - min.y,
|
||||
'z': max.z - min.z
|
||||
};
|
||||
|
||||
pgg.projection = greyhoundInfo.srs;
|
||||
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.
|
||||
// Once that is possible in Greyhound, this will need to be changed.
|
||||
pgg.bbOffset = globalOffset;
|
||||
pgg.offset = nodeOffset;
|
||||
pgg.bbOffset = new THREE.Vector3(0,0,0);
|
||||
pgg.offset = new THREE.Vector3(0,0,0);
|
||||
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 = {};
|
||||
|
||||
{ // load root
|
||||
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.hasChildren = true;
|
||||
root.numPoints = greyhoundInfo.numPoints;
|
||||
|
||||
@ -168,7 +168,7 @@ Potree.Viewer = function(domElement, args){
|
||||
// load pointcloud
|
||||
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.
|
||||
Potree.GreyhoundLoader.load(path, function(geometry) {
|
||||
if(!geometry){
|
||||
|
||||
@ -30,27 +30,37 @@ function CustomView(buffer) {
|
||||
};
|
||||
}
|
||||
|
||||
function networkToNative(val) {
|
||||
return ((val & 0x00FF) << 24) |
|
||||
((val & 0xFF00) << 8) |
|
||||
((val >> 8) & 0xFF00) |
|
||||
((val >> 24) & 0x00FF);
|
||||
}
|
||||
|
||||
Potree = {};
|
||||
|
||||
|
||||
onmessage = function(event){
|
||||
var NUM_POINTS_BYTE_SIZE = 4;
|
||||
var NUM_POINTS_BYTES = 4;
|
||||
|
||||
var buffer = event.data.buffer;
|
||||
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 version = new Potree.Version(event.data.version);
|
||||
var min = event.data.min;
|
||||
var max = event.data.max;
|
||||
var nodeOffset = event.data.offset;
|
||||
var bbOffset = event.data.bbOffset;
|
||||
var scale = event.data.scale;
|
||||
var tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_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 offset = 0;
|
||||
@ -64,9 +74,9 @@ onmessage = function(event){
|
||||
var positions = new Float32Array(buff);
|
||||
|
||||
for (var j = 0; j < numPoints; j++) {
|
||||
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+2] = (cv.getUint32(offset + j*pointAttributes.byteSize+8) - nodeOffset[2]);
|
||||
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+2] = (cv.getUint32(offset + j*pointAttributes.byteSize+8) /*- nodeOffset[2]*/);
|
||||
|
||||
tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3*j+0]);
|
||||
tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3*j+1]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user