@loaders.gl/las 4.0.0-alpha.8 → 4.0.0-beta.1
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/es5/las-loader.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.LASLoader = void 0;
|
|
7
|
-
var VERSION = typeof "4.0.0-
|
|
7
|
+
var VERSION = typeof "4.0.0-beta.1" !== 'undefined' ? "4.0.0-beta.1" : 'latest';
|
|
8
8
|
var DEFAULT_LAS_OPTIONS = {
|
|
9
9
|
las: {
|
|
10
10
|
shape: 'mesh',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"las-loader.js","names":["VERSION","DEFAULT_LAS_OPTIONS","las","shape","fp64","skip","colorDepth","LASLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options","exports"],"sources":["../../src/las-loader.ts"],"sourcesContent":["// LASER (LAS) FILE FORMAT\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {LASMesh} from './lib/las-types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type LASLoaderOptions = LoaderOptions & {\n las?: {\n shape?: 'mesh' | 'columnar-table' | 'arrow-table';\n fp64?: boolean;\n skip?: number;\n colorDepth?: number | string;\n };\n onProgress?: Function;\n};\n\nconst DEFAULT_LAS_OPTIONS: LASLoaderOptions = {\n las: {\n shape: 'mesh',\n fp64: false,\n skip: 1,\n colorDepth: 8\n }\n};\n\n/**\n * Loader for the LAS (LASer) point cloud format\n */\nexport const LASLoader: Loader<LASMesh, never, LASLoaderOptions> = {\n name: 'LAS',\n id: 'las',\n module: 'las',\n version: VERSION,\n worker: true,\n extensions: ['las', 'laz'], // LAZ is the \"compressed\" flavor of LAS,\n mimeTypes: ['application/octet-stream'], // TODO - text version?\n text: true,\n binary: true,\n tests: ['LAS'],\n options: DEFAULT_LAS_OPTIONS\n};\n"],"mappings":";;;;;;AAMA,IAAMA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"las-loader.js","names":["VERSION","DEFAULT_LAS_OPTIONS","las","shape","fp64","skip","colorDepth","LASLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options","exports"],"sources":["../../src/las-loader.ts"],"sourcesContent":["// LASER (LAS) FILE FORMAT\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {LASMesh} from './lib/las-types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type LASLoaderOptions = LoaderOptions & {\n las?: {\n shape?: 'mesh' | 'columnar-table' | 'arrow-table';\n fp64?: boolean;\n skip?: number;\n colorDepth?: number | string;\n };\n onProgress?: Function;\n};\n\nconst DEFAULT_LAS_OPTIONS: LASLoaderOptions = {\n las: {\n shape: 'mesh',\n fp64: false,\n skip: 1,\n colorDepth: 8\n }\n};\n\n/**\n * Loader for the LAS (LASer) point cloud format\n */\nexport const LASLoader: Loader<LASMesh, never, LASLoaderOptions> = {\n name: 'LAS',\n id: 'las',\n module: 'las',\n version: VERSION,\n worker: true,\n extensions: ['las', 'laz'], // LAZ is the \"compressed\" flavor of LAS,\n mimeTypes: ['application/octet-stream'], // TODO - text version?\n text: true,\n binary: true,\n tests: ['LAS'],\n options: DEFAULT_LAS_OPTIONS\n};\n"],"mappings":";;;;;;AAMA,IAAMA,OAAO,GAAG,qBAAkB,KAAK,WAAW,oBAAiB,QAAQ;AAY3E,IAAMC,mBAAqC,GAAG;EAC5CC,GAAG,EAAE;IACHC,KAAK,EAAE,MAAM;IACbC,IAAI,EAAE,KAAK;IACXC,IAAI,EAAE,CAAC;IACPC,UAAU,EAAE;EACd;AACF,CAAC;AAKM,IAAMC,SAAmD,GAAG;EACjEC,IAAI,EAAE,KAAK;EACXC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,OAAO,EAAEX,OAAO;EAChBY,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;EAC1BC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,CAAC,KAAK,CAAC;EACdC,OAAO,EAAEjB;AACX,CAAC;AAACkB,OAAA,CAAAZ,SAAA,GAAAA,SAAA"}
|
package/dist/esm/las-loader.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"las-loader.js","names":["VERSION","DEFAULT_LAS_OPTIONS","las","shape","fp64","skip","colorDepth","LASLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options"],"sources":["../../src/las-loader.ts"],"sourcesContent":["// LASER (LAS) FILE FORMAT\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {LASMesh} from './lib/las-types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type LASLoaderOptions = LoaderOptions & {\n las?: {\n shape?: 'mesh' | 'columnar-table' | 'arrow-table';\n fp64?: boolean;\n skip?: number;\n colorDepth?: number | string;\n };\n onProgress?: Function;\n};\n\nconst DEFAULT_LAS_OPTIONS: LASLoaderOptions = {\n las: {\n shape: 'mesh',\n fp64: false,\n skip: 1,\n colorDepth: 8\n }\n};\n\n/**\n * Loader for the LAS (LASer) point cloud format\n */\nexport const LASLoader: Loader<LASMesh, never, LASLoaderOptions> = {\n name: 'LAS',\n id: 'las',\n module: 'las',\n version: VERSION,\n worker: true,\n extensions: ['las', 'laz'], // LAZ is the \"compressed\" flavor of LAS,\n mimeTypes: ['application/octet-stream'], // TODO - text version?\n text: true,\n binary: true,\n tests: ['LAS'],\n options: DEFAULT_LAS_OPTIONS\n};\n"],"mappings":"AAMA,MAAMA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"las-loader.js","names":["VERSION","DEFAULT_LAS_OPTIONS","las","shape","fp64","skip","colorDepth","LASLoader","name","id","module","version","worker","extensions","mimeTypes","text","binary","tests","options"],"sources":["../../src/las-loader.ts"],"sourcesContent":["// LASER (LAS) FILE FORMAT\nimport type {Loader, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {LASMesh} from './lib/las-types';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type LASLoaderOptions = LoaderOptions & {\n las?: {\n shape?: 'mesh' | 'columnar-table' | 'arrow-table';\n fp64?: boolean;\n skip?: number;\n colorDepth?: number | string;\n };\n onProgress?: Function;\n};\n\nconst DEFAULT_LAS_OPTIONS: LASLoaderOptions = {\n las: {\n shape: 'mesh',\n fp64: false,\n skip: 1,\n colorDepth: 8\n }\n};\n\n/**\n * Loader for the LAS (LASer) point cloud format\n */\nexport const LASLoader: Loader<LASMesh, never, LASLoaderOptions> = {\n name: 'LAS',\n id: 'las',\n module: 'las',\n version: VERSION,\n worker: true,\n extensions: ['las', 'laz'], // LAZ is the \"compressed\" flavor of LAS,\n mimeTypes: ['application/octet-stream'], // TODO - text version?\n text: true,\n binary: true,\n tests: ['LAS'],\n options: DEFAULT_LAS_OPTIONS\n};\n"],"mappings":"AAMA,MAAMA,OAAO,GAAG,qBAAkB,KAAK,WAAW,oBAAiB,QAAQ;AAY3E,MAAMC,mBAAqC,GAAG;EAC5CC,GAAG,EAAE;IACHC,KAAK,EAAE,MAAM;IACbC,IAAI,EAAE,KAAK;IACXC,IAAI,EAAE,CAAC;IACPC,UAAU,EAAE;EACd;AACF,CAAC;AAKD,OAAO,MAAMC,SAAmD,GAAG;EACjEC,IAAI,EAAE,KAAK;EACXC,EAAE,EAAE,KAAK;EACTC,MAAM,EAAE,KAAK;EACbC,OAAO,EAAEX,OAAO;EAChBY,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;EAC1BC,SAAS,EAAE,CAAC,0BAA0B,CAAC;EACvCC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,CAAC,KAAK,CAAC;EACdC,OAAO,EAAEjB;AACX,CAAC"}
|
package/dist/las-worker.js
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
-
// (disabled):fs
|
|
7
|
-
var require_fs = __commonJS({
|
|
8
|
-
"(disabled):fs"() {
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
|
|
12
6
|
// (disabled):path
|
|
13
7
|
var require_path = __commonJS({
|
|
14
8
|
"(disabled):path"() {
|
|
15
9
|
}
|
|
16
10
|
});
|
|
17
11
|
|
|
12
|
+
// (disabled):fs
|
|
13
|
+
var require_fs = __commonJS({
|
|
14
|
+
"(disabled):fs"() {
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
|
|
18
18
|
// ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
|
|
19
19
|
function getTransferList(object, recursive = true, transfers) {
|
|
20
20
|
const transfersSet = transfers || new Set();
|
|
@@ -141,7 +141,7 @@
|
|
|
141
141
|
options,
|
|
142
142
|
context: {
|
|
143
143
|
...context,
|
|
144
|
-
|
|
144
|
+
_parse: parseOnMainThread
|
|
145
145
|
}
|
|
146
146
|
});
|
|
147
147
|
WorkerBody.postMessage("done", { result });
|
|
@@ -154,7 +154,7 @@
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
-
function parseOnMainThread(arrayBuffer, options) {
|
|
157
|
+
function parseOnMainThread(arrayBuffer, loader, options, context) {
|
|
158
158
|
return new Promise((resolve, reject) => {
|
|
159
159
|
const id = requestId++;
|
|
160
160
|
const onMessage = (type, payload2) => {
|
|
@@ -178,7 +178,12 @@
|
|
|
178
178
|
WorkerBody.postMessage("process", payload);
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
|
-
async function parseData({
|
|
181
|
+
async function parseData({
|
|
182
|
+
loader,
|
|
183
|
+
arrayBuffer,
|
|
184
|
+
options,
|
|
185
|
+
context
|
|
186
|
+
}) {
|
|
182
187
|
let data;
|
|
183
188
|
let parser;
|
|
184
189
|
if (loader.parseSync || loader.parse) {
|
|
@@ -200,7 +205,7 @@
|
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
// src/las-loader.ts
|
|
203
|
-
var VERSION = true ? "4.0.0-
|
|
208
|
+
var VERSION = true ? "4.0.0-beta.1" : "latest";
|
|
204
209
|
var DEFAULT_LAS_OPTIONS = {
|
|
205
210
|
las: {
|
|
206
211
|
shape: "mesh",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/las",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
4
|
"description": "Framework-independent loader for the LAS and LAZ formats",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -41,9 +41,8 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@babel/runtime": "^7.3.1",
|
|
44
|
-
"@loaders.gl/loader-utils": "4.0.0-
|
|
45
|
-
"@loaders.gl/schema": "4.0.0-
|
|
46
|
-
"apache-arrow": "^9.0.0"
|
|
44
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.1",
|
|
45
|
+
"@loaders.gl/schema": "4.0.0-beta.1"
|
|
47
46
|
},
|
|
48
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "35c625e67132b0784e597d9ddabae8aefea29ff2"
|
|
49
48
|
}
|
package/dist/bundle.js
DELETED
package/dist/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LASLoader = exports.LASWorkerLoader = void 0;
|
|
4
|
-
const las_loader_1 = require("./las-loader");
|
|
5
|
-
Object.defineProperty(exports, "LASWorkerLoader", { enumerable: true, get: function () { return las_loader_1.LASLoader; } });
|
|
6
|
-
const parse_las_1 = require("./lib/parse-las");
|
|
7
|
-
/**
|
|
8
|
-
* Loader for the LAS (LASer) point cloud format
|
|
9
|
-
*/
|
|
10
|
-
exports.LASLoader = {
|
|
11
|
-
...las_loader_1.LASLoader,
|
|
12
|
-
parse: async (arrayBuffer, options) => (0, parse_las_1.parseLAS)(arrayBuffer, options),
|
|
13
|
-
parseSync: (arrayBuffer, options) => (0, parse_las_1.parseLAS)(arrayBuffer, options)
|
|
14
|
-
};
|
package/dist/las-loader.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LASLoader = void 0;
|
|
4
|
-
// __VERSION__ is injected by babel-plugin-version-inline
|
|
5
|
-
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
6
|
-
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
7
|
-
const DEFAULT_LAS_OPTIONS = {
|
|
8
|
-
las: {
|
|
9
|
-
shape: 'mesh',
|
|
10
|
-
fp64: false,
|
|
11
|
-
skip: 1,
|
|
12
|
-
colorDepth: 8
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Loader for the LAS (LASer) point cloud format
|
|
17
|
-
*/
|
|
18
|
-
exports.LASLoader = {
|
|
19
|
-
name: 'LAS',
|
|
20
|
-
id: 'las',
|
|
21
|
-
module: 'las',
|
|
22
|
-
version: VERSION,
|
|
23
|
-
worker: true,
|
|
24
|
-
extensions: ['las', 'laz'],
|
|
25
|
-
mimeTypes: ['application/octet-stream'],
|
|
26
|
-
text: true,
|
|
27
|
-
binary: true,
|
|
28
|
-
tests: ['LAS'],
|
|
29
|
-
options: DEFAULT_LAS_OPTIONS
|
|
30
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeMetadataFromLasHeader = exports.getLASSchema = void 0;
|
|
4
|
-
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
-
/**
|
|
6
|
-
* Gets schema from PLY header
|
|
7
|
-
* @param lasHeader
|
|
8
|
-
* @param metadata
|
|
9
|
-
* @returns Schema
|
|
10
|
-
*/
|
|
11
|
-
function getLASSchema(lasHeader, attributes) {
|
|
12
|
-
const metadataMap = makeMetadataFromLasHeader(lasHeader);
|
|
13
|
-
const schema = (0, schema_1.deduceMeshSchema)(attributes, metadataMap);
|
|
14
|
-
return schema;
|
|
15
|
-
}
|
|
16
|
-
exports.getLASSchema = getLASSchema;
|
|
17
|
-
/**
|
|
18
|
-
* Make arrow like schema metadata by LASHeader properties
|
|
19
|
-
* @param lasHeader
|
|
20
|
-
* @returns
|
|
21
|
-
*/
|
|
22
|
-
function makeMetadataFromLasHeader(lasHeader) {
|
|
23
|
-
const metadata = {};
|
|
24
|
-
/* eslint-disable camelcase */
|
|
25
|
-
metadata.las_pointsOffset = lasHeader.pointsOffset.toString(10);
|
|
26
|
-
metadata.las_pointsFormatId = lasHeader.pointsFormatId.toString(10);
|
|
27
|
-
metadata.las_pointsStructSize = lasHeader.pointsStructSize.toString(10);
|
|
28
|
-
metadata.las_pointsCount = lasHeader.pointsCount.toString(10);
|
|
29
|
-
metadata.las_scale = JSON.stringify(lasHeader.scale);
|
|
30
|
-
metadata.las_offset = JSON.stringify(lasHeader.offset);
|
|
31
|
-
if (lasHeader.maxs !== undefined) {
|
|
32
|
-
metadata.las_maxs = JSON.stringify(lasHeader.maxs);
|
|
33
|
-
}
|
|
34
|
-
if (lasHeader.mins !== undefined) {
|
|
35
|
-
metadata.las_mins = JSON.stringify(lasHeader.mins);
|
|
36
|
-
}
|
|
37
|
-
metadata.las_totalToRead = lasHeader.totalToRead.toString(10);
|
|
38
|
-
metadata.las_pointsFortotalReadmatId = lasHeader.totalRead.toString(10);
|
|
39
|
-
if (lasHeader.versionAsString !== undefined) {
|
|
40
|
-
metadata.las_versionAsString = lasHeader.versionAsString;
|
|
41
|
-
}
|
|
42
|
-
if (lasHeader.isCompressed !== undefined) {
|
|
43
|
-
metadata.las_isCompressed = lasHeader.isCompressed.toString();
|
|
44
|
-
}
|
|
45
|
-
return metadata;
|
|
46
|
-
}
|
|
47
|
-
exports.makeMetadataFromLasHeader = makeMetadataFromLasHeader;
|
package/dist/lib/las-types.js
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LASModuleWasLoaded = exports.LASFile = void 0;
|
|
7
|
-
const laz_perf_1 = __importDefault(require("./libs/laz-perf"));
|
|
8
|
-
let Module = null;
|
|
9
|
-
const POINT_FORMAT_READERS = {
|
|
10
|
-
0: (dv) => {
|
|
11
|
-
return {
|
|
12
|
-
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
13
|
-
intensity: dv.getUint16(12, true),
|
|
14
|
-
classification: dv.getUint8(15)
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
1: (dv) => {
|
|
18
|
-
return {
|
|
19
|
-
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
20
|
-
intensity: dv.getUint16(12, true),
|
|
21
|
-
classification: dv.getUint8(15)
|
|
22
|
-
};
|
|
23
|
-
},
|
|
24
|
-
2: (dv) => {
|
|
25
|
-
return {
|
|
26
|
-
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
27
|
-
intensity: dv.getUint16(12, true),
|
|
28
|
-
classification: dv.getUint8(15),
|
|
29
|
-
color: [dv.getUint16(20, true), dv.getUint16(22, true), dv.getUint16(24, true)]
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
3: (dv) => {
|
|
33
|
-
return {
|
|
34
|
-
position: [dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
|
35
|
-
intensity: dv.getUint16(12, true),
|
|
36
|
-
classification: dv.getUint8(15),
|
|
37
|
-
color: [dv.getUint16(28, true), dv.getUint16(30, true), dv.getUint16(32, true)]
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Reads incoming binary data depends on the Type parameter
|
|
43
|
-
* @param buf
|
|
44
|
-
* @param Type
|
|
45
|
-
* @param offset
|
|
46
|
-
* @param count
|
|
47
|
-
* @returns number | number[] from incoming binary data
|
|
48
|
-
*/
|
|
49
|
-
function readAs(buf, Type = {}, offset, count) {
|
|
50
|
-
count = count === undefined || count === 0 ? 1 : count;
|
|
51
|
-
const sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count);
|
|
52
|
-
const r = new Type(sub);
|
|
53
|
-
if (count === 1) {
|
|
54
|
-
return r[0];
|
|
55
|
-
}
|
|
56
|
-
const ret = [];
|
|
57
|
-
for (let i = 0; i < count; i++) {
|
|
58
|
-
ret.push(r[i]);
|
|
59
|
-
}
|
|
60
|
-
return ret;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Parsing of header's attributes
|
|
64
|
-
* @param arraybuffer
|
|
65
|
-
* @returns header as LASHeader
|
|
66
|
-
*/
|
|
67
|
-
function parseLASHeader(arraybuffer) {
|
|
68
|
-
let start = 32 * 3 + 35;
|
|
69
|
-
const o = {
|
|
70
|
-
pointsOffset: readAs(arraybuffer, Uint32Array, 32 * 3),
|
|
71
|
-
pointsFormatId: readAs(arraybuffer, Uint8Array, 32 * 3 + 8),
|
|
72
|
-
pointsStructSize: readAs(arraybuffer, Uint16Array, 32 * 3 + 8 + 1),
|
|
73
|
-
pointsCount: readAs(arraybuffer, Uint32Array, 32 * 3 + 11),
|
|
74
|
-
scale: readAs(arraybuffer, Float64Array, start, 3)
|
|
75
|
-
};
|
|
76
|
-
start += 24; // 8*3
|
|
77
|
-
o.offset = readAs(arraybuffer, Float64Array, start, 3);
|
|
78
|
-
start += 24;
|
|
79
|
-
const bounds = readAs(arraybuffer, Float64Array, start, 6);
|
|
80
|
-
start += 48; // 8*6;
|
|
81
|
-
o.maxs = [bounds[0], bounds[2], bounds[4]];
|
|
82
|
-
o.mins = [bounds[1], bounds[3], bounds[5]];
|
|
83
|
-
return o;
|
|
84
|
-
}
|
|
85
|
-
// LAS Loader
|
|
86
|
-
// Loads uncompressed files
|
|
87
|
-
//
|
|
88
|
-
class LASLoader {
|
|
89
|
-
constructor(arraybuffer) {
|
|
90
|
-
this.readOffset = 0;
|
|
91
|
-
this.header = {
|
|
92
|
-
pointsOffset: 0,
|
|
93
|
-
pointsFormatId: 0,
|
|
94
|
-
pointsStructSize: 0,
|
|
95
|
-
pointsCount: 0,
|
|
96
|
-
scale: [0, 0, 0],
|
|
97
|
-
offset: [0, 0, 0],
|
|
98
|
-
maxs: [0],
|
|
99
|
-
mins: [0],
|
|
100
|
-
totalToRead: 0,
|
|
101
|
-
totalRead: 0,
|
|
102
|
-
versionAsString: '',
|
|
103
|
-
isCompressed: true
|
|
104
|
-
};
|
|
105
|
-
this.arraybuffer = arraybuffer;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* @returns boolean
|
|
109
|
-
*/
|
|
110
|
-
open() {
|
|
111
|
-
// Nothing needs to be done to open this
|
|
112
|
-
return true;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Parsing of incoming binary
|
|
116
|
-
* @returns LASHeader
|
|
117
|
-
*/
|
|
118
|
-
getHeader() {
|
|
119
|
-
this.header = parseLASHeader(this.arraybuffer);
|
|
120
|
-
return this.header;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Reading data
|
|
124
|
-
* @param count
|
|
125
|
-
* @param skip
|
|
126
|
-
* @returns new ArrayBuffer, count, hasMoreData
|
|
127
|
-
*/
|
|
128
|
-
readData(count, skip) {
|
|
129
|
-
const { header, arraybuffer } = this;
|
|
130
|
-
if (!header) {
|
|
131
|
-
throw new Error('Cannot start reading data till a header request is issued');
|
|
132
|
-
}
|
|
133
|
-
let { readOffset } = this;
|
|
134
|
-
let start;
|
|
135
|
-
if (skip <= 1) {
|
|
136
|
-
count = Math.min(count, header.pointsCount - readOffset);
|
|
137
|
-
start = header.pointsOffset + readOffset * header.pointsStructSize;
|
|
138
|
-
const end = start + count * header.pointsStructSize;
|
|
139
|
-
readOffset += count;
|
|
140
|
-
this.readOffset = readOffset;
|
|
141
|
-
return {
|
|
142
|
-
buffer: arraybuffer.slice(start, end),
|
|
143
|
-
count,
|
|
144
|
-
hasMoreData: readOffset < header.pointsCount
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
const pointsToRead = Math.min(count * skip, header.pointsCount - readOffset);
|
|
148
|
-
const bufferSize = Math.ceil(pointsToRead / skip);
|
|
149
|
-
let pointsRead = 0;
|
|
150
|
-
const buf = new Uint8Array(bufferSize * header.pointsStructSize);
|
|
151
|
-
for (let i = 0; i < pointsToRead; i++) {
|
|
152
|
-
if (i % skip === 0) {
|
|
153
|
-
start = header.pointsOffset + readOffset * header.pointsStructSize;
|
|
154
|
-
const src = new Uint8Array(arraybuffer, start, header.pointsStructSize);
|
|
155
|
-
buf.set(src, pointsRead * header.pointsStructSize);
|
|
156
|
-
pointsRead++;
|
|
157
|
-
}
|
|
158
|
-
readOffset++;
|
|
159
|
-
}
|
|
160
|
-
this.readOffset = readOffset;
|
|
161
|
-
return {
|
|
162
|
-
buffer: buf.buffer,
|
|
163
|
-
count: pointsRead,
|
|
164
|
-
hasMoreData: readOffset < header.pointsCount
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Method which brings data to null to close the file
|
|
169
|
-
* @returns
|
|
170
|
-
*/
|
|
171
|
-
close() {
|
|
172
|
-
// @ts-ignore Possibly null
|
|
173
|
-
this.arraybuffer = null;
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* LAZ Loader
|
|
179
|
-
* Uses NaCL module to load LAZ files
|
|
180
|
-
*/
|
|
181
|
-
class LAZLoader {
|
|
182
|
-
constructor(arraybuffer) {
|
|
183
|
-
this.instance = null; // LASZip instance
|
|
184
|
-
this.header = null;
|
|
185
|
-
this.arraybuffer = arraybuffer;
|
|
186
|
-
if (!Module) {
|
|
187
|
-
// Avoid executing laz-perf on import
|
|
188
|
-
Module = (0, laz_perf_1.default)();
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Opens the file
|
|
193
|
-
* @returns boolean
|
|
194
|
-
*/
|
|
195
|
-
open() {
|
|
196
|
-
try {
|
|
197
|
-
const { arraybuffer } = this;
|
|
198
|
-
this.instance = new Module.LASZip();
|
|
199
|
-
const abInt = new Uint8Array(arraybuffer);
|
|
200
|
-
const buf = Module._malloc(arraybuffer.byteLength);
|
|
201
|
-
this.instance.arraybuffer = arraybuffer;
|
|
202
|
-
this.instance.buf = buf;
|
|
203
|
-
Module.HEAPU8.set(abInt, buf);
|
|
204
|
-
this.instance.open(buf, arraybuffer.byteLength);
|
|
205
|
-
this.instance.readOffset = 0;
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
throw new Error(`Failed to open file: ${error.message}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
getHeader() {
|
|
213
|
-
if (!this.instance) {
|
|
214
|
-
throw new Error('You need to open the file before trying to read header');
|
|
215
|
-
}
|
|
216
|
-
try {
|
|
217
|
-
const header = parseLASHeader(this.instance.arraybuffer);
|
|
218
|
-
header.pointsFormatId &= 0x3f;
|
|
219
|
-
this.header = header;
|
|
220
|
-
return header;
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
throw new Error(`Failed to get header: ${error.message}`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* @param count
|
|
228
|
-
* @param offset
|
|
229
|
-
* @param skip
|
|
230
|
-
* @returns Data
|
|
231
|
-
*/
|
|
232
|
-
readData(count, offset, skip) {
|
|
233
|
-
if (!this.instance) {
|
|
234
|
-
throw new Error('You need to open the file before trying to read stuff');
|
|
235
|
-
}
|
|
236
|
-
const { header, instance } = this;
|
|
237
|
-
if (!header) {
|
|
238
|
-
throw new Error('You need to query header before reading, I maintain state that way, sorry :(');
|
|
239
|
-
}
|
|
240
|
-
try {
|
|
241
|
-
const pointsToRead = Math.min(count * skip, header.pointsCount - instance.readOffset);
|
|
242
|
-
const bufferSize = Math.ceil(pointsToRead / skip);
|
|
243
|
-
let pointsRead = 0;
|
|
244
|
-
const thisBuf = new Uint8Array(bufferSize * header.pointsStructSize);
|
|
245
|
-
const bufRead = Module._malloc(header.pointsStructSize);
|
|
246
|
-
for (let i = 0; i < pointsToRead; i++) {
|
|
247
|
-
instance.getPoint(bufRead);
|
|
248
|
-
if (i % skip === 0) {
|
|
249
|
-
const a = new Uint8Array(Module.HEAPU8.buffer, bufRead, header.pointsStructSize);
|
|
250
|
-
thisBuf.set(a, pointsRead * header.pointsStructSize);
|
|
251
|
-
pointsRead++;
|
|
252
|
-
}
|
|
253
|
-
instance.readOffset++;
|
|
254
|
-
}
|
|
255
|
-
return {
|
|
256
|
-
buffer: thisBuf.buffer,
|
|
257
|
-
count: pointsRead,
|
|
258
|
-
hasMoreData: instance.readOffset < header.pointsCount
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
catch (error) {
|
|
262
|
-
throw new Error(`Failed to read data: ${error.message}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Deletes the instance
|
|
267
|
-
* @returns boolean
|
|
268
|
-
*/
|
|
269
|
-
close() {
|
|
270
|
-
try {
|
|
271
|
-
if (this.instance !== null) {
|
|
272
|
-
this.instance.delete();
|
|
273
|
-
this.instance = null;
|
|
274
|
-
}
|
|
275
|
-
return true;
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
throw new Error(`Failed to close file: ${error.message}`);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Helper class: Decodes LAS records into points
|
|
284
|
-
*/
|
|
285
|
-
class LASDecoder {
|
|
286
|
-
constructor(buffer, len, header) {
|
|
287
|
-
this.arrayb = buffer;
|
|
288
|
-
this.decoder = POINT_FORMAT_READERS[header.pointsFormatId];
|
|
289
|
-
this.pointsCount = len;
|
|
290
|
-
this.pointSize = header.pointsStructSize;
|
|
291
|
-
this.scale = header.scale;
|
|
292
|
-
this.offset = header.offset;
|
|
293
|
-
this.mins = header.mins;
|
|
294
|
-
this.maxs = header.maxs;
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Decodes data depends on this point size
|
|
298
|
-
* @param index
|
|
299
|
-
* @returns New object
|
|
300
|
-
*/
|
|
301
|
-
getPoint(index) {
|
|
302
|
-
if (index < 0 || index >= this.pointsCount) {
|
|
303
|
-
throw new Error('Point index out of range');
|
|
304
|
-
}
|
|
305
|
-
const dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
|
|
306
|
-
return this.decoder(dv);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* A single consistent interface for loading LAS/LAZ files
|
|
311
|
-
*/
|
|
312
|
-
class LASFile {
|
|
313
|
-
constructor(arraybuffer) {
|
|
314
|
-
this.formatId = 0;
|
|
315
|
-
this.isCompressed = true;
|
|
316
|
-
this.isOpen = false;
|
|
317
|
-
this.version = 0;
|
|
318
|
-
this.versionAsString = '';
|
|
319
|
-
this.arraybuffer = arraybuffer;
|
|
320
|
-
if (this.determineVersion() > 13) {
|
|
321
|
-
throw new Error('Only file versions <= 1.3 are supported at this time');
|
|
322
|
-
}
|
|
323
|
-
this.determineFormat();
|
|
324
|
-
if (POINT_FORMAT_READERS[this.formatId] === undefined) {
|
|
325
|
-
throw new Error('The point format ID is not supported');
|
|
326
|
-
}
|
|
327
|
-
this.loader = this.isCompressed
|
|
328
|
-
? new LAZLoader(this.arraybuffer)
|
|
329
|
-
: new LASLoader(this.arraybuffer);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* Determines format in parameters of LASHeaer
|
|
333
|
-
*/
|
|
334
|
-
determineFormat() {
|
|
335
|
-
const formatId = readAs(this.arraybuffer, Uint8Array, 32 * 3 + 8);
|
|
336
|
-
const bit7 = (formatId & 0x80) >> 7;
|
|
337
|
-
const bit6 = (formatId & 0x40) >> 6;
|
|
338
|
-
if (bit7 === 1 && bit6 === 1) {
|
|
339
|
-
throw new Error('Old style compression not supported');
|
|
340
|
-
}
|
|
341
|
-
this.formatId = formatId & 0x3f;
|
|
342
|
-
this.isCompressed = bit7 === 1 || bit6 === 1;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Determines version
|
|
346
|
-
* @returns version
|
|
347
|
-
*/
|
|
348
|
-
determineVersion() {
|
|
349
|
-
const ver = new Int8Array(this.arraybuffer, 24, 2);
|
|
350
|
-
this.version = ver[0] * 10 + ver[1];
|
|
351
|
-
this.versionAsString = `${ver[0]}.${ver[1]}`;
|
|
352
|
-
return this.version;
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Reads if the file is open
|
|
356
|
-
* @returns boolean
|
|
357
|
-
*/
|
|
358
|
-
open() {
|
|
359
|
-
if (this.loader.open()) {
|
|
360
|
-
this.isOpen = true;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Gets the header
|
|
365
|
-
* @returns Header
|
|
366
|
-
*/
|
|
367
|
-
getHeader() {
|
|
368
|
-
return this.loader.getHeader();
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* @param count
|
|
372
|
-
* @param start
|
|
373
|
-
* @param skip
|
|
374
|
-
* @returns Data
|
|
375
|
-
*/
|
|
376
|
-
readData(count, start, skip) {
|
|
377
|
-
return this.loader.readData(count, start, skip);
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Closes the file
|
|
381
|
-
*/
|
|
382
|
-
close() {
|
|
383
|
-
if (this.loader.close()) {
|
|
384
|
-
this.isOpen = false;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
*/
|
|
389
|
-
getUnpacker() {
|
|
390
|
-
return LASDecoder;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
exports.LASFile = LASFile;
|
|
394
|
-
exports.LASModuleWasLoaded = false;
|
|
395
|
-
/* eslint no-use-before-define: 2 */
|