diff --git a/libs/shapefile/shapefile.js b/libs/shapefile/shapefile.js new file mode 100644 index 00000000..8c0713a1 --- /dev/null +++ b/libs/shapefile/shapefile.js @@ -0,0 +1,469 @@ +// https://github.com/mbostock/shapefile Version 0.6.2. Copyright 2017 Mike Bostock. +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (factory((global.shapefile = global.shapefile || {}))); +}(this, (function (exports) { 'use strict'; + +var array_cancel = function() { + this._array = null; + return Promise.resolve(); +}; + +var array_read = function() { + var array = this._array; + this._array = null; + return Promise.resolve(array ? {done: false, value: array} : {done: true, value: undefined}); +}; + +function array(array) { + return new ArraySource(array instanceof Uint8Array ? array : new Uint8Array(array)); +} + +function ArraySource(array) { + this._array = array; +} + +ArraySource.prototype.read = array_read; +ArraySource.prototype.cancel = array_cancel; + +var fetchPath = function(url) { + return fetch(url).then(function(response) { + return response.body && response.body.getReader + ? response.body.getReader() + : response.arrayBuffer().then(array); + }); +}; + +var requestPath = function(url) { + return new Promise(function(resolve, reject) { + var request = new XMLHttpRequest; + request.responseType = "arraybuffer"; + request.onload = function() { resolve(array(request.response)); }; + request.onerror = reject; + request.ontimeout = reject; + request.open("GET", url, true); + request.send(); + }); +}; + +function path(path) { + return (typeof fetch === "function" ? fetchPath : requestPath)(path); +} + +function stream(source) { + return typeof source.read === "function" ? source : source.getReader(); +} + +var empty = new Uint8Array(0); + +var slice_cancel = function() { + return this._source.cancel(); +}; + +function concat(a, b) { + if (!a.length) return b; + if (!b.length) return a; + var c = new Uint8Array(a.length + b.length); + c.set(a); + c.set(b, a.length); + return c; +} + +var slice_read = function() { + var that = this, array = that._array.subarray(that._index); + return that._source.read().then(function(result) { + that._array = empty; + that._index = 0; + return result.done ? (array.length > 0 + ? {done: false, value: array} + : {done: true, value: undefined}) + : {done: false, value: concat(array, result.value)}; + }); +}; + +var slice_slice = function(length) { + if ((length |= 0) < 0) throw new Error("invalid length"); + var that = this, index = this._array.length - this._index; + + // If the request fits within the remaining buffer, resolve it immediately. + if (this._index + length <= this._array.length) { + return Promise.resolve(this._array.subarray(this._index, this._index += length)); + } + + // Otherwise, read chunks repeatedly until the request is fulfilled. + var array = new Uint8Array(length); + array.set(this._array.subarray(this._index)); + return (function read() { + return that._source.read().then(function(result) { + + // When done, it’s possible the request wasn’t fully fullfilled! + // If so, the pre-allocated array is too big and needs slicing. + if (result.done) { + that._array = empty; + that._index = 0; + return index > 0 ? array.subarray(0, index) : null; + } + + // If this chunk fulfills the request, return the resulting array. + if (index + result.value.length >= length) { + that._array = result.value; + that._index = length - index; + array.set(result.value.subarray(0, length - index), index); + return array; + } + + // Otherwise copy this chunk into the array, then read the next chunk. + array.set(result.value, index); + index += result.value.length; + return read(); + }); + })(); +}; + +function slice(source) { + return typeof source.slice === "function" ? source : + new SliceSource(typeof source.read === "function" ? source + : source.getReader()); +} + +function SliceSource(source) { + this._source = source; + this._array = empty; + this._index = 0; +} + +SliceSource.prototype.read = slice_read; +SliceSource.prototype.slice = slice_slice; +SliceSource.prototype.cancel = slice_cancel; + +var dbf_cancel = function() { + return this._source.cancel(); +}; + +var readBoolean = function(value) { + return /^[nf]$/i.test(value) ? false + : /^[yt]$/i.test(value) ? true + : null; +}; + +var readDate = function(value) { + return new Date(+value.substring(0, 4), value.substring(4, 6) - 1, +value.substring(6, 8)); +}; + +var readNumber = function(value) { + return !(value = value.trim()) || isNaN(value = +value) ? null : value; +}; + +var readString = function(value) { + return value.trim() || null; +}; + +var types = { + B: readNumber, + C: readString, + D: readDate, + F: readNumber, + L: readBoolean, + M: readNumber, + N: readNumber +}; + +var dbf_read = function() { + var that = this, i = 1; + return that._source.slice(that._recordLength).then(function(value) { + return value && (value[0] !== 0x1a) ? {done: false, value: that._fields.reduce(function(p, f) { + p[f.name] = types[f.type](that._decode(value.subarray(i, i += f.length))); + return p; + }, {})} : {done: true, value: undefined}; + }); +}; + +var view = function(array) { + return new DataView(array.buffer, array.byteOffset, array.byteLength); +}; + +var dbf = function(source, decoder) { + source = slice(source); + return source.slice(32).then(function(array) { + var head = view(array); + return source.slice(head.getUint16(8, true) - 32).then(function(array) { + return new Dbf(source, decoder, head, view(array)); + }); + }); +}; + +function Dbf(source, decoder, head, body) { + this._source = source; + this._decode = decoder.decode.bind(decoder); + this._recordLength = head.getUint16(10, true); + this._fields = []; + for (var n = 0; body.getUint8(n) !== 0x0d; n += 32) { + for (var j = 0; j < 11; ++j) if (body.getUint8(n + j) === 0) break; + this._fields.push({ + name: this._decode(new Uint8Array(body.buffer, body.byteOffset + n, j)), + type: String.fromCharCode(body.getUint8(n + 11)), + length: body.getUint8(n + 16) + }); + } +} + +var prototype = Dbf.prototype; +prototype.read = dbf_read; +prototype.cancel = dbf_cancel; + +function cancel() { + return this._source.cancel(); +} + +var readMultiPoint = function(record) { + var i = 40, j, n = record.getInt32(36, true), coordinates = new Array(n); + for (j = 0; j < n; ++j, i += 16) coordinates[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true)]; + return {type: "MultiPoint", coordinates: coordinates}; +}; + +var readNull = function() { + return null; +}; + +var readPoint = function(record) { + return {type: "Point", coordinates: [record.getFloat64(4, true), record.getFloat64(12, true)]}; +}; + +var readPolygon = function(record) { + var i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m), polygons = [], holes = []; + for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true); + for (j = 0; j < m; ++j, i += 16) points[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true)]; + + parts.forEach(function(i, j) { + var ring = points.slice(i, parts[j + 1]); + if (ringClockwise(ring)) polygons.push([ring]); + else holes.push(ring); + }); + + holes.forEach(function(hole) { + polygons.some(function(polygon) { + if (ringContainsSome(polygon[0], hole)) { + polygon.push(hole); + return true; + } + }) || polygons.push([hole]); + }); + + return polygons.length === 1 + ? {type: "Polygon", coordinates: polygons[0]} + : {type: "MultiPolygon", coordinates: polygons}; +}; + +function ringClockwise(ring) { + if ((n = ring.length) < 4) return false; + var i = 0, n, area = ring[n - 1][1] * ring[0][0] - ring[n - 1][0] * ring[0][1]; + while (++i < n) area += ring[i - 1][1] * ring[i][0] - ring[i - 1][0] * ring[i][1]; + return area >= 0; +} + +function ringContainsSome(ring, hole) { + var i = -1, n = hole.length, c; + while (++i < n) { + if (c = ringContains(ring, hole[i])) { + return c > 0; + } + } + return false; +} + +function ringContains(ring, point) { + var x = point[0], y = point[1], contains = -1; + for (var i = 0, n = ring.length, j = n - 1; i < n; j = i++) { + var pi = ring[i], xi = pi[0], yi = pi[1], + pj = ring[j], xj = pj[0], yj = pj[1]; + if (segmentContains(pi, pj, point)) { + return 0; + } + if (((yi > y) !== (yj > y)) && ((x < (xj - xi) * (y - yi) / (yj - yi) + xi))) { + contains = -contains; + } + } + return contains; +} + +function segmentContains(p0, p1, p2) { + var x20 = p2[0] - p0[0], y20 = p2[1] - p0[1]; + if (x20 === 0 && y20 === 0) return true; + var x10 = p1[0] - p0[0], y10 = p1[1] - p0[1]; + if (x10 === 0 && y10 === 0) return false; + var t = (x20 * x10 + y20 * y10) / (x10 * x10 + y10 * y10); + return t < 0 || t > 1 ? false : t === 0 || t === 1 ? true : t * x10 === x20 && t * y10 === y20; +} + +var readPolyLine = function(record) { + var i = 44, j, n = record.getInt32(36, true), m = record.getInt32(40, true), parts = new Array(n), points = new Array(m); + for (j = 0; j < n; ++j, i += 4) parts[j] = record.getInt32(i, true); + for (j = 0; j < m; ++j, i += 16) points[j] = [record.getFloat64(i, true), record.getFloat64(i + 8, true)]; + return n === 1 + ? {type: "LineString", coordinates: points} + : {type: "MultiLineString", coordinates: parts.map(function(i, j) { return points.slice(i, parts[j + 1]); })}; +}; + +var shp_read = function() { + var that = this; + return that._source.slice(8).then(function(array) { + if (array == null) return {done: true, value: undefined}; + var header = view(array); + return that._source.slice(header.getInt32(4, false) * 2).then(function(array) { + var record = view(array); + return {done: false, value: record.getInt32(0, true) ? that._type(record) : readNull()}; + }); + }); +}; + +var types$1 = { + 0: readNull, + 1: readPoint, + 3: readPolyLine, + 5: readPolygon, + 8: readMultiPoint, + 11: readPoint, + 13: readPolyLine, + 15: readPolygon, + 18: readMultiPoint +}; + +var shp = function(source) { + source = slice(source); + return source.slice(100).then(function(array) { + return new Shp(source, view(array)); + }); +}; + +function Shp(source, header) { + var type = header.getInt32(32, true); + if (!(type in types$1)) throw new Error("unsupported shape type: " + type); + this._source = source; + this._type = types$1[type]; + this.bbox = [header.getFloat64(36, true), header.getFloat64(44, true), header.getFloat64(52, true), header.getFloat64(60, true)]; +} + +var prototype$2 = Shp.prototype; +prototype$2.read = shp_read; +prototype$2.cancel = cancel; + +function noop() {} + +var shapefile_cancel = function() { + return Promise.all([ + this._dbf && this._dbf.cancel(), + this._shp.cancel() + ]).then(noop); +}; + +var shapefile_read = function() { + var that = this; + return Promise.all([ + that._dbf ? that._dbf.read() : {value: {}}, + that._shp.read() + ]).then(function(results) { + var dbf = results[0], shp = results[1]; + return shp.done ? shp : { + done: false, + value: { + type: "Feature", + properties: dbf.value, + geometry: shp.value + } + }; + }); +}; + +var shapefile = function(shpSource, dbfSource, decoder) { + return Promise.all([ + shp(shpSource), + dbfSource && dbf(dbfSource, decoder) + ]).then(function(sources) { + return new Shapefile(sources[0], sources[1]); + }); +}; + +function Shapefile(shp$$1, dbf$$1) { + this._shp = shp$$1; + this._dbf = dbf$$1; + this.bbox = shp$$1.bbox; +} + +var prototype$1 = Shapefile.prototype; +prototype$1.read = shapefile_read; +prototype$1.cancel = shapefile_cancel; + +function open(shp$$1, dbf$$1, options) { + if (typeof dbf$$1 === "string") { + if (!/\.dbf$/.test(dbf$$1)) dbf$$1 += ".dbf"; + dbf$$1 = path(dbf$$1, options); + } else if (dbf$$1 instanceof ArrayBuffer || dbf$$1 instanceof Uint8Array) { + dbf$$1 = array(dbf$$1); + } else if (dbf$$1 != null) { + dbf$$1 = stream(dbf$$1); + } + if (typeof shp$$1 === "string") { + if (!/\.shp$/.test(shp$$1)) shp$$1 += ".shp"; + if (dbf$$1 === undefined) dbf$$1 = path(shp$$1.substring(0, shp$$1.length - 4) + ".dbf", options).catch(function() {}); + shp$$1 = path(shp$$1, options); + } else if (shp$$1 instanceof ArrayBuffer || shp$$1 instanceof Uint8Array) { + shp$$1 = array(shp$$1); + } else { + shp$$1 = stream(shp$$1); + } + return Promise.all([shp$$1, dbf$$1]).then(function(sources) { + var shp$$1 = sources[0], dbf$$1 = sources[1], encoding = "windows-1252"; + if (options && options.encoding != null) encoding = options.encoding; + return shapefile(shp$$1, dbf$$1, dbf$$1 && new TextDecoder(encoding)); + }); +} + +function openShp(source, options) { + if (typeof source === "string") { + if (!/\.shp$/.test(source)) source += ".shp"; + source = path(source, options); + } else if (source instanceof ArrayBuffer || source instanceof Uint8Array) { + source = array(source); + } else { + source = stream(source); + } + return Promise.resolve(source).then(shp); +} + +function openDbf(source, options) { + var encoding = "windows-1252"; + if (options && options.encoding != null) encoding = options.encoding; + encoding = new TextDecoder(encoding); + if (typeof source === "string") { + if (!/\.dbf$/.test(source)) source += ".dbf"; + source = path(source, options); + } else if (source instanceof ArrayBuffer || source instanceof Uint8Array) { + source = array(source); + } else { + source = stream(source); + } + return Promise.resolve(source).then(function(source) { + return dbf(source, encoding); + }); +} + +function read(shp$$1, dbf$$1, options) { + return open(shp$$1, dbf$$1, options).then(function(source) { + var features = [], collection = {type: "FeatureCollection", features: features, bbox: source.bbox}; + return source.read().then(function read(result) { + if (result.done) return collection; + features.push(result.value); + return source.read().then(read); + }); + }); +} + +exports.open = open; +exports.openShp = openShp; +exports.openDbf = openDbf; +exports.read = read; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); \ No newline at end of file diff --git a/resources/shapefiles/south_sorvilier.dbf b/resources/shapefiles/south_sorvilier.dbf new file mode 100644 index 00000000..d8d8f359 Binary files /dev/null and b/resources/shapefiles/south_sorvilier.dbf differ diff --git a/resources/shapefiles/south_sorvilier.shp b/resources/shapefiles/south_sorvilier.shp new file mode 100644 index 00000000..89cece3f Binary files /dev/null and b/resources/shapefiles/south_sorvilier.shp differ diff --git a/src/Annotation.js b/src/Annotation.js index d736f48a..360364ce 100644 --- a/src/Annotation.js +++ b/src/Annotation.js @@ -224,10 +224,13 @@ Potree.Annotation = class extends THREE.EventDispatcher{ if(!this.hasView()){ return; } - + + let view = this.scene.view; + var animationDuration = 800; var easing = TWEEN.Easing.Quartic.Out; + let endTarget; if(this.cameraTarget){ endTarget = this.cameraTarget; @@ -236,37 +239,61 @@ Potree.Annotation = class extends THREE.EventDispatcher{ }else{ endTarget = this.boundingBox.getCenter(); } - let endPosition = this.cameraPosition; - if(!endPosition){ - let direction = this.scene.view.direction; - endPosition = endTarget.clone().add(direction.multiplyScalar(-this.radius)); - } - - { // animate camera position - let tween = new TWEEN.Tween(this.scene.view.position).to(endPosition, animationDuration); - tween.easing(easing); - tween.start(); - } - { // animate camera target - var camTargetDistance = camera.position.distanceTo(endTarget); - var target = new THREE.Vector3().addVectors( - camera.position, - camera.getWorldDirection().clone().multiplyScalar(camTargetDistance) - ); - var tween = new TWEEN.Tween(target).to(endTarget, animationDuration); - tween.easing(easing); - tween.onUpdate(() => { - this.scene.view.lookAt(target); - }); - tween.onComplete(() => { - this.scene.view.lookAt(target); - this.dispatchEvent({type: "focusing_finished", target: this}); - }); + if(this.cameraPosition){ + + let endPosition = this.cameraPosition; + + { // animate camera position + let tween = new TWEEN.Tween(view.position).to(endPosition, animationDuration); + tween.easing(easing); + tween.start(); + } + + { // animate camera target + var camTargetDistance = camera.position.distanceTo(endTarget); + var target = new THREE.Vector3().addVectors( + camera.position, + camera.getWorldDirection().clone().multiplyScalar(camTargetDistance) + ); + var tween = new TWEEN.Tween(target).to(endTarget, animationDuration); + tween.easing(easing); + tween.onUpdate(() => { + view.lookAt(target); + }); + tween.onComplete(() => { + view.lookAt(target); + this.dispatchEvent({type: "focusing_finished", target: this}); + }); + + this.dispatchEvent({type: "focusing_started", target: this}); + tween.start(); + } + }else if(this.radius){ + let direction = view.direction; + let endPosition = endTarget.clone().add(direction.multiplyScalar(-this.radius)); + let startRadius = view.radius; + let endRadius = this.radius; + + { // animate camera position + let tween = new TWEEN.Tween(view.position).to(endPosition, animationDuration); + tween.easing(easing); + tween.start(); + } + + { // animate radius + let t = {x: 0}; + + let tween = new TWEEN.Tween(t) + .to({x: 1}, animationDuration) + .onUpdate(function(){ + view.radius = this.x * endRadius + (1 - this.x) * startRadius; + }); + tween.easing(easing); + tween.start(); + } + } - - this.dispatchEvent({type: "focusing_started", target: this}); - tween.start(); }; dispose(){ diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index 394b805a..a5c80261 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -98,7 +98,12 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree{ toTreeNode(geometryNode, parent){ var node = new Potree.PointCloudOctreeNode(); + + //if(geometryNode.name === "r40206"){ + // console.log("creating node for r40206"); + //} var sceneNode = new THREE.Points(geometryNode.geometry, this.material); + sceneNode.name = geometryNode.name; node.geometryNode = geometryNode; node.sceneNode = sceneNode; @@ -857,6 +862,8 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree{ gl.enableVertexAttribArray( apIndices ); } + //renderer.resetGLState(); + for(let i = 0; i < nodes.length; i++){ let node = nodes[i]; let object = node.sceneNode; @@ -900,9 +907,10 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree{ gl.uniform1f(uniforms["pcIndex"], pickMaterial.pcIndex); - let numPoints = node.getNumPoints(); + //let numPoints = node.getNumPoints(); + let numPoints = geometry.attributes.position.count; if(numPoints > 0){ - gl.drawArrays( gl.POINTS, 0, node.getNumPoints()); + gl.drawArrays( gl.POINTS, 0, numPoints); } // TODO hack @@ -929,7 +937,7 @@ Potree.PointCloudOctree = class extends Potree.PointCloudTree{ // renderer.context.readPixels( 0, 0, width, height, // renderer.context.RGBA, renderer.context.UNSIGNED_BYTE, bp); // - // var img = pixelsArrayToImage(bp, width, height); + // var img = Potree.utils.pixelsArrayToImage(bp, width, height); // var screenshot = img.src; // // var w = window.open(); diff --git a/src/Potree.js b/src/Potree.js index 841ea5f2..a7975d19 100644 --- a/src/Potree.js +++ b/src/Potree.js @@ -375,6 +375,21 @@ Potree.updateVisibility = function(pointclouds, camera, renderer){ unloadedGeometry[i].load(); } + for(let node of visibleNodes){ + //let allowedNodes = ["r", "r0", "r4", "r04", "r40", "r402", "r4020", "r4022", "r40206", "r40224", "r40202", "r40220", "r00", "r042"]; + //let allowedNodes = ["r", "r0", "r4", "r04", "r40", "r402", "r4020", "r4022", "r00", "r042"]; + //let allowedNodes = ["r", "r0", "r04", "r042"]; + let allowedNodes = ["r", "r4", "r40", "r402", "r4020", "r40206"]; + //let allowedNodes = ["r", "r4", "r40", "r402", "r4020"]; + node.sceneNode.visible = allowedNodes.includes(node.geometryNode.name); + + if(node.boundingBoxNode){ + node.boundingBoxNode.visible = node.boundingBoxNode.visible && node.sceneNode.visible; + } + + } + + Potree.updateDEMs(renderer, visibleNodes); return { diff --git a/src/loader/GreyhoundLoader.js b/src/loader/GreyhoundLoader.js index 223adca0..32cfb9f6 100644 --- a/src/loader/GreyhoundLoader.js +++ b/src/loader/GreyhoundLoader.js @@ -5,131 +5,136 @@ * @author Oscar Martinez Rubi * @author Connor Manning */ -var getQueryParam = function(name) { - name = name.replace(/[\[\]]/g, "\\$&"); - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), - results = regex.exec(window.location.href); - if (!results) return null; - if (!results[2]) return ''; - return decodeURIComponent(results[2].replace(/\+/g, " ")); -} + +class GreyhoundUtils{ + + static getQueryParam(name) { + name = name.replace(/[\[\]]/g, "\\$&"); + var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), + results = regex.exec(window.location.href); + if (!results) return null; + if (!results[2]) return ''; + return decodeURIComponent(results[2].replace(/\+/g, " ")); + } + + static createSchema(attributes) { + var schema = [ + { "name": "X", "size": 4, "type": "signed" }, + { "name": "Y", "size": 4, "type": "signed" }, + { "name": "Z", "size": 4, "type": "signed" } + ]; + + // Once we include options in the UI to load a dynamic list of available + // attributes for visualization (f.e. Classification, Intensity etc.) + // we will be able to ask for that specific attribute from the server, + // where we are now requesting all attributes for all points all the time. + // If we do that though, we also need to tell Potree to redraw the points + // that are already loaded (with different attributes). + // This is not default behaviour. + attributes.forEach(function(item) { + if(item === 'COLOR_PACKED') { + schema.push({ "name": "Red", "size": 2, "type": "unsigned" }); + schema.push({ "name": "Green", "size": 2, "type": "unsigned" }); + schema.push({ "name": "Blue", "size": 2, "type": "unsigned" }); + } else if(item === 'INTENSITY'){ + schema.push({ "name": "Intensity", "size": 2, "type": "unsigned" }); + } else if(item === 'CLASSIFICATION') { + schema.push( + { "name": "Classification", "size": 1, "type": "unsigned" }); + } + }); + + return schema; + } + + static fetch(url, cb) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + if (xhr.status === 200 || xhr.status === 0) { + cb(null, xhr.responseText); + } + else { + cb(xhr.responseText); + } + } + }; + xhr.send(null); + }; + + static fetchBinary(url, cb) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, true); + xhr.responseType = 'arraybuffer'; + xhr.onreadystatechange = function() { + if (xhr.readyState === 4) { + if (xhr.status === 200 || xhr.status === 0) { + cb(null, xhr.response); + } + else { + cb(xhr.responseText); + } + } + }; + xhr.send(null); + }; + + static pointSizeFrom(schema) { + return schema.reduce((p, c) => p + c.size, 0); + }; + + static getNormalization(serverURL, baseDepth, cb) { + var s = [ + { "name": "X", "size": 4, "type": "floating" }, + { "name": "Y", "size": 4, "type": "floating" }, + { "name": "Z", "size": 4, "type": "floating" }, + { "name": "Red", "size": 2, "type": "unsigned" }, + { "name": "Green", "size": 2, "type": "unsigned" }, + { "name": "Blue", "size": 2, "type": "unsigned" }, + { "name": "Intensity", "size": 2, "type": "unsigned" } + ]; + + var url = serverURL + 'read?depth=' + baseDepth + + '&schema=' + JSON.stringify(s); + + GreyhoundUtils.fetchBinary(url, function(err, buffer) { + if (err) throw new Error(err); + + var view = new DataView(buffer); + var numBytes = buffer.byteLength - 4; + var numPoints = view.getUint32(numBytes, true); + var pointSize = GreyhoundUtils.pointSizeFrom(s); + + var colorNorm = false, intensityNorm = false; + var v; + + for (var offset = 0; offset < numBytes; offset += pointSize) { + if (view.getUint16(offset + 12, true) > 255 || + view.getUint16(offset + 14, true) > 255 || + view.getUint16(offset + 16, true) > 255) { + colorNorm = true; + } + + if (view.getUint16(18, true) > 255) { + intensityNorm = true; + } + + if (colorNorm && intensityNorm) break; + } + + if (colorNorm) console.log('Normalizing color'); + if (intensityNorm) console.log('Normalizing intensity'); + + cb(null, { color: colorNorm, intensity: intensityNorm }); + }); + }; + +}; Potree.GreyhoundLoader = function() { }; Potree.GreyhoundLoader.loadInfoJSON = function load(url, callback) { } -var createSchema = function(attributes) { - var schema = [ - { "name": "X", "size": 4, "type": "signed" }, - { "name": "Y", "size": 4, "type": "signed" }, - { "name": "Z", "size": 4, "type": "signed" } - ]; - - // Once we include options in the UI to load a dynamic list of available - // attributes for visualization (f.e. Classification, Intensity etc.) - // we will be able to ask for that specific attribute from the server, - // where we are now requesting all attributes for all points all the time. - // If we do that though, we also need to tell Potree to redraw the points - // that are already loaded (with different attributes). - // This is not default behaviour. - attributes.forEach(function(item) { - if(item === 'COLOR_PACKED') { - schema.push({ "name": "Red", "size": 2, "type": "unsigned" }); - schema.push({ "name": "Green", "size": 2, "type": "unsigned" }); - schema.push({ "name": "Blue", "size": 2, "type": "unsigned" }); - } else if(item === 'INTENSITY'){ - schema.push({ "name": "Intensity", "size": 2, "type": "unsigned" }); - } else if(item === 'CLASSIFICATION') { - schema.push( - { "name": "Classification", "size": 1, "type": "unsigned" }); - } - }); - - return schema; -} - -var fetch = function(url, cb) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', url, true); - xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - if (xhr.status === 200 || xhr.status === 0) { - cb(null, xhr.responseText); - } - else { - cb(xhr.responseText); - } - } - }; - xhr.send(null); -}; - -var fetchBinary = function(url, cb) { - var xhr = new XMLHttpRequest(); - xhr.open('GET', url, true); - xhr.responseType = 'arraybuffer'; - xhr.onreadystatechange = function() { - if (xhr.readyState === 4) { - if (xhr.status === 200 || xhr.status === 0) { - cb(null, xhr.response); - } - else { - cb(xhr.responseText); - } - } - }; - xhr.send(null); -}; - -var pointSizeFrom = function(schema) { - return schema.reduce((p, c) => p + c.size, 0); -}; - -var getNormalization = function(serverURL, baseDepth, cb) { - var s = [ - { "name": "X", "size": 4, "type": "floating" }, - { "name": "Y", "size": 4, "type": "floating" }, - { "name": "Z", "size": 4, "type": "floating" }, - { "name": "Red", "size": 2, "type": "unsigned" }, - { "name": "Green", "size": 2, "type": "unsigned" }, - { "name": "Blue", "size": 2, "type": "unsigned" }, - { "name": "Intensity", "size": 2, "type": "unsigned" } - ]; - - var url = serverURL + 'read?depth=' + baseDepth + - '&schema=' + JSON.stringify(s); - - fetchBinary(url, function(err, buffer) { - if (err) throw new Error(err); - - var view = new DataView(buffer); - var numBytes = buffer.byteLength - 4; - var numPoints = view.getUint32(numBytes, true); - var pointSize = pointSizeFrom(s); - - var colorNorm = false, intensityNorm = false; - var v; - - for (var offset = 0; offset < numBytes; offset += pointSize) { - if (view.getUint16(offset + 12, true) > 255 || - view.getUint16(offset + 14, true) > 255 || - view.getUint16(offset + 16, true) > 255) { - colorNorm = true; - } - - if (view.getUint16(18, true) > 255) { - intensityNorm = true; - } - - if (colorNorm && intensityNorm) break; - } - - if (colorNorm) console.log('Normalizing color'); - if (intensityNorm) console.log('Normalizing intensity'); - - cb(null, { color: colorNorm, intensity: intensityNorm }); - }); -}; - /** * @return a point cloud octree with the root node data loaded. * loading of descendants happens asynchronously when they're needed @@ -148,7 +153,7 @@ Potree.GreyhoundLoader.load = function load(url, callback) { serverURL = 'http://' + serverURL; } - fetch(serverURL + 'info', function(err, data) { + GreyhoundUtils.fetch(serverURL + 'info', function(err, data) { if (err) throw new Error(err); /* We parse the result of the info query, which should be a JSON @@ -187,7 +192,7 @@ Potree.GreyhoundLoader.load = function load(url, callback) { scale = Math.min(scale[0], scale[1], scale[2]); } - if (getQueryParam('scale')) { + if (GreyhoundUtils.getQueryParam('scale')) { scale = parseFloat(getQueryParam('scale')); } @@ -232,7 +237,7 @@ Potree.GreyhoundLoader.load = function load(url, callback) { pgg.baseDepth = baseDepth; pgg.hierarchyStepSize = HIERARCHY_STEP_SIZE; - pgg.schema = createSchema(attributes); + pgg.schema = GreyhoundUtils.createSchema(attributes); var pointSize = pointSizeFrom(pgg.schema); pgg.pointAttributes = new Potree.PointAttributes(attributes); @@ -281,7 +286,7 @@ Potree.GreyhoundLoader.load = function load(url, callback) { pgg.nodes = nodes; - getNormalization(serverURL, greyhoundInfo.baseDepth, + GreyhoundUtils.getNormalization(serverURL, greyhoundInfo.baseDepth, function(err, normalize) { if (normalize.color) pgg.normalize.color = true; if (normalize.intensity) pgg.normalize.intensity = true; diff --git a/src/viewer/potree.css b/src/viewer/potree.css index 66c6a303..c781b958 100644 --- a/src/viewer/potree.css +++ b/src/viewer/potree.css @@ -89,7 +89,6 @@ #potree_sidebar_container a{ color: #8Aa1c4; - //color: red; } .potree_menu_toggle{ @@ -144,8 +143,6 @@ a:hover, a:visited, a:link, a:active{ } .annotation{ - //-webkit-transition: opacity .1s; - //transition: opacity .1s; position: absolute; padding: 10px; opacity: 0.5; @@ -158,14 +155,15 @@ a:hover, a:visited, a:link, a:active{ font-size: 1em; opacity: 1; margin: auto; - width: fit-content; + display: table; + /* width: fit-content; */ } .annotation-expand{ color: white; font-size: 0.6em; opacity: 1; - width: fit-content; + /* width: fit-content; */ } .annotation-action-icon{ @@ -206,22 +204,19 @@ a:hover, a:visited, a:link, a:active{ } .annotation-label{ - //position: relative; display: inline-block; height: 100%; flex-grow: 1; - //margin: 2px 8px; user-select: none; + -moz-user-select: none; z-index: 100; - width: fit-content; + /* width: fit-content; */ vertical-align: middle; line-height: 1.5em; - //text-align: center; font-family: Arial; font-weight: bold; padding: 1px 8px 0px 8px; cursor: default; - user-select: none; white-space: nowrap; } @@ -416,7 +411,7 @@ body{ } .ui-widget-content{ - background-color: none !important; + background-color: transparent !important; color: var(--font-color) !important; } @@ -488,22 +483,9 @@ body{ -/* no scrollbar styling in firefox, sadly */ -.navmenu::-webkit-scrollbar{ - height: 12px; -} - -.navmenu::-webkit-scrollbar-track{ - background: rgba(0, 0, 0, 0.1); -} - -.navmenu::-webkit-scrollbar-thumb{ - background: rgba(0, 0, 0, 0.5); -} - .pv-titlebar{ background-color: var(--color-1); - color: #var(--color-2); + color: var(--color-2); font-weight: 700; padding: 5px; } @@ -604,11 +586,11 @@ body{ border-radius: 100px; display: block; user-select: none; + -moz-user-select: none; } .hover_menu_icon{ position: absolute; - //border: 1px solid black; display: inline-block; width: 16px; height: 16px;