• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iTowns / itowns / 8896060322

30 Apr 2024 01:56PM UTC coverage: 89.361% (-0.04%) from 89.402%
8896060322

push

github

Desplandis
docs(COPC): expose doc for COPCLayer and COPCSource

2712 of 3600 branches covered (75.33%)

Branch coverage included in aggregate %.

23226 of 25426 relevant lines covered (91.35%)

342.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.84
/src/Parser/LASParser.js
1
import * as THREE from 'three';
1✔
2
import LASLoader from 'Parser/LASLoader';
1✔
3

1✔
4
const lasLoader = new LASLoader();
1✔
5

2✔
6
function buildBufferGeometry(attributes) {
2✔
7
    const geometry = new THREE.BufferGeometry();
2✔
8

2✔
9
    const positionBuffer = new THREE.BufferAttribute(attributes.position, 3);
2✔
10
    geometry.setAttribute('position', positionBuffer);
2✔
11

2✔
12
    const intensityBuffer = new THREE.BufferAttribute(attributes.intensity, 1);
2✔
13
    geometry.setAttribute('intensity', intensityBuffer);
2✔
14

2✔
15
    const returnNumber = new THREE.BufferAttribute(attributes.returnNumber, 1);
2✔
16
    geometry.setAttribute('returnNumber', returnNumber);
2✔
17

2✔
18
    const numberOfReturns = new THREE.BufferAttribute(attributes.numberOfReturns, 1);
2✔
19
    geometry.setAttribute('numberOfReturns', numberOfReturns);
2✔
20

2✔
21
    const classBuffer = new THREE.BufferAttribute(attributes.classification, 1);
2✔
22
    geometry.setAttribute('classification', classBuffer);
2✔
23

2✔
24
    const pointSourceID = new THREE.BufferAttribute(attributes.pointSourceID, 1);
2✔
25
    geometry.setAttribute('pointSourceID', pointSourceID);
2✔
26

1✔
27
    if (attributes.color) {
1✔
28
        const colorBuffer = new THREE.BufferAttribute(attributes.color, 4, true);
1✔
29
        geometry.setAttribute('color', colorBuffer);
2✔
30
    }
2✔
31
    const scanAngle = new THREE.BufferAttribute(attributes.scanAngle, 1);
2✔
32
    geometry.setAttribute('scanAngle', scanAngle);
2✔
33

2✔
34
    geometry.userData.origin = new THREE.Vector3().fromArray(attributes.origin);
1✔
35

1✔
36
    return geometry;
1✔
37
}
1✔
38

1✔
39
/** The LASParser module provides a [parse]{@link
1✔
40
 * module:LASParser.parse} method that takes a LAS or LAZ (LASZip) file in, and
1✔
41
 * gives a `THREE.BufferGeometry` containing all the necessary attributes to be
1✔
42
 * displayed in iTowns. It uses the
1✔
43
 * [copc.js](https://github.com/connormanning/copc.js/) library.
1✔
44
 *
1✔
45
 * @module LASParser
1✔
46
 */
1✔
47
export default {
1✔
48
    /*
1✔
49
     * Set the laz-perf decoder path.
1✔
50
     * @param {string} path - path to `laz-perf.wasm` folder.
1!
51
     */
×
52
    enableLazPerf(path) {
×
53
        if (!path) {
1✔
54
            throw new Error('Path to laz-perf is mandatory');
1✔
55
        }
1✔
56
        lasLoader.lazPerf = path;
1✔
57
    },
1✔
58

1✔
59

1✔
60
    /**
1✔
61
     * Parses a chunk of a LAS or LAZ (LASZip) and returns the corresponding
1✔
62
     * `THREE.BufferGeometry`.
1✔
63
     *
1✔
64
     * @param {ArrayBuffer} data - The file content to parse.
1✔
65
     * @param {Object} options
1✔
66
     * @param {Object} options.in - Options to give to the parser.
1✔
67
     * @param {number} options.in.pointCount - Number of points encoded in this
1✔
68
     * data chunk.
1✔
69
     * @param {Object} options.in.header - Partial LAS file header.
1✔
70
     * @param {number} options.in.header.pointDataRecordFormat - Type of Point
1✔
71
     * Data Record contained in the LAS file.
1✔
72
     * @param {number} options.in.header.pointDataRecordLength - Size (in bytes)
1✔
73
     * of the Point Data Record.
1✔
74
     * @param {Object} [options.eb] - Extra bytes LAS VLRs headers.
1✔
75
     * @param { 8 | 16 } [options.in.colorDepth] - Color depth (in bits).
1✔
76
     * Defaults to 8 bits for LAS 1.2 and 16 bits for later versions
1✔
77
     * (as mandatory by the specification)
1✔
78
     *
×
79
     * @return {Promise<THREE.BufferGeometry>} A promise resolving with a
×
80
     * `THREE.BufferGeometry`.
×
81
     */
×
82
    parseChunk(data, options = {}) {
×
83
        return lasLoader.parseChunk(data, options.in).then((parsedData) => {
×
84
            const geometry = buildBufferGeometry(parsedData.attributes);
1✔
85
            geometry.computeBoundingBox();
1✔
86
            return geometry;
1✔
87
        });
1✔
88
    },
1✔
89

1✔
90
    /**
1✔
91
     * Parses a LAS file or a LAZ (LASZip) file and return the corresponding
1✔
92
     * `THREE.BufferGeometry`.
1✔
93
     *
1✔
94
     * @param {ArrayBuffer} data - The file content to parse.
1✔
95
     * @param {Object} [options]
1✔
96
     * @param {Object} [options.in] - Options to give to the parser.
1✔
97
     * @param { 8 | 16 } [options.in.colorDepth] - Color depth (in bits).
1✔
98
     * Defaults to 8 bits for LAS 1.2 and 16 bits for later versions
1✔
99
     * (as mandatory by the specification)
1✔
100
     *
1✔
101
     * @return {Promise} A promise resolving with a `THREE.BufferGeometry`. The
1✔
102
     * header of the file is contained in `userData`.
3✔
103
     */
1✔
104
    parse(data, options = {}) {
3✔
105
        if (options.out?.skip) {
3✔
106
            console.warn("Warning: options 'skip' not supported anymore");
3!
107
        }
×
108
        return lasLoader.parseFile(data, {
×
109
            colorDepth: options.in?.colorDepth,
3✔
110
        }).then((parsedData) => {
3✔
111
            const geometry = buildBufferGeometry(parsedData.attributes);
3✔
112
            geometry.userData.header = parsedData.header;
3✔
113
            geometry.computeBoundingBox();
2✔
114
            return geometry;
2✔
115
        });
2✔
116
    },
2✔
117
};
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc