2011-06-05 14:45:39 +00:00
|
|
|
/*
|
2016-07-17 21:57:10 -04:00
|
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
2014-08-11 17:00:55 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
#ifndef DBDRIVERSQLITE3_H_
|
|
|
|
|
#define DBDRIVERSQLITE3_H_
|
|
|
|
|
|
|
|
|
|
#include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
|
|
|
|
|
#include "rtabmap/core/DBDriver.h"
|
2012-12-11 18:05:05 +00:00
|
|
|
#include <opencv2/features2d/features2d.hpp>
|
2014-01-24 21:42:35 +00:00
|
|
|
#include "sqlite3/sqlite3.h"
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
namespace rtabmap {
|
|
|
|
|
|
|
|
|
|
class RTABMAP_EXP DBDriverSqlite3: public DBDriver {
|
|
|
|
|
public:
|
|
|
|
|
DBDriverSqlite3(const ParametersMap & parameters = ParametersMap());
|
|
|
|
|
virtual ~DBDriverSqlite3();
|
|
|
|
|
|
|
|
|
|
virtual void parseParameters(const ParametersMap & parameters);
|
|
|
|
|
void setDbInMemory(bool dbInMemory);
|
|
|
|
|
void setJournalMode(int journalMode);
|
|
|
|
|
void setCacheSize(unsigned int cacheSize);
|
2012-03-03 01:46:30 +00:00
|
|
|
void setSynchronous(int synchronous);
|
|
|
|
|
void setTempStore(int tempStore);
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
private:
|
2016-04-04 13:03:43 -04:00
|
|
|
virtual bool connectDatabaseQuery(const std::string & url, bool overwritten = false);
|
|
|
|
|
virtual void disconnectDatabaseQuery(bool save = true);
|
2011-06-05 14:45:39 +00:00
|
|
|
virtual bool isConnectedQuery() const;
|
|
|
|
|
virtual long getMemoryUsedQuery() const; // In bytes
|
2015-07-26 17:45:48 -04:00
|
|
|
virtual bool getDatabaseVersionQuery(std::string & version) const;
|
2015-10-24 17:03:44 -04:00
|
|
|
virtual long getImagesMemoryUsedQuery() const;
|
|
|
|
|
virtual long getDepthImagesMemoryUsedQuery() const;
|
|
|
|
|
virtual long getLaserScansMemoryUsedQuery() const;
|
|
|
|
|
virtual long getUserDataMemoryUsedQuery() const;
|
|
|
|
|
virtual long getWordsMemoryUsedQuery() const;
|
|
|
|
|
virtual int getLastNodesSizeQuery() const;
|
|
|
|
|
virtual int getLastDictionarySizeQuery() const;
|
|
|
|
|
virtual int getTotalNodesSizeQuery() const;
|
|
|
|
|
virtual int getTotalDictionarySizeQuery() const;
|
2016-06-13 17:34:17 -04:00
|
|
|
virtual ParametersMap getLastParametersQuery() const;
|
2016-09-20 11:19:34 -04:00
|
|
|
virtual std::map<std::string, float> getStatisticsQuery(int nodeId, double & stamp) const;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2012-12-11 18:05:05 +00:00
|
|
|
virtual void executeNoResultQuery(const std::string & sql) const;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2012-12-11 18:05:05 +00:00
|
|
|
virtual void getWeightQuery(int signatureId, int & weight) const;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2012-12-11 18:05:05 +00:00
|
|
|
virtual void saveQuery(const std::list<Signature *> & signatures) const;
|
2012-12-12 16:40:18 +00:00
|
|
|
virtual void saveQuery(const std::list<VisualWord *> & words) const;
|
2015-02-04 17:40:16 -05:00
|
|
|
virtual void updateQuery(const std::list<Signature *> & signatures, bool updateTimestamp) const;
|
|
|
|
|
virtual void updateQuery(const std::list<VisualWord *> & words, bool updateTimestamp) const;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2015-10-16 14:54:47 -04:00
|
|
|
virtual void addLinkQuery(const Link & link) const;
|
|
|
|
|
virtual void updateLinkQuery(const Link & link) const;
|
|
|
|
|
|
2016-08-25 23:47:01 -04:00
|
|
|
virtual void updateOccupancyGridQuery(
|
|
|
|
|
int nodeId,
|
|
|
|
|
const cv::Mat & ground,
|
|
|
|
|
const cv::Mat & obstacles,
|
|
|
|
|
float cellSize,
|
|
|
|
|
const cv::Point3f & viewpoint) const;
|
|
|
|
|
|
2016-09-20 11:19:34 -04:00
|
|
|
virtual void addStatisticsQuery(const Statistics & statistics) const;
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
// Load objects
|
2012-12-11 18:05:05 +00:00
|
|
|
virtual void loadQuery(VWDictionary * dictionary) const;
|
|
|
|
|
virtual void loadLastNodesQuery(std::list<Signature *> & signatures) const;
|
|
|
|
|
virtual void loadSignaturesQuery(const std::list<int> & ids, std::list<Signature *> & signatures) const;
|
|
|
|
|
virtual void loadWordsQuery(const std::set<int> & wordIds, std::list<VisualWord *> & vws) const;
|
2014-12-14 16:42:10 -05:00
|
|
|
virtual void loadLinksQuery(int signatureId, std::map<int, Link> & links, Link::Type type = Link::kUndef) const;
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2016-08-21 19:33:01 -04:00
|
|
|
virtual void loadNodeDataQuery(std::list<Signature *> & signatures, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const;
|
2016-04-03 21:35:30 -04:00
|
|
|
virtual bool getCalibrationQuery(int signatureId, std::vector<CameraModel> & models, StereoCameraModel & stereoModel) const;
|
2016-01-07 19:39:21 -05:00
|
|
|
virtual bool getNodeInfoQuery(int signatureId, Transform & pose, int & mapId, int & weight, std::string & label, double & stamp, Transform & groundTruthPose) const;
|
2015-10-28 16:50:18 -04:00
|
|
|
virtual void getAllNodeIdsQuery(std::set<int> & ids, bool ignoreChildren, bool ignoreBadSignatures) const;
|
2015-06-21 18:29:12 -04:00
|
|
|
virtual void getAllLinksQuery(std::multimap<int, Link> & links, bool ignoreNullLinks) const;
|
2012-12-11 18:05:05 +00:00
|
|
|
virtual void getLastIdQuery(const std::string & tableName, int & id) const;
|
|
|
|
|
virtual void getInvertedIndexNiQuery(int signatureId, int & ni) const;
|
2015-02-27 15:24:15 -05:00
|
|
|
virtual void getNodeIdByLabelQuery(const std::string & label, int & id) const;
|
2015-03-06 16:14:09 -05:00
|
|
|
virtual void getAllLabelsQuery(std::map<int, std::string> & labels) const;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2012-03-03 01:46:30 +00:00
|
|
|
private:
|
2012-06-24 17:19:34 +00:00
|
|
|
std::string queryStepNode() const;
|
2012-12-11 18:05:05 +00:00
|
|
|
std::string queryStepImage() const;
|
2013-12-11 00:12:44 +00:00
|
|
|
std::string queryStepDepth() const;
|
2015-05-29 14:46:48 -04:00
|
|
|
std::string queryStepSensorData() const;
|
2015-10-16 14:54:47 -04:00
|
|
|
std::string queryStepLinkUpdate() const;
|
2012-06-24 17:19:34 +00:00
|
|
|
std::string queryStepLink() const;
|
2012-03-03 01:46:30 +00:00
|
|
|
std::string queryStepWordsChanged() const;
|
|
|
|
|
std::string queryStepKeypoint() const;
|
2016-08-25 23:47:01 -04:00
|
|
|
std::string queryStepOccupancyGridUpdate() const;
|
2012-12-11 18:05:05 +00:00
|
|
|
void stepNode(sqlite3_stmt * ppStmt, const Signature * s) const;
|
2013-12-11 00:12:44 +00:00
|
|
|
void stepImage(
|
|
|
|
|
sqlite3_stmt * ppStmt,
|
|
|
|
|
int id,
|
2014-10-28 19:57:21 +00:00
|
|
|
const cv::Mat & imageBytes) const;
|
2015-05-29 14:46:48 -04:00
|
|
|
void stepDepth(sqlite3_stmt * ppStmt, const SensorData & sensorData) const;
|
|
|
|
|
void stepSensorData(sqlite3_stmt * ppStmt, const SensorData & sensorData) const;
|
|
|
|
|
void stepLink(sqlite3_stmt * ppStmt, const Link & link) const;
|
2012-12-11 18:05:05 +00:00
|
|
|
void stepWordsChanged(sqlite3_stmt * ppStmt, int signatureId, int oldWordId, int newWordId) const;
|
2016-02-15 19:35:24 -05:00
|
|
|
void stepKeypoint(sqlite3_stmt * ppStmt, int signatureId, int wordId, const cv::KeyPoint & kp, const cv::Point3f & pt, const cv::Mat & descriptor) const;
|
2016-08-25 23:47:01 -04:00
|
|
|
void stepOccupancyGrid(sqlite3_stmt * ppStmt,
|
|
|
|
|
int nodeId,
|
|
|
|
|
const cv::Mat & ground,
|
|
|
|
|
const cv::Mat & obstacles,
|
|
|
|
|
float cellSize,
|
|
|
|
|
const cv::Point3f & viewpoint) const;
|
2012-03-03 01:46:30 +00:00
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
private:
|
2012-12-11 18:05:05 +00:00
|
|
|
void loadLinksQuery(std::list<Signature *> & signatures) const;
|
2011-06-05 14:45:39 +00:00
|
|
|
int loadOrSaveDb(sqlite3 *pInMemory, const std::string & fileName, int isSave) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
sqlite3 * _ppDb;
|
2014-07-26 04:36:00 +00:00
|
|
|
std::string _version;
|
2011-06-05 14:45:39 +00:00
|
|
|
bool _dbInMemory;
|
|
|
|
|
unsigned int _cacheSize;
|
|
|
|
|
int _journalMode;
|
2012-03-03 01:46:30 +00:00
|
|
|
int _synchronous;
|
|
|
|
|
int _tempStore;
|
2011-06-05 14:45:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* DBDRIVERSQLITE3_H_ */
|