ReUseX  0.0.1
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
ReUseX::io::RTABMapDatabase Class Reference

Core database class that wraps RTABMap's database functionality. More...

#include <RTABMapDatabase.hpp>

Public Member Functions

 RTABMapDatabase (std::filesystem::path dbPath, bool readOnly=false)
 Opens an RTABMap database and validates its schema.
 ~RTABMapDatabase ()
 Destructor closes database connection.
 RTABMapDatabase (const RTABMapDatabase &)=delete
RTABMapDatabaseoperator= (const RTABMapDatabase &)=delete
 RTABMapDatabase (RTABMapDatabase &&) noexcept
RTABMapDatabaseoperator= (RTABMapDatabase &&) noexcept
bool isOpen () const noexcept
 Check if database connection is open.
const std::filesystem::path & getPath () const noexcept
 Get the path to the database file.
void validateSchema () const
 Validate that required RTABMap tables exist.
std::vector< int > getNodeIds (bool ignoreChildren=false) const
 Get list of all node IDs in the database.
cv::Mat getImage (int nodeId) const
 Get image data for a specific node.
void getGraph (std::map< int, rtabmap::Transform > &poses, std::multimap< int, rtabmap::Link > &links, std::map< int, rtabmap::Signature > *signatures=nullptr, bool optimized=true, bool withImages=false, bool withScan=false) const
 Retrieve the SLAM graph (poses, links, signatures).
bool hasSegmentation (int nodeId) const
 Check if a node has segmentation labels stored.
cv::Mat getLabels (int nodeId) const
 Get segmentation labels for a node.
void saveLabels (int nodeId, const cv::Mat &labels, bool autoRotate=true)
 Save segmentation labels for a single node.
void saveLabels (const std::vector< int > &nodeIds, const std::vector< cv::Mat > &labels, bool autoRotate=true)
 Save segmentation labels for multiple nodes (batch operation).

Detailed Description

Core database class that wraps RTABMap's database functionality.

This class provides a unified interface for accessing RTABMap databases, including both the core RTABMap tables (Node, Data, Link) and custom extensions (Segmentation table for labels).

The class uses RAII for resource management and the Pimpl idiom to hide RTABMap implementation details. It is not thread-safe; create separate instances for each thread if concurrent access is needed.

Thread Safety: NOT thread-safe. sqlite3 connections should not be shared between threads. Create per-thread instances if needed.

Definition at line 36 of file RTABMapDatabase.hpp.

Constructor & Destructor Documentation

◆ RTABMapDatabase() [1/3]

ReUseX::io::RTABMapDatabase::RTABMapDatabase ( std::filesystem::path dbPath,
bool readOnly = false )
explicit

Opens an RTABMap database and validates its schema.

Parameters
dbPathPath to the database file
readOnlyIf true, opens database in read-only mode
Exceptions
std::runtime_errorif database cannot be opened or schema is invalid

Referenced by operator=(), operator=(), RTABMapDatabase(), and RTABMapDatabase().

◆ ~RTABMapDatabase()

ReUseX::io::RTABMapDatabase::~RTABMapDatabase ( )

Destructor closes database connection.

◆ RTABMapDatabase() [2/3]

ReUseX::io::RTABMapDatabase::RTABMapDatabase ( const RTABMapDatabase & )
delete

References RTABMapDatabase().

◆ RTABMapDatabase() [3/3]

ReUseX::io::RTABMapDatabase::RTABMapDatabase ( RTABMapDatabase && )
noexcept

References RTABMapDatabase().

Member Function Documentation

◆ getGraph()

void ReUseX::io::RTABMapDatabase::getGraph ( std::map< int, rtabmap::Transform > & poses,
std::multimap< int, rtabmap::Link > & links,
std::map< int, rtabmap::Signature > * signatures = nullptr,
bool optimized = true,
bool withImages = false,
bool withScan = false ) const

Retrieve the SLAM graph (poses, links, signatures).

This uses RTABMap's high-level Rtabmap class to extract graph data.

Parameters
posesOutput map of node IDs to 3D transforms
linksOutput multimap of node IDs to links (edges)
signaturesOptional output map of node IDs to full signatures
optimizedIf true, return optimized poses
withImagesIf true, include image data in signatures
withScanIf true, include laser scan data in signatures
Exceptions
std::runtime_errorif graph retrieval fails

References getGraph().

Referenced by getGraph().

◆ getImage()

cv::Mat ReUseX::io::RTABMapDatabase::getImage ( int nodeId) const

Get image data for a specific node.

Retrieves the image from the Data table and applies 90° clockwise rotation to match RTABMap's coordinate convention.

Parameters
nodeIdThe node ID to retrieve image for
Returns
OpenCV Mat containing the image (empty if not found)
Exceptions
std::runtime_errorif database access fails

References getImage().

Referenced by getImage().

◆ getLabels()

cv::Mat ReUseX::io::RTABMapDatabase::getLabels ( int nodeId) const

Get segmentation labels for a node.

Returns labels as CV_32S with -1 for unlabeled/background pixels and 0+ for class labels. Applies 90° clockwise rotation to match the image coordinate system.

Parameters
nodeIdNode ID to retrieve labels for
Returns
OpenCV Mat with labels (CV_32S), empty if not found
Exceptions
std::runtime_errorif database access fails

References getLabels().

Referenced by getLabels().

◆ getNodeIds()

std::vector< int > ReUseX::io::RTABMapDatabase::getNodeIds ( bool ignoreChildren = false) const

Get list of all node IDs in the database.

Parameters
ignoreChildrenIf true, only return parent nodes (not children)
Returns
Vector of node IDs

References getNodeIds().

Referenced by getNodeIds().

◆ getPath()

const std::filesystem::path & ReUseX::io::RTABMapDatabase::getPath ( ) const
noexcept

Get the path to the database file.

Returns
filesystem path to the database

References getPath().

Referenced by getPath().

◆ hasSegmentation()

bool ReUseX::io::RTABMapDatabase::hasSegmentation ( int nodeId) const

Check if a node has segmentation labels stored.

Parameters
nodeIdNode ID to check
Returns
true if labels exist for this node

References hasSegmentation().

Referenced by hasSegmentation().

◆ isOpen()

bool ReUseX::io::RTABMapDatabase::isOpen ( ) const
noexcept

Check if database connection is open.

Returns
true if database is open and valid

References isOpen().

Referenced by isOpen().

◆ operator=() [1/2]

RTABMapDatabase & ReUseX::io::RTABMapDatabase::operator= ( const RTABMapDatabase & )
delete

References RTABMapDatabase().

◆ operator=() [2/2]

RTABMapDatabase & ReUseX::io::RTABMapDatabase::operator= ( RTABMapDatabase && )
noexcept

References RTABMapDatabase().

◆ saveLabels() [1/2]

void ReUseX::io::RTABMapDatabase::saveLabels ( const std::vector< int > & nodeIds,
const std::vector< cv::Mat > & labels,
bool autoRotate = true )

Save segmentation labels for multiple nodes (batch operation).

Uses a database transaction for efficiency. All nodes must exist in the Node table or the entire operation fails.

Parameters
nodeIdsVector of node IDs
labelsVector of label Mats (must match nodeIds length)
autoRotateIf true, applies 90° counterclockwise rotation before saving
Exceptions
std::runtime_errorif sizes don't match, nodes don't exist, or save fails

References saveLabels().

◆ saveLabels() [2/2]

void ReUseX::io::RTABMapDatabase::saveLabels ( int nodeId,
const cv::Mat & labels,
bool autoRotate = true )

Save segmentation labels for a single node.

Labels should be CV_32S with -1 for unlabeled/background and 0+ for class labels. Internally converts to CV_16U with +1 offset for storage (0 = background).

Parameters
nodeIdNode ID to save labels for
labelsOpenCV Mat with labels (CV_32S)
autoRotateIf true, applies 90° counterclockwise rotation before saving
Exceptions
std::runtime_errorif node doesn't exist or save fails

References saveLabels().

Referenced by saveLabels(), and saveLabels().

◆ validateSchema()

void ReUseX::io::RTABMapDatabase::validateSchema ( ) const

Validate that required RTABMap tables exist.

Exceptions
std::runtime_errorif required tables are missing

References validateSchema().

Referenced by validateSchema().


The documentation for this class was generated from the following file: