|
RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
|
Abstract database driver for RTAB-Map maps (signatures, links, words, statistics). More...
#include <DBDriver.h>


Public Member Functions | |
| virtual void | parseParameters (const ParametersMap ¶meters) |
| Parse driver parameters from the map (e.g. target schema version). | |
| virtual bool | isInMemory () const |
| True when no database file URL was set at open time. | |
| const std::string & | getUrl () const |
| const std::string & | getTargetVersion () const |
| void | asyncSave (Signature *s) |
| Queue a signature for deferred save; ownership is transferred. | |
| void | asyncSave (VisualWord *vw) |
| Queue a visual word for deferred save; ownership is transferred. | |
| void | emptyTrashes (bool async=false) |
| Flush queued signatures and visual words to the database. | |
| double | getEmptyTrashesTime () const |
| void | setTimestampUpdateEnabled (bool enabled) |
| void | generateGraph (const std::string &fileName, const std::set< int > &ids=std::set< int >(), const std::map< int, Signature * > &otherSignatures=std::map< int, Signature * >()) |
| Export the pose graph to a Graphviz DOT file for visualization. | |
| void | executeNoResult (const std::string &sql) const |
| Run a SQL statement that does not return result rows. | |
Direct database updates | |
Write node or link data immediately (not via the async trash). | |
| void | addLink (const Link &link) |
| Insert or replace a link in the database. | |
| void | removeLink (int from, int to) |
| Remove a link between two nodes. | |
| void | updateLink (const Link &link) |
| Update an existing link in the database. | |
| void | updateOccupancyGrid (int nodeId, const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty, float cellSize, const cv::Point3f &viewpoint) |
| Update occupancy grid cells for a node. | |
| void | updateCalibration (int nodeId, const std::vector< CameraModel > &models, const std::vector< StereoCameraModel > &stereoModels) |
| Update camera calibration stored for a node. | |
| void | updateDepthImage (int nodeId, const cv::Mat &image, const std::string &format) |
| Update the depth image stored for a node. | |
| void | updateLaserScan (int nodeId, const LaserScan &scan) |
| Update the laser scan stored for a node. | |
Session exports and map artifacts | |
Statistics, preview image, optimized poses, 2D map, mesh and FLANN index. | |
| void | addInfoAfterRun (int stMemSize, int lastSignAdded, int processMemUsed, int databaseMemUsed, int dictionarySize, const ParametersMap ¶meters) const |
| void | addStatistics (const Statistics &statistics, bool saveWmState) const |
| Append a Statistics record for a processed node. | |
| void | savePreviewImage (const cv::Mat &image) const |
| Save the map preview thumbnail in the Admin table. | |
| cv::Mat | loadPreviewImage () const |
| Load and uncompress the map preview thumbnail from the Admin table. | |
| void | saveOptimizedPoses (const std::map< int, Transform > &optimizedPoses, const Transform &lastlocalizationPose) const |
| Persist graph-optimized poses and last localization pose. | |
| std::map< int, Transform > | loadOptimizedPoses (Transform *lastlocalizationPose=0) const |
| Load optimized poses; optional last localization pose output. | |
| void | save2DMap (const cv::Mat &map, float xMin, float yMin, float cellSize) const |
| Save the assembled 2D occupancy grid and its origin metadata. | |
| cv::Mat | load2DMap (float &xMin, float &yMin, float &cellSize) const |
| Load the 2D map and fill origin/cell size outputs. | |
| void | saveOptimizedMesh (const cv::Mat &cloud, const std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > &polygons=std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > >(), const std::vector< std::vector< Eigen::Vector2f > > &texCoords=std::vector< std::vector< Eigen::Vector2f > >(), const cv::Mat &textures=cv::Mat()) const |
| Persist the global optimized 3D mesh to the database. | |
| cv::Mat | loadOptimizedMesh (std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > *polygons=0, std::vector< std::vector< Eigen::Vector2f > > *texCoords=0, cv::Mat *textures=0) const |
| void | saveFlannIndex (const std::vector< unsigned char > &indexData) const |
| Persist the visual word dictionary FLANN index (serialized blob). | |
Connection and database introspection | |
Mutex-protected wrappers around protected | |
| bool | openConnection (const std::string &url, bool overwritten=false, bool readOnly=false) |
Open or create the database at url (empty url uses an in-memory database). | |
| void | closeConnection (bool save=true, const std::string &outputUrl="") |
Close the connection; optionally flush trashes and save in-memory DB to outputUrl. | |
| bool | isConnected () const |
| unsigned long | getMemoryUsed () const |
| std::string | getDatabaseVersion () const |
| long | getNodesMemoryUsed () const |
| long | getLinksMemoryUsed () const |
| long | getImagesMemoryUsed () const |
| long | getDepthImagesMemoryUsed () const |
| long | getCalibrationsMemoryUsed () const |
| long | getGridsMemoryUsed () const |
| long | getLaserScansMemoryUsed () const |
| long | getUserDataMemoryUsed () const |
| long | getWordsMemoryUsed () const |
| long | getFeaturesMemoryUsed () const |
| long | getStatisticsMemoryUsed () const |
| int | getLastNodesSize () const |
| int | getLastDictionarySize () const |
| int | getTotalNodesSize () const |
| int | getTotalDictionarySize () const |
| ParametersMap | getLastParameters () const |
| std::map< std::string, float > | getStatistics (int nodeId, double &stamp, std::vector< int > *wmState=0) const |
| std::map< int, std::pair< std::map< std::string, float >, double > > | getAllStatistics () const |
| std::map< int, std::vector< int > > | getAllStatisticsWmStates () const |
Load and query | |
Load signatures, words, links and node metadata from the database. | |
| void | load (VWDictionary &dictionary, bool lastStateOnly=true, bool idsOnly=false) const |
| void | loadLastNodes (std::list< Signature * > &signatures, bool loadWordIdsOnly=false) const |
| Signature * | loadSignature (int id, bool *loadedFromTrash=0) |
| Load one signature by id; caller must delete the returned pointer. | |
| void | loadSignatures (const std::list< int > &ids, std::list< Signature * > &signatures, std::set< int > *loadedFromTrash=0, bool loadWordIdsOnly=false) |
| void | loadWords (const std::set< int > &wordIds, std::list< VisualWord * > &vws) |
| void | loadNodeData (Signature &signature, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const |
| void | loadNodeData (std::list< Signature * > &signatures, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const |
| void | getNodeData (int signatureId, SensorData &data, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const |
| bool | getCalibration (int signatureId, std::vector< CameraModel > &models, std::vector< StereoCameraModel > &stereoModels) const |
| bool | getLaserScanInfo (int signatureId, LaserScan &info) const |
| bool | getNodeInfo (int signatureId, Transform &pose, int &mapId, int &weight, std::string &label, double &stamp, Transform &groundTruthPose, std::vector< float > &velocity, GPS &gps, EnvSensors &sensors) const |
| void | getLocalFeatures (int signatureId, std::multimap< int, int > &words, std::vector< cv::KeyPoint > &keypoints, std::vector< cv::Point3f > &points, cv::Mat &descriptors) const |
| void | loadLinks (int signatureId, std::multimap< int, Link > &links, Link::Type type=Link::kUndef) const |
Load outgoing links from signatureId, optionally filtered by type. | |
| void | getWeight (int signatureId, int &weight) const |
| void | getLastNodeIds (std::set< int > &ids) const |
| void | getAllNodeIds (std::set< int > &ids, bool ignoreChildren=false, bool ignoreBadSignatures=false, bool ignoreIntermediateNodes=false) const |
| void | getAllOdomPoses (std::map< int, Transform > &poses, bool ignoreChildren=false, bool ignoreIntermediateNodes=false) const |
| void | getAllLinks (std::multimap< int, Link > &links, bool ignoreNullLinks=true, bool withLandmarks=false) const |
| void | getLastNodeId (int &id) const |
| void | getLastMapId (int &mapId) const |
| void | getLastWordId (int &id) const |
| void | getInvertedIndexNi (int signatureId, int &ni) const |
| void | getNodesObservingLandmark (int landmarkId, std::map< int, Link > &nodes) const |
| void | getNodeIdByLabel (const std::string &label, int &id) const |
| void | getAllLabels (std::map< int, std::string > &labels) const |
Public Member Functions inherited from UThread | |
| UThread (Priority priority=kPNormal) | |
| virtual | ~UThread () |
| void | start () |
| void | kill () |
| void | join (bool killFirst=false) |
| void | setPriority (Priority priority) |
| void | setAffinity (int cpu=0) |
| bool | isCreating () const |
| bool | isRunning () const |
| bool | isIdle () const |
| bool | isKilled () const |
| Handle | getThreadHandle () const |
| unsigned long | getThreadId () const |
Public Member Functions inherited from UThreadC< void > | |
| int | Create (Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
| int | Create (unsigned long &ThreadId, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
| int | Create (Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
| int | Create (unsigned long &ThreadId, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) const |
Static Public Member Functions | |
| static DBDriver * | create (const ParametersMap ¶meters=ParametersMap()) |
| Factory: returns a SQLite database driver (DBDriverSqlite3). | |
Static Public Member Functions inherited from UThread | |
| static unsigned long | currentThreadId () |
Static Public Member Functions inherited from UThreadC< void > | |
| static int | Create (const Handler &Function, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) |
| static int | Join (Handle H) |
| static int | Kill (Handle H) |
| static int | Detach (Handle H) |
| static int | Create (const Handler &Function, Handle *const &H=0, const bool &CreateDetached=false, const unsigned int &StackSize=0, const bool &CancelEnable=false, const bool &CancelAsync=false) |
| static int | Join (const Handle &H) |
| static int | Kill (const Handle &H) |
| static int | Detach (const Handle &H) |
Protected Member Functions | |
| DBDriver (const ParametersMap ¶meters=ParametersMap()) | |
| Protected constructor for subclasses. | |
Backend implementation (subclass responsibility) | |
Pure virtual SQL/backend hooks invoked by public wrappers above. | |
| virtual bool | connectDatabaseQuery (const std::string &url, bool overwritten=false, bool readOnly=false)=0 |
| virtual void | disconnectDatabaseQuery (bool save=true, const std::string &outputUrl="")=0 |
| virtual bool | isConnectedQuery () const =0 |
| virtual unsigned long | getMemoryUsedQuery () const =0 |
| virtual bool | getDatabaseVersionQuery (std::string &version) const =0 |
| virtual long | getNodesMemoryUsedQuery () const =0 |
| virtual long | getLinksMemoryUsedQuery () const =0 |
| virtual long | getImagesMemoryUsedQuery () const =0 |
| virtual long | getDepthImagesMemoryUsedQuery () const =0 |
| virtual long | getCalibrationsMemoryUsedQuery () const =0 |
| virtual long | getGridsMemoryUsedQuery () const =0 |
| virtual long | getLaserScansMemoryUsedQuery () const =0 |
| virtual long | getUserDataMemoryUsedQuery () const =0 |
| virtual long | getWordsMemoryUsedQuery () const =0 |
| virtual long | getFeaturesMemoryUsedQuery () const =0 |
| virtual long | getStatisticsMemoryUsedQuery () const =0 |
| virtual int | getLastNodesSizeQuery () const =0 |
| virtual int | getLastDictionarySizeQuery () const =0 |
| virtual int | getTotalNodesSizeQuery () const =0 |
| virtual int | getTotalDictionarySizeQuery () const =0 |
| virtual ParametersMap | getLastParametersQuery () const =0 |
| virtual std::map< std::string, float > | getStatisticsQuery (int nodeId, double &stamp, std::vector< int > *wmState) const =0 |
| virtual std::map< int, std::pair< std::map< std::string, float >, double > > | getAllStatisticsQuery () const =0 |
| virtual std::map< int, std::vector< int > > | getAllStatisticsWmStatesQuery () const =0 |
| virtual void | executeNoResultQuery (const std::string &sql) const =0 |
| virtual void | getWeightQuery (int signatureId, int &weight) const =0 |
| virtual void | saveQuery (const std::list< Signature * > &signatures)=0 |
| virtual void | saveQuery (const std::list< VisualWord * > &words) const =0 |
| virtual void | updateQuery (const std::list< Signature * > &signatures, bool updateTimestamp) const =0 |
| virtual void | updateQuery (const std::list< VisualWord * > &words, bool updateTimestamp) const =0 |
| virtual void | addLinkQuery (const Link &link) const =0 |
| virtual void | updateLinkQuery (const Link &link) const =0 |
| virtual void | updateOccupancyGridQuery (int nodeId, const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty, float cellSize, const cv::Point3f &viewpoint) const =0 |
| virtual void | updateCalibrationQuery (int nodeId, const std::vector< CameraModel > &models, const std::vector< StereoCameraModel > &stereoModels) const =0 |
| virtual void | updateDepthImageQuery (int nodeId, const cv::Mat &image, const std::string &format) const =0 |
| virtual void | updateLaserScanQuery (int nodeId, const LaserScan &scan) const =0 |
| virtual void | addStatisticsQuery (const Statistics &statistics, bool saveWmState) const =0 |
| virtual void | savePreviewImageQuery (const cv::Mat &image) const =0 |
| virtual cv::Mat | loadPreviewImageQuery () const =0 |
| virtual void | saveOptimizedPosesQuery (const std::map< int, Transform > &optimizedPoses, const Transform &lastlocalizationPose) const =0 |
| virtual std::map< int, Transform > | loadOptimizedPosesQuery (Transform *lastlocalizationPose=0) const =0 |
| virtual void | save2DMapQuery (const cv::Mat &map, float xMin, float yMin, float cellSize) const =0 |
| virtual cv::Mat | load2DMapQuery (float &xMin, float &yMin, float &cellSize) const =0 |
| virtual void | saveOptimizedMeshQuery (const cv::Mat &cloud, const std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > &polygons, const std::vector< std::vector< Eigen::Vector2f > > &texCoords, const cv::Mat &textures) const =0 |
| virtual cv::Mat | loadOptimizedMeshQuery (std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > *polygons, std::vector< std::vector< Eigen::Vector2f > > *texCoords, cv::Mat *textures) const =0 |
| virtual void | saveFlannIndexQuery (const std::vector< unsigned char > &indexData) const =0 |
| virtual void | loadQuery (VWDictionary &dictionary, bool lastStateOnly=true, bool idsOnly=false) const =0 |
| virtual void | loadLastNodesQuery (std::list< Signature * > &signatures, bool loadWordIdsOnly) const =0 |
| virtual void | loadSignaturesQuery (const std::list< int > &ids, std::list< Signature * > &signatures, bool loadWordIdsOnly) const =0 |
| virtual void | loadWordsQuery (const std::set< int > &wordIds, std::list< VisualWord * > &vws) const =0 |
| virtual void | loadLinksQuery (int signatureId, std::multimap< int, Link > &links, Link::Type type=Link::kUndef) const =0 |
| virtual void | loadNodeDataQuery (std::list< Signature * > &signatures, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const =0 |
| virtual bool | getCalibrationQuery (int signatureId, std::vector< CameraModel > &models, std::vector< StereoCameraModel > &stereoModels) const =0 |
| virtual bool | getLaserScanInfoQuery (int signatureId, LaserScan &info) const =0 |
| virtual bool | getNodeInfoQuery (int signatureId, Transform &pose, int &mapId, int &weight, std::string &label, double &stamp, Transform &groundTruthPose, std::vector< float > &velocity, GPS &gps, EnvSensors &sensors) const =0 |
| virtual void | getLocalFeaturesQuery (int signatureId, std::multimap< int, int > &words, std::vector< cv::KeyPoint > &keypoints, std::vector< cv::Point3f > &points, cv::Mat &descriptors) const =0 |
| virtual void | getLastNodeIdsQuery (std::set< int > &ids) const =0 |
| virtual void | getAllNodeIdsQuery (std::set< int > &ids, bool ignoreChildren, bool ignoreBadSignatures, bool ignoreIntermediateNodes) const =0 |
| virtual void | getAllOdomPosesQuery (std::map< int, Transform > &poses, bool ignoreChildren, bool ignoreIntermediateNodes) const =0 |
| virtual void | getAllLinksQuery (std::multimap< int, Link > &links, bool ignoreNullLinks, bool withLandmarks) const =0 |
| virtual void | getLastIdQuery (const std::string &tableName, int &id, const std::string &fieldName="id") const =0 |
| virtual void | getInvertedIndexNiQuery (int signatureId, int &ni) const =0 |
| virtual void | getNodesObservingLandmarkQuery (int landmarkId, std::map< int, Link > &nodes) const =0 |
| virtual void | getNodeIdByLabelQuery (const std::string &label, int &id) const =0 |
| virtual void | getAllLabelsQuery (std::map< int, std::string > &labels) const =0 |
Additional Inherited Members | |
Public Types inherited from UThread | |
| enum | Priority { kPLow , kPBelowNormal , kPNormal , kPAboveNormal , kPRealTime } |
Public Types inherited from UThreadC< void > | |
| typedef THREAD_HANDLE | Handle |
| typedef void(* | Handler) () |
| typedef THREAD_HANDLE | Handle |
| typedef void(* | Handler) () |
Static Protected Member Functions inherited from UThreadC< void > | |
| static void | Exit () |
| static void | TestCancel () |
| static Handle | Self () |
| static void | Exit () |
| static void | TestCancel () |
| static int | Self () |
Abstract database driver for RTAB-Map maps (signatures, links, words, statistics).
DBDriver is the persistence layer used by Memory, DBReader and tools that read or write .db files. The default implementation is DBDriverSqlite3, created by create().
The driver extends UThreadNode. Pending Signature and VisualWord objects are queued with asyncSave() and flushed to the database by emptyTrashes() (also called from the background thread on closeConnection()).
Public methods are thread-safe where noted (mutex-protected wrappers). Subclasses implement SQL-specific logic in protected *Query() virtual methods.
Definition at line 71 of file DBDriver.h.
|
static |
Factory: returns a SQLite database driver (DBDriverSqlite3).
| parameters | Optional driver parameters (e.g. Parameters::kDbTargetVersion()). |
|
virtual |
Parse driver parameters from the map (e.g. target schema version).
Reimplemented in rtabmap::DBDriverSqlite3.
|
inlinevirtual |
True when no database file URL was set at open time.
Reimplemented in rtabmap::DBDriverSqlite3.
Definition at line 90 of file DBDriver.h.
|
inline |
Definition at line 92 of file DBDriver.h.
|
inline |
Definition at line 94 of file DBDriver.h.
| void rtabmap::DBDriver::asyncSave | ( | Signature * | s | ) |
Queue a signature for deferred save; ownership is transferred.
| void rtabmap::DBDriver::emptyTrashes | ( | bool | async = false | ) |
Flush queued signatures and visual words to the database.
| async | If true, signal the background thread instead of flushing synchronously. |
|
inline |
Definition at line 116 of file DBDriver.h.
|
inline |
Definition at line 117 of file DBDriver.h.
| void rtabmap::DBDriver::generateGraph | ( | const std::string & | fileName, |
| const std::set< int > & | ids = std::set< int >(), |
||
| const std::map< int, Signature * > & | otherSignatures = std::map< int, Signature * >() |
||
| ) |
Export the pose graph to a Graphviz DOT file for visualization.
Reads nodes and links from the database (and optionally from otherSignatures not yet persisted) and writes fileName. Does not modify the database. If ids is empty, all node ids are included.
| void rtabmap::DBDriver::updateOccupancyGrid | ( | int | nodeId, |
| const cv::Mat & | ground, | ||
| const cv::Mat & | obstacles, | ||
| const cv::Mat & | empty, | ||
| float | cellSize, | ||
| const cv::Point3f & | viewpoint | ||
| ) |
Update occupancy grid cells for a node.
| ground | Ground cells (raw CV_32FC2/ or compressed CV_8UC1 1×N). |
| obstacles | Obstacle cells (same formats as ground). |
| empty | Empty cells (same formats as ground; ignored on DB schema < 0.16.0). Raw mats are compressed internally via SensorData::setOccupancyGrid() before writing. |
| void rtabmap::DBDriver::updateDepthImage | ( | int | nodeId, |
| const cv::Mat & | image, | ||
| const std::string & | format | ||
| ) |
Update the depth image stored for a node.
| image | Raw depth image, or pre-compressed blob (CV_8UC1, single row). |
| format | Compression format when image is raw (e.g. ".png"); ignored if already compressed. Uncompressed images are compressed with compressImage2() before writing. |
| void rtabmap::DBDriver::updateLaserScan | ( | int | nodeId, |
| const LaserScan & | scan | ||
| ) |
Update the laser scan stored for a node.
| scan | Uncompressed scan, or already compressed (LaserScan::isCompressed()). Uncompressed data is compressed with compressData2() before writing. |
| void rtabmap::DBDriver::addStatistics | ( | const Statistics & | statistics, |
| bool | saveWmState | ||
| ) | const |
Append a Statistics record for a processed node.
| statistics | Metrics for Statistics::refImageId() (insert skipped if id ≤ 0 or data empty). |
| saveWmState | If true and schema ≥ 0.16.2, also store compressed working-memory state. |
| void rtabmap::DBDriver::savePreviewImage | ( | const cv::Mat & | image | ) | const |
Save the map preview thumbnail in the Admin table.
| image | Raw image or JPEG-compressed blob (CV_8UC1, single row); empty clears it. |
| void rtabmap::DBDriver::saveOptimizedMesh | ( | const cv::Mat & | cloud, |
| const std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > & | polygons = std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > >(), |
||
| const std::vector< std::vector< Eigen::Vector2f > > & | texCoords = std::vector< std::vector< Eigen::Vector2f > >(), |
||
| const cv::Mat & | textures = cv::Mat() |
||
| ) | const |
Persist the global optimized 3D mesh to the database.
| cloud | Point cloud (CV_32FC1 or CV_32FC3). |
| polygons | Optional per-texture polygon index lists (texture → polygon → vertex indices). |
| texCoords | Optional UV coordinates per texture (one per polygon vertex). |
| textures | Optional concatenated square texture images (same size per texture). |
| void rtabmap::DBDriver::saveFlannIndex | ( | const std::vector< unsigned char > & | indexData | ) | const |
Persist the visual word dictionary FLANN index (serialized blob).
| indexData | Serialized index from VWDictionary::serializeIndex(); pass empty to clear. |
| bool rtabmap::DBDriver::isConnected | ( | ) | const |
| std::string rtabmap::DBDriver::getDatabaseVersion | ( | ) | const |
| void rtabmap::DBDriver::executeNoResult | ( | const std::string & | sql | ) | const |
Run a SQL statement that does not return result rows.
Executes sql on the open database (e.g. INSERT, UPDATE, DELETE, CREATE, PRAGMA). Thread-safe wrapper around the backend's SQL execution.
For reads, use the dedicated loadSignature(), loadLinks() and related query methods instead of raw SQL.
| sql | Complete SQL statement (SQLite syntax for DBDriverSqlite3). |
sql is passed verbatim; sanitize any user-controlled values before calling.