Overview
TheLocalMapping class manages the local map and performs local bundle adjustment. It runs in a separate thread, processing new keyframes from the Tracking thread, creating new map points, and optimizing the local map structure.
Constructor
Parameters
pSys: Pointer to the System objectpAtlas: Pointer to the Atlas (multi-map manager)bMonocular: True if using monocular sensorbInertial: True if using inertial measurements (IMU)_strSeqName: Optional sequence name for debugging
Thread Control Methods
Run
RequestStop
Stop
Release
isStopped
stopRequested
RequestFinish
isFinished
SetNotStop
flag: If true, prevents stopping
Keyframe Management
InsertKeyFrame
pKF: Pointer to the keyframe to be processed
EmptyQueue
KeyframesInQueue
AcceptKeyFrames
SetAcceptKeyFrames
flag: True to accept keyframes, false to reject
Thread Communication
SetLoopCloser
pLoopCloser: Pointer to LoopClosing object
SetTracker
pTracker: Pointer to Tracking object
State Management
RequestReset
RequestResetActiveMap
pMap: Pointer to the map to reset
InterruptBA
Information Retrieval
IsInitializing
GetCurrKFTime
GetCurrKF
IMU Initialization (Inertial Mode)
Public IMU Variables
These variables are accessible for IMU initialization and scale estimation:Initialization Statistics
IMU Flags
Point Filtering
Far Points Configuration
Usage Example
Local Mapping Pipeline
The local mapping thread follows this processing pipeline:- Check for New Keyframes: Wait for keyframes from the tracking thread
- Process New Keyframe:
- Compute Bag-of-Words representation
- Update connections with other keyframes
- Insert keyframe into map
- Map Point Culling: Remove low-quality map points
- Create New Map Points: Triangulate new points from keyframe connections
- Search in Neighbors: Fuse duplicate map points
- Local Bundle Adjustment: Optimize local map (keyframes + points)
- Keyframe Culling: Remove redundant keyframes
Thread Synchronization
The LocalMapping class uses several mutexes for thread-safe operation:mMutexNewKFs: Protects the keyframe queuemMutexStop: Protects stop-related flagsmMutexFinish: Protects finish-related flagsmMutexAccept: Protects keyframe acceptance flagmMutexReset: Protects reset requestsmMutexImuInit: Protects IMU initialization data
Bundle Adjustment Control
Local Bundle Adjustment (LBA) optimizes:- Keyframes: Local keyframes (poses)
- Map Points: Points visible in local keyframes
- Fixed Keyframes: Covisible keyframes kept fixed
InterruptBA() when:
- A new keyframe arrives
- Loop closure is detected
- System reset is requested
IMU Integration
WhenbInertial is true, the local mapping performs:
- IMU Initialization: Estimates gravity direction, scale, and IMU biases
- Scale Refinement: Refines the scale estimate over multiple keyframes
- Inertial BA: Performs bundle adjustment with IMU constraints
Related Classes
- System - Main SLAM system interface
- Tracking - Provides keyframes to local mapping
- LoopClosing - Performs global optimization after loop detection