36 #include "DatabaseSchema_sql.h"
37 #include "DatabaseSchema_0_18_3_sql.h"
38 #include "DatabaseSchema_0_18_0_sql.h"
39 #include "DatabaseSchema_0_17_0_sql.h"
40 #include "DatabaseSchema_0_16_2_sql.h"
41 #include "DatabaseSchema_0_16_1_sql.h"
42 #include "DatabaseSchema_0_16_0_sql.h"
55 _memoryUsedEstimate(0),
56 _dbInMemory(
Parameters::defaultDbSqlite3InMemory()),
57 _cacheSize(
Parameters::defaultDbSqlite3CacheSize()),
58 _journalMode(
Parameters::defaultDbSqlite3JournalMode()),
59 _synchronous(
Parameters::defaultDbSqlite3Synchronous()),
60 _tempStore(
Parameters::defaultDbSqlite3TempStore())
73 ParametersMap::const_iterator
iter;
74 if((
iter=parameters.find(Parameters::kDbSqlite3CacheSize())) != parameters.end())
78 if((
iter=parameters.find(Parameters::kDbSqlite3JournalMode())) != parameters.end())
82 if((
iter=parameters.find(Parameters::kDbSqlite3Synchronous())) != parameters.end())
86 if((
iter=parameters.find(Parameters::kDbSqlite3TempStore())) != parameters.end())
90 if((
iter=parameters.find(Parameters::kDbSqlite3InMemory())) != parameters.end())
102 std::string query =
"PRAGMA cache_size = ";
110 if(journalMode >= 0 && journalMode < 5)
144 if(synchronous >= 0 && synchronous < 3)
172 if(tempStore >= 0 && tempStore < 3)
200 UDEBUG(
"dbInMemory=%d", dbInMemory?1:0);
254 pFrom = (isSave ? pInMemory : pFile);
255 pTo = (isSave ? pFile : pInMemory);
292 std::stringstream query;
294 query <<
"SELECT version FROM Admin;";
329 bool dbFileExist =
false;
333 if(dbFileExist && overwritten)
335 UINFO(
"Deleting database %s...",
url.c_str());
359 ULOGGER_INFO(
"Using database \"%s\" from the hard drive.",
url.c_str());
364 UFATAL(
"DB error : %s (path=\"%s\"). Make sure that your user has write "
365 "permission on the target directory (you may have to change the working directory). ",
sqlite3_errmsg(
_ppDb),
url.c_str());
390 ULOGGER_INFO(
"Database \"%s\" doesn't exist, creating a new one...",
url.c_str());
393 std::string schema = DATABASESCHEMA_SQL;
395 if(!targetVersion.empty())
398 std::vector<std::pair<std::string, std::string> > schemas;
399 schemas.push_back(std::make_pair(
"0.16.0", DATABASESCHEMA_0_16_0_SQL));
400 schemas.push_back(std::make_pair(
"0.16.1", DATABASESCHEMA_0_16_1_SQL));
401 schemas.push_back(std::make_pair(
"0.16.2", DATABASESCHEMA_0_16_2_SQL));
402 schemas.push_back(std::make_pair(
"0.17.0", DATABASESCHEMA_0_17_0_SQL));
403 schemas.push_back(std::make_pair(
"0.18.0", DATABASESCHEMA_0_18_0_SQL));
404 schemas.push_back(std::make_pair(
"0.18.3", DATABASESCHEMA_0_18_3_SQL));
405 schemas.push_back(std::make_pair(
uNumber2Str(RTABMAP_VERSION_MAJOR)+
"."+
uNumber2Str(RTABMAP_VERSION_MINOR), DATABASESCHEMA_SQL));
406 for(
size_t i=0;
i<schemas.size(); ++
i)
412 UERROR(
"Cannot create database with target version \"%s\" (not implemented), using latest version.", targetVersion.c_str());
418 schema = schemas[
i].second;
432 UERROR(
"Opened database version (%s) is more recent than rtabmap "
433 "installed version (%s). Please update rtabmap to new version!",
469 if(!outputUrl.empty())
475 UWARN(
"Database was initialized with an empty url (in memory). To save it, "
476 "the output url should not be empty. The database is thus closed without being saved!");
493 if(
save && !
_dbInMemory && !outputUrl.empty() && !
this->getUrl().empty() && outputUrl.compare(
this->getUrl()) != 0)
495 UWARN(
"Output database path (%s) is different than the opened database "
496 "path (%s). Opened database path is overwritten then renamed to output path.",
497 outputUrl.c_str(),
this->getUrl().c_str());
500 UERROR(
"Failed to rename just closed db %s to %s", this->
getUrl().
c_str(), outputUrl.c_str());
547 query =
"SELECT sum(length(id) + length(map_id) + length(weight) + length(pose) + length(stamp) + ifnull(length(label),0) + length(ground_truth_pose) + ifnull(length(velocity),0) + ifnull(length(gps),0) + ifnull(length(env_sensors),0) + length(time_enter)) from Node;";
551 query =
"SELECT sum(length(id) + length(map_id) + length(weight) + length(pose) + length(stamp) + ifnull(length(label),0) + length(ground_truth_pose) + ifnull(length(velocity),0) + ifnull(length(gps),0) + length(time_enter)) from Node;";
555 query =
"SELECT sum(length(id) + length(map_id) + length(weight) + length(pose) + length(stamp) + ifnull(length(label),0) + length(ground_truth_pose) + ifnull(length(velocity),0) + length(time_enter)) from Node;";
559 query =
"SELECT sum(length(id) + length(map_id) + length(weight) + length(pose) + length(stamp) + ifnull(length(label),0) + length(ground_truth_pose)+ length(time_enter)) from Node;";
563 query =
"SELECT sum(length(id) + length(map_id) + length(weight) + length(pose) + length(stamp) + ifnull(length(label),0) + length(time_enter)) from Node;";
567 query =
"SELECT sum(length(id) + length(map_id) + length(weight) + length(pose)+ length(time_enter)) from Node;";
595 query =
"SELECT sum(length(type) + length(information_matrix) + length(transform) + ifnull(length(user_data),0) + length(from_id) + length(to_id)) from Link;";
599 query =
"SELECT sum(length(type) + length(rot_variance) + length(trans_variance) + length(transform) + ifnull(length(user_data),0) + length(from_id) + length(to_id)) from Link;";
603 query =
"SELECT sum(length(type) + length(rot_variance) + length(trans_variance) + length(transform) + length(from_id) + length(to_id)) from Link;";
607 query =
"SELECT sum(length(type) + length(variance) + length(transform) + length(from_id) + length(to_id)) from Link;";
611 query =
"SELECT sum(length(type) + length(transform) + length(from_id) + length(to_id)) from Link;";
639 query =
"SELECT sum(ifnull(length(image),0) + ifnull(length(time_enter),0)) from Data;";
643 query =
"SELECT sum(length(data) + ifnull(length(time_enter),0)) from Image;";
671 query =
"SELECT sum(ifnull(length(depth),0) + ifnull(length(time_enter),0)) from Data;";
675 query =
"SELECT sum(length(data) + ifnull(length(time_enter),0)) from Depth;";
704 query =
"SELECT sum(length(calibration)) from Data;";
708 query =
"SELECT sum(length(fx) + length(fy) + length(cx) + length(cy) + length(local_transform)) from Depth;";
712 query =
"SELECT sum(length(constant) + length(local_transform)) from Depth;";
741 query =
"SELECT sum(ifnull(length(ground_cells),0) + ifnull(length(obstacle_cells),0) + ifnull(length(empty_cells),0) + length(cell_size) + length(view_point_x) + length(view_point_y) + length(view_point_z)) from Data;";
745 query =
"SELECT sum(ifnull(length(ground_cells),0) + ifnull(length(obstacle_cells),0) + length(cell_size) + length(view_point_x) + length(view_point_y) + length(view_point_z)) from Data;";
778 query =
"SELECT sum(ifnull(length(scan_info),0) + ifnull(length(scan),0)) from Data;";
782 query =
"SELECT sum(length(scan_max_pts) + length(scan_max_range) + ifnull(length(scan),0)) from Data;";
786 query =
"SELECT sum(length(scan_max_pts) + ifnull(length(scan),0)) from Data;";
790 query =
"SELECT sum(length(data2d) + length(data2d_max_pts)) from Depth;";
794 query =
"SELECT sum(length(data2d)) from Depth;";
822 query =
"SELECT sum(length(user_data)) from Data;";
826 query =
"SELECT sum(length(user_data)) from Node;";
855 std::string query =
"SELECT sum(length(id) + length(descriptor_size) + length(descriptor) + length(time_enter)) from Word;";
882 query =
"SELECT sum(length(node_id) + length(word_id) + length(pos_x) + length(pos_y) + length(size) + length(dir) + length(response) + length(octave) + ifnull(length(depth_x),0) + ifnull(length(depth_y),0) + ifnull(length(depth_z),0) + ifnull(length(descriptor_size),0) + ifnull(length(descriptor),0)) "
887 query =
"SELECT sum(length(node_id) + length(word_id) + length(pos_x) + length(pos_y) + length(size) + length(dir) + length(response) + length(octave) + ifnull(length(depth_x),0) + ifnull(length(depth_y),0) + ifnull(length(depth_z),0) + ifnull(length(descriptor_size),0) + ifnull(length(descriptor),0)) "
888 "FROM Map_Node_Word";
892 query =
"SELECT sum(length(node_id) + length(word_id) + length(pos_x) + length(pos_y) + length(size) + length(dir) + length(response) + ifnull(length(depth_x),0) + ifnull(length(depth_y),0) + ifnull(length(depth_z),0) + ifnull(length(descriptor_size),0) + ifnull(length(descriptor),0)) "
893 "FROM Map_Node_Word";
897 query =
"SELECT sum(length(node_id) + length(word_id) + length(pos_x) + length(pos_y) + length(size) + length(dir) + length(response) + ifnull(length(depth_x),0) + ifnull(length(depth_y),0) + ifnull(length(depth_z),0) "
898 "FROM Map_Node_Word";
926 query =
"SELECT sum(length(id) + length(stamp) + ifnull(length(data),0) + ifnull(length(wm_state),0)) FROM Statistics;";
930 query =
"SELECT sum(length(id) + length(stamp) + length(data)) FROM Statistics;";
962 query =
"SELECT count(id) from Node WHERE time_enter >= (SELECT MAX(time_enter) FROM Info);";
966 query =
"SELECT count(id) from Node WHERE time_enter >= (SELECT MAX(time_enter) FROM Statistics);";
994 query =
"SELECT count(id) from Word WHERE time_enter >= (SELECT MAX(time_enter) FROM Info);";
998 query =
"SELECT count(id) from Word WHERE time_enter >= (SELECT MAX(time_enter) FROM Statistics);";
1023 std::string query =
"SELECT count(id) from Node;";
1047 std::string query =
"SELECT count(id) from Word;";
1077 query =
"SELECT parameters "
1079 "WHERE time_enter >= (SELECT MAX(time_enter) FROM Info);";
1083 query =
"SELECT parameters "
1085 "WHERE time_enter >= (SELECT MAX(time_enter) FROM Statistics);";
1114 UDEBUG(
"nodeId=%d", nodeId);
1115 std::map<std::string, float>
data;
1120 std::stringstream query;
1124 query <<
"SELECT stamp, data, wm_state "
1125 <<
"FROM Statistics "
1126 <<
"WHERE id=" << nodeId <<
";";
1130 query <<
"SELECT stamp, data "
1131 <<
"FROM Statistics "
1132 <<
"WHERE id=" << nodeId <<
";";
1150 if(dataSize>0 && dataPtr)
1169 if(dataSize>0 && dataPtr)
1171 cv::Mat wmStateMat =
uncompressData(cv::Mat(1, dataSize, CV_8UC1, (
void *)dataPtr));
1172 UASSERT(wmStateMat.type() == CV_32SC1 && wmStateMat.rows == 1);
1173 wmState->resize(wmStateMat.cols);
1174 memcpy(wmState->data(), wmStateMat.data, wmState->size()*
sizeof(
int));
1191 std::map<int, std::pair<std::map<std::string, float>,
double> >
data;
1196 std::stringstream query;
1198 query <<
"SELECT id, stamp, data "
1199 <<
"FROM Statistics;";
1215 const void * dataPtr = 0;
1219 if(dataSize>0 && dataPtr)
1248 std::map<int, std::vector<int> >
data;
1253 std::stringstream query;
1255 query <<
"SELECT id, wm_state "
1256 <<
"FROM Statistics;";
1268 std::vector<int> wmState;
1271 if(dataSize>0 && dataPtr)
1273 cv::Mat wmStateMat =
uncompressData(cv::Mat(1, dataSize, CV_8UC1, (
void *)dataPtr));
1274 UASSERT(wmStateMat.type() == CV_32SC1 && wmStateMat.rows == 1);
1275 wmState.resize(wmStateMat.cols);
1276 memcpy(wmState.data(), wmStateMat.data, wmState.size()*
sizeof(
int));
1279 if(!wmState.empty())
1281 data.insert(std::make_pair(
id, wmState));
1297 UDEBUG(
"load data for %d signatures images=%d scan=%d userData=%d, grid=%d",
1298 (
int)signatures.size(), images?1:0, scan?1:0, userData?1:0, occupancyGrid?1:0);
1300 if(!images && !scan && !userData && !occupancyGrid)
1302 UWARN(
"All requested data fields are false! Nothing loaded...");
1312 std::stringstream query;
1316 std::stringstream fields;
1320 fields <<
"image, depth, calibration";
1321 if(scan || userData || occupancyGrid)
1328 fields <<
"scan_info, scan";
1329 if(userData || occupancyGrid)
1336 fields <<
"user_data";
1346 fields <<
"ground_cells, obstacle_cells, empty_cells, cell_size, view_point_x, view_point_y, view_point_z";
1350 fields <<
"ground_cells, obstacle_cells, cell_size, view_point_x, view_point_y, view_point_z";
1354 query <<
"SELECT " << fields.str().c_str() <<
" "
1361 query <<
"SELECT image, depth, calibration, scan_max_pts, scan_max_range, scan, user_data "
1368 query <<
"SELECT image, depth, calibration, scan_max_pts, scan, user_data "
1375 query <<
"SELECT Data.image, Data.depth, Data.calibration, Data.scan_max_pts, Data.scan, Node.user_data "
1377 <<
"INNER JOIN Node "
1378 <<
"ON Data.id = Node.id "
1379 <<
"WHERE Data.id = ?"
1384 query <<
"SELECT Image.data, "
1385 "Depth.data, Depth.local_transform, Depth.fx, Depth.fy, Depth.cx, Depth.cy, Depth.data2d_max_pts, Depth.data2d, Node.user_data "
1387 <<
"INNER JOIN Node "
1388 <<
"on Image.id = Node.id "
1389 <<
"LEFT OUTER JOIN Depth "
1390 <<
"ON Image.id = Depth.id "
1391 <<
"WHERE Image.id = ?"
1396 query <<
"SELECT Image.data, "
1397 "Depth.data, Depth.local_transform, Depth.fx, Depth.fy, Depth.cx, Depth.cy, Depth.data2d, Node.user_data "
1399 <<
"INNER JOIN Node "
1400 <<
"on Image.id = Node.id "
1401 <<
"LEFT OUTER JOIN Depth "
1402 <<
"ON Image.id = Depth.id "
1403 <<
"WHERE Image.id = ?"
1408 query <<
"SELECT Image.data, "
1409 "Depth.data, Depth.local_transform, Depth.fx, Depth.fy, Depth.cx, Depth.cy, Depth.data2d "
1411 <<
"LEFT OUTER JOIN Depth "
1412 <<
"ON Image.id = Depth.id "
1413 <<
"WHERE Image.id = ?"
1418 query <<
"SELECT Image.data, "
1419 "Depth.data, Depth.local_transform, Depth.constant, Depth.data2d "
1421 <<
"LEFT OUTER JOIN Depth "
1422 <<
"ON Image.id = Depth.id "
1423 <<
"WHERE Image.id = ?"
1430 const void *
data = 0;
1434 for(std::list<Signature*>::iterator
iter = signatures.begin();
iter!=signatures.end(); ++
iter)
1449 cv::Mat imageCompressed;
1450 cv::Mat depthOrRightCompressed;
1451 std::vector<CameraModel> models;
1452 std::vector<StereoCameraModel> stereoModels;
1454 cv::Mat scanCompressed;
1455 cv::Mat userDataCompressed;
1462 if(dataSize>4 &&
data)
1464 imageCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
1470 if(dataSize>4 &&
data)
1472 depthOrRightCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
1479 if((
unsigned int)dataSize == localTransform.
size()*
sizeof(
float) &&
data)
1481 memcpy(localTransform.
data(),
data, dataSize);
1496 if(dataSize > 0 &&
data)
1500 if(dataSize >=
int(
sizeof(
int)*4))
1502 const int * dataInt = (
const int *)
data;
1503 int type = dataInt[3];
1507 int bytesReadTotal = 0;
1508 unsigned int bytesRead = 0;
1509 while(bytesReadTotal < dataSize &&
1510 (bytesRead=
model.deserialize((
const unsigned char *)
data+bytesReadTotal, dataSize-bytesReadTotal))!=0)
1512 bytesReadTotal+=bytesRead;
1513 models.push_back(
model);
1515 UASSERT(bytesReadTotal == dataSize);
1520 int bytesReadTotal = 0;
1521 unsigned int bytesRead = 0;
1522 while(bytesReadTotal < dataSize &&
1523 (bytesRead=
model.deserialize((
const unsigned char *)
data+bytesReadTotal, dataSize-bytesReadTotal))!=0)
1525 bytesReadTotal+=bytesRead;
1526 stereoModels.push_back(
model);
1528 UASSERT(bytesReadTotal == dataSize);
1537 UFATAL(
"Wrong format of the Data.calibration field (size=%d bytes)", dataSize);
1542 float * dataFloat = (
float*)
data;
1544 (
unsigned int)dataSize % (6+localTransform.
size())*
sizeof(
float) == 0)
1546 int cameraCount = dataSize / ((6+localTransform.
size())*
sizeof(
float));
1547 UDEBUG(
"Loading calibration for %d cameras (%d bytes)", cameraCount, dataSize);
1548 int max = cameraCount*(6+localTransform.
size());
1549 for(
int i=0;
i<
max;
i+=6+localTransform.
size())
1553 memcpy(localTransform.
data(), dataFloat+
i+6, localTransform.
size()*
sizeof(
float));
1559 (
double)dataFloat[
i],
1560 (
double)dataFloat[
i+1],
1561 (
double)dataFloat[
i+2],
1562 (
double)dataFloat[
i+3],
1564 models.back().setImageSize(cv::Size(dataFloat[
i+4], dataFloat[
i+5]));
1565 UDEBUG(
"%f %f %f %f %f %f %s", dataFloat[
i], dataFloat[
i+1], dataFloat[
i+2],
1566 dataFloat[
i+3], dataFloat[
i+4], dataFloat[
i+5],
1571 (
unsigned int)dataSize % (4+localTransform.
size())*
sizeof(
float) == 0)
1573 int cameraCount = dataSize / ((4+localTransform.
size())*
sizeof(
float));
1574 UDEBUG(
"Loading calibration for %d cameras (%d bytes)", cameraCount, dataSize);
1575 int max = cameraCount*(4+localTransform.
size());
1576 for(
int i=0;
i<
max;
i+=4+localTransform.
size())
1580 memcpy(localTransform.
data(), dataFloat+
i+4, localTransform.
size()*
sizeof(
float));
1586 (
double)dataFloat[
i],
1587 (
double)dataFloat[
i+1],
1588 (
double)dataFloat[
i+2],
1589 (
double)dataFloat[
i+3],
1593 else if((
unsigned int)dataSize == (7+localTransform.
size())*
sizeof(
float))
1595 UDEBUG(
"Loading calibration of a stereo camera");
1596 memcpy(localTransform.
data(), dataFloat+7, localTransform.
size()*
sizeof(
float));
1608 cv::Size(dataFloat[5],dataFloat[6])));
1610 else if((
unsigned int)dataSize == (5+localTransform.
size())*
sizeof(
float))
1612 UDEBUG(
"Loading calibration of a stereo camera");
1613 memcpy(localTransform.
data(), dataFloat+5, localTransform.
size()*
sizeof(
float));
1628 UFATAL(
"Wrong format of the Data.calibration field (size=%d bytes)", dataSize);
1636 UDEBUG(
"Loading calibration version >= 0.7.0");
1641 if(fyOrBaseline < 1.0)
1653 UDEBUG(
"Loading calibration version < 0.7.0");
1655 float fx = 1.0f/depthConstant;
1656 float fy = 1.0f/depthConstant;
1663 int laserScanMaxPts = 0;
1664 float laserScanMinRange = 0.0f;
1665 float laserScanMaxRange = 0.0f;
1666 int laserScanFormat = 0;
1667 float laserScanAngleMin = 0.0f;
1668 float laserScanAngleMax = 0.0f;
1669 float laserScanAngleInc = 0.0f;
1679 if(dataSize > 0 &&
data)
1681 float * dataFloat = (
float*)
data;
1685 UASSERT(dataSize == (
int)((scanLocalTransform.
size()+7)*
sizeof(
float)));
1686 laserScanFormat = (
int)dataFloat[0];
1687 laserScanMinRange = dataFloat[1];
1688 laserScanMaxRange = dataFloat[2];
1689 laserScanAngleMin = dataFloat[3];
1690 laserScanAngleMax = dataFloat[4];
1691 laserScanAngleInc = dataFloat[5];
1692 laserScanMaxPts = (
int)dataFloat[6];
1693 memcpy(scanLocalTransform.
data(), dataFloat+7, scanLocalTransform.
size()*
sizeof(
float));
1697 if(
uStrNumCmp(
_version,
"0.16.1") >= 0 && dataSize == (
int)((scanLocalTransform.
size()+3)*
sizeof(
float)))
1700 laserScanFormat = (
int)dataFloat[2];
1701 memcpy(scanLocalTransform.
data(), dataFloat+3, scanLocalTransform.
size()*
sizeof(
float));
1703 else if(dataSize == (
int)((scanLocalTransform.
size()+2)*
sizeof(
float)))
1705 memcpy(scanLocalTransform.
data(), dataFloat+2, scanLocalTransform.
size()*
sizeof(
float));
1709 UFATAL(
"Unexpected size %d for laser scan info!", dataSize);
1716 laserScanMaxPts = (
int)dataFloat[0];
1717 laserScanMaxRange = dataFloat[1];
1737 if(dataSize>4 &&
data)
1739 scanCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
1750 if(dataSize>4 &&
data)
1754 userDataCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
1759 userDataCompressed =
compressData2(cv::Mat(1, dataSize, CV_8SC1, (
void *)
data));
1766 cv::Mat groundCellsCompressed;
1767 cv::Mat obstacleCellsCompressed;
1768 cv::Mat emptyCellsCompressed;
1769 float cellSize = 0.0f;
1770 cv::Point3f viewPoint;
1776 if(dataSize > 0 &&
data)
1778 groundCellsCompressed = cv::Mat(1, dataSize, CV_8UC1);
1779 memcpy((
void*)groundCellsCompressed.data,
data, dataSize);
1785 if(dataSize > 0 &&
data)
1787 obstacleCellsCompressed = cv::Mat(1, dataSize, CV_8UC1);
1788 memcpy((
void*)obstacleCellsCompressed.data,
data, dataSize);
1796 if(dataSize > 0 &&
data)
1798 emptyCellsCompressed = cv::Mat(1, dataSize, CV_8UC1);
1799 memcpy((
void*)emptyCellsCompressed.data,
data, dataSize);
1812 if(laserScanAngleMin < laserScanAngleMax && laserScanAngleInc != 0.0
f)
1814 laserScan =
LaserScan(scanCompressed, (
LaserScan::Format)laserScanFormat, laserScanMinRange, laserScanMaxRange, laserScanAngleMin, laserScanAngleMax, laserScanAngleInc, scanLocalTransform);
1818 laserScan =
LaserScan(scanCompressed, laserScanMaxPts, laserScanMaxRange, (
LaserScan::Format)laserScanFormat, scanLocalTransform);
1820 (*iter)->sensorData().setLaserScan(laserScan);
1826 (*iter)->sensorData().setRGBDImage(imageCompressed, depthOrRightCompressed, models);
1830 (*iter)->sensorData().setStereoImage(imageCompressed, depthOrRightCompressed, stereoModels);
1835 (*iter)->sensorData().setUserData(userDataCompressed);
1840 (*iter)->sensorData().setOccupancyGrid(groundCellsCompressed, obstacleCellsCompressed, emptyCellsCompressed, cellSize, viewPoint);
1861 std::vector<CameraModel> & models,
1862 std::vector<StereoCameraModel> & stereoModels)
const
1865 if(
_ppDb && signatureId)
1869 std::stringstream query;
1873 query <<
"SELECT calibration "
1875 <<
"WHERE id = " << signatureId
1880 query <<
"SELECT local_transform, fx, fy, cx, cy "
1882 <<
"WHERE id = " << signatureId
1887 query <<
"SELECT local_transform, constant "
1889 <<
"WHERE id = " << signatureId
1896 const void *
data = 0;
1912 if((
unsigned int)dataSize == localTransform.
size()*
sizeof(
float) &&
data)
1914 memcpy(localTransform.
data(),
data, dataSize);
1925 if(dataSize > 0 &&
data)
1929 if(dataSize >=
int(
sizeof(
int)*4))
1931 const int * dataInt = (
const int *)
data;
1932 int type = dataInt[3];
1936 int bytesReadTotal = 0;
1937 unsigned int bytesRead = 0;
1938 while(bytesReadTotal < dataSize &&
1939 (bytesRead=
model.deserialize((
const unsigned char *)
data+bytesReadTotal, dataSize-bytesReadTotal))!=0)
1941 bytesReadTotal+=bytesRead;
1942 models.push_back(
model);
1944 UASSERT(bytesReadTotal == dataSize);
1949 int bytesReadTotal = 0;
1950 unsigned int bytesRead = 0;
1951 while(bytesReadTotal < dataSize &&
1952 (bytesRead=
model.deserialize((
const unsigned char *)
data+bytesReadTotal, dataSize-bytesReadTotal))!=0)
1954 bytesReadTotal+=bytesRead;
1955 stereoModels.push_back(
model);
1957 UASSERT(bytesReadTotal == dataSize);
1966 UFATAL(
"Wrong format of the Data.calibration field (size=%d bytes)", dataSize);
1971 float * dataFloat = (
float*)
data;
1973 (
unsigned int)dataSize % (6+localTransform.
size())*
sizeof(
float) == 0)
1975 int cameraCount = dataSize / ((6+localTransform.
size())*
sizeof(
float));
1976 UDEBUG(
"Loading calibration for %d cameras (%d bytes)", cameraCount, dataSize);
1977 int max = cameraCount*(6+localTransform.
size());
1978 for(
int i=0;
i<
max;
i+=6+localTransform.
size())
1982 memcpy(localTransform.
data(), dataFloat+
i+6, localTransform.
size()*
sizeof(
float));
1988 (
double)dataFloat[
i],
1989 (
double)dataFloat[
i+1],
1990 (
double)dataFloat[
i+2],
1991 (
double)dataFloat[
i+3],
1993 models.back().setImageSize(cv::Size(dataFloat[
i+4], dataFloat[
i+5]));
1994 UDEBUG(
"%f %f %f %f %f %f %s", dataFloat[
i], dataFloat[
i+1], dataFloat[
i+2],
1995 dataFloat[
i+3], dataFloat[
i+4], dataFloat[
i+5],
2000 (
unsigned int)dataSize % (4+localTransform.
size())*
sizeof(
float) == 0)
2002 int cameraCount = dataSize / ((4+localTransform.
size())*
sizeof(
float));
2003 UDEBUG(
"Loading calibration for %d cameras (%d bytes)", cameraCount, dataSize);
2004 int max = cameraCount*(4+localTransform.
size());
2005 for(
int i=0;
i<
max;
i+=4+localTransform.
size())
2009 memcpy(localTransform.
data(), dataFloat+
i+4, localTransform.
size()*
sizeof(
float));
2015 (
double)dataFloat[
i],
2016 (
double)dataFloat[
i+1],
2017 (
double)dataFloat[
i+2],
2018 (
double)dataFloat[
i+3],
2022 else if((
unsigned int)dataSize == (7+localTransform.
size())*
sizeof(
float))
2024 UDEBUG(
"Loading calibration of a stereo camera");
2025 memcpy(localTransform.
data(), dataFloat+7, localTransform.
size()*
sizeof(
float));
2037 cv::Size(dataFloat[5],dataFloat[6])));
2039 else if((
unsigned int)dataSize == (5+localTransform.
size())*
sizeof(
float))
2041 UDEBUG(
"Loading calibration of a stereo camera");
2042 memcpy(localTransform.
data(), dataFloat+5, localTransform.
size()*
sizeof(
float));
2057 UFATAL(
"Wrong format of the Data.calibration field (size=%d bytes)", dataSize);
2065 UDEBUG(
"Loading calibration version >= 0.7.0");
2070 UDEBUG(
"fx=%f fyOrBaseline=%f cx=%f cy=%f",
fx, fyOrBaseline,
cx,
cy);
2071 if(fyOrBaseline < 1.0)
2083 UDEBUG(
"Loading calibration version < 0.7.0");
2085 float fx = 1.0f/depthConstant;
2086 float fy = 1.0f/depthConstant;
2108 if(
_ppDb && signatureId)
2112 std::stringstream query;
2116 query <<
"SELECT scan_info "
2118 <<
"WHERE id = " << signatureId
2129 const void *
data = 0;
2134 float minRange = 0.0f;
2135 float maxRange = 0.0f;
2136 float angleMin = 0.0f;
2137 float angleMax = 0.0f;
2138 float angleInc = 0.0f;
2151 if(dataSize > 0 &&
data)
2153 float * dataFloat = (
float*)
data;
2156 UASSERT(dataSize == (
int)((localTransform.
size()+7)*
sizeof(
float)));
2158 minRange = dataFloat[1];
2159 maxRange = dataFloat[2];
2160 angleMin = dataFloat[3];
2161 angleMax = dataFloat[4];
2162 angleInc = dataFloat[5];
2163 maxPts = (
int)dataFloat[6];
2164 memcpy(localTransform.
data(), dataFloat+7, localTransform.
size()*
sizeof(
float));
2172 memcpy(localTransform.
data(), dataFloat+3, localTransform.
size()*
sizeof(
float));
2174 else if(dataSize == (
int)((localTransform.
size()+2)*
sizeof(
float)))
2176 memcpy(localTransform.
data(), dataFloat+2, localTransform.
size()*
sizeof(
float));
2180 UFATAL(
"Unexpected size %d for laser scan info!", dataSize);
2186 maxPts = (
int)dataFloat[0];
2187 maxRange = dataFloat[1];
2190 if(angleInc != 0.0
f && angleMin < angleMax)
2215 std::string & label,
2218 std::vector<float> & velocity,
2223 if(
_ppDb && signatureId)
2227 std::stringstream query;
2231 query <<
"SELECT pose, map_id, weight, label, stamp, ground_truth_pose, velocity, gps, env_sensors "
2233 "WHERE id = " << signatureId <<
2238 query <<
"SELECT pose, map_id, weight, label, stamp, ground_truth_pose, velocity, gps "
2240 "WHERE id = " << signatureId <<
2245 query <<
"SELECT pose, map_id, weight, label, stamp, ground_truth_pose, velocity "
2247 "WHERE id = " << signatureId <<
2252 query <<
"SELECT pose, map_id, weight, label, stamp, ground_truth_pose "
2254 "WHERE id = " << signatureId <<
2259 query <<
"SELECT pose, map_id, weight, label, stamp "
2261 "WHERE id = " << signatureId <<
2266 query <<
"SELECT pose, map_id, weight "
2268 "WHERE id = " << signatureId <<
2275 const void *
data = 0;
2286 if((
unsigned int)dataSize == pose.
size()*
sizeof(
float) &&
data)
2288 memcpy(pose.
data(),
data, dataSize);
2303 label =
reinterpret_cast<const char*
>(
p);
2311 if((
unsigned int)dataSize == groundTruthPose.
size()*
sizeof(
float) &&
data)
2313 memcpy(groundTruthPose.
data(),
data, dataSize);
2325 if((
unsigned int)dataSize ==
velocity.size()*
sizeof(
float) &&
data)
2335 if((
unsigned int)dataSize == 6*
sizeof(
double) &&
data)
2337 const double * dataDouble = (
const double *)
data;
2338 gps =
GPS(dataDouble[0], dataDouble[1], dataDouble[2], dataDouble[3], dataDouble[4], dataDouble[5]);
2347 UASSERT(dataSize%
sizeof(
double)==0 && (dataSize/
sizeof(
double))%3 == 0);
2348 const double * dataDouble = (
const double *)
data;
2349 int sensorsNum = (dataSize/
sizeof(double))/3;
2350 for(
int i=0;
i<sensorsNum;++
i)
2353 sensors.insert(std::make_pair(
type,
EnvSensor(
type, dataDouble[
i*3+1], dataDouble[
i*3+2])));
2384 query =
"SELECT n.id "
2386 "WHERE n.time_enter >= (SELECT MAX(time_enter) FROM Info) "
2391 query =
"SELECT n.id "
2393 "WHERE n.time_enter >= (SELECT MAX(time_enter) FROM Statistics) "
2424 std::stringstream query;
2426 query <<
"SELECT DISTINCT id "
2430 query <<
"INNER JOIN Link ";
2431 query <<
"ON id = to_id ";
2432 query <<
"WHERE from_id != to_id ";
2433 query <<
"AND weight>-9 ";
2434 if(ignoreIntermediateNodes)
2436 query <<
"AND weight!=-1 ";
2439 else if(ignoreIntermediateNodes)
2441 query <<
"WHERE weight!=-1 ";
2444 if(ignoreBadSignatures)
2446 if(ignoreChildren || ignoreIntermediateNodes)
2456 query <<
" id in (select node_id from Feature) ";
2460 query <<
" id in (select node_id from Map_Node_Word) ";
2464 query <<
"ORDER BY id";
2495 std::stringstream query;
2499 query <<
"SELECT from_id, to_id, type, transform, information_matrix, user_data FROM Link WHERE type!=" <<
Link::kLandmark <<
" ORDER BY from_id, to_id";
2503 query <<
"SELECT from_id, to_id, type, transform, information_matrix, user_data FROM Link ORDER BY from_id, to_id";
2507 query <<
"SELECT from_id, to_id, type, transform, rot_variance, trans_variance, user_data FROM Link ORDER BY from_id, to_id";
2511 query <<
"SELECT from_id, to_id, type, transform, rot_variance, trans_variance FROM Link ORDER BY from_id, to_id";
2515 query <<
"SELECT from_id, to_id, type, transform, variance FROM Link ORDER BY from_id, to_id";
2519 query <<
"SELECT from_id, to_id, type, transform FROM Link ORDER BY from_id, to_id";
2528 const void *
data = 0;
2545 if((
unsigned int)dataSize ==
transform.size()*
sizeof(
float) &&
data)
2555 UERROR(
"Error while loading link transform from %d to %d! Setting to null...", fromId, toId);
2558 if(!ignoreNullLinks || !
transform.isNull())
2560 cv::Mat informationMatrix = cv::Mat::eye(6,6,CV_64FC1);
2568 informationMatrix = cv::Mat(6, 6, CV_64FC1, (
void *)
data).clone();
2574 UASSERT(rotVariance > 0.0 && transVariance>0.0);
2575 informationMatrix.at<
double>(0,0) = 1.0/transVariance;
2576 informationMatrix.at<
double>(1,1) = 1.0/transVariance;
2577 informationMatrix.at<
double>(2,2) = 1.0/transVariance;
2578 informationMatrix.at<
double>(3,3) = 1.0/rotVariance;
2579 informationMatrix.at<
double>(4,4) = 1.0/rotVariance;
2580 informationMatrix.at<
double>(5,5) = 1.0/rotVariance;
2583 cv::Mat userDataCompressed;
2589 if(dataSize>4 &&
data)
2591 userDataCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
2595 links.insert(links.end(), std::make_pair(fromId,
Link(fromId, toId, (
Link::Type)
type,
transform, informationMatrix, userDataCompressed)));
2601 informationMatrix *= 1.0/variance;
2626 UDEBUG(
"get last %s from table \"%s\"", fieldName.c_str(), tableName.c_str());
2631 std::stringstream query;
2633 query <<
"SELECT COALESCE(MAX(" << fieldName <<
"), " <<
id <<
") "
2634 <<
"FROM " << tableName
2651 UDEBUG(
"No result from the DB for table %s with field %s", tableName.c_str(), fieldName.c_str());
2670 std::stringstream query;
2674 query <<
"SELECT count(word_id) "
2676 <<
"WHERE node_id=" << nodeId <<
";";
2680 query <<
"SELECT count(word_id) "
2681 <<
"FROM Map_Node_Word "
2682 <<
"WHERE node_id=" << nodeId <<
";";
2718 std::stringstream query;
2720 query <<
"SELECT from_id, type, information_matrix, transform, user_data FROM Link WHERE to_id=" << landmarkId <<
"";
2728 std::list<Link> links;
2729 const void *
data = 0;
2740 cv::Mat userDataCompressed;
2741 cv::Mat informationMatrix = cv::Mat::eye(6,6,CV_64FC1);
2746 informationMatrix = cv::Mat(6, 6, CV_64FC1, (
void *)
data).clone();
2751 if(dataSize>4 &&
data)
2753 userDataCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
2760 if((
unsigned int)dataSize ==
transform.size()*
sizeof(
float) &&
data)
2766 UERROR(
"Error while loading link transform from %d to %d! Setting to null...", fromId, landmarkId);
2771 nodes.insert(std::make_pair(fromId,
Link(fromId, landmarkId, (
Link::Type)linkType,
transform, informationMatrix, userDataCompressed)));
2775 UFATAL(
"Not supported link type %d ! (fromId=%d, toId=%d)",
2776 linkType, fromId, landmarkId);
2798 std::stringstream query;
2799 query <<
"SELECT id FROM Node WHERE label='" << label <<
"'";
2828 std::stringstream query;
2829 query <<
"SELECT id,label FROM Node WHERE label IS NOT NULL";
2843 std::string label =
reinterpret_cast<const char*
>(
p);
2846 labels.insert(std::make_pair(
id, label));
2869 std::stringstream query;
2871 query <<
"SELECT weight FROM node WHERE id = "
2898 if(
_ppDb && ids.size())
2905 std::stringstream query;
2906 unsigned int loaded = 0;
2911 query <<
"SELECT id, map_id, weight, pose, stamp, label, ground_truth_pose, velocity, gps, env_sensors "
2917 query <<
"SELECT id, map_id, weight, pose, stamp, label, ground_truth_pose, velocity, gps "
2923 query <<
"SELECT id, map_id, weight, pose, stamp, label, ground_truth_pose, velocity "
2929 query <<
"SELECT id, map_id, weight, pose, stamp, label, ground_truth_pose "
2935 query <<
"SELECT id, map_id, weight, pose, stamp, label "
2941 query <<
"SELECT id, map_id, weight, pose "
2949 for(std::list<int>::const_iterator
iter=ids.begin();
iter!=ids.end(); ++
iter)
2963 std::vector<double> gps;
2965 const void *
data = 0;
2980 if((
unsigned int)dataSize == pose.
size()*
sizeof(
float) &&
data)
2982 memcpy(pose.
data(),
data, dataSize);
2995 label =
reinterpret_cast<const char*
>(
p);
3002 if((
unsigned int)dataSize == groundTruthPose.
size()*
sizeof(
float) &&
data)
3004 memcpy(groundTruthPose.
data(),
data, dataSize);
3016 if((
unsigned int)dataSize ==
velocity.size()*
sizeof(
float) &&
data)
3027 if((
unsigned int)dataSize == gps.size()*
sizeof(
double) &&
data)
3029 memcpy(gps.data(),
data, dataSize);
3038 UASSERT(dataSize%
sizeof(
double)==0 && (dataSize/
sizeof(
double))%3 == 0);
3039 const double * dataDouble = (
const double *)
data;
3040 int sensorsNum = (dataSize/
sizeof(double))/3;
3041 for(
int i=0;
i<sensorsNum;++
i)
3044 sensors.insert(std::make_pair(
type,
EnvSensor(
type, dataDouble[
i*3+1], dataDouble[
i*3+2])));
3074 s->sensorData().setGPS(
GPS(gps[0], gps[1], gps[2], gps[3], gps[4], gps[5]));
3076 s->sensorData().setEnvSensors(sensors);
3083 UERROR(
"Signature %d not found in database!", *
iter);
3098 std::stringstream query2;
3101 query2 <<
"SELECT word_id, pos_x, pos_y, size, dir, response, octave, depth_x, depth_y, depth_z, descriptor_size, descriptor "
3103 "WHERE node_id = ? ";
3107 query2 <<
"SELECT word_id, pos_x, pos_y, size, dir, response, octave, depth_x, depth_y, depth_z, descriptor_size, descriptor "
3108 "FROM Map_Node_Word "
3109 "WHERE node_id = ? ";
3113 query2 <<
"SELECT word_id, pos_x, pos_y, size, dir, response, depth_x, depth_y, depth_z, descriptor_size, descriptor "
3114 "FROM Map_Node_Word "
3115 "WHERE node_id = ? ";
3119 query2 <<
"SELECT word_id, pos_x, pos_y, size, dir, response, depth_x, depth_y, depth_z "
3120 "FROM Map_Node_Word "
3121 "WHERE node_id = ? ";
3124 query2 <<
" ORDER BY word_id";
3130 float nanFloat = std::numeric_limits<float>::quiet_NaN ();
3139 int visualWordId = 0;
3140 int descriptorSize = 0;
3144 std::multimap<int, int> visualWords;
3145 std::vector<cv::KeyPoint> visualWordsKpts;
3146 std::vector<cv::Point3f> visualWords3;
3147 cv::Mat descriptors;
3148 bool allWords3NaN =
true;
3149 cv::Point3f depth(0,0,0);
3197 visualWordsKpts.push_back(kpt);
3198 visualWords.insert(visualWords.end(), std::make_pair(visualWordId, visualWordsKpts.size()-1));
3199 visualWords3.push_back(depth);
3203 allWords3NaN =
false;
3212 if(
descriptor && descriptorSize>0 && dRealSize>0)
3215 if(dRealSize == descriptorSize)
3218 d = cv::Mat(1, descriptorSize, CV_8U);
3220 else if(dRealSize/
int(
sizeof(
float)) == descriptorSize)
3223 d = cv::Mat(1, descriptorSize, CV_32F);
3227 UFATAL(
"Saved buffer size (%d bytes) is not the same as descriptor size (%d)", dRealSize, descriptorSize);
3232 descriptors.push_back(
d);
3240 if(visualWords.size()==0)
3242 UDEBUG(
"Empty signature detected! (id=%d)", (*iter)->id());
3248 visualWords3.clear();
3250 (*iter)->setWords(visualWords, visualWordsKpts, visualWords3, descriptors);
3251 ULOGGER_DEBUG(
"Add %d keypoints, %d 3d points and %d descriptors to node %d", (
int)visualWords.size(), allWords3NaN?0:(
int)visualWords3.size(), (
int)descriptors.rows, (*iter)->id());
3270 (*iter)->setModified(
false);
3276 std::stringstream query3;
3277 query3 <<
"SELECT calibration "
3294 const void *
data = 0;
3297 std::vector<CameraModel> models;
3298 std::vector<StereoCameraModel> stereoModels;
3305 if(dataSize > 0 &&
data)
3309 if(dataSize >=
int(
sizeof(
int)*4))
3311 const int * dataInt = (
const int *)
data;
3312 int type = dataInt[3];
3316 int bytesReadTotal = 0;
3317 unsigned int bytesRead = 0;
3318 while(bytesReadTotal < dataSize &&
3319 (bytesRead=
model.deserialize((
const unsigned char *)
data+bytesReadTotal, dataSize-bytesReadTotal))!=0)
3321 bytesReadTotal+=bytesRead;
3322 models.push_back(
model);
3324 UASSERT(bytesReadTotal == dataSize);
3329 int bytesReadTotal = 0;
3330 unsigned int bytesRead = 0;
3331 while(bytesReadTotal < dataSize &&
3332 (bytesRead=
model.deserialize((
const unsigned char *)
data+bytesReadTotal, dataSize-bytesReadTotal))!=0)
3334 bytesReadTotal+=bytesRead;
3335 stereoModels.push_back(
model);
3337 UASSERT(bytesReadTotal == dataSize);
3346 UFATAL(
"Wrong format of the Data.calibration field (size=%d bytes)", dataSize);
3351 float * dataFloat = (
float*)
data;
3353 (
unsigned int)dataSize % (6+localTransform.
size())*
sizeof(
float) == 0)
3355 int cameraCount = dataSize / ((6+localTransform.
size())*
sizeof(
float));
3356 UDEBUG(
"Loading calibration for %d cameras (%d bytes)", cameraCount, dataSize);
3357 int max = cameraCount*(6+localTransform.
size());
3358 for(
int i=0;
i<
max;
i+=6+localTransform.
size())
3362 memcpy(localTransform.
data(), dataFloat+
i+6, localTransform.
size()*
sizeof(
float));
3368 (
double)dataFloat[
i],
3369 (
double)dataFloat[
i+1],
3370 (
double)dataFloat[
i+2],
3371 (
double)dataFloat[
i+3],
3374 cv::Size(dataFloat[
i+4], dataFloat[
i+5])));
3375 UDEBUG(
"%f %f %f %f %f %f %s", dataFloat[
i], dataFloat[
i+1], dataFloat[
i+2],
3376 dataFloat[
i+3], dataFloat[
i+4], dataFloat[
i+5],
3381 (
unsigned int)dataSize % (4+localTransform.
size())*
sizeof(
float) == 0)
3383 int cameraCount = dataSize / ((4+localTransform.
size())*
sizeof(
float));
3384 UDEBUG(
"Loading calibration for %d cameras (%d bytes)", cameraCount, dataSize);
3385 int max = cameraCount*(4+localTransform.
size());
3386 for(
int i=0;
i<
max;
i+=4+localTransform.
size())
3390 memcpy(localTransform.
data(), dataFloat+
i+4, localTransform.
size()*
sizeof(
float));
3396 (
double)dataFloat[
i],
3397 (
double)dataFloat[
i+1],
3398 (
double)dataFloat[
i+2],
3399 (
double)dataFloat[
i+3],
3403 else if((
unsigned int)dataSize == (7+localTransform.
size())*
sizeof(
float))
3405 UDEBUG(
"Loading calibration of a stereo camera");
3406 memcpy(localTransform.
data(), dataFloat+7, localTransform.
size()*
sizeof(
float));
3418 cv::Size(dataFloat[5], dataFloat[6])));
3420 else if((
unsigned int)dataSize == (5+localTransform.
size())*
sizeof(
float))
3422 UDEBUG(
"Loading calibration of a stereo camera");
3423 memcpy(localTransform.
data(), dataFloat+5, localTransform.
size()*
sizeof(
float));
3438 UFATAL(
"Wrong format of the Data.calibration field (size=%d bytes, db version=%s)", dataSize,
_version.c_str());
3442 (*iter)->sensorData().setCameraModels(models);
3443 (*iter)->sensorData().setStereoCameraModels(stereoModels);
3463 std::stringstream query3;
3464 query3 <<
"SELECT type, info, data "
3465 "FROM GlobalDescriptor "
3466 "WHERE node_id = ? ";
3477 std::vector<GlobalDescriptor> globalDescriptors;
3483 const void *
data = 0;
3492 if(dataSize &&
data)
3498 if(dataSize &&
data)
3510 if(!globalDescriptors.empty())
3512 (*iter)->sensorData().setGlobalDescriptors(globalDescriptors);
3513 ULOGGER_DEBUG(
"Add %d global descriptors to node %d", (
int)globalDescriptors.size(), (*iter)->id());
3527 if(ids.size() != loaded)
3529 UERROR(
"Some signatures not found in database");
3549 query =
"SELECT n.id "
3551 "WHERE n.time_enter >= (SELECT MAX(time_enter) FROM Info) "
3556 query =
"SELECT n.id "
3558 "WHERE n.time_enter >= (SELECT MAX(time_enter) FROM Statistics) "
3588 if(
_ppDb && dictionary)
3595 std::stringstream query;
3596 std::list<VisualWord *> visualWords;
3599 query <<
"SELECT id, descriptor_size, descriptor FROM Word ";
3604 query <<
"WHERE time_enter >= (SELECT MAX(time_enter) FROM Info) ";
3608 query <<
"WHERE time_enter >= (SELECT MAX(time_enter) FROM Statistics) ";
3611 query <<
"ORDER BY id;";
3618 int descriptorSize = 0;
3633 if(dRealSize == descriptorSize)
3636 d = cv::Mat(1, descriptorSize, CV_8U);
3638 else if(dRealSize/
int(
sizeof(
float)) == descriptorSize)
3641 d = cv::Mat(1, descriptorSize, CV_32F);
3645 UFATAL(
"Saved buffer size (%d bytes) is not the same as descriptor size (%d)", dRealSize, descriptorSize);
3653 if(++
count % 5000 == 0)
3676 if(
_ppDb && wordIds.size())
3683 std::stringstream query;
3684 std::set<int> loaded;
3687 query <<
"SELECT vw.descriptor_size, vw.descriptor "
3697 unsigned long dRealSizeTotal = 0;
3698 for(std::set<int>::const_iterator
iter=wordIds.begin();
iter!=wordIds.end(); ++
iter)
3714 if(dRealSize == descriptorSize)
3717 d = cv::Mat(1, descriptorSize, CV_8U);
3719 else if(dRealSize/
int(
sizeof(
float)) == descriptorSize)
3722 d = cv::Mat(1, descriptorSize, CV_32F);
3726 UFATAL(
"Saved buffer size (%d bytes) is not the same as descriptor size (%d)", dRealSize, descriptorSize);
3730 dRealSizeTotal+=dRealSize;
3737 loaded.insert(loaded.end(), *
iter);
3752 UDEBUG(
"Time=%fs (%d words, %lu MB)",
timer.ticks(), (
int)vws.size(), dRealSizeTotal/1000000);
3754 if(wordIds.size() != loaded.size())
3756 for(std::set<int>::const_iterator
iter = wordIds.begin();
iter!=wordIds.end(); ++
iter)
3758 if(loaded.find(*
iter) == loaded.end())
3763 UERROR(
"Query (%d) doesn't match loaded words (%d)", wordIds.size(), loaded.size());
3770 std::multimap<int, Link> & links,
3780 std::stringstream query;
3784 query <<
"SELECT to_id, type, transform, information_matrix, user_data FROM Link ";
3788 query <<
"SELECT to_id, type, transform, rot_variance, trans_variance, user_data FROM Link ";
3792 query <<
"SELECT to_id, type, transform, rot_variance, trans_variance FROM Link ";
3796 query <<
"SELECT to_id, type, transform, variance FROM Link ";
3800 query <<
"SELECT to_id, type, transform FROM Link ";
3802 query <<
"WHERE from_id = " << signatureId;
3807 query <<
" AND type = " << typeIn;
3811 query <<
" AND type = 0";
3815 query <<
" AND type > 0";
3823 query <<
" ORDER BY to_id";
3830 const void *
data = 0;
3846 if((
unsigned int)dataSize ==
transform.size()*
sizeof(
float) &&
data)
3856 UERROR(
"Error while loading link transform from %d to %d! Setting to null...", signatureId, toId);
3859 cv::Mat informationMatrix = cv::Mat::eye(6,6,CV_64FC1);
3867 informationMatrix = cv::Mat(6, 6, CV_64FC1, (
void *)
data).clone();
3873 UASSERT(rotVariance > 0.0 && transVariance>0.0);
3874 informationMatrix.at<
double>(0,0) = 1.0/transVariance;
3875 informationMatrix.at<
double>(1,1) = 1.0/transVariance;
3876 informationMatrix.at<
double>(2,2) = 1.0/transVariance;
3877 informationMatrix.at<
double>(3,3) = 1.0/rotVariance;
3878 informationMatrix.at<
double>(4,4) = 1.0/rotVariance;
3879 informationMatrix.at<
double>(5,5) = 1.0/rotVariance;
3882 cv::Mat userDataCompressed;
3888 if(dataSize>4 &&
data)
3890 userDataCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
3894 links.insert(links.end(), std::make_pair(toId,
Link(signatureId, toId, (
Link::Type)
type,
transform, informationMatrix, userDataCompressed)));
3900 informationMatrix *= 1.0/variance;
3918 if(links.size() == 0)
3933 std::stringstream query;
3937 query <<
"SELECT to_id, type, information_matrix, user_data, transform FROM Link "
3938 <<
"WHERE from_id = ? "
3939 <<
"ORDER BY to_id";
3943 query <<
"SELECT to_id, type, rot_variance, trans_variance, user_data, transform FROM Link "
3944 <<
"WHERE from_id = ? "
3945 <<
"ORDER BY to_id";
3949 query <<
"SELECT to_id, type, rot_variance, trans_variance, transform FROM Link "
3950 <<
"WHERE from_id = ? "
3951 <<
"ORDER BY to_id";
3955 query <<
"SELECT to_id, type, variance, transform FROM Link "
3956 <<
"WHERE from_id = ? "
3957 <<
"ORDER BY to_id";
3961 query <<
"SELECT to_id, type, transform FROM Link "
3962 <<
"WHERE from_id = ? "
3963 <<
"ORDER BY to_id";
3969 for(std::list<Signature*>::iterator
iter=signatures.begin();
iter!=signatures.end(); ++
iter)
3977 std::list<Link> links;
3978 const void *
data = 0;
3989 cv::Mat userDataCompressed;
3990 cv::Mat informationMatrix = cv::Mat::eye(6,6,CV_64FC1);
3998 informationMatrix = cv::Mat(6, 6, CV_64FC1, (
void *)
data).clone();
4004 UASSERT(rotVariance > 0.0 && transVariance>0.0);
4005 informationMatrix.at<
double>(0,0) = 1.0/transVariance;
4006 informationMatrix.at<
double>(1,1) = 1.0/transVariance;
4007 informationMatrix.at<
double>(2,2) = 1.0/transVariance;
4008 informationMatrix.at<
double>(3,3) = 1.0/rotVariance;
4009 informationMatrix.at<
double>(4,4) = 1.0/rotVariance;
4010 informationMatrix.at<
double>(5,5) = 1.0/rotVariance;
4018 if(dataSize>4 &&
data)
4020 userDataCompressed = cv::Mat(1, dataSize, CV_8UC1, (
void *)
data).clone();
4028 informationMatrix *= 1.0/variance;
4035 if((
unsigned int)dataSize ==
transform.size()*
sizeof(
float) &&
data)
4045 UERROR(
"Error while loading link transform from %d to %d! Setting to null...", (*iter)->id(), toId);
4052 (*iter)->addLandmark(
Link((*iter)->id(), toId, (
Link::Type)linkType,
transform, informationMatrix, userDataCompressed));
4058 links.push_back(
Link((*iter)->id(), toId, (
Link::Type)linkType,
transform, informationMatrix, userDataCompressed));
4068 UFATAL(
"Not supported link type %d ! (fromId=%d, toId=%d)",
4069 linkType, (*iter)->id(), toId);
4077 (*iter)->addLinks(links);
4082 UDEBUG(
"time=%fs, node=%d, links.size=%d",
timer.ticks(), (*iter)->id(), links.size());
4107 query =
"UPDATE Node SET weight=?, label=?, time_enter = DATETIME('NOW') WHERE id=?;";
4111 query =
"UPDATE Node SET weight=?, label=? WHERE id=?;";
4118 query =
"UPDATE Node SET weight=?, time_enter = DATETIME('NOW') WHERE id=?;";
4122 query =
"UPDATE Node SET weight=? WHERE id=?;";
4128 for(std::list<Signature *>::const_iterator
i=
nodes.begin();
i!=
nodes.end(); ++
i)
4139 if(
s->getLabel().empty())
4175 query =
uFormat(
"DELETE FROM Link WHERE from_id=?;");
4179 for(std::list<Signature *>::const_iterator
j=
nodes.begin();
j!=
nodes.end(); ++
j)
4181 if((*j)->isLinksModified())
4201 for(std::list<Signature *>::const_iterator
j=
nodes.begin();
j!=
nodes.end(); ++
j)
4203 if((*j)->isLinksModified())
4206 const std::multimap<int, Link> & links = (*j)->getLinks();
4207 for(std::multimap<int, Link>::const_iterator
i=links.begin();
i!=links.end(); ++
i)
4222 for(std::list<Signature *>::const_iterator
j=
nodes.begin();
j!=
nodes.end(); ++
j)
4224 if((*j)->getWordsChanged().size())
4226 const std::map<int, int> & wordsChanged = (*j)->getWordsChanged();
4227 for(std::map<int, int>::const_iterator
iter=wordsChanged.begin();
iter!=wordsChanged.end(); ++
iter)
4243 if(
_ppDb && words.size() && updateTimestamp)
4252 std::string query =
"UPDATE Word SET time_enter = DATETIME('NOW') WHERE id=?;";
4256 for(std::list<VisualWord *>::const_iterator
i=words.begin();
i!=words.end(); ++
i)
4284 if(
_ppDb && signatures.size())
4297 for(std::list<Signature *>::const_iterator
i=signatures.begin();
i!=signatures.end(); ++
i)
4301 _memoryUsedEstimate -= (*i)->sensorData().imageRaw().empty()?0:(*i)->sensorData().imageRaw().total() * (*i)->sensorData().imageRaw().elemSize();
4302 _memoryUsedEstimate -= (*i)->sensorData().depthOrRightRaw().empty()?0:(*i)->sensorData().depthOrRightRaw().total() * (*i)->sensorData().depthOrRightRaw().elemSize();
4303 _memoryUsedEstimate -= (*i)->sensorData().laserScanRaw().empty()?0:(*i)->sensorData().laserScanRaw().data().total() * (*i)->sensorData().laserScanRaw().data().elemSize();
4317 for(std::list<Signature *>::const_iterator jter=signatures.begin(); jter!=signatures.end(); ++jter)
4320 const std::multimap<int, Link> & links = (*jter)->getLinks();
4321 for(std::multimap<int, Link>::const_iterator
i=links.begin();
i!=links.end(); ++
i)
4328 const std::map<int, Link> & links = (*jter)->getLandmarks();
4329 for(std::map<int, Link>::const_iterator
i=links.begin();
i!=links.end(); ++
i)
4346 float nanFloat = std::numeric_limits<float>::quiet_NaN ();
4347 for(std::list<Signature *>::const_iterator
i=signatures.begin();
i!=signatures.end(); ++
i)
4349 UASSERT((*i)->getWords().size() == (*i)->getWordsKpts().size());
4350 UASSERT((*i)->getWords3().empty() || (*i)->getWords().size() == (*i)->getWords3().size());
4351 UASSERT((*i)->getWordsDescriptors().empty() || (
int)(*i)->getWords().size() == (*i)->getWordsDescriptors().rows);
4353 for(std::multimap<int, int>::const_iterator
w=(*i)->getWords().begin();
w!=(*i)->getWords().end(); ++
w)
4355 cv::Point3f pt(nanFloat,nanFloat,nanFloat);
4356 if(!(*i)->getWords3().empty())
4358 pt = (*i)->getWords3()[
w->second];
4362 if(!(*i)->getWordsDescriptors().empty())
4364 descriptor = (*i)->getWordsDescriptors().row(
w->second);
4382 for(std::list<Signature *>::const_iterator
i=signatures.begin();
i!=signatures.end(); ++
i)
4384 for(
size_t d=0;
d<(*i)->sensorData().globalDescriptors().
size(); ++
d)
4402 UDEBUG(
"Saving %d images", signatures.size());
4404 for(std::list<Signature *>::const_iterator
i=signatures.begin();
i!=signatures.end(); ++
i)
4406 if(!(*i)->sensorData().imageCompressed().empty() ||
4407 !(*i)->sensorData().depthOrRightCompressed().empty() ||
4408 !(*i)->sensorData().laserScanCompressed().isEmpty() ||
4409 !(*i)->sensorData().userDataCompressed().empty() ||
4410 !(*i)->sensorData().cameraModels().empty() ||
4411 !(*i)->sensorData().stereoCameraModels().empty())
4413 UASSERT((*i)->id() == (*i)->sensorData().id());
4429 UDEBUG(
"Saving %d images", signatures.size());
4431 for(std::list<Signature *>::const_iterator
i=signatures.begin();
i!=signatures.end(); ++
i)
4433 if(!(*i)->sensorData().imageCompressed().empty())
4435 stepImage(ppStmt, (*i)->id(), (*i)->sensorData().imageCompressed());
4448 for(std::list<Signature *>::const_iterator
i=signatures.begin();
i!=signatures.end(); ++
i)
4451 if(!(*i)->sensorData().depthOrRightCompressed().empty() || !(*i)->sensorData().laserScanCompressed().isEmpty())
4453 UASSERT((*i)->id() == (*i)->sensorData().id());
4468 UDEBUG(
"visualWords size=%d", words.size());
4481 query = std::string(
"INSERT INTO Word(id, descriptor_size, descriptor) VALUES(?,?,?);");
4484 for(std::list<VisualWord *>::const_iterator
iter=words.begin();
iter!=words.end(); ++
iter)
4494 UASSERT(
w->getDescriptor().type() == CV_32F ||
w->getDescriptor().type() == CV_8U);
4495 if(
w->getDescriptor().type() == CV_32F)
4581 const cv::Mat & ground,
4582 const cv::Mat & obstacles,
4583 const cv::Mat &
empty,
4585 const cv::Point3f & viewpoint)
const
4620 const std::vector<CameraModel> & models,
4621 const std::vector<StereoCameraModel> & stereoModels)
const
4653 const cv::Mat & image)
const
4728 if(param.size() && statistics.
refImageId()>0)
4733 query =
"INSERT INTO Statistics(id, stamp, data, wm_state) values(?,?,?,?);";
4737 query =
"INSERT INTO Statistics(id, stamp, data) values(?,?,?);";
4748 cv::Mat compressedParam;
4761 cv::Mat compressedWmState;
4764 if(saveWmState && !statistics.
wmState().empty())
4806 query =
uFormat(
"UPDATE Admin SET preview_image=? WHERE version='%s';",
_version.c_str());
4811 cv::Mat compressedImage;
4820 if(image.rows == 1 && image.type() == CV_8UC1)
4823 compressedImage = image;
4854 std::stringstream query;
4856 query <<
"SELECT preview_image "
4858 <<
"WHERE version='" <<
_version.c_str()
4869 const void *
data = 0;
4876 if(dataSize>0 &&
data)
4880 UDEBUG(
"Image=%dx%d", image.cols, image.rows);
4897 UDEBUG(
"poses=%d lastlocalizationPose=%s", (
int)poses.size(), lastlocalizationPose.
prettyPrint().c_str());
4907 query =
uFormat(
"UPDATE Admin SET opt_ids=?, opt_poses=?, opt_last_localization=?, time_enter = DATETIME('NOW') WHERE version='%s';",
_version.c_str());
4914 cv::Mat compressedIds;
4915 cv::Mat compressedPoses;
4925 std::vector<int> serializedIds(poses.size());
4926 std::vector<float> serializedPoses(poses.size()*12);
4928 for(std::map<int, Transform>::const_iterator
iter=poses.begin();
iter!=poses.end(); ++
iter)
4930 serializedIds[
i] =
iter->first;
4931 memcpy(serializedPoses.data()+(12*
i),
iter->second.data(), 12*
sizeof(
float));
4935 compressedIds =
compressData2(cv::Mat(1,serializedIds.size(), CV_32SC1, serializedIds.data()));
4936 compressedPoses =
compressData2(cv::Mat(1,serializedPoses.size(), CV_32FC1, serializedPoses.data()));
4944 if(lastlocalizationPose.
isNull())
4971 std::map<int, Transform> poses;
4978 std::stringstream query;
4980 query <<
"SELECT opt_ids, opt_poses, opt_last_localization "
4982 <<
"WHERE version='" <<
_version.c_str()
4993 const void *
data = 0;
4998 cv::Mat serializedIds;
5001 if(dataSize>0 &&
data)
5004 UDEBUG(
"serializedIds=%d", serializedIds.cols);
5009 if(dataSize>0 &&
data)
5011 cv::Mat serializedPoses =
uncompressData(cv::Mat(1, dataSize, CV_8UC1, (
void *)
data));
5012 UDEBUG(
"serializedPoses=%d", serializedPoses.cols);
5014 UASSERT(serializedIds.cols == serializedPoses.cols/12);
5015 UASSERT(serializedPoses.type() == CV_32FC1);
5016 UASSERT(serializedIds.type() == CV_32SC1);
5017 for(
int i=0;
i<serializedIds.cols; ++
i)
5019 Transform t(serializedPoses.at<
float>(
i*12), serializedPoses.at<
float>(
i*12+1), serializedPoses.at<
float>(
i*12+2), serializedPoses.at<
float>(
i*12+3),
5020 serializedPoses.at<
float>(
i*12+4), serializedPoses.at<
float>(
i*12+5), serializedPoses.at<
float>(
i*12+6), serializedPoses.at<
float>(
i*12+7),
5021 serializedPoses.at<
float>(
i*12+8), serializedPoses.at<
float>(
i*12+9), serializedPoses.at<
float>(
i*12+10), serializedPoses.at<
float>(
i*12+11));
5022 poses.insert(std::make_pair(serializedIds.at<
int>(
i),
t));
5023 UDEBUG(
"Optimized pose %d: %s", serializedIds.at<
int>(
i),
t.prettyPrint().c_str());
5029 if(lastlocalizationPose)
5031 if((
unsigned int)dataSize == lastlocalizationPose->
size()*
sizeof(
float) &&
data)
5033 memcpy(lastlocalizationPose->
data(),
data, dataSize);
5063 query =
uFormat(
"UPDATE Admin SET opt_map=?, opt_map_x_min=?, opt_map_y_min=?, opt_map_resolution=?, time_enter = DATETIME('NOW') WHERE version='%s';",
_version.c_str());
5070 cv::Mat compressedMap;
5113 std::stringstream query;
5115 query <<
"SELECT opt_map, opt_map_x_min, opt_map_y_min, opt_map_resolution "
5117 <<
"WHERE version='" <<
_version.c_str()
5128 const void *
data = 0;
5135 if(dataSize>0 &&
data)
5138 UDEBUG(
"map=%d/%d", map.cols, map.rows);
5146 UDEBUG(
"cellSize=%f", cellSize);
5162 const cv::Mat & cloud,
5163 const std::vector<std::vector<std::vector<RTABMAP_PCL_INDEX> > > & polygons,
5164 #
if PCL_VERSION_COMPARE(>=, 1, 8, 0)
5167 const std::vector<std::vector<Eigen::Vector2f> > & texCoords,
5169 const cv::Mat & textures)
const
5181 query =
uFormat(
"UPDATE Admin SET opt_cloud=?, opt_polygons_size=?, opt_polygons=?, opt_tex_coords=?, opt_tex_materials=?, time_enter = DATETIME('NOW') WHERE version='%s';",
_version.c_str());
5188 for(
int i=1;
i<=5; ++
i)
5203 cv::Mat compressedCloud;
5204 if(cloud.rows == 1 && cloud.type() == CV_8UC1)
5207 compressedCloud = cloud;
5211 UDEBUG(
"Cloud points=%d", cloud.cols);
5214 UDEBUG(
"Cloud compressed bytes=%d", compressedCloud.cols);
5219 cv::Mat compressedPolygons;
5220 cv::Mat compressedTexCoords;
5221 cv::Mat compressedTextures;
5223 if(polygons.empty())
5240 std::vector<int> serializedPolygons;
5241 std::vector<float> serializedTexCoords;
5242 int polygonSize = 0;
5243 int totalPolygonIndices = 0;
5244 UASSERT(texCoords.empty() || polygons.size() == texCoords.size());
5245 for(
unsigned int t=0;
t<polygons.size(); ++
t)
5247 UDEBUG(
"t=%d, polygons=%d",
t, (
int)polygons[
t].
size());
5248 unsigned int materialPolygonIndices = 0;
5249 for(
unsigned int p=0;
p<polygons[
t].size(); ++
p)
5251 if(polygonSize == 0)
5254 polygonSize = polygons[
t][
p].size();
5261 materialPolygonIndices += polygons[
t][
p].size();
5263 totalPolygonIndices += materialPolygonIndices;
5265 if(!texCoords.empty())
5267 UASSERT(materialPolygonIndices == texCoords[
t].
size());
5270 UASSERT(totalPolygonIndices>0);
5271 serializedPolygons.resize(totalPolygonIndices+polygons.size());
5272 if(!texCoords.empty())
5274 serializedTexCoords.resize(totalPolygonIndices*2+polygons.size());
5279 for(
unsigned int t=0;
t<polygons.size(); ++
t)
5281 serializedPolygons[oi++] = polygons[
t].size();
5282 if(!texCoords.empty())
5284 serializedTexCoords[ci++] = texCoords[
t].size();
5286 for(
unsigned int p=0;
p<polygons[
t].size(); ++
p)
5288 int texIndex =
p*polygonSize;
5289 for(
unsigned int i=0;
i<polygons[
t][
p].size(); ++
i)
5291 serializedPolygons[oi++] = polygons[
t][
p][
i];
5293 if(!texCoords.empty())
5295 serializedTexCoords[ci++] = texCoords[
t][texIndex+
i][0];
5296 serializedTexCoords[ci++] = texCoords[
t][texIndex+
i][1];
5302 UDEBUG(
"serializedPolygons=%d", (
int)serializedPolygons.size());
5303 compressedPolygons =
compressData2(cv::Mat(1,serializedPolygons.size(), CV_32SC1, serializedPolygons.data()));
5313 if(texCoords.empty())
5324 UDEBUG(
"serializedTexCoords=%d", (
int)serializedTexCoords.size());
5325 compressedTexCoords =
compressData2(cv::Mat(1,serializedTexCoords.size(), CV_32FC1, serializedTexCoords.data()));
5329 UASSERT(!textures.empty() && textures.cols % textures.rows == 0 && textures.cols/textures.rows == (
int)texCoords.size());
5330 if(textures.rows == 1 && textures.type() == CV_8UC1)
5333 compressedTextures = textures;
5358 std::vector<std::vector<std::vector<RTABMAP_PCL_INDEX> > > * polygons,
5359 #
if PCL_VERSION_COMPARE(>=, 1, 8, 0)
5362 std::vector<std::vector<Eigen::Vector2f> > * texCoords,
5364 cv::Mat * textures)
const
5374 std::stringstream query;
5376 query <<
"SELECT opt_cloud, opt_polygons_size, opt_polygons, opt_tex_coords, opt_tex_materials "
5378 <<
"WHERE version='" <<
_version.c_str()
5389 const void *
data = 0;
5396 if(dataSize>0 &&
data)
5400 UDEBUG(
"Cloud=%d points", cloud.cols);
5404 UDEBUG(
"polygonSize=%d", polygonSize);
5409 if(dataSize>0 &&
data)
5414 cv::Mat serializedPolygons =
uncompressData(cv::Mat(1, dataSize, CV_8UC1, (
void *)
data));
5415 UDEBUG(
"serializedPolygons=%d", serializedPolygons.cols);
5416 UASSERT(serializedPolygons.total());
5417 for(
int t=0;
t<serializedPolygons.cols; ++
t)
5419 UASSERT(serializedPolygons.at<
int>(
t) > 0);
5420 std::vector<std::vector<RTABMAP_PCL_INDEX> > materialPolygons(serializedPolygons.at<
int>(
t), std::vector<RTABMAP_PCL_INDEX>(polygonSize));
5422 UASSERT(
t < serializedPolygons.cols);
5423 UDEBUG(
"materialPolygons=%d", (
int)materialPolygons.size());
5424 for(
int p=0;
p<(
int)materialPolygons.size(); ++
p)
5426 for(
int i=0;
i<polygonSize; ++
i)
5428 materialPolygons[
p][
i] = serializedPolygons.at<
int>(
t +
p*polygonSize +
i);
5431 t+=materialPolygons.size()*polygonSize;
5432 polygons->push_back(materialPolygons);
5439 if(dataSize>0 &&
data)
5443 cv::Mat serializedTexCoords =
uncompressData(cv::Mat(1, dataSize, CV_8UC1, (
void *)
data));
5444 UDEBUG(
"serializedTexCoords=%d", serializedTexCoords.cols);
5445 UASSERT(serializedTexCoords.total());
5446 for(
int t=0;
t<serializedTexCoords.cols; ++
t)
5448 UASSERT(
int(serializedTexCoords.at<
float>(
t)) > 0);
5449 #if PCL_VERSION_COMPARE(>=, 1, 8, 0)
5450 std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > materialtexCoords(
int(serializedTexCoords.at<
float>(
t)));
5452 std::vector<Eigen::Vector2f> materialtexCoords(
int(serializedTexCoords.at<
float>(
t)));
5455 UASSERT(
t < serializedTexCoords.cols);
5456 UDEBUG(
"materialtexCoords=%d", (
int)materialtexCoords.size());
5457 for(
int p=0;
p<(
int)materialtexCoords.size(); ++
p)
5459 materialtexCoords[
p][0] = serializedTexCoords.at<
float>(
t +
p*2);
5460 materialtexCoords[
p][1] = serializedTexCoords.at<
float>(
t +
p*2 + 1);
5462 t+=materialtexCoords.size()*2;
5463 texCoords->push_back(materialtexCoords);
5470 if(dataSize>0 &&
data)
5475 UDEBUG(
"textures=%dx%d", textures->cols, textures->rows);
5498 return "INSERT INTO Node(id, map_id, weight, pose, stamp, label, ground_truth_pose, velocity, gps, env_sensors) VALUES(?,?,?,?,?,?,?,?,?,?);";
5502 return "INSERT INTO Node(id, map_id, weight, pose, stamp, label, ground_truth_pose, velocity, gps) VALUES(?,?,?,?,?,?,?,?,?);";
5506 return "INSERT INTO Node(id, map_id, weight, pose, stamp, label, ground_truth_pose, velocity) VALUES(?,?,?,?,?,?,?,?);";
5510 return "INSERT INTO Node(id, map_id, weight, pose, stamp, label, ground_truth_pose) VALUES(?,?,?,?,?,?,?);";
5514 return "INSERT INTO Node(id, map_id, weight, pose, stamp, label) VALUES(?,?,?,?,?,?);";
5518 return "INSERT INTO Node(id, map_id, weight, pose, stamp, label, user_data) VALUES(?,?,?,?,?,?,?);";
5522 return "INSERT INTO Node(id, map_id, weight, pose, stamp, label) VALUES(?,?,?,?,?,?);";
5524 return "INSERT INTO Node(id, map_id, weight, pose) VALUES(?,?,?,?);";
5528 UDEBUG(
"Save node %d",
s->id());
5550 if(
s->getLabel().empty())
5562 std::vector<double> gps;
5563 std::vector<double> envSensors;
5575 if(
s->getVelocity().empty())
5589 if(
s->sensorData().gps().stamp() <= 0.0)
5597 gps[0] =
s->sensorData().gps().stamp();
5598 gps[1] =
s->sensorData().gps().longitude();
5599 gps[2] =
s->sensorData().gps().latitude();
5600 gps[3] =
s->sensorData().gps().altitude();
5601 gps[4] =
s->sensorData().gps().error();
5602 gps[5] =
s->sensorData().gps().bearing();
5609 const EnvSensors & sensors =
s->sensorData().envSensors();
5610 if(sensors.size() == 0)
5618 envSensors.resize(sensors.size()*3,0.0);
5620 for(std::map<EnvSensor::Type, EnvSensor>::const_iterator
iter=sensors.begin();
iter!=sensors.end(); ++
iter,
j+=3)
5622 envSensors[
j] = (double)
iter->second.type();
5623 envSensors[
j+1] =
iter->second.value();
5624 envSensors[
j+2] =
iter->second.stamp();
5635 if(
s->sensorData().userDataCompressed().empty())
5658 return "INSERT INTO Image(id, data) VALUES(?,?);";
5662 const cv::Mat & imageBytes)
const
5665 UDEBUG(
"Save image %d (size=%d)",
id, (
int)imageBytes.cols);
5677 if(!imageBytes.empty())
5700 return "INSERT INTO Depth(id, data, fx, fy, cx, cy, local_transform, data2d, data2d_max_pts) VALUES(?,?,?,?,?,?,?,?,?);";
5704 return "INSERT INTO Depth(id, data, fx, fy, cx, cy, local_transform, data2d) VALUES(?,?,?,?,?,?,?,?);";
5708 return "INSERT INTO Depth(id, data, constant, local_transform, data2d) VALUES(?,?,?,?,?);";
5714 UDEBUG(
"Save depth %d (size=%d) depth2d = %d",
5739 float fx=0, fyOrBaseline=0,
cx=0,
cy=0;
5744 uFormat(
"Database version %s doesn't support multi-camera!",
_version.c_str()).c_str());
5750 localTransform = sensorData.
cameraModels()[0].localTransform();
5755 uFormat(
"Database version %s doesn't support multi-camera!",
_version.c_str()).c_str());
5810 return "UPDATE Data SET calibration=? WHERE id=?;";
5815 const std::vector<CameraModel> & models,
5816 const std::vector<StereoCameraModel> & stereoModels)
const
5827 std::vector<unsigned char> calibrationData;
5828 std::vector<float> calibration;
5831 if(models.size() && models[0].isValidForProjection())
5835 for(
unsigned int i=0;
i<models.size(); ++
i)
5837 UASSERT(models[
i].isValidForProjection());
5838 std::vector<unsigned char>
data = models[
i].serialize();
5840 unsigned int oldSize = calibrationData.size();
5841 calibrationData.resize(calibrationData.size() +
data.size());
5842 memcpy(calibrationData.data()+oldSize,
data.data(),
data.size());
5848 for(
unsigned int i=0;
i<models.size(); ++
i)
5850 UASSERT(models[
i].isValidForProjection());
5851 const Transform & localTransform = models[
i].localTransform();
5852 calibration[
i*(6+localTransform.
size())] = models[
i].
fx();
5853 calibration[
i*(6+localTransform.
size())+1] = models[
i].
fy();
5854 calibration[
i*(6+localTransform.
size())+2] = models[
i].
cx();
5855 calibration[
i*(6+localTransform.
size())+3] = models[
i].
cy();
5856 calibration[
i*(6+localTransform.
size())+4] = models[
i].imageWidth();
5857 calibration[
i*(6+localTransform.
size())+5] = models[
i].imageHeight();
5858 memcpy(calibration.data()+
i*(6+localTransform.
size())+6, localTransform.
data(), localTransform.
size()*
sizeof(
float));
5864 for(
unsigned int i=0;
i<models.size(); ++
i)
5866 UASSERT(models[
i].isValidForProjection());
5867 const Transform & localTransform = models[
i].localTransform();
5868 calibration[
i*(4+localTransform.
size())] = models[
i].
fx();
5869 calibration[
i*(4+localTransform.
size())+1] = models[
i].
fy();
5870 calibration[
i*(4+localTransform.
size())+2] = models[
i].
cx();
5871 calibration[
i*(4+localTransform.
size())+3] = models[
i].
cy();
5872 memcpy(calibration.data()+
i*(4+localTransform.
size())+4, localTransform.
data(), localTransform.
size()*
sizeof(
float));
5876 else if(stereoModels.size() && stereoModels[0].isValidForProjection())
5880 for(
unsigned int i=0;
i<stereoModels.size(); ++
i)
5882 UASSERT(stereoModels[
i].isValidForProjection());
5883 std::vector<unsigned char>
data = stereoModels[
i].serialize();
5885 unsigned int oldSize = calibrationData.size();
5886 calibrationData.resize(calibrationData.size() +
data.size());
5887 memcpy(calibrationData.data()+oldSize,
data.data(),
data.size());
5892 UASSERT_MSG(stereoModels.size()==1,
uFormat(
"Database version (%s) is too old for saving multiple stereo cameras",
_version.c_str()).c_str());
5893 const Transform & localTransform = stereoModels[0].left().localTransform();
5894 calibration.resize(7+localTransform.
size());
5895 calibration[0] = stereoModels[0].left().fx();
5896 calibration[1] = stereoModels[0].left().fy();
5897 calibration[2] = stereoModels[0].left().cx();
5898 calibration[3] = stereoModels[0].left().cy();
5899 calibration[4] = stereoModels[0].baseline();
5900 calibration[5] = stereoModels[0].left().imageWidth();
5901 calibration[6] = stereoModels[0].left().imageHeight();
5902 memcpy(calibration.data()+7, localTransform.
data(), localTransform.
size()*
sizeof(
float));
5906 if(calibrationData.size())
5910 else if(calibration.size())
5936 return "UPDATE Depth SET data=? WHERE id=?;";
5940 return "UPDATE Data SET depth=? WHERE id=?;";
5953 cv::Mat imageCompressed;
5954 if(!image.empty() && (image.type()!=CV_8UC1 || image.rows > 1))
5961 imageCompressed = image;
5963 if(!imageCompressed.empty())
5990 return "UPDATE Data SET scan_info=?, scan=? WHERE id=?;";
5994 return "UPDATE Data SET scan_max_pts=?, scan_max_range=?, scan=? WHERE id=?;";
5998 return "UPDATE Data SET scan_max_pts=? scan=? WHERE id=?;";
6011 std::vector<float> scanInfo;
6024 scanInfo[0] = scan.
format();
6032 memcpy(scanInfo.data()+7, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6039 scanInfo[2] = scan.
format();
6041 memcpy(scanInfo.data()+3, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6050 memcpy(scanInfo.data()+2, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6080 cv::Mat scanCompressed;
6083 scanCompressed = scan.
data();
6089 if(!scanCompressed.empty())
6116 return "INSERT INTO Data(id, image, depth, calibration, scan_info, scan, user_data, ground_cells, obstacle_cells, empty_cells, cell_size, view_point_x, view_point_y, view_point_z) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
6120 return "INSERT INTO Data(id, image, depth, calibration, scan_info, scan, user_data, ground_cells, obstacle_cells, cell_size, view_point_x, view_point_y, view_point_z) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);";
6124 return "INSERT INTO Data(id, image, depth, calibration, scan_max_pts, scan_max_range, scan, user_data) VALUES(?,?,?,?,?,?,?,?);";
6128 return "INSERT INTO Data(id, image, depth, calibration, scan_max_pts, scan, user_data) VALUES(?,?,?,?,?,?,?);";
6132 return "INSERT INTO Data(id, image, depth, calibration, scan_max_pts, scan) VALUES(?,?,?,?,?,?);";
6139 UDEBUG(
"Save sensor data %d (image=%d depth=%d) depth2d = %d",
6179 std::vector<unsigned char> calibrationData;
6180 std::vector<float> calibration;
6192 unsigned int oldSize = calibrationData.size();
6193 calibrationData.resize(calibrationData.size() +
data.size());
6194 memcpy(calibrationData.data()+oldSize,
data.data(),
data.size());
6208 calibration[
i*(6+localTransform.
size())+4] = sensorData.
cameraModels()[
i].imageWidth();
6209 calibration[
i*(6+localTransform.
size())+5] = sensorData.
cameraModels()[
i].imageHeight();
6210 memcpy(calibration.data()+
i*(6+localTransform.
size())+6, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6224 memcpy(calibration.data()+
i*(4+localTransform.
size())+4, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6237 unsigned int oldSize = calibrationData.size();
6238 calibrationData.resize(calibrationData.size() +
data.size());
6239 memcpy(calibrationData.data()+oldSize,
data.data(),
data.size());
6246 calibration.resize(7+localTransform.
size());
6254 memcpy(calibration.data()+7, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6258 if(calibrationData.size())
6262 else if(calibration.size())
6272 std::vector<float> scanInfo;
6293 memcpy(scanInfo.data()+7, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6302 memcpy(scanInfo.data()+3, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6311 memcpy(scanInfo.data()+2, localTransform.
data(), localTransform.
size()*
sizeof(
float));
6432 return "UPDATE Link SET type=?, information_matrix=?, transform=?, user_data=? WHERE from_id=? AND to_id = ?;";
6436 return "UPDATE Link SET type=?, rot_variance=?, trans_variance=?, transform=?, user_data=? WHERE from_id=? AND to_id = ?;";
6440 return "UPDATE Link SET type=?, rot_variance=?, trans_variance=?, transform=? WHERE from_id=? AND to_id = ?;";
6444 return "UPDATE Link SET type=?, variance=?, transform=? WHERE from_id=? AND to_id = ?;";
6448 return "UPDATE Link SET type=?, transform=? WHERE from_id=? AND to_id = ?;";
6456 return "INSERT INTO Link(type, information_matrix, transform, user_data, from_id, to_id) VALUES(?,?,?,?,?,?);";
6460 return "INSERT INTO Link(type, rot_variance, trans_variance, transform, user_data, from_id, to_id) VALUES(?,?,?,?,?,?,?);";
6464 return "INSERT INTO Link(type, rot_variance, trans_variance, transform, from_id, to_id) VALUES(?,?,?,?,?,?);";
6468 return "INSERT INTO Link(type, variance, transform, from_id, to_id) VALUES(?,?,?,?,?);";
6472 return "INSERT INTO Link(type, transform, from_id, to_id) VALUES(?,?,?,?);";
6477 const Link & link)
const
6483 UDEBUG(
"Save link from %d to %d, type=%d", link.
from(), link.
to(), link.
type());
6488 UDEBUG(
"Virtual link ignored....");
6549 return "UPDATE Feature SET word_id = ? WHERE word_id = ? AND node_id = ?;";
6553 return "UPDATE Map_Node_Word SET word_id = ? WHERE word_id = ? AND node_id = ?;";
6582 return "INSERT INTO Feature(node_id, word_id, pos_x, pos_y, size, dir, response, octave, depth_x, depth_y, depth_z, descriptor_size, descriptor) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);";
6586 return "INSERT INTO Map_Node_Word(node_id, word_id, pos_x, pos_y, size, dir, response, octave, depth_x, depth_y, depth_z, descriptor_size, descriptor) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?);";
6590 return "INSERT INTO Map_Node_Word(node_id, word_id, pos_x, pos_y, size, dir, response, depth_x, depth_y, depth_z, descriptor_size, descriptor) VALUES(?,?,?,?,?,?,?,?,?,?,?,?);";
6592 return "INSERT INTO Map_Node_Word(node_id, word_id, pos_x, pos_y, size, dir, response, depth_x, depth_y, depth_z) VALUES(?,?,?,?,?,?,?,?,?,?);";
6597 const cv::KeyPoint & kp,
6598 const cv::Point3f & pt,
6696 return "INSERT INTO GlobalDescriptor(node_id, type, info, data) VALUES(?,?,?,?);";
6719 if(infoBytes.empty())
6731 if(dataBytes.empty())
6753 return "UPDATE Data SET ground_cells=?, obstacle_cells=?, empty_cells=?, cell_size=?, view_point_x=?, view_point_y=?, view_point_z=? WHERE id=?;";
6755 return "UPDATE Data SET ground_cells=?, obstacle_cells=?, cell_size=?, view_point_x=?, view_point_y=?, view_point_z=? WHERE id=?;";
6759 const cv::Mat & ground,
6760 const cv::Mat & obstacles,
6761 const cv::Mat &
empty,
6763 const cv::Point3f & viewpoint)
const
6766 UASSERT(ground.empty() || ground.type() == CV_8UC1);
6767 UASSERT(obstacles.empty() || obstacles.type() == CV_8UC1);
6769 UDEBUG(
"Update occupancy grid %d: ground=%d obstacles=%d empty=%d cell=%f viewpoint=(%f,%f,%f)",
6800 if(obstacles.empty())