2011-06-05 14:45:39 +00:00
|
|
|
/*
|
2014-08-11 17:00:55 +00:00
|
|
|
Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
|
|
|
|
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"
|
2013-12-11 00:12:44 +00:00
|
|
|
#include <pcl/point_types.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:
|
2012-03-03 01:46:30 +00:00
|
|
|
virtual bool connectDatabaseQuery(const std::string & url, bool overwirtten = false);
|
2011-06-05 14:45:39 +00:00
|
|
|
virtual void disconnectDatabaseQuery();
|
|
|
|
|
virtual bool isConnectedQuery() const;
|
|
|
|
|
virtual long getMemoryUsedQuery() const; // In bytes
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
virtual void loadNodeDataQuery(std::list<Signature *> & signatures, bool loadMetricData) const;
|
|
|
|
|
virtual void getNodeDataQuery(
|
|
|
|
|
int signatureId,
|
2014-10-28 19:57:21 +00:00
|
|
|
cv::Mat & imageCompressed,
|
|
|
|
|
cv::Mat & depthCompressed,
|
2014-12-14 16:42:10 -05:00
|
|
|
cv::Mat & laserScanCompressed,
|
2014-07-26 04:36:00 +00:00
|
|
|
float & fx,
|
|
|
|
|
float & fy,
|
|
|
|
|
float & cx,
|
|
|
|
|
float & cy,
|
2015-05-01 07:30:09 -04:00
|
|
|
Transform & localTransform,
|
|
|
|
|
int & laserScanMaxPts) const;
|
2014-10-28 19:57:21 +00:00
|
|
|
virtual void getNodeDataQuery(int signatureId, cv::Mat & imageCompressed) const;
|
2015-03-25 13:31:12 -04:00
|
|
|
virtual bool getNodeInfoQuery(int signatureId, Transform & pose, int & mapId, int & weight, std::string & label, double & stamp, std::vector<unsigned char> & userData) const;
|
2014-10-01 21:44:46 +00:00
|
|
|
virtual void getAllNodeIdsQuery(std::set<int> & ids, bool ignoreChildren) 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;
|
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;
|
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;
|
2013-12-11 00:12:44 +00:00
|
|
|
void stepDepth(
|
|
|
|
|
sqlite3_stmt * ppStmt,
|
|
|
|
|
int id,
|
2014-10-28 19:57:21 +00:00
|
|
|
const cv::Mat & depthBytes,
|
|
|
|
|
const cv::Mat & depth2dBytes,
|
2014-07-26 04:36:00 +00:00
|
|
|
float fx,
|
|
|
|
|
float fy,
|
|
|
|
|
float cx,
|
|
|
|
|
float cy,
|
2015-05-01 07:30:09 -04:00
|
|
|
const Transform & localTransform,
|
|
|
|
|
int depth2dMaxPts) const;
|
2015-02-24 16:06:02 -05:00
|
|
|
void stepLink(sqlite3_stmt * ppStmt, int fromId, int toId, Link::Type type, float rotVariance, float transVariance, const Transform & transform) const;
|
2012-12-11 18:05:05 +00:00
|
|
|
void stepWordsChanged(sqlite3_stmt * ppStmt, int signatureId, int oldWordId, int newWordId) const;
|
2013-12-11 00:12:44 +00:00
|
|
|
void stepKeypoint(sqlite3_stmt * ppStmt, int signatureId, int wordId, const cv::KeyPoint & kp, const pcl::PointXYZ & pt) 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;
|
2014-07-26 04:36:00 +00:00
|
|
|
bool getVersion(std::string &) const;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
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_ */
|