250 std::map<std::string, float> statistics;
259 std::map<int, std::pair<std::map<std::string, float>,
double> > statistics;
268 std::map<int, std::vector<int> > wmStates;
277 std::string version =
"0.0.0";
323 std::map<int, Signature*> signatures;
324 std::map<int, VisualWord*> visualWords;
337 if(signatures.size() || visualWords.size())
342 if(signatures.size())
350 for(std::map<int, Signature *>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
357 if(visualWords.size())
365 for(std::map<int, VisualWord *>::iterator iter=visualWords.begin(); iter!=visualWords.end(); ++iter)
367 delete (*iter).second;
410 std::list<Signature *> toSave;
411 std::list<Signature *> toUpdate;
414 for(std::vector<Signature *>::const_iterator i=signatures.begin(); i!=signatures.end();++i)
418 toUpdate.push_back(*i);
422 toSave.push_back(*i);
440 std::list<VisualWord *> toSave;
441 std::list<VisualWord *> toUpdate;
444 for(std::vector<VisualWord *>::const_iterator i=words.begin(); i!=words.end();++i)
448 toUpdate.push_back(*i);
452 toSave.push_back(*i);
485 const cv::Mat & ground,
486 const cv::Mat & obstacles,
487 const cv::Mat & empty,
489 const cv::Point3f & viewpoint)
526 this->
loadQuery(dictionary, lastStateOnly);
541 std::list<Signature*> signatures;
542 std::set<int> loadedFromTrashSet;
544 if(loadedFromTrash && loadedFromTrashSet.size())
546 *loadedFromTrash =
true;
548 if(!signatures.empty())
550 return signatures.front();
555 std::list<Signature *> & signatures,
556 std::set<int> * loadedFromTrash)
560 std::list<int> ids = signIds;
561 bool valueFound =
false;
564 for(std::list<int>::iterator iter = ids.begin(); iter != ids.end();)
569 if(sIter->first == *iter)
571 signatures.push_back(sIter->second);
586 loadedFromTrash->insert(*iter);
588 iter = ids.erase(iter);
609 std::set<int> ids = wordIds;
610 std::map<int, VisualWord*>::iterator wIter;
611 std::list<VisualWord *> puttedBack;
616 for(std::set<int>::iterator iter = ids.begin(); iter != ids.end();)
622 UDEBUG(
"put back word %d from trash", *iter);
623 puttedBack.push_back(wIter->second);
642 else if(puttedBack.size())
650 std::list<Signature *> signatures;
651 signatures.push_back(signature);
652 this->
loadNodeData(signatures, images, scan, userData, occupancyGrid);
655 void DBDriver::loadNodeData(std::list<Signature *> & signatures,
bool images,
bool scan,
bool userData,
bool occupancyGrid)
const 662 for(std::list<Signature *>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
678 bool images,
bool scan,
bool userData,
bool occupancyGrid)
const 695 data.
setRGBDImage(cv::Mat(), cv::Mat(), std::vector<CameraModel>());
717 std::list<Signature *> signatures;
719 signatures.push_back(&tmp);
721 data = signatures.front()->sensorData();
728 std::vector<CameraModel> & models,
729 std::vector<StereoCameraModel> & stereoModels)
const 738 stereoModels =
_trashSignatures.at(signatureId)->sensorData().stereoCameraModels();
762 info =
_trashSignatures.at(signatureId)->sensorData().laserScanCompressed();
784 std::vector<float> & velocity,
798 groundTruthPose =
_trashSignatures.at(signatureId)->getGroundTruthPose().clone();
799 velocity = std::vector<float>(
_trashSignatures.at(signatureId)->getVelocity());
809 found = this->
getNodeInfoQuery(signatureId, pose, mapId, weight, label, stamp, groundTruthPose, velocity, gps, sensors);
824 for(std::map<int, Link>::const_iterator nIter = s->
getLinks().begin();
830 links.insert(*nIter);
876 void DBDriver::getAllNodeIds(std::set<int> & ids,
bool ignoreChildren,
bool ignoreBadSignatures,
bool ignoreIntermediateNodes)
const 884 bool hasNeighbors = !ignoreChildren;
887 for(std::map<int, Link>::const_iterator nIter = sIter->second->getLinks().begin();
888 nIter!=sIter->second->getLinks().end();
899 if(hasNeighbors && (!ignoreIntermediateNodes || sIter->second->getWeight() != -1))
901 ids.insert(sIter->first);
911 this->
getAllNodeIdsQuery(ids, ignoreChildren, ignoreBadSignatures, ignoreIntermediateNodes);
927 links.erase(iter->first);
928 for(std::map<int, Link>::const_iterator jter=iter->second->getLinks().begin();
929 jter!=iter->second->getLinks().end();
932 if(!ignoreNullLinks || jter->second.isValid())
934 links.insert(std::make_pair(iter->first, jter->second));
939 for(std::map<int, Link>::const_iterator jter=iter->second->getLandmarks().begin();
940 jter!=iter->second->getLandmarks().end();
943 if(!ignoreNullLinks || jter->second.isValid())
945 links.insert(std::make_pair(iter->first, jter->second));
966 int statisticsId = 0;
970 if(statisticsId >
id)
1036 std::map<int, Link>::const_iterator kter = sIter->second->getLandmarks().find(landmarkId);
1037 if(kter != sIter->second->getLandmarks().end())
1039 nodes.insert(std::make_pair(sIter->second->id(), kter->second));
1051 UWARN(
"Can't search with an empty label!");
1064 if(sIter->second->getLabel().compare(label) == 0)
1066 idFound = sIter->first;
1086 UWARN(
"Can't search with an empty label!");
1096 if(!sIter->second->getLabel().empty())
1098 labels.insert(std::make_pair(sIter->first, sIter->second->getLabel()));
1113 int databaseMemUsed,
1120 std::stringstream query;
1126 query <<
"INSERT INTO Info(STM_size,last_sign_added,process_mem_used,database_mem_used,dictionary_size,parameters) values(" 1128 << lastSignAdded <<
"," 1129 << processMemUsed <<
"," 1130 << databaseMemUsed <<
"," 1131 << dictionarySize <<
"," 1132 "\"" << param.c_str() <<
"\");";
1136 query <<
"INSERT INTO Statistics(STM_size,last_sign_added,process_mem_used,database_mem_used,dictionary_size,parameters) values(" 1138 << lastSignAdded <<
"," 1139 << processMemUsed <<
"," 1140 << databaseMemUsed <<
"," 1141 << dictionarySize <<
"," 1142 "\"" << param.c_str() <<
"\");";
1147 query <<
"INSERT INTO Statistics(STM_size,last_sign_added,process_mem_used,database_mem_used,dictionary_size) values(" 1149 << lastSignAdded <<
"," 1150 << processMemUsed <<
"," 1151 << databaseMemUsed <<
"," 1152 << dictionarySize <<
");";
1211 const cv::Mat & cloud,
1212 const std::vector<std::vector<std::vector<RTABMAP_PCL_INDEX> > > & polygons,
1213 #
if PCL_VERSION_COMPARE(>=, 1, 8, 0)
1214 const std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > & texCoords,
1216 const std::vector<std::vector<Eigen::Vector2f> > & texCoords,
1218 const cv::Mat & textures)
const 1226 std::vector<std::vector<std::vector<RTABMAP_PCL_INDEX> > > * polygons,
1227 #
if PCL_VERSION_COMPARE(>=, 1, 8, 0)
1228 std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > * texCoords,
1230 std::vector<std::vector<Eigen::Vector2f> > * texCoords,
1232 cv::Mat * textures)
const 1241 const std::string & fileName,
1242 const std::set<int> & idsInput,
1243 const std::map<int, Signature *> & otherSignatures)
1247 if(!fileName.empty())
1251 fopen_s(&fout, fileName.c_str(),
"w");
1253 fout = fopen(fileName.c_str(),
"w");
1258 UERROR(
"Cannot open file %s!", fileName.c_str());
1263 if(idsInput.size() == 0)
1266 UDEBUG(
"ids.size()=%d", ids.size());
1267 for(std::map<int, Signature*>::const_iterator iter=otherSignatures.begin(); iter!=otherSignatures.end(); ++iter)
1269 ids.insert(iter->first);
1277 const char * colorG =
"green";
1278 const char * colorP =
"pink";
1279 const char * colorNM =
"blue";
1280 UINFO(
"Generating map with %d locations", ids.size());
1281 fprintf(fout,
"digraph G {\n");
1282 for(std::set<int>::iterator i=ids.begin(); i!=ids.end(); ++i)
1284 if(otherSignatures.find(*i) == otherSignatures.end())
1287 std::multimap<int, Link> links;
1291 for(std::multimap<int, Link>::iterator iter = links.begin(); iter!=links.end(); ++iter)
1293 int weightNeighbor = 0;
1294 if(otherSignatures.find(iter->first) == otherSignatures.end())
1296 this->
getWeight(iter->first, weightNeighbor);
1300 weightNeighbor = otherSignatures.find(iter->first)->second->getWeight();
1305 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\"\n",
1314 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"M\", fontcolor=%s, fontsize=8];\n",
1321 else if(iter->first >
id)
1324 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"L\", fontcolor=%s, fontsize=8];\n",
1334 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"C\", fontcolor=%s, fontsize=8];\n",
1344 for(std::map<int, Signature*>::const_iterator i=otherSignatures.begin(); i!=otherSignatures.end(); ++i)
1346 if(ids.find(i->first) != ids.end())
1348 int id = i->second->id();
1349 const std::multimap<int, Link> & links = i->second->getLinks();
1350 int weight = i->second->getWeight();
1351 for(std::multimap<int, Link>::const_iterator iter = links.begin(); iter!=links.end(); ++iter)
1353 int weightNeighbor = 0;
1361 this->
getWeight(iter->first, weightNeighbor);
1366 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\"\n",
1374 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"M\", fontcolor=%s, fontsize=8];\n",
1381 else if(iter->first >
id)
1384 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"L\", fontcolor=%s, fontsize=8];\n",
1391 else if(iter->first !=
id)
1394 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"C\", fontcolor=%s, fontsize=8];\n",
1404 fprintf(fout,
"}\n");
1406 UINFO(
"Graph saved to \"%s\" (Tip: $ neato -Tpdf \"%s\" -o out.pdf)", fileName.c_str(), fileName.c_str());
UMutex _dbSafeAccessMutex
std::string _targetVersion
static bool parse(const ParametersMap ¶meters, const std::string &key, bool &value)
std::map< std::string, float > getStatistics(int nodeId, double &stamp, std::vector< int > *wmState=0) const
virtual void loadWordsQuery(const std::set< int > &wordIds, std::list< VisualWord *> &vws) const =0
virtual void addLinkQuery(const Link &link) const =0
virtual void addStatisticsQuery(const Statistics &statistics, bool saveWmState) const =0
long getWordsMemoryUsed() const
void loadLastNodes(std::list< Signature *> &signatures) const
virtual void saveQuery(const std::list< Signature *> &signatures)=0
void getWeight(int signatureId, int &weight) const
const cv::Mat & gridObstacleCellsCompressed() const
void asyncSave(Signature *s)
cv::Mat load2DMap(float &xMin, float &yMin, float &cellSize) const
virtual void loadSignaturesQuery(const std::list< int > &ids, std::list< Signature *> &signatures) const =0
virtual bool getDatabaseVersionQuery(std::string &version) const =0
void getAllLabels(std::map< int, std::string > &labels) const
void save2DMap(const cv::Mat &map, float xMin, float yMin, float cellSize) const
virtual void getAllLinksQuery(std::multimap< int, Link > &links, bool ignoreNullLinks, bool withLandmarks) const =0
void setOccupancyGrid(const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty, float cellSize, const cv::Point3f &viewPoint)
void getLastMapId(int &mapId) const
std::map< int, Signature * > _trashSignatures
virtual void loadLastNodesQuery(std::list< Signature *> &signatures) const =0
void load(VWDictionary *dictionary, bool lastStateOnly=true) const
virtual void savePreviewImageQuery(const cv::Mat &image) const =0
std::vector< K > uKeys(const std::multimap< K, V > &mm)
Signature * loadSignature(int id, bool *loadedFromTrash=0)
void loadWords(const std::set< int > &wordIds, std::list< VisualWord *> &vws)
long getStatisticsMemoryUsed() const
void updateLaserScan(int nodeId, const LaserScan &scan)
void setLaserScan(const LaserScan &laserScan, bool clearPreviousData=true)
const LaserScan & laserScanCompressed() const
virtual cv::Mat load2DMapQuery(float &xMin, float &yMin, float &cellSize) const =0
virtual bool isConnectedQuery() const =0
int uStrNumCmp(const std::string &a, const std::string &b)
void getInvertedIndexNi(int signatureId, int &ni) const
virtual void updateOccupancyGridQuery(int nodeId, const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty, float cellSize, const cv::Point3f &viewpoint) const =0
const cv::Mat & gridGroundCellsCompressed() const
virtual void saveOptimizedMeshQuery(const cv::Mat &cloud, const std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > &polygons, const std::vector< std::vector< Eigen::Vector2f > > &texCoords, const cv::Mat &textures) const =0
unsigned long getMemoryUsed() const
void saveOptimizedMesh(const cv::Mat &cloud, const std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > &polygons=std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > >(), const std::vector< std::vector< Eigen::Vector2f > > &texCoords=std::vector< std::vector< Eigen::Vector2f > >(), const cv::Mat &textures=cv::Mat()) const
void setRGBDImage(const cv::Mat &rgb, const cv::Mat &depth, const CameraModel &model, bool clearPreviousData=true)
virtual void getAllLabelsQuery(std::map< int, std::string > &labels) const =0
long getFeaturesMemoryUsed() const
std::map< std::string, std::string > ParametersMap
virtual long getNodesMemoryUsedQuery() const =0
Basic mathematics functions.
Some conversion functions.
void loadLinks(int signatureId, std::multimap< int, Link > &links, Link::Type type=Link::kUndef) const
virtual void getLastNodeIdsQuery(std::set< int > &ids) const =0
virtual std::map< int, Transform > loadOptimizedPosesQuery(Transform *lastlocalizationPose=0) const =0
void executeNoResult(const std::string &sql) const
virtual int getTotalNodesSizeQuery() const =0
void getNodesObservingLandmark(int landmarkId, std::map< int, Link > &nodes) const
long getNodesMemoryUsed() const
void addInfoAfterRun(int stMemSize, int lastSignAdded, int processMemUsed, int databaseMemUsed, int dictionarySize, const ParametersMap ¶meters) const
virtual void updateQuery(const std::list< Signature *> &signatures, bool updateTimestamp) const =0
void addStatistics(const Statistics &statistics, bool saveWmState) const
void beginTransaction() const
virtual void executeNoResultQuery(const std::string &sql) const =0
void generateGraph(const std::string &fileName, const std::set< int > &ids=std::set< int >(), const std::map< int, Signature *> &otherSignatures=std::map< int, Signature *>())
std::map< int, Transform > loadOptimizedPoses(Transform *lastlocalizationPose=0) const
void saveOptimizedPoses(const std::map< int, Transform > &optimizedPoses, const Transform &lastlocalizationPose) const
float gridCellSize() const
void getLastNodeId(int &id) const
const std::map< int, Link > & getLandmarks() const
bool openConnection(const std::string &url, bool overwritten=false)
void getAllLinks(std::multimap< int, Link > &links, bool ignoreNullLinks=true, bool withLandmarks=false) const
long getLaserScansMemoryUsed() const
void getLastNodeIds(std::set< int > &ids) const
virtual long getImagesMemoryUsedQuery() const =0
#define UASSERT(condition)
Wrappers of STL for convenient functions.
virtual void getInvertedIndexNiQuery(int signatureId, int &ni) const =0
void saveOrUpdate(const std::vector< Signature *> &signatures)
virtual long getLinksMemoryUsedQuery() const =0
int getTotalDictionarySize() const
virtual int getTotalDictionarySizeQuery() const =0
static std::string serialize(const ParametersMap ¶meters)
const std::multimap< int, Link > & getLinks() const
#define ULOGGER_DEBUG(...)
bool getNodeInfo(int signatureId, Transform &pose, int &mapId, int &weight, std::string &label, double &stamp, Transform &groundTruthPose, std::vector< float > &velocity, GPS &gps, EnvSensors &sensors) const
virtual long getCalibrationsMemoryUsedQuery() const =0
virtual ParametersMap getLastParametersQuery() const =0
virtual void save2DMapQuery(const cv::Mat &map, float xMin, float yMin, float cellSize) const =0
#define UASSERT_MSG(condition, msg_str)
void closeConnection(bool save=true, const std::string &outputUrl="")
virtual void getAllNodeIdsQuery(std::set< int > &ids, bool ignoreChildren, bool ignoreBadSignatures, bool ignoreIntermediateNodes) const =0
bool getCalibration(int signatureId, std::vector< CameraModel > &models, std::vector< StereoCameraModel > &stereoModels) const
virtual void updateLaserScanQuery(int nodeId, const LaserScan &scan) const =0
void getAllNodeIds(std::set< int > &ids, bool ignoreChildren=false, bool ignoreBadSignatures=false, bool ignoreIntermediateNodes=false) const
void savePreviewImage(const cv::Mat &image) const
cv::Mat loadPreviewImage() const
virtual long getStatisticsMemoryUsedQuery() const =0
void getNodeData(int signatureId, SensorData &data, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const
long getGridsMemoryUsed() const
virtual std::map< std::string, float > getStatisticsQuery(int nodeId, double &stamp, std::vector< int > *wmState) const =0
virtual bool getLaserScanInfoQuery(int signatureId, LaserScan &info) const =0
void updateLink(const Link &link)
virtual long getGridsMemoryUsedQuery() const =0
virtual void getLastIdQuery(const std::string &tableName, int &id, const std::string &fieldName="id") const =0
void updateDepthImage(int nodeId, const cv::Mat &image)
virtual long getDepthImagesMemoryUsedQuery() const =0
virtual std::map< int, std::vector< int > > getAllStatisticsWmStatesQuery() const =0
bool getLaserScanInfo(int signatureId, LaserScan &info) const
bool uContains(const std::list< V > &list, const V &value)
std::map< int, std::pair< std::map< std::string, float >, double > > getAllStatistics() const
virtual long getWordsMemoryUsedQuery() const =0
static DBDriver * create(const ParametersMap ¶meters=ParametersMap())
long getCalibrationsMemoryUsed() const
void setUserData(const cv::Mat &userData, bool clearPreviousData=true)
virtual void loadNodeDataQuery(std::list< Signature *> &signatures, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const =0
int getLastNodesSize() const
virtual long getLaserScansMemoryUsedQuery() const =0
virtual void disconnectDatabaseQuery(bool save=true, const std::string &outputUrl="")=0
virtual bool getCalibrationQuery(int signatureId, std::vector< CameraModel > &models, std::vector< StereoCameraModel > &stereoModels) const =0
virtual void loadLinksQuery(int signatureId, std::multimap< int, Link > &links, Link::Type type=Link::kUndef) const =0
virtual std::map< int, std::pair< std::map< std::string, float >, double > > getAllStatisticsQuery() const =0
std::vector< V > uValues(const std::multimap< K, V > &mm)
virtual void getWeightQuery(int signatureId, int &weight) const =0
virtual long getUserDataMemoryUsedQuery() const =0
std::map< int, VisualWord * > _trashVisualWords
void getLastWordId(int &id) const
int getTotalNodesSize() const
SensorData & sensorData()
void loadNodeData(Signature *signature, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const
void loadSignatures(const std::list< int > &ids, std::list< Signature *> &signatures, std::set< int > *loadedFromTrash=0)
DBDriver(const ParametersMap ¶meters=ParametersMap())
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 =0
const cv::Mat & userDataCompressed() const
void updateOccupancyGrid(int nodeId, const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty, float cellSize, const cv::Point3f &viewpoint)
ULogger class and convenient macros.
long getDepthImagesMemoryUsed() const
ParametersMap getLastParameters() const
cv::Mat loadOptimizedMesh(std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > *polygons=0, std::vector< std::vector< Eigen::Vector2f > > *texCoords=0, cv::Mat *textures=0) const
virtual void updateLinkQuery(const Link &link) const =0
virtual void updateDepthImageQuery(int nodeId, const cv::Mat &image) const =0
long getImagesMemoryUsed() const
void uAppend(std::list< V > &list, const std::list< V > &newItems)
std::string getDatabaseVersion() const
int getLastDictionarySize() const
void getNodeIdByLabel(const std::string &label, int &id) const
virtual void loadQuery(VWDictionary *dictionary, bool lastStateOnly=true) const =0
std::map< EnvSensor::Type, EnvSensor > EnvSensors
virtual int getLastNodesSizeQuery() const =0
virtual void getNodesObservingLandmarkQuery(int landmarkId, std::map< int, Link > &nodes) const =0
void join(bool killFirst=false)
long getUserDataMemoryUsed() const
virtual long getFeaturesMemoryUsedQuery() const =0
virtual bool connectDatabaseQuery(const std::string &url, bool overwritten=false)=0
virtual unsigned long getMemoryUsedQuery() const =0
void addLink(const Link &link)
const cv::Mat & gridEmptyCellsCompressed() const
virtual cv::Mat loadOptimizedMeshQuery(std::vector< std::vector< std::vector< RTABMAP_PCL_INDEX > > > *polygons, std::vector< std::vector< Eigen::Vector2f > > *texCoords, cv::Mat *textures) const =0
void removeLink(int from, int to)
std::string UTILITE_EXP uFormat(const char *fmt,...)
virtual int getLastDictionarySizeQuery() const =0
long getLinksMemoryUsed() const
virtual cv::Mat loadPreviewImageQuery() const =0
virtual void parseParameters(const ParametersMap ¶meters)
const cv::Mat & imageCompressed() const
V uValue(const std::map< K, V > &m, const K &key, const V &defaultValue=V())
virtual void getNodeIdByLabelQuery(const std::string &label, int &id) const =0
void emptyTrashes(bool async=false)
std::map< int, std::vector< int > > getAllStatisticsWmStates() const
virtual void saveOptimizedPosesQuery(const std::map< int, Transform > &optimizedPoses, const Transform &lastlocalizationPose) const =0