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)
517 this->
loadQuery(dictionary, lastStateOnly);
529 std::list<Signature *> & signatures,
530 std::set<int> * loadedFromTrash)
534 std::list<int> ids = signIds;
535 bool valueFound =
false;
538 for(std::list<int>::iterator iter = ids.begin(); iter != ids.end();)
543 if(sIter->first == *iter)
545 signatures.push_back(sIter->second);
560 loadedFromTrash->insert(*iter);
562 iter = ids.erase(iter);
583 std::set<int> ids = wordIds;
584 std::map<int, VisualWord*>::iterator wIter;
585 std::list<VisualWord *> puttedBack;
590 for(std::set<int>::iterator iter = ids.begin(); iter != ids.end();)
596 UDEBUG(
"put back word %d from trash", *iter);
597 puttedBack.push_back(wIter->second);
616 else if(puttedBack.size())
622 void DBDriver::loadNodeData(std::list<Signature *> & signatures,
bool images,
bool scan,
bool userData,
bool occupancyGrid)
const 629 for(std::list<Signature *>::iterator iter=signatures.begin(); iter!=signatures.end(); ++iter)
645 bool images,
bool scan,
bool userData,
bool occupancyGrid)
const 668 std::list<Signature *> signatures;
670 signatures.push_back(&tmp);
672 data = signatures.front()->sensorData();
679 std::vector<CameraModel> & models,
689 stereoModel =
_trashSignatures.at(signatureId)->sensorData().stereoCameraModel();
713 info =
_trashSignatures.at(signatureId)->sensorData().laserScanCompressed();
735 std::vector<float> & velocity,
757 found = this->
getNodeInfoQuery(signatureId, pose, mapId, weight, label, stamp, groundTruthPose, velocity, gps);
772 for(std::map<int, Link>::const_iterator nIter = s->
getLinks().begin();
776 if(type ==
Link::kUndef || nIter->second.type() == type)
778 links.insert(*nIter);
821 bool hasNeighbors = !ignoreChildren;
824 for(std::map<int, Link>::const_iterator nIter = sIter->second->getLinks().begin();
825 nIter!=sIter->second->getLinks().end();
838 ids.insert(sIter->first);
864 links.erase(iter->first);
865 for(std::map<int, Link>::const_iterator jter=iter->second->getLinks().begin();
866 jter!=iter->second->getLinks().end();
869 if(!ignoreNullLinks || jter->second.isValid())
871 links.insert(std::make_pair(iter->first, jter->second));
891 int statisticsId = 0;
895 if(statisticsId >
id)
947 if(sIter->second->getLabel().compare(label) == 0)
949 idFound = sIter->first;
969 UWARN(
"Can't search with an empty label!");
979 if(!sIter->second->getLabel().empty())
981 labels.insert(std::make_pair(sIter->first, sIter->second->getLabel()));
1003 std::stringstream query;
1009 query <<
"INSERT INTO Info(STM_size,last_sign_added,process_mem_used,database_mem_used,dictionary_size,parameters) values(" 1011 << lastSignAdded <<
"," 1012 << processMemUsed <<
"," 1013 << databaseMemUsed <<
"," 1014 << dictionarySize <<
"," 1015 "\"" << param.c_str() <<
"\");";
1019 query <<
"INSERT INTO Statistics(STM_size,last_sign_added,process_mem_used,database_mem_used,dictionary_size,parameters) values(" 1021 << lastSignAdded <<
"," 1022 << processMemUsed <<
"," 1023 << databaseMemUsed <<
"," 1024 << dictionarySize <<
"," 1025 "\"" << param.c_str() <<
"\");";
1030 query <<
"INSERT INTO Statistics(STM_size,last_sign_added,process_mem_used,database_mem_used,dictionary_size) values(" 1032 << lastSignAdded <<
"," 1033 << processMemUsed <<
"," 1034 << databaseMemUsed <<
"," 1035 << dictionarySize <<
");";
1094 const cv::Mat & cloud,
1095 const std::vector<std::vector<std::vector<unsigned int> > > & polygons,
1096 #
if PCL_VERSION_COMPARE(>=, 1, 8, 0)
1097 const std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > & texCoords,
1099 const std::vector<std::vector<Eigen::Vector2f> > & texCoords,
1101 const cv::Mat & textures)
const 1109 std::vector<std::vector<std::vector<unsigned int> > > * polygons,
1110 #
if PCL_VERSION_COMPARE(>=, 1, 8, 0)
1111 std::vector<std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > > * texCoords,
1113 std::vector<std::vector<Eigen::Vector2f> > * texCoords,
1115 cv::Mat * textures)
const 1124 const std::string & fileName,
1125 const std::set<int> & idsInput,
1126 const std::map<int, Signature *> & otherSignatures)
1130 if(!fileName.empty())
1134 fopen_s(&fout, fileName.c_str(),
"w");
1136 fout = fopen(fileName.c_str(),
"w");
1141 UERROR(
"Cannot open file %s!", fileName.c_str());
1146 if(idsInput.size() == 0)
1149 UDEBUG(
"ids.size()=%d", ids.size());
1150 for(std::map<int, Signature*>::const_iterator iter=otherSignatures.begin(); iter!=otherSignatures.end(); ++iter)
1152 ids.insert(iter->first);
1160 const char * colorG =
"green";
1161 const char * colorP =
"pink";
1162 const char * colorNM =
"blue";
1163 UINFO(
"Generating map with %d locations", ids.size());
1164 fprintf(fout,
"digraph G {\n");
1165 for(std::set<int>::iterator i=ids.begin(); i!=ids.end(); ++i)
1167 if(otherSignatures.find(*i) == otherSignatures.end())
1170 std::map<int, Link> links;
1174 for(std::map<int, Link>::iterator iter = links.begin(); iter!=links.end(); ++iter)
1176 int weightNeighbor = 0;
1177 if(otherSignatures.find(iter->first) == otherSignatures.end())
1179 this->
getWeight(iter->first, weightNeighbor);
1183 weightNeighbor = otherSignatures.find(iter->first)->second->getWeight();
1188 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\"\n",
1197 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"M\", fontcolor=%s, fontsize=8];\n",
1204 else if(iter->first >
id)
1207 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"L\", fontcolor=%s, fontsize=8];\n",
1217 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"C\", fontcolor=%s, fontsize=8];\n",
1227 for(std::map<int, Signature*>::const_iterator i=otherSignatures.begin(); i!=otherSignatures.end(); ++i)
1229 if(ids.find(i->first) != ids.end())
1231 int id = i->second->id();
1232 const std::map<int, Link> & links = i->second->getLinks();
1233 int weight = i->second->getWeight();
1234 for(std::map<int, Link>::const_iterator iter = links.begin(); iter!=links.end(); ++iter)
1236 int weightNeighbor = 0;
1244 this->
getWeight(iter->first, weightNeighbor);
1249 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\"\n",
1257 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"M\", fontcolor=%s, fontsize=8];\n",
1264 else if(iter->first >
id)
1267 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"L\", fontcolor=%s, fontsize=8];\n",
1274 else if(iter->first !=
id)
1277 fprintf(fout,
" \"%d\\n%d\" -> \"%d\\n%d\" [label=\"C\", fontcolor=%s, fontsize=8];\n",
1287 fprintf(fout,
"}\n");
1289 UINFO(
"Graph saved to \"%s\" (Tip: $ neato -Tpdf \"%s\" -o out.pdf)", fileName.c_str(), fileName.c_str());
UMutex _dbSafeAccessMutex
virtual void addLinkQuery(const Link &link) const =0
void getLastNodeId(int &id) const
cv::Mat loadPreviewImage() const
virtual void getLastIdQuery(const std::string &tableName, int &id) const =0
virtual void addStatisticsQuery(const Statistics &statistics) const =0
cv::Mat loadOptimizedMesh(std::vector< std::vector< std::vector< unsigned int > > > *polygons=0, std::vector< std::vector< Eigen::Vector2f > > *texCoords=0, cv::Mat *textures=0) const
void asyncSave(Signature *s)
virtual bool getDatabaseVersionQuery(std::string &version) const =0
virtual void loadNodeDataQuery(std::list< Signature * > &signatures, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const =0
long getFeaturesMemoryUsed() const
long getGridsMemoryUsed() const
void setOccupancyGrid(const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty, float cellSize, const cv::Point3f &viewPoint)
long getImagesMemoryUsed() const
std::map< int, Signature * > _trashSignatures
virtual void getAllNodeIdsQuery(std::set< int > &ids, bool ignoreChildren, bool ignoreBadSignatures) const =0
void saveOptimizedPoses(const std::map< int, Transform > &optimizedPoses, const Transform &lastlocalizationPose) const
virtual void savePreviewImageQuery(const cv::Mat &image) const =0
std::vector< K > uKeys(const std::multimap< K, V > &mm)
long getUserDataMemoryUsed() const
void addInfoAfterRun(int stMemSize, int lastSignAdded, int processMemUsed, int databaseMemUsed, int dictionarySize, const ParametersMap ¶meters) const
const LaserScan & laserScanCompressed() const
void executeNoResult(const std::string &sql) const
void beginTransaction() const
virtual cv::Mat load2DMapQuery(float &xMin, float &yMin, float &cellSize) const =0
void loadLinks(int signatureId, std::map< int, Link > &links, Link::Type type=Link::kUndef) const
virtual void updateQuery(const std::list< Signature * > &signatures, bool updateTimestamp) const =0
virtual bool isConnectedQuery() const =0
int uStrNumCmp(const std::string &a, const std::string &b)
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
void getAllNodeIds(std::set< int > &ids, bool ignoreChildren=false, bool ignoreBadSignatures=false) const
virtual std::map< int, Transform > loadOptimizedPosesQuery(Transform *lastlocalizationPose) const =0
void getAllLinks(std::multimap< int, Link > &links, bool ignoreNullLinks=true) const
long getWordsMemoryUsed() const
virtual void getAllLabelsQuery(std::map< int, std::string > &labels) const =0
void getNodeData(int signatureId, SensorData &data, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const
std::map< std::string, std::string > ParametersMap
virtual long getNodesMemoryUsedQuery() const =0
void loadWords(const std::set< int > &wordIds, std::list< VisualWord * > &vws)
float gridCellSize() const
Basic mathematics functions.
void load(VWDictionary *dictionary, bool lastStateOnly=true) const
const cv::Mat & gridObstacleCellsCompressed() const
Some conversion functions.
virtual void loadLastNodesQuery(std::list< Signature * > &signatures) const =0
const cv::Mat & gridGroundCellsCompressed() const
bool getNodeInfo(int signatureId, Transform &pose, int &mapId, int &weight, std::string &label, double &stamp, Transform &groundTruthPose, std::vector< float > &velocity, GPS &gps) const
const cv::Mat & gridEmptyCellsCompressed() const
virtual int getTotalNodesSizeQuery() 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 * >())
virtual void executeNoResultQuery(const std::string &sql) const =0
virtual void saveOptimizedMeshQuery(const cv::Mat &cloud, const std::vector< std::vector< std::vector< unsigned int > > > &polygons, const std::vector< std::vector< Eigen::Vector2f > > &texCoords, const cv::Mat &textures) const =0
void getAllLabels(std::map< int, std::string > &labels) const
std::map< std::string, float > getStatistics(int nodeId, double &stamp, std::vector< int > *wmState=0) const
virtual void saveQuery(const std::list< Signature * > &signatures)=0
virtual void getAllLinksQuery(std::multimap< int, Link > &links, bool ignoreNullLinks) const =0
std::map< int, std::vector< int > > getAllStatisticsWmStates() const
void getNodeIdByLabel(const std::string &label, int &id) const
bool openConnection(const std::string &url, bool overwritten=false)
virtual long getImagesMemoryUsedQuery() const =0
#define UASSERT(condition)
virtual void loadSignaturesQuery(const std::list< int > &ids, std::list< Signature * > &signatures) const =0
Wrappers of STL for convenient functions.
void getWeight(int signatureId, int &weight) const
virtual void getInvertedIndexNiQuery(int signatureId, int &ni) const =0
virtual cv::Mat loadOptimizedMeshQuery(std::vector< std::vector< std::vector< unsigned int > > > *polygons, std::vector< std::vector< Eigen::Vector2f > > *texCoords, cv::Mat *textures) const =0
bool getLaserScanInfo(int signatureId, LaserScan &info) const
virtual long getLinksMemoryUsedQuery() const =0
virtual void loadLinksQuery(int signatureId, std::map< int, Link > &links, Link::Type type=Link::kUndef) const =0
virtual int getTotalDictionarySizeQuery() const =0
static std::string serialize(const ParametersMap ¶meters)
std::map< int, Transform > loadOptimizedPoses(Transform *lastlocalizationPose) const
#define ULOGGER_DEBUG(...)
virtual long getCalibrationsMemoryUsedQuery() const =0
virtual ParametersMap getLastParametersQuery() const =0
virtual bool getCalibrationQuery(int signatureId, std::vector< CameraModel > &models, StereoCameraModel &stereoModel) const =0
virtual void save2DMapQuery(const cv::Mat &map, float xMin, float yMin, float cellSize) const =0
#define UASSERT_MSG(condition, msg_str)
long getLaserScansMemoryUsed() const
void closeConnection(bool save=true, const std::string &outputUrl="")
void loadSignatures(const std::list< int > &ids, std::list< Signature * > &signatures, std::set< int > *loadedFromTrash=0)
std::map< int, std::pair< std::map< std::string, float >, double > > getAllStatistics() const
cv::Mat load2DMap(float &xMin, float &yMin, float &cellSize) const
virtual long getStatisticsMemoryUsedQuery() const =0
bool getCalibration(int signatureId, std::vector< CameraModel > &models, StereoCameraModel &stereoModel) const
int getLastDictionarySize() 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)
long getStatisticsMemoryUsed() const
long getMemoryUsed() const
long getCalibrationsMemoryUsed() const
void loadNodeData(std::list< Signature * > &signatures, bool images=true, bool scan=true, bool userData=true, bool occupancyGrid=true) const
virtual long getGridsMemoryUsedQuery() const =0
void saveOptimizedMesh(const cv::Mat &cloud, const std::vector< std::vector< std::vector< unsigned int > > > &polygons=std::vector< std::vector< std::vector< unsigned int > > >(), const std::vector< std::vector< Eigen::Vector2f > > &texCoords=std::vector< std::vector< Eigen::Vector2f > >(), const cv::Mat &textures=cv::Mat()) const
void updateDepthImage(int nodeId, const cv::Mat &image)
virtual long getDepthImagesMemoryUsedQuery() const =0
virtual std::map< int, std::vector< int > > getAllStatisticsWmStatesQuery() const =0
long getDepthImagesMemoryUsed() const
virtual bool getNodeInfoQuery(int signatureId, Transform &pose, int &mapId, int &weight, std::string &label, double &stamp, Transform &groundTruthPose, std::vector< float > &velocity, GPS &gps) const =0
void addStatistics(const Statistics &statistics) const
bool uContains(const std::list< V > &list, const V &value)
int getTotalNodesSize() const
virtual long getWordsMemoryUsedQuery() const =0
static DBDriver * create(const ParametersMap ¶meters=ParametersMap())
virtual long getLaserScansMemoryUsedQuery() const =0
const cv::Mat & userDataCompressed() const
virtual void disconnectDatabaseQuery(bool save=true, const std::string &outputUrl="")=0
const std::map< int, Link > & getLinks() const
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
SensorData & sensorData()
DBDriver(const ParametersMap ¶meters=ParametersMap())
void savePreviewImage(const cv::Mat &image) const
void updateOccupancyGrid(int nodeId, const cv::Mat &ground, const cv::Mat &obstacles, const cv::Mat &empty, float cellSize, const cv::Point3f &viewpoint)
ParametersMap getLastParameters() const
ULogger class and convenient macros.
int getTotalDictionarySize() const
const cv::Mat & imageCompressed() const
std::string getDatabaseVersion() const
virtual void updateLinkQuery(const Link &link) const =0
virtual void loadWordsQuery(const std::set< int > &wordIds, std::list< VisualWord * > &vws) const =0
void loadLastNodes(std::list< Signature * > &signatures) const
virtual void updateDepthImageQuery(int nodeId, const cv::Mat &image) const =0
void uAppend(std::list< V > &list, const std::list< V > &newItems)
virtual void loadQuery(VWDictionary *dictionary, bool lastStateOnly=true) const =0
virtual int getLastNodesSizeQuery() const =0
void join(bool killFirst=false)
virtual long getFeaturesMemoryUsedQuery() const =0
virtual bool connectDatabaseQuery(const std::string &url, bool overwritten=false)=0
void addLink(const Link &link)
void getInvertedIndexNi(int signatureId, int &ni) const
void save2DMap(const cv::Mat &map, float xMin, float yMin, float cellSize) const
void removeLink(int from, int to)
std::string UTILITE_EXP uFormat(const char *fmt,...)
virtual int getLastDictionarySizeQuery() const =0
virtual cv::Mat loadPreviewImageQuery() const =0
long getLinksMemoryUsed() const
void getLastWordId(int &id) const
virtual void parseParameters(const ParametersMap ¶meters)
virtual long getMemoryUsedQuery() const =0
int getLastNodesSize() 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)
void saveOrUpdate(const std::vector< Signature * > &signatures)
long getNodesMemoryUsed() const
virtual void saveOptimizedPosesQuery(const std::map< int, Transform > &optimizedPoses, const Transform &lastlocalizationPose) const =0