### Install LAZperf library Source: https://github.com/hobuinc/laz-perf/blob/master/README.md Installs the built library and supporting header files after building. ```bash make install ``` -------------------------------- ### Inspect LAZ VLR and Construct WKT VLR in C++ Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/vlrs.md Use this example to read an LAZ VLR from a file and to build a WKT VLR for writing. It includes the necessary includes and uses the lazperf namespace. The example prints the number of codec items and shows how to obtain the payload data from the WKT VLR. ```cpp #include "vlr.hpp" using namespace lazperf; // Inspect the LAZ VLR of a file. reader::named_file f("file.laz"); laz_vlr laz = f.lazVlr(); bool variable = laz.variableChunks(); uint32_t chunkSize = laz.chunk_size; std::cout << laz.items.size() << " codec items\n"; // Construct a WKT VLR for writing. wkt_vlr crs("PROJCS[\"WGS 84 / UTM zone 17N\",...]"); std::vector payload = crs.data(); // feed into your own writer ``` -------------------------------- ### mem_file usage example Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/readers.md Shows how to use reader::mem_file to read points from an in-memory buffer. The example iterates over the point count from the header and calls readPoint for each point. ```cpp using namespace lazperf; reader::mem_file f(buf, bufsize); char pointbuf[100]; for (size_t i = 0; i < f.header().point_count; ++i) f.readPoint(pointbuf); ``` -------------------------------- ### Example — clamp and bit-cast Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/utils.md Demonstrates clamping a value to uint8_t, bit-casting between double and uint64_t, and clearing a bit. ```cpp using namespace lazperf; uint8_t b = utils::clamp(300); // 255 double d = utils::u2d(0x3FF0000000000000ULL); // 1.0 uint64_t bits = utils::d2u(1.0); // 0x3FF0000000000000 int v = utils::clearBit<3>(15); // 7 ``` -------------------------------- ### Example — unpack a raw point Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/utils.md Shows how to unpack three int32_t values from a raw byte buffer using the unpack function. ```cpp #include "utils.hpp" char raw[20] = { /* ... */ }; int32_t x = lazperf::utils::unpack(raw); int32_t y = lazperf::utils::unpack(raw + 4); int32_t z = lazperf::utils::unpack(raw + 8); ``` -------------------------------- ### named_file usage example Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/readers.md Shows how to use reader::named_file to read points from a file. The example iterates over the point count from the header and calls readPoint for each point. ```cpp using namespace lazperf; reader::named_file f(filename); char pointbuf[100]; for (size_t i = 0; i < f.header().point_count; ++i) f.readPoint(pointbuf); ``` -------------------------------- ### Build a header manually for writing Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/headers.md Example showing how to construct a header14 object manually for writing LAZ files, setting version, point format, record length, scale, and offset. ```APIDOC ## Build a header manually for writing ### Description Example showing how to construct a header14 object manually for writing LAZ files, setting version, point format, record length, scale, and offset. ### Code Example ```cpp #include "header.hpp" using namespace lazperf; header14 h; h.version.minor = 4; h.point_format_id = 6; h.point_record_length = baseCount(6); // 30 h.scale = vector3(0.01, 0.01, 0.01); h.offset = vector3(0, 0, 0); ``` ``` -------------------------------- ### chunk_compressor usage example Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Example showing how to use writer::chunk_compressor to compress points into a chunk. It creates a compressor with format 3 and 0 extra bytes, compresses 50000 points, and retrieves the compressed chunk. The comment notes reversing with reader::chunk_decompressor. ```cpp using namespace lazperf; writer::chunk_compressor cc(3, 0); las::point10 p; for (int i = 0; i < 50000; ++i) { p.x = i; p.y = i; p.z = i; cc.compress(reinterpret_cast(&p)); } std::vector chunk = cc.done(); // reverse with reader::chunk_decompressor(format, ebCount, chunk.data()) ``` -------------------------------- ### Install laz-perf npm package Source: https://github.com/hobuinc/laz-perf/blob/master/README.md Installs the laz-perf UMD module for JavaScript/TypeScript, compatible with NodeJS and browsers. ```bash npm install laz-perf ``` -------------------------------- ### Variable-size chunks with explicit chunk boundaries Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Example of writing a file with variable-size chunks. The config uses laz_vlr::VariableChunkSize (0xFFFFFFFF) to enable variable chunking. newChunk() is called to start each chunk, and close() is called at the end. ```cpp writer::named_file::config c2(vector3(1, 1, 1), vector3(0, 0, 0), laz_vlr::VariableChunkSize); // 0xFFFFFFFF writer::named_file out2("var.laz", c2); for (int chunk = 0; chunk < 5; ++chunk) { out2.newChunk(); for (int i = 0; i < 1000; ++i) out2.writePoint(reinterpret_cast(&p)); } out2.close(); ``` -------------------------------- ### File-based compression with callbacks using OutFileStream and InFileStream Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/streams.md Compresses 100 points to a file using point_compressor_1 and then decompresses them back using point_decompressor_1. Uses OutFileStream and InFileStream with callbacks. The example writes to 'out.laz.bin' and reads it back later. ```cpp #include "filestream.hpp" #include "lazperf.hpp" using namespace lazperf; std::ofstream outfile("out.laz.bin", std::ios::binary); OutFileStream out(outfile); point_compressor_1 comp(out.cb()); // format 1 las::gpstime g; g.value = 0; for (int i = 0; i < 100; ++i) { las::point10 p; comp.compress(reinterpret_cast(&p)); } comp.done(); // Later: read back std::ifstream infile("out.laz.bin", std::ios::binary); InFileStream in(infile); point_decompressor_1 decomp(in.cb()); las::point10 p2; for (int i = 0; i < 100; ++i) decomp.decompress(reinterpret_cast(&p2)); ``` -------------------------------- ### Decompress LAZ point format 0 with callback Source: https://github.com/hobuinc/laz-perf/blob/master/README.md C++ example showing how to decompress LAZ data by creating a point_decompressor_0 with a callback that provides data from the LAZ source. The callback copies data into a static buffer. ```cpp using namespace lazperf; void cb(unsigned char *buf, int len) { static unsigned char my_laz_data[] = {...}; static int idx = 0; std::copy(buf, buf + len, my_laz_data + idx); idx += len; } point_decompressor_0 decompressor(cb); char pointbuf[100]; for (int i = 0; i < num_points; ++i) { decompressor(pointbuf); // Do something with the point data in 'pointbuf' } ``` -------------------------------- ### Read a header and derive point formation Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/headers.md Example showing how to open a LAZ file, read its header, and extract point format, extra bytes count, compression flag, and point count. ```APIDOC ## Read a header and derive point formation ### Description Example showing how to open a LAZ file, read its header, and extract point format, extra bytes count, compression flag, and point count. ### Code Example ```cpp #include "readers.hpp" #include "header.hpp" using namespace lazperf; reader::named_file f("file.laz"); const header14& h = f.header(); int format = h.pointFormat(); // e.g. 3 int ebCount = h.ebCount(); // extra bytes per record bool isCompressed = h.compressed(); // LAZ compression bit uint64_t count = f.pointCount(); // h.point_count_14 for 1.4 files ``` ``` -------------------------------- ### basic_file::newChunk Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Starts a new chunk, finalizing the current compressor and recording the chunk position. Intended for variable-size chunks. ```APIDOC ## basic_file::newChunk ### Description Starts a new chunk, finalizing the current compressor and recording the chunk position. Intended for variable-size chunks. ### Method newChunk ### Signature uint64_t newChunk() ### Return Value - **uint64_t** - The byte position (absolute, in the output stream) where the new chunk's data starts. ### Behavior Finalizes the current compressor (done()), records {chunk_point_num, position} in the chunk vector, and creates a fresh compressor. Asserts laz_vlr::variableChunks(p_->chunk_size) in debug builds. ``` -------------------------------- ### In-memory istream over a buffer using charbuf and reader::generic_file Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/streams.md Creates an std::istream over a vector of bytes using charbuf, then reads points from a generic_file reader. The example reads one point and breaks out of the loop. ```cpp #include "charbuf.hpp" #include "readers.hpp" using namespace lazperf; std::vector bytes = /* LAS/LAZ contents */; charbuf sb(bytes); std::istream in(&sb); reader::generic_file f(in); char pointbuf[100]; while (f.pointCount()) { f.readPoint(pointbuf); break; // e.g. read one point } ``` -------------------------------- ### writer::named_file::newChunk() Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Starts a new chunk in the output. Used for variable-size chunk writing. ```APIDOC ## writer::named_file::newChunk() ### Description Starts a new chunk in the output. This is used when writing variable-size chunks with explicit chunk boundaries. ### Method newChunk ### Parameters None ### Returns void ### Example ```cpp writer::named_file::config c2(vector3(1, 1, 1), vector3(0, 0, 0), laz_vlr::VariableChunkSize); // 0xFFFFFFFF writer::named_file out2("var.laz", c2); for (int chunk = 0; chunk < 5; ++chunk) { out2.newChunk(); for (int i = 0; i < 1000; ++i) out2.writePoint(reinterpret_cast(&p)); } out2.close(); ``` ``` -------------------------------- ### reader::generic_file constructor Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/readers.md Creates a reader that reads LAS/LAZ data from any readable stream positioned at the start of a LAS/LAZ file. Throws lazperf::error on parse failure. ```APIDOC ## reader::generic_file ### Description Creates a reader that reads LAS/LAZ data from any readable stream positioned at the start of a LAS/LAZ file. Throws `lazperf::error` on parse failure. ### Constructor `generic_file(std::istream& in)` ### Parameters - **in** (`std::istream&`) - Required - Any readable stream positioned at the start of a LAS/LAZ file ### Throws - `lazperf::error` - `"Couldn't open generic_file as LAS/LAZ"` on parse failure. ### Usage Use with a `std::ifstream` or a `charbuf`-backed stream (see [streams.md](streams.md)). ``` -------------------------------- ### Write compressed LAS 1.4 file (format 6) Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Example of writing a compressed LAS 1.4 file with point format 6. The config is set with a scale of 0.01 and offset of 0. The close() call is required to write header fixups and the chunk table. ```cpp #include "writers.hpp" using namespace lazperf; writer::named_file::config c(vector3(0.01, 0.01, 0.01), vector3(0, 0, 0)); c.pdrf = 6; c.minor_version = 4; writer::named_file out("points.laz", c); las::point14 p; for (int i = 0; i < 100000; ++i) { p.setX(i); p.setY(i); p.setZ(i); out.writePoint(reinterpret_cast(&p)); } out.close(); // REQUIRED: writes header fixups and the chunk table ``` -------------------------------- ### LeExtractor public API Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/internal-codecs.md Highlights the public API of `LeExtractor` from `Extractor.hpp`. It provides little-endian reading over a byte buffer with a seekable cursor, used for header/VLR serialization. The `operator>>` handles integers, doubles, and strings, sized by the type; `get` with explicit `size` reads the specified number of bytes. ```cpp struct LeExtractor { void seek(std::size_t pos); void skip(std::size_t cnt); void get(std::string& s, size_t size); void get(std::vector& buf); void get(std::vector& buf); void get(char *buf, size_t size); void get(unsigned char *buf, size_t size); template LeExtractor& operator >> (T& t); }; ``` -------------------------------- ### basic_file::open Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Opens the output stream and initializes the writer with a header template and chunk size. Returns false if the header version is not supported. ```APIDOC ## basic_file::open ### Description Opens the output stream and initializes the writer with a header template and chunk size. Returns false if the header version is not supported. ### Method open ### Signature bool open(std::ostream& out, const header12& h, uint32_t chunk_size) ### Parameters - **out** (std::ostream&) - Required - Output stream for the LAS/LAZ bytes - **h** (const header12&) - Required - Header template; the writer takes version, scale, offset, point_format_id, point_record_length from it and updates bounds/counts as points are written - **chunk_size** (uint32_t) - Required - Points per chunk. 0 disables compression (uncompressed LAS). laz_vlr::VariableChunkSize (0xFFFFFFFF) enables variable-size chunks, which require explicit newChunk() calls. ### Return Value - **bool** - false if h.version.major != 1 || h.version.minor < 2 || h.version.minor > 4; true otherwise. On success it writes the header, reserves 8 bytes for the chunk table offset (when compressed), and initializes the output stream adapter. Compression is selected purely by chunk_size. ``` -------------------------------- ### Build a header manually for writing Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/headers.md Shows how to construct a header14 object manually, setting version, point format, record length, scale, and offset for writing. ```cpp #include "header.hpp" using namespace lazperf; header14 h; h.version.minor = 4; h.point_format_id = 6; h.point_record_length = baseCount(6); // 30 h.scale = vector3(0.01, 0.01, 0.01); h.offset = vector3(0, 0, 0); ``` -------------------------------- ### Build LAZperf with CMake Source: https://github.com/hobuinc/laz-perf/blob/master/README.md Commands to clone, configure, and build the LAZperf library on Unix-like systems. Requires Git, CMake, make, and a C++11 compiler. Produces liblazperf.so. ```bash git clone https://github.com/hobu/laz-perf.git cd laz-perf mkdir build cd build cmake .. make ``` -------------------------------- ### streaming_median class template Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/utils.md A 5-element streaming median filter used by XYZ predictors. get() returns values[2] as the median. ```cpp template class streaming_median { public: std::array values; bool high; void init(); inline void add(const T& v); inline T get() const; streaming_median(); }; ``` -------------------------------- ### create Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Alias of `createLazPerf` for loading the Emscripten module. ```APIDOC ## create ### Description Alias of `createLazPerf`; loads and initializes the Emscripten module. ### Method Function call ### Signature `create(): Promise` ### Parameters None ### Returns - **LazPerf** (object) - The resolved Emscripten module instance. ### Example ```typescript import { create } from 'laz-perf' const lazPerf = await create() ``` ``` -------------------------------- ### Compress and decompress point10 with lazperf Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/internal-codecs.md Shows the full workflow: create a MemoryStream, use point_compressor_0 to compress 1000 point10 records, then use point_decompressor_0 to decompress them back. Requires including the listed headers and using namespace lazperf. ```cpp #include "las.hpp" #include "encoder.hpp" #include "decoder.hpp" #include "compressor.hpp" #include "decompressor.hpp" #include "streams.hpp" using namespace lazperf; MemoryStream s; point_compressor_0 compressor(s.outCb(), 0); las::point10 p; for (int i = 0; i < 1000; ++i) { p.x = i; p.y = i + 1000; p.z = i + 10000; compressor.compress(reinterpret_cast(&p)); } compressor.done(); point_decompressor_0 decompressor(s.inCb(), 0); las::point10 p2; for (int i = 0; i < 1000; ++i) decompressor.decompress(reinterpret_cast(&p2)); ``` -------------------------------- ### C++ streaming_median template class Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/types.md A 5-value streaming median template. get() returns values[2]. Used internally by Point10Base and ChannelCtx. ```cpp template class streaming_median { public: std::array values; bool high; void init(); inline void add(const T& v); inline T get() const; streaming_median(); }; ``` -------------------------------- ### vlr (abstract base) Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/types.md Abstract base class for VLR types. Provides pure virtual methods to get the size and header information. ```APIDOC ## vlr (abstract base) ### Description Abstract base class for VLR types. Provides pure virtual methods to get the size and header information. ### Methods - `uint64_t size() const` - Returns the size of the VLR. - `vlr_header header() const` - Returns the vlr_header. - `evlr_header eheader() const` - Returns the evlr_header. ### Concrete Subtypes - `laz_vlr` - `eb_vlr` - `wkt_vlr` - `copc_info_vlr` See api-reference/vlrs.md for details. ``` -------------------------------- ### Build points and compress with format 6 Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/las-point-formats.md Uses lazperf::point_compressor_6 to compress 1000 points into a MemoryStream, then decompresses with point_decompressor_6. Requires including las.hpp, lazperf.hpp, and streams.hpp. ```cpp #include "las.hpp" #include "lazperf.hpp" #include "streams.hpp" using namespace lazperf; MemoryStream ms; point_compressor_6 comp(ms.outCb()); las::point14 p; for (int i = 0; i < 1000; ++i) { p.setX(i); p.setY(i * 2); p.setZ(i / 2); p.setReturnNum(1); p.setNumReturns(1); p.setGpsTime(1e9 + i); comp.compress(reinterpret_cast(&p)); } comp.done(); point_decompressor_6 decomp(ms.inCb()); las::point14 q; decomp.decompress(reinterpret_cast(&q)); ``` -------------------------------- ### Build points and compress with format 6 Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/las-point-formats.md Demonstrates creating a point_compressor_6 and point_decompressor_6 to compress and decompress las::point14 data. ```APIDOC ## Build points and compress with format 6 ### Description Creates a point_compressor_6 to compress 1000 las::point14 points into a MemoryStream, then decompresses them with a point_decompressor_6. ### Method N/A (C++ API) ### Endpoint N/A (C++ API) ### Parameters #### Constructor: point_compressor_6(streams::out_cb cb) - **cb** (streams::out_cb) - Required - Callback for output stream. #### Constructor: point_decompressor_6(streams::in_cb cb) - **cb** (streams::in_cb) - Required - Callback for input stream. #### Method: comp.compress(const char *data) - **data** (const char*) - Required - Pointer to point data to compress. #### Method: comp.done() No parameters. #### Method: decomp.decompress(char *data) - **data** (char*) - Required - Pointer to buffer to receive decompressed point data. ### Request Example ```cpp #include "las.hpp" #include "lazperf.hpp" #include "streams.hpp" using namespace lazperf; MemoryStream ms; point_compressor_6 comp(ms.outCb()); las::point14 p; for (int i = 0; i < 1000; ++i) { p.setX(i); p.setY(i * 2); p.setZ(i / 2); p.setReturnNum(1); p.setNumReturns(1); p.setGpsTime(1e9 + i); comp.compress(reinterpret_cast(&p)); } comp.done(); point_decompressor_6 decomp(ms.inCb()); las::point14 q; decomp.decompress(reinterpret_cast(&q)); ``` ### Response #### Success Response No explicit return value; decompressed data is written to the provided buffer. #### Response Example N/A ``` -------------------------------- ### basic_file::writePoint Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Writes a single point record to the output. Buffers the point, updates bounds and counts, and starts a new chunk when the chunk size is reached. ```APIDOC ## basic_file::writePoint ### Description Writes a single point record to the output. Buffers the point, updates bounds and counts, and starts a new chunk when the chunk size is reached. ### Method writePoint ### Signature void writePoint(const char *p) ### Parameters - **p** (const char *) - Required - Raw point record matching the header's format and record length ### Behavior Buffers the point, updating point_count_14, min/max bounds (computed via scale/offset, from las::point10 x/y/z fields), and starts a new chunk whenever chunk_point_num == chunk_size for fixed-size chunks (lazily creating the compressor on the first point). ``` -------------------------------- ### Memory round-trip using MemoryStream Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/streams.md Compresses a single point into a MemoryStream and then decompresses it back. Shows how to get the compressed size with numBytesPut(). Uses point_compressor_0 and point_decompressor_0. ```cpp #include "streams.hpp" #include "lazperf.hpp" using namespace lazperf; MemoryStream ms; { point_compressor_0 comp(ms.outCb()); las::point10 p; comp.compress(reinterpret_cast(&p)); comp.done(); } size_t bytesWritten = ms.numBytesPut(); // compressed size point_decompressor_0 decomp(ms.inCb()); las::point10 again; decomp.decompress(reinterpret_cast(&again)); ``` -------------------------------- ### newChunk method declaration Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Declaration of the newChunk method, which finalizes the current compressor and starts a new chunk, returning the byte position of the new chunk's data. ```cpp LAZPERF_EXPORT uint64_t newChunk(); ``` -------------------------------- ### Point decompressor usage with callback Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/index.md Shows how to construct a point decompressor with an I/O callback and decompress raw point buffers in a loop. The callback feeds the internal stream and arithmetic coder. ```cpp point_decompressor_0 decompressor(cb); // cb: InputCb for (...) { decompressor(pointbuf); } // operator() -> char* decompress(char*) ``` -------------------------------- ### Configure and create writer::named_file with config Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/configuration.md Shows how to instantiate writer::named_file::config, set scale, offset, pdrf, minor_version, extra_bytes, and chunk_size, then create a writer::named_file output. The comment notes that with extra_bytes = 4, the record length becomes baseCount(3) + 4 = 38. ```cpp using namespace lazperf; writer::named_file::config c; c.scale = vector3(0.01, 0.01, 0.01); c.offset = vector3(500000, 4000000, 0); c.pdrf = 3; c.minor_version = 4; c.extra_bytes = 4; // record length becomes baseCount(3) + 4 = 38 c.chunk_size = 100000; writer::named_file out("out.laz", c); ``` -------------------------------- ### abstract struct vlr Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/vlrs.md Polymorphic base class for all typed VLR payloads. Provides pure virtual methods to get the payload size, the VLR header, and the EVLR header. ```APIDOC ## abstract struct vlr ### Description Polymorphic base class for all typed VLR payloads. Provides pure virtual methods to get the payload size, the VLR header, and the EVLR header. ### Methods - **size()** -> uint64_t - Returns the payload size in bytes. - **header()** -> vlr_header - Returns the 54-byte VLR header describing this payload. - **eheader()** -> evlr_header - Returns the 60-byte EVLR header describing this payload. ``` -------------------------------- ### wkt_vlr - Construct WKT VLR Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/vlrs.md Shows how to construct a WKT (Well-Known Text) VLR for writing, and obtain its payload data as a vector of characters. ```APIDOC ## wkt_vlr - Construct WKT VLR ### Description Construct a WKT VLR for writing. The constructor takes a WKT string and provides a `data()` method to retrieve the payload for use in a custom writer. ### Method N/A (C++ class constructor and method) ### Endpoint N/A (C++ API) ### Parameters #### Constructor Parameters - **wkt** (string) - Required - The Well-Known Text representation of the CRS. #### Methods - **data()** (vector) - Returns the payload data of the WKT VLR. ### Request Example ```cpp #include "vlr.hpp" using namespace lazperf; wkt_vlr crs("PROJCS[\"WGS 84 / UTM zone 17N\",...]"); std::vector payload = crs.data(); // feed into your own writer ``` ### Response #### Success Response No explicit return value; the example retrieves the payload data. #### Response Example ``` std::vector containing the WKT VLR payload ``` ``` -------------------------------- ### Catch lazperf::error when reading a file Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/errors.md Shows a try/catch block that catches `lazperf::error` when opening a LAS/LAZ file with `lazperf::reader::named_file`. The example prints the error message to `std::cerr`. ```cpp try { lazperf::reader::named_file f("broken.laz"); } catch (const lazperf::error& e) { std::cerr << "LAS/LAZ read failed: " << e.what() << std::endl; } ``` -------------------------------- ### LASZip.open Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Opens a LAS/LAZ file from a heap pointer and length, parsing the header, VLRs, and chunk table. ```APIDOC ## LASZip.open ### Description Opens a LAS/LAZ file from a heap pointer and length. Parses the header, VLRs, and chunk table immediately. Throws an exception if the buffer is not a valid LAS/LAZ file. ### Method `open(data: Pointer, length: number): void` ### Parameters - **data** (Pointer, number) - Required - Heap pointer to the LAS/LAZ byte contents. - **length** (number) - Required - Number of bytes at `data`. ### Exceptions Throws a C++ `lazperf::error` if the buffer is not a valid LAS/LAZ file. ``` -------------------------------- ### Read a header and derive point formation Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/headers.md Shows how to open a LAZ file, access its header, and derive point format, extra bytes count, compression flag, and point count. ```cpp #include "readers.hpp" #include "header.hpp" using namespace lazperf; reader::named_file f("file.laz"); const header14& h = f.header(); int format = h.pointFormat(); // e.g. 3 int ebCount = h.ebCount(); // extra bytes per record bool isCompressed = h.compressed(); // LAZ compression bit uint64_t count = f.pointCount(); // h.point_count_14 for 1.4 files ``` -------------------------------- ### TypeScript: Handling WASM initialization and LASZip open errors Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/errors.md Shows how to use createLazPerf() and LASZip.open() with error handling. createLazPerf() may reject if WASM initialization fails, and laszip.open() may throw a JavaScript exception if the file is invalid. The caught error is the C++ what() message. ```typescript const LazPerf = await createLazPerf() // may reject const laszip = new LazPerf.LASZip() try { laszip.open(filePtr, byteLength) // may throw (invalid file) } catch (err) { console.error('open failed', err) // err is the C++ what() message } ``` -------------------------------- ### coderbase.hpp: Shared unions and constants Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/internal-codecs.md Defines unions U32I32F32 and U64I64F64 for type-punning, along with constants for arithmetic coding (AC_HEADER_BYTE, AC_BUFFER_SIZE, AC__MinLength, AC__MaxLength) and model parameters (BM__LengthShift, BM__MaxCount, DM__LengthShift, DM__MaxCount). These are internal and not installed with the library. ```cpp typedef union U32I32F32 { uint32_t u32; int32_t i32; float f32; } U32I32F32; typedef union U64I64F64 { uint64_t u64; int64_t i64; double f64; } U64I64F64; const int AC_HEADER_BYTE = 2; const int AC_BUFFER_SIZE = 1024; const uint32_t AC__MinLength = 0x01000000U; // threshold for renormalization const uint32_t AC__MaxLength = 0xFFFFFFFFU; // maximum AC interval length const uint32_t BM__LengthShift = 13; // length bits discarded before mult. const uint32_t BM__MaxCount = 1 << BM__LengthShift; // for adaptive models const uint32_t DM__LengthShift = 15; // length bits discarded before mult. const uint32_t DM__MaxCount = 1 << DM__LengthShift; // for adaptive models ``` -------------------------------- ### Round-trip a format 3 record with the raw struct Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/las-point-formats.md Demonstrates packing and unpacking a las::point10 struct to and from a raw buffer for format 3 records. ```APIDOC ## Round-trip a format 3 record with the raw struct ### Description Shows how to pack a las::point10 struct into a 34-byte buffer and unpack it back, verifying the round-trip. ### Method N/A (C++ API) ### Endpoint N/A (C++ API) ### Parameters #### Method: in.pack(char *buf) - **buf** (char*) - Required - Pointer to buffer of at least 34 bytes to receive packed data. #### Constructor: las::point10(const char *buf) - **buf** (const char*) - Required - Pointer to buffer containing packed point data. ### Request Example ```cpp las::point10 in; // zeros in.x = 123; in.y = 45; in.z = 67; in.intensity = 500; in.classification = 2; in.point_source_ID = 99; char buf[34]; // format 3 record length = 34 in.pack(buf); las::point10 out(buf); assert(out.x == 123); ``` ### Response #### Success Response No explicit return value; the unpacked point is available in the constructed object. #### Response Example N/A ``` -------------------------------- ### generic_file class declaration Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/readers.md Declares the reader::generic_file class, which reads LAS/LAZ data from any readable std::istream positioned at the start of a LAS/LAZ file. Throws lazperf::error "Couldn't open generic_file as LAS/LAZ" on parse failure. ```cpp class generic_file : public basic_file { public: LAZPERF_EXPORT ~generic_file(); LAZPERF_EXPORT generic_file(std::istream& in); }; ``` -------------------------------- ### createLazPerf() Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Creates and initializes the laz-perf WASM module. Returns a Promise that resolves to the LazPerf module object, or rejects if the WASM module cannot be fetched or initialized. ```APIDOC ## createLazPerf() ### Description Creates and initializes the laz-perf WASM module. Returns a Promise that resolves to the LazPerf module object, or rejects if the WASM module cannot be fetched or initialized (standard Emscripten factory semantics). ### Method Factory function (async) ### Parameters #### Factory Options (optional) - **locateFile** (function) - Optional - A function that maps a WASM asset path to a custom URL. Example: `(path) => `/assets/${path}`` ### Return Value - **Promise** - Resolves to the initialized LazPerf module object. ### Example ```typescript import createLazPerf from 'laz-perf' const LazPerf = await createLazPerf({ locateFile: (path) => `/assets/${path}`, }) ``` ``` -------------------------------- ### ChunkDecoder.open() Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Opens a compressed chunk for decoding. Must be called before using getPoint. ```APIDOC ## ChunkDecoder.open() ### Description Opens a compressed chunk for decoding. Must be called before using getPoint. ### Method Instance method (via Embind) ### Parameters - **pointFormat** (number) - Required - The point format (e.g., 3). - **pointSize** (number) - Required - The point record length (e.g., 34). - **chunkPtr** (Pointer) - Required - Pointer to the chunk data in the Emscripten heap. ### Example ```typescript const decoder = new LazPerf.ChunkDecoder() decoder.open(3, 34, chunkPtr) ``` ``` -------------------------------- ### open(pointDataRecordFormat, pointDataRecordLength, pointer) Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Opens a compressed chunk for decompression. The point data record format and length are used to derive the extra bytes count, and the pointer must reference the compressed chunk data in the heap. ```APIDOC ## open(pointDataRecordFormat, pointDataRecordLength, pointer) ### Description Opens a compressed chunk for decompression. The point data record format and length are used to derive the extra bytes count, and the pointer must reference the compressed chunk data in the heap. ### Method open ### Parameters #### Parameters - **pointDataRecordFormat** (number) - Required - Point format id (`0-3`, `6-8`) - **pointDataRecordLength** (number) - Required - Total point record length; extra-bytes count is derived as `pointDataRecordLength - lazperf::baseCount(pdrf)` - **pointer** (Pointer) - Required - Heap pointer to the **compressed chunk data** (not a whole file) ### Response Returns void. ``` -------------------------------- ### LASZip.open() Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Opens a LAZ file from a memory pointer for whole-file decoding. Must be called before using getCount or getPoint. ```APIDOC ## LASZip.open() ### Description Opens a LAZ file from a memory pointer for whole-file decoding. Must be called before using getCount or getPoint. ### Method Instance method (via Embind) ### Parameters - **filePtr** (Pointer) - Required - Pointer to the file bytes in the Emscripten heap. - **fileSize** (number) - Required - Byte length of the file. ### Example ```typescript const laszip = new LazPerf.LASZip() laszip.open(filePtr, fileBytes.byteLength) ``` ``` -------------------------------- ### build_las_compressor Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/lazperf-core.md Factory-based streaming compression with a callback and error check. ```APIDOC ## build_las_compressor ### Description Factory-based streaming compression with a callback and error check. ### Usage ```cpp #include "lazperf.hpp" #include using namespace lazperf; void onOutput(const unsigned char *buf, size_t len) { /* append to compressed file */ } // ebCount must match the extra-bytes part of the point record length. las_compressor::ptr c = build_las_compressor(onOutput, 3 /* format */, 2 /* extra bytes */); if (!c) throw std::runtime_error("Unsupported point format"); las::point14 p; for (int i = 0; i < 50000; ++i) c->compress(reinterpret_cast(&p)); c->done(); ``` ### Parameters - `onOutput` (callback) - Required - Callback function that receives compressed data. - `format` (int) - Required - Point format number. - `extraBytes` (int) - Required - Number of extra bytes in the point record. ### Returns - `las_compressor::ptr` - A pointer to a compressor object, or null if the format is unsupported. ### Methods - `void compress(const char* point)` - Compresses a point record. - `void done()` - Flushes the arithmetic stream. ``` -------------------------------- ### open method declaration Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/writers.md Declaration of the open method, which initializes the writer with an output stream, header template, and chunk size. Returns false for unsupported header versions. ```cpp LAZPERF_EXPORT bool open(std::ostream& out, const header12& h, uint32_t chunk_size); ``` -------------------------------- ### open and close method signatures Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/readers.md open is protected and called by derived constructors; it returns false if the header cannot be interpreted. close closes the underlying stream. ```cpp bool open(std::istream& in); void close(); ``` -------------------------------- ### Factory-based streaming with callback and error check Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/lazperf-core.md Builds a las_compressor using build_las_compressor with a callback for output and a point format of 3 with 2 extra bytes. The ebCount must match the extra-bytes part of the point record length. Throws std::runtime_error if the point format is unsupported. ```cpp #include "lazperf.hpp" #include using namespace lazperf; void onOutput(const unsigned char *buf, size_t len) { /* append to compressed file */ } // ebCount must match the extra-bytes part of the point record length. las_compressor::ptr c = build_las_compressor(onOutput, 3 /* format */, 2 /* extra bytes */); if (!c) throw std::runtime_error("Unsupported point format"); las::point14 p; for (int i = 0; i < 50000; ++i) c->compress(reinterpret_cast(&p)); c->done(); ``` -------------------------------- ### createLazPerf failure mode with locateFile Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Shows how to pass factory options to createLazPerf, such as locateFile, to override WASM asset lookup. The promise rejects if the WASM module cannot be fetched or initialized. ```typescript import createLazPerf from 'laz-perf' const LazPerf = await createLazPerf({ locateFile: (path) => `/assets/${path}`, }) ``` -------------------------------- ### Round-trip a format 3 record with the raw struct Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/las-point-formats.md Packs a las::point10 struct into a 34-byte buffer (format 3 record length) and unpacks it back, asserting the x value. Demonstrates raw struct packing for format 3. ```cpp las::point10 in; // zeros in.x = 123; in.y = 45; in.z = 67; in.intensity = 500; in.classification = 2; in.point_source_ID = 99; char buf[34]; // format 3 record length = 34 in.pack(buf); las::point10 out(buf); assert(out.x == 123); ``` -------------------------------- ### reader::mem_file constructor Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/readers.md Creates a reader that reads LAS/LAZ data from an in-memory buffer. Throws lazperf::error if the buffer cannot be parsed as LAS/LAZ. ```APIDOC ## reader::mem_file ### Description Creates a reader that reads LAS/LAZ data from an in-memory buffer. Throws `lazperf::error` if the buffer cannot be parsed as LAS/LAZ. ### Constructor `mem_file(char *buf, size_t count)` ### Parameters - **buf** (`char *`) - Required - In-memory LAS/LAZ bytes - **count** (`size_t`) - Required - Number of bytes in `buf` ### Throws - `lazperf::error` - `"Couldn't open mem_file as LAS/LAZ"` if the buffer cannot be parsed as a LAS/LAZ file. ### Example ```cpp using namespace lazperf; reader::mem_file f(buf, bufsize); char pointbuf[100]; for (size_t i = 0; i < f.header().point_count; ++i) f.readPoint(pointbuf); ``` ``` -------------------------------- ### unpack / pack Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/utils.md Read/write a primitive from/to a byte buffer in little-endian order. The primary template is unimplemented; only specialized instances may be used. ```APIDOC ## unpack / pack ### Description Reads a primitive from a byte buffer (unpack) or writes a primitive to a byte buffer (pack) in little-endian order. Specializations exist for uint64_t, uint32_t, float, double, uint16_t, int64_t, int32_t, int16_t. ### Functions ```cpp template T unpack(const char *in); inline void pack(uint64_t v, char *out); inline void pack(const uint32_t v, char *out); inline void pack(const double& d, char *buf); inline void pack(const uint16_t v, char *out); inline void pack(int64_t t, char *out); inline void pack(int32_t t, char *out); inline void pack(int16_t t, char *out); ``` ### Parameters - `in` (const char*) - Required - Pointer to the byte buffer to read from. - `out`/`buf` (char*) - Required - Pointer to the byte buffer to write to. - `v`/`t`/`d` - Required - The value to pack. ### Returns - `T` - The unpacked value. ### Example ```cpp char raw[20] = { /* ... */ }; int32_t x = lazperf::utils::unpack(raw); int32_t y = lazperf::utils::unpack(raw + 4); int32_t z = lazperf::utils::unpack(raw + 8); ``` ``` -------------------------------- ### LASZip Constructor Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Creates an un-opened file reader for LAS/LAZ files. ```APIDOC ## LASZip Constructor ### Description Creates an un-opened file reader for LAS/LAZ files. ### Constructor `new LASZip()` ### Parameters None. ``` -------------------------------- ### createLazPerf Source: https://github.com/hobuinc/laz-perf/blob/master/_autodocs/api-reference/emscripten.md Loads and initializes the Emscripten module, resolving to the LazPerf module object for decoding LAS/LAZ data. ```APIDOC ## createLazPerf ### Description Loads and initializes the Emscripten module and resolves to the `LazPerf` module object, which provides decoding capabilities for LAS/LAZ files. ### Method Function call ### Signature `createLazPerf(): Promise` ### Parameters None ### Returns - **LazPerf** (object) - The resolved Emscripten module instance with decoding methods. ### Example ```typescript import { createLazPerf } from 'laz-perf' const lazPerf = await createLazPerf() ``` ```