gtsam_points

repository·master·Indexed 18 days ago

https://github.com/koide3/gtsam_points

A collection of GTSAM factors and optimizers for range-based SLAM. It provides capabilities for scan matching (ICP, GICP, VGICP, LOAM), colored scan matching, continuous-time ICP, and bundle adjustment. The library includes GPU implementations for VGICP, nearest neighbor search tools like KdTree and IncrementalVoxelMap, global registration (PFH, FPFH, RANSAC, GNC), and a PoseInterpolator tool for trajectory interpolation and IMU measurement derivation.

Tokens
2.5K
Snippets
4
Records
6
Agent score
14%

What's inside gtsam_points

  1. Overview of gtsam_points factors and features

    master

    The gtsam_points library provides a collection of GTSAM factors and optimizers designed for range-based SLAM. Key components include:

    Scan Matching Factors

    • ICP: IntegratedICPFactor (point-to-point) and IntegratedPointToPlaneICPFactor (point-to-plane).
    • GICP: IntegratedGICPFactor (distribution-to-distribution).
    • VGICP: IntegratedVGICPFactor and its GPU implementation IntegratedVGICPFactorGPU (requires -DBUILD_WITH_CUDA=ON).
    • LOAM: IntegratedLOAMFactor (point-to-plane and point-to-edge).

    Colored Scan Matching Factors

    • IntegratedColorConsistencyFactor (Photometric ICP error).
    • IntegratedColoredGICPFactor (Photometric + GICP geometric error).

    Continuous-time ICP Factors

    • IntegratedCT_ICPFactor and IntegratedCT_GICPFactor (Continuous Time ICP).

    Bundle Adjustment Factors

    • PlaneEVMFactor and EdgeEVMFactor (Eigenvalue minimization).
    • LsqBundleAdjustmentFactor (EVM and EF optimal condition satisfaction).

    Other Features

    • Optimizers for GPU Factors: LevenbergMarquardtOptimizerExt, ISAM2Ext, IncrementalFixedLagSmootherExt.
    • Nearest Neighbor Search: KdTree, IncrementalVoxelMap (iVox), IncrementalCovarianceVoxelMap, FastOccupancyGrid.
    • Global Registration: PFH, FPFH, RANSAC (6DoF/4DoF), and Graduated Non-Convexity (GNC).
    • Segmentation: Region Growing and Min-Cut segmentation.
  2. Install gtsam_points via PPA (Ubuntu 22.04, 24.04)

    master

    For Ubuntu 22.04 and 24.04 on AMD64 or ARM64, you can use the official PPA.

    1. Setup PPA:
    curl -s https://koide3.github.io/ppa/setup_ppa.sh | sudo bash
    1. Install package: Choose the package corresponding to your CUDA version:
    • No CUDA: libgtsam-points-dev
    • CUDA 12.2 (Ubuntu 22.04 only): libgtsam-points-cuda12.2-dev
    • CUDA 12.5: libgtsam-points-cuda12.5-dev
    • CUDA 13.1: libgtsam-points-cuda13.1-dev
    # Setup PPA
    curl -s https://koide3.github.io/ppa/setup_ppa.sh | sudo bash
    
    # Without CUDA
    sudo apt install -y libgtsam-points-dev
    
    # with CUDA 12.2 (for only Ubuntu 22.04)
    sudo apt install -y libgtsam-points-cuda12.2-dev
    
    # with CUDA 12.5
    sudo apt install -y libgtsam-points-cuda12.5-dev
    
    # with CUDA 13.1
    sudo apt install -y libgtsam-points-cuda13.1-dev
  3. Install gtsam_points from source

    master

    To install gtsam_points from source, you must first install GTSAM (version 4.3a1 is recommended).

    1. Install GTSAM:
    git clone https://github.com/borglab/gtsam
    cd gtsam
    git checkout 4.3a1
    
    mkdir build && cd build
    cmake .. \
      -DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \
      -DGTSAM_BUILD_TESTS=OFF \
      -DGTSAM_WITH_TBB=OFF \
      -DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF
    
    make -j$(nproc)
    sudo make install
    1. Install iridescence (Optional): Required only for running demo programs.
    sudo apt install -y libglm-dev libglfw3-dev libpng-dev
    git clone https://github.com/koide3/iridescence --recursive
    mkdir iridescence/build && cd iridescence/build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    make -j$(nproc)
    sudo make install
    1. Build gtsam_points:
    git clone https://github.com/koide3/gtsam_points
    mkdir gtsam_points/build && cd gtsam_points/build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    make -j$(nproc)
    sudo make install
    # Install gtsam
    git clone https://github.com/borglab/gtsam
    cd gtsam
    git checkout 4.3a1
    
    mkdir build && cd build
    cmake .. \
      -DGTSAM_BUILD_EXAMPLES_ALWAYS=OFF \
      -DGTSAM_BUILD_TESTS=OFF \
      -DGTSAM_WITH_TBB=OFF \
      -DGTSAM_BUILD_WITH_MARCH_NATIVE=OFF
    
    make -j$(nproc)
    sudo make install
    
    # [optional] Install iridescence visualization library
    sudo apt install -y libglm-dev libglfw3-dev libpng-dev
    git clone https://github.com/koide3/iridescence --recursive
    mkdir iridescence/build && cd iridescence/build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    make -j$(nproc)
    sudo make install
    
    ## Build gtsam_points
    git clone https://github.com/koide3/gtsam_points
    mkdir gtsam_points/build && cd gtsam_points/build
    cmake .. -DCMAKE_BUILD_TYPE=Release
    
    make -j$(nproc)
    sudo make install
  4. Configure gtsam_points CMake build options

    master

    When building gtsam_points from source, you can use several CMake arguments to customize the build:

    • -DBUILD_DEMO=ON/OFF: Build demo programs (default is OFF).
    • -DBUILD_TESTS=ON/OFF: Build unit tests.
    • -DBUILD_TOOLS=ON/OFF: Build tools.
    • -DBUILD_WITH_TBB=ON/OFF: Enable TBB support.
    • -DBUILD_WITH_OPENMP=ON/OFF: Enable OpenMP support.
    • -DBUILD_WITH_CUDA=ON/OFF: Enable CUDA support (required for IntegratedVGICPFactorGPU).
    • -DBUILD_WITH_CUDA_MULTIARCH=ON/OFF: Enable multi-arch CUDA support.
    • -DCMAKE_CUDA_ARCHITECTURES=<arch>: Specify CUDA architecture (e.g., 89). If not specified, "native" is used.
    • -DBUILD_WITH_MARCH_NATIVE=ON/OFF: Enable -march=native. It is recommended to keep this OFF.
  5. Interpolate poses and IMU data with PoseInterpolator

    master

    The PoseInterpolator class provides a programmatic interface for trajectory interpolation. It uses a continuous-time trajectory model to fit knots to input poses and then samples both poses and IMU measurements at desired timestamps.

    Key Methods

    • load_input_poses(filename): Loads input poses in TUM format (timestamp x y z qx qy qz qw).
    • load_timestamps(filename): Loads a list of target timestamps from a file.
    • generate_timestamps_arange(start, end, step): Generates a sequence of timestamps from start to end with a given step. If start or end are negative, it uses the bounds of the input trajectory.
    • interpolate(knot_interval, smoothness): Performs the spline fitting. If knot_interval is negative, it is automatically estimated from the input data.
    • save_poses(filename): Saves interpolated poses to a file in TUM format.
    • save_imu(filename): Saves interpolated IMU measurements (6-DOF: acc x,y,z and gyro x,y,z) to a file.
    • visualize(): Opens an interactive viewer to inspect the input poses, knots, interpolated trajectory, and IMU plots.
    PoseInterpolator interpolator;
    
    // 1. Load data
    interpolator.load_input_poses("input_poses.txt");
    interpolator.generate_timestamps_arange(-1.0, -1.0, 0.01);
    
    // 2. Perform interpolation
    // knot_interval = -1 (auto), smoothness = 1e-3
    interpolator.interpolate(-1.0, 1e-3);
    
    // 3. Save or Visualize
    interpolator.save_poses("output_poses.txt");
    interpolator.save_imu("output_imu.txt");
    interpolator.visualize();
  6. Use the PoseInterpolator CLI tool

    master

    The PoseInterpolator tool is a command-line utility used to interpolate trajectories from discrete poses. It can generate a continuous trajectory (spline) and derive corresponding IMU measurements (accelerations and angular velocities) at specified timestamps.

    Input Formats

    • Input Poses: Requires a file in TUM format: [timestamp, x, y, z, qx, qy, qz, qw].
    • Timestamps: If a timestamp file is provided, it should contain one timestamp per row. If not provided, the tool generates a range of timestamps based on the input trajectory's bounds and a specified step.

    CLI Options

    OptionDescription
    --input <file>Required. Input trajectory filename (TUM format).
    --timestamps <file>Optional. File containing interpolation timestamps (one per row).
    --output <file>Optional. Filename to save interpolated poses.
    --imu_output <file>Optional. Filename to save interpolated IMU measurements.
    --t_begin <double>Start time for interpolation. -1 uses the first input timestamp.
    --t_end <double>End time for interpolation. -1 uses the last input timestamp.
    --t_step <double>Time step for interpolation (used if --timestamps is not provided).
    --knot_interval <double>Knot interval for the spline. -1 estimates it from input intervals.
    --smoothness <double>Smoothness parameter for the spline.
    --visualize, -vEnable interactive visualization of the trajectory and IMU data.
    # Example: Interpolate a trajectory with a 0.01s step and save results
    ./pose_interpolator --input trajectory.txt --output interpolated_poses.txt --imu_output imu.txt --t_step 0.01
    
    # Example: Visualize the interpolation process
    ./pose_interpolator --input trajectory.txt --visualize