DBDriverSqlite3.h
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2014, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #ifndef DBDRIVERSQLITE3_H_
00029 #define DBDRIVERSQLITE3_H_
00030 
00031 #include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
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; // In bytes
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         // Load objects
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 /* DBDRIVERSQLITE3_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Fri Aug 28 2015 12:51:31