@loaders.gl/las 4.0.0-alpha.9 → 4.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es5/las-loader.js +1 -1
- package/dist/es5/las-loader.js.map +1 -1
- package/dist/esm/las-loader.js +1 -1
- package/dist/esm/las-loader.js.map +1 -1
- package/dist/las-worker.js +15 -10
- package/package.json +4 -5
- package/dist/bundle.js +0 -5
- package/dist/index.js +0 -14
- package/dist/las-loader.js +0 -30
- package/dist/lib/get-las-schema.js +0 -47
- package/dist/lib/las-types.js +0 -2
- package/dist/lib/laslaz-decoder.js +0 -395
- package/dist/lib/libs/laz-perf.js +0 -19006
- package/dist/lib/parse-las.js +0 -191
- package/dist/workers/las-worker.js +0 -5
package/dist/lib/parse-las.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseLASChunked = exports.parseLAS = void 0;
|
|
4
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
-
const laslaz_decoder_1 = require("./laslaz-decoder");
|
|
6
|
-
const get_las_schema_1 = require("./get-las-schema");
|
|
7
|
-
/**
|
|
8
|
-
* Parsing of .las file
|
|
9
|
-
* @param arrayBuffer
|
|
10
|
-
* @param options
|
|
11
|
-
* @returns LASHeader
|
|
12
|
-
*/
|
|
13
|
-
function parseLAS(arrayBuffer, options) {
|
|
14
|
-
return parseLASMesh(arrayBuffer, options);
|
|
15
|
-
// This code breaks pointcloud example on the website
|
|
16
|
-
// const mesh = parseLASMesh(arrayBuffer, options);
|
|
17
|
-
// return convertMesh(mesh, options?.las?.shape || 'mesh') as LASMesh | ArrowTable | ColumnarTable;
|
|
18
|
-
}
|
|
19
|
-
exports.parseLAS = parseLAS;
|
|
20
|
-
/**
|
|
21
|
-
* Parsing of .las file
|
|
22
|
-
* @param arrayBuffer
|
|
23
|
-
* @param options
|
|
24
|
-
* @returns LASHeader
|
|
25
|
-
*/
|
|
26
|
-
function parseLASMesh(arrayBuffer, options = {}) {
|
|
27
|
-
let pointIndex = 0;
|
|
28
|
-
let positions;
|
|
29
|
-
let colors;
|
|
30
|
-
let intensities;
|
|
31
|
-
let classifications;
|
|
32
|
-
let originalHeader;
|
|
33
|
-
const lasMesh = {
|
|
34
|
-
loader: 'las',
|
|
35
|
-
loaderData: {},
|
|
36
|
-
// shape: 'mesh',
|
|
37
|
-
schema: { fields: [], metadata: {} },
|
|
38
|
-
header: {
|
|
39
|
-
vertexCount: 0,
|
|
40
|
-
boundingBox: [
|
|
41
|
-
[0, 0, 0],
|
|
42
|
-
[0, 0, 0]
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
|
-
attributes: {},
|
|
46
|
-
topology: 'point-list',
|
|
47
|
-
mode: 0 // GL.POINTS
|
|
48
|
-
};
|
|
49
|
-
/* eslint-disable max-statements */
|
|
50
|
-
// @ts-ignore Possibly undefined
|
|
51
|
-
parseLASChunked(arrayBuffer, options.las?.skip, (decoder = {}, lasHeader) => {
|
|
52
|
-
if (!originalHeader) {
|
|
53
|
-
originalHeader = lasHeader;
|
|
54
|
-
const total = lasHeader.totalToRead;
|
|
55
|
-
const PositionsType = options.las?.fp64 ? Float64Array : Float32Array;
|
|
56
|
-
positions = new PositionsType(total * 3);
|
|
57
|
-
// laslaz-decoder.js `pointFormatReaders`
|
|
58
|
-
colors = lasHeader.pointsFormatId >= 2 ? new Uint8Array(total * 4) : null;
|
|
59
|
-
intensities = new Uint16Array(total);
|
|
60
|
-
classifications = new Uint8Array(total);
|
|
61
|
-
lasMesh.loaderData = lasHeader;
|
|
62
|
-
lasMesh.attributes = {
|
|
63
|
-
POSITION: { value: positions, size: 3 },
|
|
64
|
-
// non-gltf attributes, use non-capitalized names for now
|
|
65
|
-
intensity: { value: intensities, size: 1 },
|
|
66
|
-
classification: { value: classifications, size: 1 }
|
|
67
|
-
};
|
|
68
|
-
if (colors) {
|
|
69
|
-
lasMesh.attributes.COLOR_0 = { value: colors, size: 4 };
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const batchSize = decoder.pointsCount;
|
|
73
|
-
const { scale: [scaleX, scaleY, scaleZ], offset: [offsetX, offsetY, offsetZ] } = lasHeader;
|
|
74
|
-
const twoByteColor = detectTwoByteColors(decoder, batchSize, options.las?.colorDepth);
|
|
75
|
-
for (let i = 0; i < batchSize; i++) {
|
|
76
|
-
const { position, color, intensity, classification } = decoder.getPoint(i);
|
|
77
|
-
positions[pointIndex * 3] = position[0] * scaleX + offsetX;
|
|
78
|
-
positions[pointIndex * 3 + 1] = position[1] * scaleY + offsetY;
|
|
79
|
-
positions[pointIndex * 3 + 2] = position[2] * scaleZ + offsetZ;
|
|
80
|
-
if (color && colors) {
|
|
81
|
-
if (twoByteColor) {
|
|
82
|
-
colors[pointIndex * 4] = color[0] / 256;
|
|
83
|
-
colors[pointIndex * 4 + 1] = color[1] / 256;
|
|
84
|
-
colors[pointIndex * 4 + 2] = color[2] / 256;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
colors[pointIndex * 4] = color[0];
|
|
88
|
-
colors[pointIndex * 4 + 1] = color[1];
|
|
89
|
-
colors[pointIndex * 4 + 2] = color[2];
|
|
90
|
-
}
|
|
91
|
-
colors[pointIndex * 4 + 3] = 255;
|
|
92
|
-
}
|
|
93
|
-
intensities[pointIndex] = intensity;
|
|
94
|
-
classifications[pointIndex] = classification;
|
|
95
|
-
pointIndex++;
|
|
96
|
-
}
|
|
97
|
-
const meshBatch = {
|
|
98
|
-
...lasMesh,
|
|
99
|
-
header: {
|
|
100
|
-
vertexCount: lasHeader.totalRead
|
|
101
|
-
},
|
|
102
|
-
progress: lasHeader.totalRead / lasHeader.totalToRead
|
|
103
|
-
};
|
|
104
|
-
options?.onProgress?.(meshBatch);
|
|
105
|
-
});
|
|
106
|
-
/* eslint-enable max-statements */
|
|
107
|
-
lasMesh.header = {
|
|
108
|
-
vertexCount: originalHeader.totalToRead,
|
|
109
|
-
boundingBox: (0, schema_1.getMeshBoundingBox)(lasMesh?.attributes || {})
|
|
110
|
-
};
|
|
111
|
-
if (lasMesh) {
|
|
112
|
-
lasMesh.schema = (0, get_las_schema_1.getLASSchema)(lasMesh.loaderData, lasMesh.attributes);
|
|
113
|
-
}
|
|
114
|
-
return lasMesh;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* parse laz data
|
|
118
|
-
* @param rawData
|
|
119
|
-
* @param skip
|
|
120
|
-
* @param onParseData
|
|
121
|
-
* @return parsed point cloud
|
|
122
|
-
*/
|
|
123
|
-
/* eslint-enable max-statements */
|
|
124
|
-
function parseLASChunked(rawData, skip, onParseData = {}) {
|
|
125
|
-
const dataHandler = new laslaz_decoder_1.LASFile(rawData);
|
|
126
|
-
try {
|
|
127
|
-
// open data
|
|
128
|
-
dataHandler.open();
|
|
129
|
-
const header = dataHandler.getHeader();
|
|
130
|
-
// start loading
|
|
131
|
-
const Unpacker = dataHandler.getUnpacker();
|
|
132
|
-
const totalToRead = Math.ceil(header.pointsCount / Math.max(1, skip));
|
|
133
|
-
header.totalToRead = totalToRead;
|
|
134
|
-
let totalRead = 0;
|
|
135
|
-
/* eslint-disable no-constant-condition */
|
|
136
|
-
while (true) {
|
|
137
|
-
const chunk = dataHandler.readData(1000 * 100, 0, skip);
|
|
138
|
-
totalRead += chunk.count;
|
|
139
|
-
header.totalRead = totalRead;
|
|
140
|
-
header.versionAsString = chunk.versionAsString;
|
|
141
|
-
header.isCompressed = chunk.isCompressed;
|
|
142
|
-
const unpacker = new Unpacker(chunk.buffer, chunk.count, header);
|
|
143
|
-
// surface unpacker and progress via call back
|
|
144
|
-
// use unpacker.pointsCount and unpacker.getPoint(i) to handle data in app
|
|
145
|
-
onParseData(unpacker, header);
|
|
146
|
-
if (!chunk.hasMoreData || totalRead >= totalToRead) {
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
throw e;
|
|
153
|
-
}
|
|
154
|
-
finally {
|
|
155
|
-
dataHandler.close();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
exports.parseLASChunked = parseLASChunked;
|
|
159
|
-
/**
|
|
160
|
-
* @param decoder
|
|
161
|
-
* @param batchSize
|
|
162
|
-
* @param colorDepth
|
|
163
|
-
* @returns boolean
|
|
164
|
-
*/
|
|
165
|
-
function detectTwoByteColors(decoder = {}, batchSize, colorDepth) {
|
|
166
|
-
let twoByteColor = false;
|
|
167
|
-
switch (colorDepth) {
|
|
168
|
-
case 8:
|
|
169
|
-
twoByteColor = false;
|
|
170
|
-
break;
|
|
171
|
-
case 16:
|
|
172
|
-
twoByteColor = true;
|
|
173
|
-
break;
|
|
174
|
-
case 'auto':
|
|
175
|
-
if (decoder.getPoint(0).color) {
|
|
176
|
-
for (let i = 0; i < batchSize; i++) {
|
|
177
|
-
const { color } = decoder.getPoint(i);
|
|
178
|
-
// eslint-disable-next-line max-depth
|
|
179
|
-
if (color[0] > 255 || color[1] > 255 || color[2] > 255) {
|
|
180
|
-
twoByteColor = true;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
default:
|
|
186
|
-
// eslint-disable-next-line
|
|
187
|
-
console.warn('las: illegal value for options.las.colorDepth');
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
return twoByteColor;
|
|
191
|
-
}
|