libE57Format

repository·master·Indexed 41 days ago

https://github.com/asmaloney/libe57format

A C++ library for reading and writing ASTM-standard E57 files containing 3D point clouds, attributes, and 2D images. It features an E57Simple API for common tasks and requires a C++14 compatible compiler, CMake 3.15+, and the Xerces-C++ library for XML parsing. Compatible with Linux, macOS, and Windows.

Tokens
1.8K
Snippets
7
Records
12
Agent score
2%

What's inside libE57Format

  1. Overview of libE57Format

    master
    libE57Format is a C++ library providing read and write support for the ASTM-standard E57 file format. It is compatible with Linux, macOS, and Windows. The library is used to handle 3D point cloud data (from laser scanners), associated attributes (such as color and intensity), and 2D images stored within E57 files.
  2. Build, install, and test libE57Format

    master

    To build and install a release version of libE57Format using CMake, follow these steps:

    1. Configure the build: Use -DCMAKE_BUILD_TYPE=Release and specify an installation prefix with -DCMAKE_INSTALL_PREFIX.
    2. Build: Use the --parallel flag to speed up the build process.
    3. Install: Install the built binaries to your specified prefix.

    If CMake cannot locate the xerces-c library, provide the path using the CMAKE_PREFIX_PATH variable.

    To run the built tests, execute the testE57 binary located in the build directory.

    # Build and install with defaults
    $ cmake -B E57-build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=E57-install libE57Format
    $ cmake --build E57-build --parallel
    $ cmake --install E57-build
    
    # Build specifying xerces-c path
    $ cmake -B E57-build \
        -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=E57-install \
        -DCMAKE_PREFIX_PATH=/path/to/xerces-c \
        libE57Format
    
    # Run tests
    $ cd E57-build
    $ ./test/testE57
  3. Install dependencies for libE57Format

    master

    libE57Format requires the Xerces-C++ library for XML parsing. Depending on your operating system, use the following commands to install the necessary dependencies:

    Ubuntu/Linux: Install libxerces-c-dev and clang-format via apt.

    macOS: Install ccache, clang-format, and xerces-c via homebrew.

    # Ubuntu
    $ sudo apt install libxerces-c-dev clang-format
    
    # macOS
    $ brew install ccache clang-format xerces-c
  4. Install CRC++ by including the header file

    master

    CRC++ is a header-only library. To use it in your project, you do not need to compile a library or manage complex build settings. Simply include the CRC.h header file in your C++ source code. It is compatible with any reasonably compliant C++03 or C++11 compiler, though C++11 is recommended for better compile-time performance.

    #include "CRC.h"
  5. Build CRC++ unit tests and documentation with CMake

    master

    While CRC++ is header-only and requires no build for basic usage, you can use CMake to build the included unit tests and Doxygen documentation.

    mkdir -p build
    cd build
    cmake .. [-DBUILD_DOC=ON]
    
    # Build and run unit tests
    make tests
    
    # Build documentation (requires Doxygen)
    make doxygen
    
    # Install the header file
    sudo make install
  6. Configure CRC++ via preprocessor macros

    master

    You can customize the behavior and types of CRC++ by defining macros before including CRC.h.

    Type Customization

    • #define crcpp_uint8: Type for 8-bit or less CRCs (default: ::std::uint8_t).
    • #define crcpp_uint16: Type for 9-16 bit CRCs (default: ::std::uint16_t).
    • #define crcpp_uint32: Type for 17-32 bit CRCs (default: ::std::uint32_t).
    • #define crcpp_uint64: Type for 33-64 bit CRCs (default: ::std::uint64_t).
    • #define crcpp_size: Type for loop iteration and signatures (default: ::std::size_t).

    Feature Flags

    • #define CRCPP_USE_NAMESPACE: Places all code within the ::CRCPP namespace.
    • #define CRCPP_BRANCHLESS: Enables a branchless implementation (uses integer multiplication instead of conditionals). Recommended for architectures with fast single-instruction integer multiplication.
    • #define CRCPP_USE_CPP11: Enables C++11 features like move semantics and constexpr.
    • #define CRCPP_INCLUDE_ESOTERIC_CRC_DEFINITIONS: Includes less common CRC definitions.
  7. Compute CRCs on non-byte-aligned bit lengths using CRC::CalculateBits()

    master

    If your input data is not a multiple of CHAR_BIT (usually 8 bits), use CRC::CalculateBits(). The second argument specifies the exact number of bits to process. Note that the input data buffer must still be a whole number of bytes; any unused bits in the final byte should be padded with zeros.

    const unsigned char data[] = { 0x98, 0x76, 0x54, 0x32, 0x10 };
    // Compute CRC for exactly 37 bits
    std::uint32_t crc = CRC::CalculateBits(data, 37, CRC::CRC_32());
  8. Compute multi-part CRCs

    master

    You can compute a CRC over multiple non-contiguous buffers by passing the result of the previous calculation as the final argument to the next CRC::Calculate call. This allows you to chain data segments together.

    std::uint32_t crc;
    // First part
    crc = CRC::Calculate(part1, size1, CRC::CRC_32());
    // Second part (chains onto the first)
    crc = CRC::Calculate(part2, size2, CRC::CRC_32(), crc);
  9. Compute a basic CRC using CRC::Calculate()

    master

    To compute a CRC, use the CRC::Calculate function. You must provide the data buffer, the size of the buffer, and a CRC definition (e.g., CRC::CRC_32()).

    #include "CRC.h"
    #include <cstdint>
    
    int main() {
        const char myString[] = { 'H', 'E', 'L', 'L', 'O' };
        std::uint32_t crc = CRC::Calculate(myString, sizeof(myString), CRC::CRC_32());
        return 0;
    }
  10. Use lookup tables for faster CRC computation

    master

    For high-performance requirements, use CRC::Table. Lookup tables are significantly faster than bit-by-bit calculation but consume more memory. A table can be reused for multiple calculations as long as it remains in scope.

    // Option 1: Explicitly define the table type
    CRC::Table<std::uint32_t, 32> table(CRC::CRC_32());
    std::uint32_t crc = CRC::Calculate(data, size, table);
    
    // Option 2: Use the auto keyword with MakeTable()
    auto table = CRC::CRC_32().MakeTable();
    std::uint32_t crc = CRC::Calculate(data, size, table);
  11. Requirements for libE57Format

    master

    To build libE57Format, your environment must meet the following requirements:

    • A C++14 compatible compiler.
    • CMake version 3.15 or higher.
    • clang-format (for code formatting).
    • Xerces-C++ (dependency for XML parsing).
    • (Optional) ccache to accelerate rebuilds.