00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef DBDRIVERSQLITE3_H_
00029 #define DBDRIVERSQLITE3_H_
00030
00031 #include "rtabmap/core/RtabmapExp.h"
00032 #include "rtabmap/core/DBDriver.h"
00033 #include <opencv2/features2d/features2d.hpp>
00034 #include "sqlite3/sqlite3.h"
00035 #include <pcl/point_types.h>
00036
00037 namespace rtabmap {
00038
00039 class RTABMAP_EXP DBDriverSqlite3: public DBDriver {
00040 public:
00041 DBDriverSqlite3(const ParametersMap & parameters = ParametersMap());
00042 virtual ~DBDriverSqlite3();
00043
00044 virtual void parseParameters(const ParametersMap & parameters);
00045 void setDbInMemory(bool dbInMemory);
00046 void setJournalMode(int journalMode);
00047 void setCacheSize(unsigned int cacheSize);
00048 void setSynchronous(int synchronous);
00049 void setTempStore(int tempStore);
00050
00051 private:
00052 virtual bool connectDatabaseQuery(const std::string & url, bool overwirtten = false);
00053 virtual void disconnectDatabaseQuery();
00054 virtual bool isConnectedQuery() const;
00055 virtual long getMemoryUsedQuery() const;
00056
00057 virtual void executeNoResultQuery(const std::string & sql) const;
00058
00059 virtual void getWeightQuery(int signatureId, int & weight) const;
00060
00061 virtual void saveQuery(const std::list<Signature *> & signatures) const;
00062 virtual void saveQuery(const std::list<VisualWord *> & words) const;
00063 virtual void updateQuery(const std::list<Signature *> & signatures, bool updateTimestamp) const;
00064 virtual void updateQuery(const std::list<VisualWord *> & words, bool updateTimestamp) const;
00065
00066
00067 virtual void loadQuery(VWDictionary * dictionary) const;
00068 virtual void loadLastNodesQuery(std::list<Signature *> & signatures) const;
00069 virtual void loadSignaturesQuery(const std::list<int> & ids, std::list<Signature *> & signatures) const;
00070 virtual void loadWordsQuery(const std::set<int> & wordIds, std::list<VisualWord *> & vws) const;
00071 virtual void loadLinksQuery(int signatureId, std::map<int, Link> & links, Link::Type type = Link::kUndef) const;
00072
00073 virtual void loadNodeDataQuery(std::list<Signature *> & signatures, bool loadMetricData) const;
00074 virtual void getNodeDataQuery(
00075 int signatureId,
00076 cv::Mat & imageCompressed,
00077 cv::Mat & depthCompressed,
00078 cv::Mat & laserScanCompressed,
00079 float & fx,
00080 float & fy,
00081 float & cx,
00082 float & cy,
00083 Transform & localTransform,
00084 int & laserScanMaxPts) const;
00085 virtual void getNodeDataQuery(int signatureId, cv::Mat & imageCompressed) const;
00086 virtual bool getNodeInfoQuery(int signatureId, Transform & pose, int & mapId, int & weight, std::string & label, double & stamp, std::vector<unsigned char> & userData) const;
00087 virtual void getAllNodeIdsQuery(std::set<int> & ids, bool ignoreChildren) const;
00088 virtual void getLastIdQuery(const std::string & tableName, int & id) const;
00089 virtual void getInvertedIndexNiQuery(int signatureId, int & ni) const;
00090 virtual void getNodeIdByLabelQuery(const std::string & label, int & id) const;
00091 virtual void getAllLabelsQuery(std::map<int, std::string> & labels) const;
00092
00093 private:
00094 std::string queryStepNode() const;
00095 std::string queryStepImage() const;
00096 std::string queryStepDepth() const;
00097 std::string queryStepLink() const;
00098 std::string queryStepWordsChanged() const;
00099 std::string queryStepKeypoint() const;
00100 void stepNode(sqlite3_stmt * ppStmt, const Signature * s) const;
00101 void stepImage(
00102 sqlite3_stmt * ppStmt,
00103 int id,
00104 const cv::Mat & imageBytes) const;
00105 void stepDepth(
00106 sqlite3_stmt * ppStmt,
00107 int id,
00108 const cv::Mat & depthBytes,
00109 const cv::Mat & depth2dBytes,
00110 float fx,
00111 float fy,
00112 float cx,
00113 float cy,
00114 const Transform & localTransform,
00115 int depth2dMaxPts) const;
00116 void stepLink(sqlite3_stmt * ppStmt, int fromId, int toId, Link::Type type, float rotVariance, float transVariance, const Transform & transform) const;
00117 void stepWordsChanged(sqlite3_stmt * ppStmt, int signatureId, int oldWordId, int newWordId) const;
00118 void stepKeypoint(sqlite3_stmt * ppStmt, int signatureId, int wordId, const cv::KeyPoint & kp, const pcl::PointXYZ & pt) const;
00119
00120 private:
00121 void loadLinksQuery(std::list<Signature *> & signatures) const;
00122 int loadOrSaveDb(sqlite3 *pInMemory, const std::string & fileName, int isSave) const;
00123 bool getVersion(std::string &) const;
00124
00125 private:
00126 sqlite3 * _ppDb;
00127 std::string _version;
00128 bool _dbInMemory;
00129 unsigned int _cacheSize;
00130 int _journalMode;
00131 int _synchronous;
00132 int _tempStore;
00133 };
00134
00135 }
00136
00137 #endif