Handle extra bytes with update laz-perf.
This commit is contained in:
parent
b372711841
commit
465d653d03
@ -5214,16 +5214,18 @@ Potree.EptLazLoader = class {
|
||||
let read = () => {
|
||||
let p = lf.readData(1000000, 0, 1);
|
||||
return p.then(function (data) {
|
||||
handler.push(
|
||||
new LASDecoder(
|
||||
data.buffer,
|
||||
header.pointsFormatId,
|
||||
header.pointsStructSize,
|
||||
data.count,
|
||||
header.scale,
|
||||
header.offset,
|
||||
mins,
|
||||
maxs));
|
||||
let d = new LASDecoder(
|
||||
data.buffer,
|
||||
header.pointsFormatId,
|
||||
header.pointsStructSize,
|
||||
data.count,
|
||||
header.scale,
|
||||
header.offset,
|
||||
mins,
|
||||
maxs);
|
||||
d.extraBytes = header.extraBytes;
|
||||
d.pointsFormatId = header.pointsFormatId;
|
||||
handler.push(d);
|
||||
|
||||
i += data.count;
|
||||
|
||||
@ -5314,7 +5316,7 @@ Potree.EptLazBatcher = class {
|
||||
buffer: las.arrayb,
|
||||
numPoints: las.pointsCount,
|
||||
pointSize: las.pointSize,
|
||||
pointFormatID: 2,
|
||||
pointFormatID: las.pointsFormatId,
|
||||
scale: las.scale,
|
||||
offset: las.offset,
|
||||
mins: las.mins,
|
||||
|
||||
@ -22,24 +22,28 @@ function readAs(buf, Type, offset, count) {
|
||||
}
|
||||
|
||||
function parseLASHeader(arraybuffer) {
|
||||
var o = {};
|
||||
var o = { };
|
||||
|
||||
o.pointsOffset = readAs(arraybuffer, Uint32Array, 32*3);
|
||||
o.pointsFormatId = readAs(arraybuffer, Uint8Array, 32*3+8);
|
||||
o.pointsFormatId = readAs(arraybuffer, Uint8Array, 32*3+8) & 0x3f;
|
||||
o.pointsStructSize = readAs(arraybuffer, Uint16Array, 32*3+8+1);
|
||||
|
||||
o.extraBytes = 0;
|
||||
|
||||
// TODO Determine if extra-bytes are present.
|
||||
switch (o.pointsFormatId) {
|
||||
case 0: o.extraBytes = o.pointsStructSize - 20; break;
|
||||
case 1: o.extraBytes = o.pointsStructSize - 28; break;
|
||||
case 2: o.extraBytes = o.pointsStructSize - 26; break;
|
||||
case 3: o.extraBytes = o.pointsStructSize - 34; break;
|
||||
}
|
||||
|
||||
o.pointsStructSize -= o.extraBytes;
|
||||
o.pointsCount = readAs(arraybuffer, Uint32Array, 32*3 + 11);
|
||||
o.pointsCount = readAs(arraybuffer, Uint32Array, 32 * 3 + 11);
|
||||
|
||||
var start = 32*3 + 35;
|
||||
o.scale = readAs(arraybuffer, Float64Array, start, 3); start += 24; // 8*3
|
||||
var start = 32 * 3 + 35;
|
||||
o.scale = readAs(arraybuffer, Float64Array, start, 3); start += 24;
|
||||
o.offset = readAs(arraybuffer, Float64Array, start, 3); start += 24;
|
||||
|
||||
var bounds = readAs(arraybuffer, Float64Array, start, 6); start += 48; // 8*6;
|
||||
var bounds = readAs(arraybuffer, Float64Array, start, 6); start += 48;
|
||||
o.maxs = [bounds[0], bounds[2], bounds[4]];
|
||||
o.mins = [bounds[1], bounds[3], bounds[5]];
|
||||
|
||||
@ -70,9 +74,8 @@ function handleEvent(msg) {
|
||||
|
||||
case "header":
|
||||
if (!instance)
|
||||
throw new Error("You need to open the file before trying to read header");
|
||||
|
||||
|
||||
throw new Error(
|
||||
"You need to open the file before reading the header");
|
||||
|
||||
var header = parseLASHeader(instance.arraybuffer);
|
||||
header.pointsFormatId &= 0x3f;
|
||||
@ -82,31 +85,45 @@ function handleEvent(msg) {
|
||||
|
||||
case "read":
|
||||
if (!instance)
|
||||
throw new Error("You need to open the file before trying to read stuff");
|
||||
throw new Error(
|
||||
"You need to open the file before trying to read");
|
||||
|
||||
var start = msg.start, count = msg.count, skip = msg.skip;
|
||||
var o = instance;
|
||||
|
||||
if (!o.header)
|
||||
throw new Error("You need to query header before reading, I maintain state that way, sorry :(");
|
||||
throw new Error(
|
||||
"You need to query header before reading");
|
||||
|
||||
var pointsToRead = Math.min(count * skip, o.header.pointsCount - o.readOffset);
|
||||
let h = o.header;
|
||||
|
||||
var pointsToRead = Math.min(
|
||||
count * skip, h.pointsCount - o.readOffset);
|
||||
var bufferSize = Math.ceil(pointsToRead / skip);
|
||||
var pointsRead = 0;
|
||||
|
||||
let buffer = new ArrayBuffer(bufferSize * o.header.pointsStructSize);
|
||||
let buffer = new ArrayBuffer(bufferSize * h.pointsStructSize);
|
||||
let this_buf = new Uint8Array(buffer);
|
||||
var buf_read = Module._malloc(o.header.pointsStructSize + o.header.extraBytes);
|
||||
var buf_read = Module._malloc(h.pointsStructSize);
|
||||
|
||||
for (var i = 0 ; i < pointsToRead ; i ++) {
|
||||
o.getPoint(buf_read);
|
||||
|
||||
if (i % skip === 0) {
|
||||
var a = new Uint8Array(Module.HEAPU8.buffer, buf_read, o.header.pointsStructSize + o.header.extraBytes);
|
||||
this_buf.set(a, pointsRead * o.header.pointsStructSize, o.header.pointsStructSize);
|
||||
pointsRead ++;
|
||||
var a = new Uint8Array(
|
||||
Module.HEAPU8.buffer,
|
||||
buf_read,
|
||||
h.pointsStructSize);
|
||||
|
||||
this_buf.set(
|
||||
a,
|
||||
pointsRead * h.pointsStructSize,
|
||||
h.pointsStructSize);
|
||||
|
||||
++pointsRead;
|
||||
}
|
||||
|
||||
o.readOffset ++;
|
||||
++o.readOffset;
|
||||
}
|
||||
Module._free(buf_read);
|
||||
|
||||
@ -122,7 +139,6 @@ function handleEvent(msg) {
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case "close":
|
||||
if (instance !== null) {
|
||||
Module._free(instance.buf);
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -54,16 +54,18 @@ Potree.EptLazLoader = class {
|
||||
let read = () => {
|
||||
let p = lf.readData(1000000, 0, 1);
|
||||
return p.then(function (data) {
|
||||
handler.push(
|
||||
new LASDecoder(
|
||||
data.buffer,
|
||||
header.pointsFormatId,
|
||||
header.pointsStructSize,
|
||||
data.count,
|
||||
header.scale,
|
||||
header.offset,
|
||||
mins,
|
||||
maxs));
|
||||
let d = new LASDecoder(
|
||||
data.buffer,
|
||||
header.pointsFormatId,
|
||||
header.pointsStructSize,
|
||||
data.count,
|
||||
header.scale,
|
||||
header.offset,
|
||||
mins,
|
||||
maxs);
|
||||
d.extraBytes = header.extraBytes;
|
||||
d.pointsFormatId = header.pointsFormatId;
|
||||
handler.push(d);
|
||||
|
||||
i += data.count;
|
||||
|
||||
@ -154,7 +156,7 @@ Potree.EptLazBatcher = class {
|
||||
buffer: las.arrayb,
|
||||
numPoints: las.pointsCount,
|
||||
pointSize: las.pointSize,
|
||||
pointFormatID: 2,
|
||||
pointFormatID: las.pointsFormatId,
|
||||
scale: las.scale,
|
||||
offset: las.offset,
|
||||
mins: las.mins,
|
||||
|
||||
@ -4,14 +4,7 @@ function readUsingDataView(event) {
|
||||
let buffer = event.data.buffer;
|
||||
let numPoints = event.data.numPoints;
|
||||
let pointSize = event.data.pointSize;
|
||||
let pointFormat = 2;
|
||||
switch (pointSize) {
|
||||
case 20: pointFormat = 0; break;
|
||||
case 28: pointFormat = 1; break;
|
||||
case 26: pointFormat = 2; break;
|
||||
case 34: pointFormat = 3; break;
|
||||
default: console.log('Could not determine point format, using 2');
|
||||
}
|
||||
let pointFormat = event.data.pointFormatID;
|
||||
let scale = event.data.scale;
|
||||
let offset = event.data.offset;
|
||||
|
||||
@ -55,7 +48,7 @@ function readUsingDataView(event) {
|
||||
let co = pointFormat == 2 ? 20 : 28;
|
||||
|
||||
// TODO This should be cached per-resource since this is an expensive check.
|
||||
var twoByteColor = false;
|
||||
let twoByteColor = false;
|
||||
if (hasColor) {
|
||||
for (let i = 0; i < numPoints && !twoByteColor; ++i) {
|
||||
let r = sourceView.getUint16(i * pointSize + co, true)
|
||||
@ -75,10 +68,6 @@ function readUsingDataView(event) {
|
||||
y = uy * scale[1] + offset[1] - event.data.mins[1];
|
||||
z = uz * scale[2] + offset[2] - event.data.mins[2];
|
||||
|
||||
//x = ux * scale[0];
|
||||
//y = uy * scale[1];
|
||||
//z = uz * scale[2];
|
||||
|
||||
positions[3 * i + 0] = x;
|
||||
positions[3 * i + 1] = y;
|
||||
positions[3 * i + 2] = z;
|
||||
@ -98,11 +87,6 @@ function readUsingDataView(event) {
|
||||
// INTENSITY
|
||||
let intensity = sourceView.getUint16(i * pointSize + 12, true);
|
||||
intensities[i] = intensity;
|
||||
if (intensity <= 5) {
|
||||
positions[3 * i + 0] = 99999999;
|
||||
positions[3 * i + 1] = 99999999;
|
||||
positions[3 * i + 2] = 99999999;
|
||||
}
|
||||
|
||||
// RETURN NUMBER, stored in the first 3 bits - 00000111
|
||||
// number of returns stored in next 3 bits - 00111000
|
||||
@ -178,7 +162,8 @@ function readUsingDataView(event) {
|
||||
message.returnNumber,
|
||||
message.numberOfReturns,
|
||||
message.pointSourceID,
|
||||
message.indices];
|
||||
message.indices
|
||||
];
|
||||
|
||||
postMessage(message, transferables);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user