RTAB-Map 0.23.10
Real-Time Appearance-Based Mapping
Loading...
Searching...
No Matches
DBDriverSqlite3.h
1/*
2Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
12 * Neither the name of the Universite de Sherbrooke nor the
13 names of its contributors may be used to endorse or promote products
14 derived from this software without specific prior written permission.
15
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28#ifndef DBDRIVERSQLITE3_H_
29#define DBDRIVERSQLITE3_H_
30
31#include "rtabmap/core/rtabmap_core_export.h" // DLL export/import defines
32#include "rtabmap/core/DBDriver.h"
33#if CV_MAJOR_VERSION < 5
34#include <opencv2/features2d/features2d.hpp>
35#else
36#include <opencv2/features.hpp>
37#endif
38
39typedef struct sqlite3_stmt sqlite3_stmt;
40typedef struct sqlite3 sqlite3;
41
42namespace rtabmap {
43
70class RTABMAP_CORE_EXPORT DBDriverSqlite3: public DBDriver {
71public:
77 virtual ~DBDriverSqlite3();
78
80 virtual void parseParameters(const ParametersMap & parameters);
85 virtual bool isInMemory() const {return getUrl().empty() || _dbInMemory;}
90 void setDbInMemory(bool dbInMemory);
110 void setJournalMode(int journalMode);
111
123 void setCacheSize(unsigned int cacheSize);
124
140 void setSynchronous(int synchronous);
141
156 void setTempStore(int tempStore);
157
158protected:
159 virtual bool connectDatabaseQuery(const std::string & url, bool overwritten = false, bool readOnly = false);
160 virtual void disconnectDatabaseQuery(bool save = true, const std::string & outputUrl = "");
161 virtual bool isConnectedQuery() const;
162 virtual unsigned long getMemoryUsedQuery() const; // In bytes
163 virtual bool getDatabaseVersionQuery(std::string & version) const;
164 virtual long getNodesMemoryUsedQuery() const;
165 virtual long getLinksMemoryUsedQuery() const;
166 virtual long getImagesMemoryUsedQuery() const;
167 virtual long getDepthImagesMemoryUsedQuery() const;
168 virtual long getCalibrationsMemoryUsedQuery() const;
169 virtual long getGridsMemoryUsedQuery() const;
170 virtual long getLaserScansMemoryUsedQuery() const;
171 virtual long getUserDataMemoryUsedQuery() const;
172 virtual long getWordsMemoryUsedQuery() const;
173 virtual long getFeaturesMemoryUsedQuery() const;
174 virtual long getStatisticsMemoryUsedQuery() const;
175 virtual int getLastNodesSizeQuery() const;
176 virtual int getLastDictionarySizeQuery() const;
177 virtual int getTotalNodesSizeQuery() const;
178 virtual int getTotalDictionarySizeQuery() const;
179 virtual ParametersMap getLastParametersQuery() const;
180 virtual std::map<std::string, float> getStatisticsQuery(int nodeId, double & stamp, std::vector<int> * wmState) const;
181 virtual std::map<int, std::pair<std::map<std::string, float>, double> > getAllStatisticsQuery() const;
182 virtual std::map<int, std::vector<int> > getAllStatisticsWmStatesQuery() const;
183
184 virtual void executeNoResultQuery(const std::string & sql) const;
185
186 virtual void getWeightQuery(int signatureId, int & weight) const;
187
188 virtual void saveQuery(const std::list<Signature *> & signatures);
189 virtual void saveQuery(const std::list<VisualWord *> & words) const;
190 virtual void updateQuery(const std::list<Signature *> & signatures, bool updateTimestamp) const;
191 virtual void updateQuery(const std::list<VisualWord *> & words, bool updateTimestamp) const;
192
193 virtual void addLinkQuery(const Link & link) const;
194 virtual void updateLinkQuery(const Link & link) const;
195
196 virtual void updateOccupancyGridQuery(
197 int nodeId,
198 const cv::Mat & ground,
199 const cv::Mat & obstacles,
200 const cv::Mat & empty,
201 float cellSize,
202 const cv::Point3f & viewpoint) const;
203
204 virtual void updateCalibrationQuery(
205 int nodeId,
206 const std::vector<CameraModel> & models,
207 const std::vector<StereoCameraModel> & stereoModels) const;
208
209 virtual void updateDepthImageQuery(
210 int nodeId,
211 const cv::Mat & image,
212 const std::string & format) const;
213
214 void updateLaserScanQuery(
215 int nodeId,
216 const LaserScan & scan) const;
217
218 virtual void addStatisticsQuery(const Statistics & statistics, bool saveWmState) const;
219 virtual void savePreviewImageQuery(const cv::Mat & image) const;
220 virtual cv::Mat loadPreviewImageQuery() const;
221 virtual void saveOptimizedPosesQuery(const std::map<int, Transform> & optimizedPoses, const Transform & lastlocalizationPose) const;
222 virtual std::map<int, Transform> loadOptimizedPosesQuery(Transform * lastlocalizationPose = 0) const;
223 virtual void save2DMapQuery(const cv::Mat & map, float xMin, float yMin, float cellSize) const;
224 virtual cv::Mat load2DMapQuery(float & xMin, float & yMin, float & cellSize) const;
225 virtual void saveOptimizedMeshQuery(
226 const cv::Mat & cloud,
227 const std::vector<std::vector<std::vector<RTABMAP_PCL_INDEX> > > & polygons,
228#if PCL_VERSION_COMPARE(>=, 1, 8, 0)
229 const std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > & texCoords,
230#else
231 const std::vector<std::vector<Eigen::Vector2f> > & texCoords,
232#endif
233 const cv::Mat & textures) const;
234 virtual cv::Mat loadOptimizedMeshQuery(
235 std::vector<std::vector<std::vector<RTABMAP_PCL_INDEX> > > * polygons,
236#if PCL_VERSION_COMPARE(>=, 1, 8, 0)
237 std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > * texCoords,
238#else
239 std::vector<std::vector<Eigen::Vector2f> > * texCoords,
240#endif
241 cv::Mat * textures) const;
242
243 virtual void saveFlannIndexQuery(const std::vector<unsigned char> & indexData) const;
244
245 // Load objects
246 virtual void loadQuery(VWDictionary & dictionary, bool lastStateOnly = true, bool idsOnly = false) const;
247 virtual void loadLastNodesQuery(std::list<Signature *> & signatures, bool loadWordIdsOnly) const;
248 virtual void loadSignaturesQuery(const std::list<int> & ids, std::list<Signature *> & signatures, bool loadWordIdsOnly) const;
249 virtual void loadWordsQuery(const std::set<int> & wordIds, std::list<VisualWord *> & vws) const;
250 virtual void loadLinksQuery(int signatureId, std::multimap<int, Link> & links, Link::Type type = Link::kUndef) const;
251
252 virtual void loadNodeDataQuery(std::list<Signature *> & signatures, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const;
253 virtual bool getCalibrationQuery(int signatureId, std::vector<CameraModel> & models, std::vector<StereoCameraModel> & stereoModels) const;
254 virtual bool getLaserScanInfoQuery(int signatureId, LaserScan & info) const;
255 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;
256 virtual void getLocalFeaturesQuery(int signatureId, std::multimap<int, int> & words, std::vector<cv::KeyPoint> & keypoints, std::vector<cv::Point3f> & points, cv::Mat & descriptors) const;
257 virtual void getLastNodeIdsQuery(std::set<int> & ids) const;
258 virtual void getAllNodeIdsQuery(std::set<int> & ids, bool ignoreChildren, bool ignoreBadSignatures, bool ignoreIntermediateNodes) const;
259 virtual void getAllOdomPosesQuery(std::map<int, Transform> & poses, bool ignoreChildren, bool ignoreIntermediateNodes) const;
260 virtual void getAllLinksQuery(std::multimap<int, Link> & links, bool ignoreNullLinks, bool withLandmarks) const;
261 virtual void getLastIdQuery(const std::string & tableName, int & id, const std::string & fieldName="id") const;
262 virtual void getInvertedIndexNiQuery(int signatureId, int & ni) const;
263 virtual void getNodesObservingLandmarkQuery(int landmarkId, std::map<int, Link> & nodes) const;
264 virtual void getNodeIdByLabelQuery(const std::string & label, int & id) const;
265 virtual void getAllLabelsQuery(std::map<int, std::string> & labels) const;
266
267private:
268 std::string queryStepNode() const;
269 std::string queryStepImage() const;
270 std::string queryStepDepth() const;
271 std::string queryStepCalibrationUpdate() const;
272 std::string queryStepDepthUpdate() const;
273 std::string queryStepScanUpdate() const;
274 std::string queryStepSensorData() const;
275 std::string queryStepLinkUpdate() const;
276 std::string queryStepLink() const;
277 std::string queryStepWordsChanged() const;
278 std::string queryStepKeypoint() const;
279 std::string queryStepGlobalDescriptor() const;
280 std::string queryStepOccupancyGridUpdate() const;
281 void stepNode(sqlite3_stmt * ppStmt, const Signature * s) const;
282 void stepImage(sqlite3_stmt * ppStmt, int id, const cv::Mat & imageBytes) const;
283 void stepDepth(sqlite3_stmt * ppStmt, const SensorData & sensorData) const;
284 void stepCalibrationUpdate(sqlite3_stmt * ppStmt, int nodeId, const std::vector<CameraModel> & models, const std::vector<StereoCameraModel> & stereoModels) const;
285 void stepDepthUpdate(sqlite3_stmt * ppStmt, int nodeId, const cv::Mat & image, const std::string & format) const;
286 void stepScanUpdate(sqlite3_stmt * ppStmt, int nodeId, const LaserScan & image) const;
287 void stepSensorData(sqlite3_stmt * ppStmt, const SensorData & sensorData) const;
288 void stepLink(sqlite3_stmt * ppStmt, const Link & link) const;
289 void stepWordsChanged(sqlite3_stmt * ppStmt, int signatureId, int oldWordId, int newWordId) const;
290 void stepKeypoint(sqlite3_stmt * ppStmt, int nodeID, int wordId, const cv::KeyPoint & kp, const cv::Point3f & pt, const cv::Mat & descriptor) const;
291 void stepGlobalDescriptor(sqlite3_stmt * ppStmt, int nodeId, const GlobalDescriptor & descriptor) const;
292 void stepOccupancyGridUpdate(sqlite3_stmt * ppStmt,
293 int nodeId,
294 const cv::Mat & ground,
295 const cv::Mat & obstacles,
296 const cv::Mat & empty,
297 float cellSize,
298 const cv::Point3f & viewpoint) const;
299
300private:
301 void loadWordsQuery(std::list<Signature *> & signatures) const;
302 void loadWordIdsQuery(std::list<Signature *> & signatures) const;
303 void loadLinksQuery(std::list<Signature *> & signatures) const;
304 int loadOrSaveDb(sqlite3 *pInMemory, const std::string & fileName, int isSave) const;
305
306protected:
307 sqlite3 * _ppDb;
308 std::string _version;
309
310private:
311 unsigned long _memoryUsedEstimate;
312 bool _dbInMemory;
313 unsigned int _cacheSize;
314 int _journalMode;
315 int _synchronous;
316 int _tempStore;
317};
318
319}
320
321#endif /* DBDRIVERSQLITE3_H_ */
SQLite3 implementation of DBDriver for RTAB-Map map databases.
void setDbInMemory(bool dbInMemory)
Enable or disable in-memory mode. If connected, the connection is closed and reopened with the new mo...
sqlite3 * _ppDb
Open SQLite connection (null when disconnected)
std::string _version
Schema version read from the database.
void setSynchronous(int synchronous)
Set how aggressively SQLite syncs the database file to disk (PRAGMA synchronous).
DBDriverSqlite3(const ParametersMap &parameters=ParametersMap())
Construct driver with optional SQLite-specific parameters.
void setTempStore(int tempStore)
Set where SQLite stores temporary tables and indices (PRAGMA temp_store).
virtual void parseParameters(const ParametersMap &parameters)
Apply SQLite parameters from the map; forwards to DBDriver::parseParameters().
void setJournalMode(int journalMode)
Set SQLite rollback journal mode (PRAGMA journal_mode).
virtual bool isInMemory() const
True when the database runs in RAM instead of on disk.
void setCacheSize(unsigned int cacheSize)
Set the number of database pages kept in SQLite's page cache (PRAGMA cache_size).
Abstract database driver for RTAB-Map maps (signatures, links, words, statistics).
Definition DBDriver.h:72
WGS84 GPS fix attached to a sensor sample or graph node.
Definition GPS.h:47
Represents 2D or 3D laser scan data with support for multiple point data formats.
Definition LaserScan.h:46
Container class for all sensor data captured at a specific time.
Definition SensorData.h:97
Represents a node in RTAB-Map's pose graph.
Definition Signature.h:84
Collects and manages runtime statistics for RTAB-Map.
Definition Statistics.h:108
Represents a 3D rigid body transformation (rotation + translation).
Definition Transform.h:53
Manages a dictionary of visual words for visual place recognition and loop closure detection.
std::map< EnvSensor::Type, EnvSensor > EnvSensors
Map of environmental readings keyed by EnvSensor::Type (at most one per type).
Definition EnvSensor.h:114
std::map< std::string, std::string > ParametersMap
Parameter keys mapped to their values, as used by every configurable class (see Parameters).
Definition Parameters.h:44