39 #include <pcl/search/kdtree.h> 40 #include <pcl/common/eigen.h> 41 #include <pcl/common/common.h> 42 #include <pcl/common/point_tests.h> 55 const std::string & filePath,
57 const std::map<int, Transform> & poses,
58 const std::multimap<int, Link> & constraints,
59 const std::map<int, double> & stamps,
62 UDEBUG(
"%s", filePath.c_str());
63 std::string tmpPath = filePath;
71 return toro.
saveGraph(tmpPath, poses, constraints);
80 return g2o.
saveGraph(tmpPath, poses, constraints);
89 if(format == 1 || format == 10)
91 if(stamps.size() != poses.size())
93 UERROR(
"When exporting poses to format 1 (RGBD-SLAM), stamps and poses maps should have the same size! stamps=%d psoes=%d",
94 (
int)stamps.size(), (int)poses.size());
101 fopen_s(&fout, tmpPath.c_str(),
"w");
103 fout = fopen(tmpPath.c_str(),
"w");
107 for(std::map<int, Transform>::const_iterator iter=poses.begin(); iter!=poses.end(); ++iter)
109 if(format == 1 || format == 10)
129 fprintf(fout,
"%f %f %f %f %f %f %f %f\n",
130 stamps.at(iter->first),
153 const float * p = (
const float *)pose.
data();
155 fprintf(fout,
"%f", p[0]);
156 for(
int i=1; i<pose.
size(); i++)
158 fprintf(fout,
" %f", p[i]);
171 const std::string & filePath,
173 std::map<int, Transform> & poses,
174 std::multimap<int, Link> * constraints,
175 std::map<int, double> * stamps)
177 UDEBUG(
"%s format=%d", filePath.c_str(), format);
180 std::multimap<int, Link> constraintsTmp;
185 *constraints = constraintsTmp;
193 std::multimap<int, Link> constraintsTmp;
194 UERROR(
"Cannot import from g2o format because it is not yet supported!");
200 file.open(filePath.c_str(), std::ifstream::in);
211 std::getline(file, str);
213 if(str.size() && str.at(str.size()-1) ==
'\r')
215 str = str.substr(0, str.size()-1);
218 if(str.empty() || str.at(0) ==
'#' || str.at(0) ==
'%')
225 std::list<std::string> strList =
uSplit(str,
',');
226 if(strList.size() == 17)
228 double stamp =
uStr2Double(strList.front())/1000000000.0;
235 UWARN(
"Null transform read!? line parsed: \"%s\"", str.c_str());
241 stamps->insert(std::make_pair(
id, stamp));
248 poses.insert(std::make_pair(
id, pose));
253 UERROR(
"Error parsing \"%s\" with EuRoC MAV format (should have 17 values: stamp x y z qw qx qy qz vx vy vz vr vp vy ax ay az)", str.c_str());
259 if(strList.size() == 10)
264 double stamp =
uStr2Double(strList[0].insert(10, 1,
'.'));
273 stamps->insert(std::make_pair(
id, stamp));
276 if(poses.size() == 0)
280 pose = originPose * pose;
281 poses.insert(std::make_pair(
id, pose));
285 UERROR(
"Error parsing \"%s\" with Karlsruhe format (should have 10 values)", str.c_str());
291 if(strList.size() == 12)
308 std::string millisecStr = strList[1];
309 while(millisecStr.size() < 6)
311 millisecStr =
"0" + millisecStr;
313 double stamp =
uStr2Double(strList[0] +
"." + millisecStr);
329 stamps->insert(std::make_pair(
id, stamp));
331 poses.insert(std::make_pair(
id,
Transform(coordENU.x,coordENU.y,coordENU.z, roll,pitch,yaw)));
335 UERROR(
"Error parsing \"%s\" with St Lucia format (should have 12 values, e.g., 101215_153851_Ins0.log)", str.c_str());
341 if(strList.size() == 25)
355 stamps->insert(std::make_pair(
id, stamp));
361 Transform & previousPose = poses.at(
id-1);
362 yaw =
atan2(y-previousPose.
y(),x-previousPose.
x());
363 previousPose =
Transform(previousPose.x(), previousPose.y(),
yaw);
365 poses.insert(std::make_pair(
id,
Transform(x,y,z,0,0,yaw)));
369 UERROR(
"Error parsing \"%s\" with Malaga Urban format (should have 25 values, *_GPS.txt)", str.c_str());
375 if(strList.size() == 3)
388 stamps->insert(std::make_pair(
id, stamp));
394 Transform & previousPose = poses.at(
id-1);
395 yaw =
atan2(y-previousPose.
y(),x-previousPose.
x());
396 previousPose =
Transform(previousPose.x(), previousPose.y(),
yaw);
399 if(poses.size() == 0)
403 pose = originPose * pose;
404 poses.insert(std::make_pair(
id, pose));
408 UDEBUG(
"Not valid values detected: \"%s\"", str.c_str());
413 UERROR(
"Error parsing \"%s\" with NewCollege format (should have 3 values: stamp x y, found %d)", str.c_str(), (int)strList.size());
416 else if(format == 1 || format==10)
418 std::list<std::string> strList =
uSplit(str);
419 if(strList.size() == 8)
423 str =
uJoin(strList,
" ");
427 UWARN(
"Null transform read!? line parsed: \"%s\"", str.c_str());
433 stamps->insert(std::make_pair(
id, stamp));
448 poses.insert(std::make_pair(
id, pose));
453 UERROR(
"Error parsing \"%s\" with RGBD-SLAM format (should have 8 values: stamp x y z qw qx qy qz)", str.c_str());
468 poses.insert(std::make_pair(
id, pose));
479 const std::string & filePath,
480 const std::map<int, GPS> & gpsValues,
483 UDEBUG(
"%s", filePath.c_str());
484 std::string tmpPath = filePath;
488 if(ext.compare(
"kml")!=0 && ext.compare(
"txt")!=0)
490 UERROR(
"Only txt and kml formats are supported!");
496 fopen_s(&fout, tmpPath.c_str(),
"w");
498 fout = fopen(tmpPath.c_str(),
"w");
502 if(ext.compare(
"kml")==0)
505 for(std::map<int, GPS>::const_iterator iter=gpsValues.begin(); iter!=gpsValues.end(); ++iter)
507 values +=
uFormat(
"%f,%f,%f ", iter->second.longitude(), iter->second.latitude(), iter->second.altitude());
511 unsigned int abgr = 0xFF << 24 | (rgba & 0xFF) << 16 | (rgba & 0xFF00) | ((rgba >> 16) &0xFF);
513 std::string colorHexa =
uFormat(
"%08x", abgr);
515 fprintf(fout,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
516 fprintf(fout,
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n");
517 fprintf(fout,
"<Document>\n" 518 " <name>%s</name>\n", tmpPath.c_str());
519 fprintf(fout,
" <StyleMap id=\"msn_ylw-pushpin\">\n" 521 " <key>normal</key>\n" 522 " <styleUrl>#sn_ylw-pushpin</styleUrl>\n" 525 " <key>highlight</key>\n" 526 " <styleUrl>#sh_ylw-pushpin</styleUrl>\n" 529 " <Style id=\"sh_ylw-pushpin\">\n" 531 " <scale>1.2</scale>\n" 534 " <color>%s</color>\n" 537 " <Style id=\"sn_ylw-pushpin\">\n" 539 " <color>%s</color>\n" 541 " </Style>\n", colorHexa.c_str(), colorHexa.c_str());
542 fprintf(fout,
" <Placemark>\n" 544 " <styleUrl>#msn_ylw-pushpin</styleUrl>" 553 uSplit(tmpPath,
'.').front().c_str(),
558 fprintf(fout,
"# stamp longitude latitude altitude error bearing\n");
559 for(std::map<int, GPS>::const_iterator iter=gpsValues.begin(); iter!=gpsValues.end(); ++iter)
561 fprintf(fout,
"%f %f %f %f %f %f\n",
562 iter->second.stamp(),
563 iter->second.longitude(),
564 iter->second.latitude(),
565 iter->second.altitude(),
566 iter->second.error(),
567 iter->second.bearing());
578 float lengths[] = {100,200,300,400,500,600,700,800};
587 errors (
int32_t first_frame,
float r_err,
float t_err,
float len,
float speed) :
588 first_frame(first_frame),r_err(r_err),t_err(t_err),len(len),speed(speed) {}
592 std::vector<float> dist;
594 for (
unsigned int i=1; i<poses.size(); i++) {
597 float dx = P1.
x()-P2.
x();
598 float dy = P1.
y()-P2.
y();
599 float dz = P1.
z()-P2.
z();
600 dist.push_back(dist[i-1]+
sqrt(dx*dx+dy*dy+dz*dz));
606 for (
unsigned int i=first_frame; i<dist.size(); i++)
607 if (dist[i]>dist[first_frame]+len)
613 float a = pose_error(0,0);
614 float b = pose_error(1,1);
615 float c = pose_error(2,2);
616 float d = 0.5*(a+b+c-1.0);
621 float dx = pose_error.
x();
622 float dy = pose_error.
y();
623 float dz = pose_error.
z();
624 return sqrt(dx*dx+dy*dy+dz*dz);
628 const std::vector<Transform> &poses_gt,
629 const std::vector<Transform> &poses_result,
633 UASSERT(poses_gt.size() == poses_result.size());
636 std::vector<errors> err;
651 float len = lengths[i];
668 float num_frames = (float)(last_frame-
first_frame+1);
669 float speed = len/(0.1*num_frames);
680 for (std::vector<errors>::iterator it=err.begin(); it!=err.end(); it++)
687 float num = err.size();
696 const std::vector<Transform> &poses_gt,
697 const std::vector<Transform> &poses_result,
701 UASSERT(poses_gt.size() == poses_result.size());
704 std::vector<errors> err;
707 for (
unsigned int i=0; i<poses_gt.size()-1; ++i)
713 float r_err = pose_error.
getAngle();
714 float t_err = pose_error.
getNorm();
717 err.push_back(
errors(i,r_err,t_err,0,0));
724 for (std::vector<errors>::iterator it=err.begin(); it!=err.end(); it++)
731 float num = err.size();
738 const std::map<int, Transform> & groundTruth,
739 const std::map<int, Transform> & poses,
740 float & translational_rmse,
741 float & translational_mean,
742 float & translational_median,
743 float & translational_std,
744 float & translational_min,
745 float & translational_max,
746 float & rotational_rmse,
747 float & rotational_mean,
748 float & rotational_median,
749 float & rotational_std,
750 float & rotational_min,
751 float & rotational_max)
754 translational_rmse = 0.0f;
755 translational_mean = 0.0f;
756 translational_median = 0.0f;
757 translational_std = 0.0f;
758 translational_min = 0.0f;
759 translational_max = 0.0f;
761 rotational_rmse = 0.0f;
762 rotational_mean = 0.0f;
763 rotational_median = 0.0f;
764 rotational_std = 0.0f;
765 rotational_min = 0.0f;
766 rotational_max = 0.0f;
769 pcl::PointCloud<pcl::PointXYZ> cloud1, cloud2;
770 cloud1.resize(poses.size());
771 cloud2.resize(poses.size());
774 for(std::map<int, Transform>::const_iterator iter=poses.begin(); iter!=poses.end(); ++iter)
776 std::map<int, Transform>::const_iterator jter=groundTruth.find(iter->first);
777 if(jter != groundTruth.end())
781 idFirst = iter->first;
783 cloud1[oi] = pcl::PointXYZ(jter->second.x(), jter->second.y(), jter->second.z());
784 cloud2[oi++] = pcl::PointXYZ(iter->second.x(), iter->second.y(), iter->second.z());
798 t = groundTruth.at(idFirst) * poses.at(idFirst).inverse();
801 std::vector<float> translationalErrors(poses.size());
802 std::vector<float> rotationalErrors(poses.size());
803 float sumTranslationalErrors = 0.0f;
804 float sumRotationalErrors = 0.0f;
805 float sumSqrdTranslationalErrors = 0.0f;
806 float sumSqrdRotationalErrors = 0.0f;
807 float radToDegree = 180.0f /
M_PI;
809 for(std::map<int, Transform>::const_iterator iter=poses.begin(); iter!=poses.end(); ++iter)
811 std::map<int, Transform>::const_iterator jter = groundTruth.find(iter->first);
812 if(jter!=groundTruth.end())
815 Eigen::Vector3f xAxis(1,0,0);
816 Eigen::Vector3f vA = pose.
toEigen3f().linear()*xAxis;
817 Eigen::Vector3f vB = jter->second.toEigen3f().linear()*xAxis;
818 double a = pcl::getAngle3D(Eigen::Vector4f(vA[0], vA[1], vA[2], 0), Eigen::Vector4f(vB[0], vB[1], vB[2], 0));
819 rotationalErrors[oi] = a*radToDegree;
820 translationalErrors[oi] = pose.
getDistance(jter->second);
822 sumTranslationalErrors+=translationalErrors[oi];
823 sumSqrdTranslationalErrors+=translationalErrors[oi]*translationalErrors[oi];
824 sumRotationalErrors+=rotationalErrors[oi];
825 sumSqrdRotationalErrors+=rotationalErrors[oi]*rotationalErrors[oi];
829 translational_min = translational_max = translationalErrors[oi];
830 rotational_min = rotational_max = rotationalErrors[oi];
834 if(translationalErrors[oi] < translational_min)
836 translational_min = translationalErrors[oi];
838 else if(translationalErrors[oi] > translational_max)
840 translational_max = translationalErrors[oi];
843 if(rotationalErrors[oi] < rotational_min)
845 rotational_min = rotationalErrors[oi];
847 else if(rotationalErrors[oi] > rotational_max)
849 rotational_max = rotationalErrors[oi];
856 translationalErrors.resize(oi);
857 rotationalErrors.resize(oi);
860 float total = float(oi);
861 translational_rmse =
std::sqrt(sumSqrdTranslationalErrors/total);
862 translational_mean = sumTranslationalErrors/total;
863 translational_median = translationalErrors[oi/2];
866 rotational_rmse =
std::sqrt(sumSqrdRotationalErrors/total);
867 rotational_mean = sumRotationalErrors/total;
868 rotational_median = rotationalErrors[oi/2];
875 const std::map<int, Transform> & poses,
876 const std::multimap<int, Link> & links,
877 float & maxLinearErrorRatio,
878 float & maxAngularErrorRatio,
879 float & maxLinearError,
880 float & maxAngularError,
881 const Link ** maxLinearErrorLink,
882 const Link ** maxAngularErrorLink)
884 maxLinearErrorRatio = -1;
885 maxAngularErrorRatio = -1;
887 maxAngularError = -1;
889 UDEBUG(
"poses=%d links=%d", (
int)poses.size(), (int)links.size());
890 for(std::multimap<int, Link>::const_iterator iter=links.begin(); iter!=links.end(); ++iter)
893 if(iter->second.transVariance() <= 1.0 && iter->second.from() != iter->second.to() && iter->second.type() !=
Link::kLandmark)
899 float linearError =
uMax3(
900 fabs(iter->second.transform().x() - t.x()),
901 fabs(iter->second.transform().y() - t.y()),
902 fabs(iter->second.transform().z() - t.z()));
903 UASSERT(iter->second.transVariance(
false)>0.0);
904 float stddevLinear =
sqrt(iter->second.transVariance(
false));
905 float linearErrorRatio = linearError/stddevLinear;
906 if(linearErrorRatio > maxLinearErrorRatio)
908 maxLinearError = linearError;
909 maxLinearErrorRatio = linearErrorRatio;
910 if(maxLinearErrorLink)
912 *maxLinearErrorLink = &iter->second;
916 float opt_roll,opt_pitch,opt_yaw;
917 float link_roll,link_pitch,link_yaw;
918 t.getEulerAngles(opt_roll, opt_pitch, opt_yaw);
920 float angularError =
uMax3(
921 fabs(opt_roll - link_roll),
922 fabs(opt_pitch - link_pitch),
923 fabs(opt_yaw - link_yaw));
924 angularError = angularError>
M_PI?2*
M_PI-angularError:angularError;
925 UASSERT(iter->second.rotVariance(
false)>0.0);
926 float stddevAngular =
sqrt(iter->second.rotVariance(
false));
927 float angularErrorRatio = angularError/stddevAngular;
928 if(angularErrorRatio > maxAngularErrorRatio)
930 maxAngularError = angularError;
931 maxAngularErrorRatio = angularErrorRatio;
932 if(maxAngularErrorLink)
934 *maxAngularErrorLink = &iter->second;
943 std::vector<double> maxOdomInf(6,0.0);
944 maxOdomInf.resize(6,0.0);
945 for(std::multimap<int, Link>::const_iterator iter=links.begin(); iter!=links.end(); ++iter)
949 for(
int i=0; i<6; ++i)
951 const double & v = iter->second.infMatrix().at<
double>(i,i);
952 if(maxOdomInf[i] < v)
959 if(maxOdomInf[0] == 0.0)
970 std::multimap<int, Link> & links,
975 std::multimap<int, Link>::iterator iter = links.find(from);
976 while(iter != links.end() && iter->first == from)
978 if(iter->second.to() == to)
988 iter = links.find(to);
989 while(iter != links.end() && iter->first == to)
991 if(iter->second.to() == from)
1002 std::multimap<int, int> & links,
1007 std::multimap<int, int>::iterator iter = links.find(from);
1008 while(iter != links.end() && iter->first == from)
1010 if(iter->second == to)
1020 iter = links.find(to);
1021 while(iter != links.end() && iter->first == to)
1023 if(iter->second == from)
1033 const std::multimap<int, Link> & links,
1039 std::multimap<int, Link>::const_iterator iter = links.find(from);
1040 while(iter != links.end() && iter->first == from)
1042 if(iter->second.to() == to && (type==
Link::kUndef || type == iter->second.type()))
1052 iter = links.find(to);
1053 while(iter != links.end() && iter->first == to)
1055 if(iter->second.to() == from && (type==
Link::kUndef || type == iter->second.type()))
1066 const std::multimap<int, int> & links,
1071 std::multimap<int, int>::const_iterator iter = links.find(from);
1072 while(iter != links.end() && iter->first == from)
1074 if(iter->second == to)
1084 iter = links.find(to);
1085 while(iter != links.end() && iter->first == to)
1087 if(iter->second == from)
1098 const std::multimap<int, Link> & links,
1101 std::list<Link> output;
1102 for(std::multimap<int, Link>::const_iterator iter=links.begin(); iter != links.end(); ++iter)
1104 if(iter->second.from() == from)
1106 output.push_back(iter->second);
1108 else if(iter->second.to() == from)
1110 output.push_back(iter->second.inverse());
1117 const std::multimap<int, Link> & links)
1119 std::multimap<int, Link> output;
1120 for(std::multimap<int, Link>::const_iterator iter=links.begin(); iter!=links.end(); ++iter)
1122 if(
graph::findLink(output, iter->second.from(), iter->second.to(),
true, iter->second.type()) == output.end())
1124 output.insert(*iter);
1131 const std::multimap<int, Link> & links,
1135 std::multimap<int, Link> output;
1136 for(std::multimap<int, Link>::const_iterator iter=links.begin(); iter!=links.end(); ++iter)
1140 if((!inverted && iter->second.from() != iter->second.to())||
1141 (inverted && iter->second.from() == iter->second.to()))
1143 output.insert(*iter);
1146 else if((!inverted && iter->second.type() != filteredType)||
1147 (inverted && iter->second.type() == filteredType))
1149 output.insert(*iter);
1156 const std::map<int, Link> & links,
1160 std::map<int, Link> output;
1161 for(std::map<int, Link>::const_iterator iter=links.begin(); iter!=links.end(); ++iter)
1165 if((!inverted && iter->second.from() != iter->second.to())||
1166 (inverted && iter->second.from() == iter->second.to()))
1168 output.insert(*iter);
1171 else if((!inverted && iter->second.type() != filteredType)||
1172 (inverted && iter->second.type() == filteredType))
1174 output.insert(*iter);
1181 const std::map<int, Transform> & poses,
1183 float horizontalFOV,
1185 float nearClipPlaneDistance,
1186 float farClipPlaneDistance,
1189 std::map<int, Transform> output;
1193 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
1194 std::vector<int> ids(poses.size());
1196 cloud->resize(poses.size());
1197 ids.resize(poses.size());
1199 for(std::map<int, rtabmap::Transform>::const_iterator iter=poses.begin(); iter!=poses.end(); ++iter)
1201 if(!iter->second.isNull())
1203 (*cloud)[oi] = pcl::PointXYZ(iter->second.x(), iter->second.y(), iter->second.z());
1204 ids[oi++] = iter->first;
1212 pcl::IndicesPtr(
new std::vector<int>),
1216 nearClipPlaneDistance,
1217 farClipPlaneDistance,
1221 for(
unsigned int i=0; i<indices->size(); ++i)
1223 output.insert(*poses.find(ids[indices->at(i)]));
1230 const std::map<int, Transform> & poses,
1235 if(poses.size() > 2 && radius > 0.0f)
1237 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
1238 cloud->resize(poses.size());
1240 for(std::map<int, Transform>::const_iterator iter = poses.begin(); iter!=poses.end(); ++iter, ++i)
1242 (*cloud)[i] = pcl::PointXYZ(iter->second.x(), iter->second.y(), iter->second.z());
1247 std::vector<int> names =
uKeys(poses);
1248 std::vector<Transform> transforms =
uValues(poses);
1250 pcl::search::KdTree<pcl::PointXYZ>::Ptr
tree (
new pcl::search::KdTree<pcl::PointXYZ> (
false));
1251 tree->setInputCloud(cloud);
1252 std::set<int> indicesChecked;
1253 std::set<int> indicesKept;
1255 for(
unsigned int i=0; i<cloud->size(); ++i)
1257 if(indicesChecked.find(i) == indicesChecked.end())
1260 std::vector<float> kDistances;
1261 tree->radiusSearch(cloud->at(i), radius,
kIndices, kDistances);
1263 std::set<int> cloudIndices;
1264 const Transform & currentT = transforms.at(i);
1265 Eigen::Vector3f vA = currentT.
toEigen3f().linear()*Eigen::Vector3f(1,0,0);
1266 for(
unsigned int j=0; j<kIndices.size(); ++j)
1268 if(indicesChecked.find(kIndices[j]) == indicesChecked.end())
1272 const Transform & checkT = transforms.at(kIndices[j]);
1274 Eigen::Vector3f vB = checkT.
toEigen3f().linear()*Eigen::Vector3f(1,0,0);
1275 double a = pcl::getAngle3D(Eigen::Vector4f(vA[0], vA[1], vA[2], 0), Eigen::Vector4f(vB[0], vB[1], vB[2], 0));
1278 cloudIndices.insert(kIndices[j]);
1283 cloudIndices.insert(kIndices[j]);
1290 bool lastAdded =
false;
1291 for(std::set<int>::reverse_iterator iter = cloudIndices.rbegin(); iter!=cloudIndices.rend(); ++iter)
1295 indicesKept.insert(*iter);
1298 indicesChecked.insert(*iter);
1303 bool firstAdded =
false;
1304 for(std::set<int>::iterator iter = cloudIndices.begin(); iter!=cloudIndices.end(); ++iter)
1308 indicesKept.insert(*iter);
1311 indicesChecked.insert(*iter);
1319 UINFO(
"Cloud filtered In = %d, Out = %d", cloud->size(), indicesKept.size());
1323 std::map<int, Transform> keptPoses;
1324 for(std::set<int>::iterator iter = indicesKept.begin(); iter!=indicesKept.end(); ++iter)
1326 keptPoses.insert(std::make_pair(names.at(*iter), transforms.at(*iter)));
1330 keptPoses.insert(*poses.begin());
1331 keptPoses.insert(*poses.rbegin());
1343 std::multimap<int, int> clusters;
1344 if(poses.size() > 1 && radius > 0.0f)
1346 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
1347 cloud->resize(poses.size());
1349 for(std::map<int, Transform>::const_iterator iter = poses.begin(); iter!=poses.end(); ++iter, ++i)
1351 (*cloud)[i] = pcl::PointXYZ(iter->second.x(), iter->second.y(), iter->second.z());
1356 std::vector<int> ids =
uKeys(poses);
1357 std::vector<Transform> transforms =
uValues(poses);
1359 pcl::search::KdTree<pcl::PointXYZ>::Ptr
tree (
new pcl::search::KdTree<pcl::PointXYZ> (
false));
1360 tree->setInputCloud(cloud);
1362 for(
unsigned int i=0; i<cloud->size(); ++i)
1365 std::vector<float> kDistances;
1366 tree->radiusSearch(cloud->at(i), radius,
kIndices, kDistances);
1368 std::set<int> cloudIndices;
1369 const Transform & currentT = transforms.at(i);
1370 Eigen::Vector3f vA = currentT.
toEigen3f().linear()*Eigen::Vector3f(1,0,0);
1371 for(
unsigned int j=0; j<kIndices.size(); ++j)
1373 if((
int)i != kIndices[j])
1377 const Transform & checkT = transforms.at(kIndices[j]);
1379 Eigen::Vector3f vB = checkT.
toEigen3f().linear()*Eigen::Vector3f(1,0,0);
1380 double a = pcl::getAngle3D(Eigen::Vector4f(vA[0], vA[1], vA[2], 0), Eigen::Vector4f(vB[0], vB[1], vB[2], 0));
1383 clusters.insert(std::make_pair(ids[i], ids[kIndices[j]]));
1388 clusters.insert(std::make_pair(ids[i], ids[kIndices[j]]));
1398 const std::map<int, Transform> & poses,
1399 const std::multimap<int, Link> & links,
1400 std::multimap<int, int> & hyperNodes,
1401 std::multimap<int, Link> & hyperLinks)
1403 UINFO(
"Input: poses=%d links=%d", (
int)poses.size(), (int)links.size());
1405 std::map<int, int> posesToHyperNodes;
1406 std::map<int, std::multimap<int, Link> > clusterloopClosureLinks;
1409 std::multimap<int, Link> bidirectionalLoopClosureLinks;
1410 for(std::multimap<int, Link>::const_iterator jter=links.begin(); jter!=links.end(); ++jter)
1414 jter->second.userDataCompressed().empty())
1416 if(
uContains(poses, jter->second.from()) &&
1419 UASSERT_MSG(
graph::findLink(links, jter->second.to(), jter->second.from(),
false) == links.end(),
"Input links should be unique!");
1420 bidirectionalLoopClosureLinks.insert(std::make_pair(jter->second.from(), jter->second));
1426 UINFO(
"Clustering hyper nodes...");
1428 for(std::map<int, Transform>::const_reverse_iterator iter=poses.rbegin(); iter!=poses.rend(); ++iter)
1430 if(posesToHyperNodes.find(iter->first) == posesToHyperNodes.end())
1432 int hyperNodeId = iter->first;
1433 std::list<int> loopClosures;
1434 std::set<int> loopClosuresAdded;
1435 loopClosures.push_back(iter->first);
1436 std::multimap<int, Link> clusterLinks;
1437 while(loopClosures.size())
1439 int id = loopClosures.front();
1440 loopClosures.pop_front();
1442 UASSERT(posesToHyperNodes.find(
id) == posesToHyperNodes.end());
1444 posesToHyperNodes.insert(std::make_pair(
id, hyperNodeId));
1445 hyperNodes.insert(std::make_pair(hyperNodeId,
id));
1447 for(std::multimap<int, Link>::const_iterator jter=bidirectionalLoopClosureLinks.find(
id); jter!=bidirectionalLoopClosureLinks.end() && jter->first==id; ++jter)
1449 if(posesToHyperNodes.find(jter->second.to()) == posesToHyperNodes.end() &&
1450 loopClosuresAdded.find(jter->second.to()) == loopClosuresAdded.end())
1452 loopClosures.push_back(jter->second.to());
1453 loopClosuresAdded.insert(jter->second.to());
1454 clusterLinks.insert(*jter);
1455 clusterLinks.insert(std::make_pair(jter->second.to(), jter->second.inverse()));
1456 if(jter->second.from() < jter->second.to())
1458 UWARN(
"Child to Parent link? %d->%d (type=%d)",
1459 jter->second.from(),
1461 jter->second.type());
1466 UASSERT(clusterloopClosureLinks.find(hyperNodeId) == clusterloopClosureLinks.end());
1467 clusterloopClosureLinks.insert(std::make_pair(hyperNodeId, clusterLinks));
1468 UDEBUG(
"Created hyper node %d with %d children (%f%%)",
1469 hyperNodeId, (
int)loopClosuresAdded.size(), float(posesToHyperNodes.size())/
float(poses.size())*100.0
f);
1472 UINFO(
"Clustering hyper nodes... done! (%f s)", timer.ticks());
1475 UINFO(
"Creating hyper links...");
1477 for(std::multimap<int, Link>::const_reverse_iterator jter=links.rbegin(); jter!=links.rend(); ++jter)
1481 !jter->second.userDataCompressed().empty()) &&
1482 uContains(poses, jter->second.from()) &&
1485 UASSERT_MSG(
uContains(posesToHyperNodes, jter->second.from()),
uFormat(
"%d->%d (type=%d)", jter->second.from(), jter->second.to(), jter->second.type()).c_str());
1486 UASSERT_MSG(
uContains(posesToHyperNodes, jter->second.to()),
uFormat(
"%d->%d (type=%d)", jter->second.from(), jter->second.to(), jter->second.type()).c_str());
1487 int hyperNodeIDFrom = posesToHyperNodes.at(jter->second.from());
1488 int hyperNodeIDTo = posesToHyperNodes.at(jter->second.to());
1491 if(hyperNodeIDFrom != hyperNodeIDTo)
1493 std::multimap<int, Link>::iterator tmpIter =
graph::findLink(hyperLinks, hyperNodeIDFrom, hyperNodeIDTo);
1494 if(tmpIter!=hyperLinks.end() &&
1495 hyperNodeIDFrom == jter->second.from() &&
1496 hyperNodeIDTo == jter->second.to() &&
1501 hyperLinks.erase(tmpIter);
1505 if(
graph::findLink(hyperLinks, hyperNodeIDFrom, hyperNodeIDTo) == hyperLinks.end())
1507 UASSERT(clusterloopClosureLinks.find(hyperNodeIDFrom) != clusterloopClosureLinks.end());
1508 UASSERT(clusterloopClosureLinks.find(hyperNodeIDTo) != clusterloopClosureLinks.end());
1509 std::multimap<int, Link> tmpLinks = clusterloopClosureLinks.at(hyperNodeIDFrom);
1510 tmpLinks.insert(clusterloopClosureLinks.at(hyperNodeIDTo).begin(), clusterloopClosureLinks.at(hyperNodeIDTo).end());
1511 tmpLinks.insert(std::make_pair(jter->second.from(), jter->second));
1513 std::list<int> path =
computePath(tmpLinks, hyperNodeIDFrom, hyperNodeIDTo,
false,
true);
1515 uFormat(
"path.size()=%d, hyperNodeIDFrom=%d, hyperNodeIDTo=%d",
1518 hyperNodeIDTo).c_str());
1520 if(path.size() > 10)
1522 UWARN(
"Large path! %d nodes", (
int)path.size());
1523 std::stringstream stream;
1524 for(std::list<int>::const_iterator iter=path.begin(); iter!=path.end();++iter)
1526 if(iter!=path.begin())
1533 UWARN(
"Path = [%s]", stream.str().c_str());
1537 std::list<int>::iterator iter=path.begin();
1541 std::multimap<int, Link>::const_iterator foundIter =
graph::findLink(tmpLinks, from, to,
false);
1542 UASSERT(foundIter != tmpLinks.end());
1543 Link hyperLink = foundIter->second;
1546 for(; iter!=path.end(); ++iter)
1549 std::multimap<int, Link>::const_iterator foundIter =
graph::findLink(tmpLinks, from, to,
false);
1550 UASSERT(foundIter != tmpLinks.end());
1551 hyperLink = hyperLink.merge(foundIter->second, jter->second.type());
1556 UASSERT(hyperLink.from() == hyperNodeIDFrom);
1557 UASSERT(hyperLink.to() == hyperNodeIDTo);
1558 hyperLinks.insert(std::make_pair(hyperNodeIDFrom, hyperLink));
1560 UDEBUG(
"Created hyper link %d->%d (%f%%)",
1561 hyperLink.from(), hyperLink.to(), float(i)/float(links.size())*100.0
f);
1562 if(hyperLink.transform().getNorm() > jter->second.transform().getNorm()+1)
1564 UWARN(
"Large hyper link %d->%d (%f m)! original %d->%d (%f m)",
1567 hyperLink.transform().getNorm(),
1568 jter->second.from(),
1570 jter->second.transform().getNorm());
1578 UINFO(
"Creating hyper links... done! (%f s)", timer.ticks());
1580 UINFO(
"Output: poses=%d links=%d", (
int)
uUniqueKeys(hyperNodes).size(), (
int)links.size());
1596 int id()
const {
return id_;}
1606 return pose_.getDistance(pose);
1624 typedef std::pair<int, float>
Pair;
1629 return a.second > b.second;
1635 const std::map<int, rtabmap::Transform> & poses,
1636 const std::multimap<int, int> & links,
1639 bool updateNewCosts)
1641 std::list<std::pair<int, Transform> > path;
1643 int startNode = from;
1646 std::map<int, Node> nodes;
1647 nodes.insert(std::make_pair(startNode,
Node(startNode, 0, poses.at(startNode))));
1648 std::priority_queue<Pair, std::vector<Pair>,
Order> pq;
1649 std::multimap<float, int> pqmap;
1652 pqmap.insert(std::make_pair(0, startNode));
1656 pq.push(
Pair(startNode, 0));
1659 while((updateNewCosts && pqmap.size()) || (!updateNewCosts && pq.size()))
1664 currentNode = &nodes.find(pqmap.begin()->second)->second;
1665 pqmap.erase(pqmap.begin());
1669 currentNode = &nodes.find(pq.top().first)->second;
1675 if(currentNode->
id() == endNode)
1677 while(currentNode->
id()!=startNode)
1679 path.push_front(std::make_pair(currentNode->
id(), currentNode->
pose()));
1680 currentNode = &nodes.find(currentNode->
fromId())->second;
1682 path.push_front(std::make_pair(startNode, poses.at(startNode)));
1687 for(std::multimap<int, int>::const_iterator iter = links.find(currentNode->
id());
1688 iter!=links.end() && iter->first == currentNode->
id();
1691 std::map<int, Node>::iterator nodeIter = nodes.find(iter->second);
1692 if(nodeIter == nodes.end())
1694 std::map<int, rtabmap::Transform>::const_iterator poseIter = poses.find(iter->second);
1695 if(poseIter == poses.end())
1697 UERROR(
"Next pose %d (from %d) should be found in poses! Ignoring it!", iter->second, iter->first);
1701 Node n(iter->second, currentNode->
id(), poseIter->second);
1703 n.setDistToEnd(n.distFrom(endPose));
1705 nodes.insert(std::make_pair(iter->second, n));
1708 pqmap.insert(std::make_pair(n.totalCost(), n.id()));
1712 pq.push(
Pair(n.id(), n.totalCost()));
1716 else if(updateNewCosts && nodeIter->second.isOpened())
1718 float newCostSoFar = currentNode->
costSoFar() + currentNode->
distFrom(nodeIter->second.pose());
1719 if(nodeIter->second.costSoFar() > newCostSoFar)
1722 for(std::multimap<float, int>::iterator mapIter=pqmap.begin(); mapIter!=pqmap.end(); ++mapIter)
1724 if(mapIter->second == nodeIter->first)
1726 pqmap.erase(mapIter);
1727 nodeIter->second.setCostSoFar(newCostSoFar);
1728 pqmap.insert(std::make_pair(nodeIter->second.totalCost(), nodeIter->first));
1741 const std::multimap<int, Link> & links,
1744 bool updateNewCosts,
1745 bool useSameCostForAllLinks)
1747 std::list<int> path;
1749 int startNode = from;
1751 std::map<int, Node> nodes;
1752 nodes.insert(std::make_pair(startNode,
Node(startNode, 0,
Transform())));
1753 std::priority_queue<Pair, std::vector<Pair>,
Order> pq;
1754 std::multimap<float, int> pqmap;
1757 pqmap.insert(std::make_pair(0, startNode));
1761 pq.push(
Pair(startNode, 0));
1764 while((updateNewCosts && pqmap.size()) || (!updateNewCosts && pq.size()))
1769 currentNode = &nodes.find(pqmap.begin()->second)->second;
1770 pqmap.erase(pqmap.begin());
1774 currentNode = &nodes.find(pq.top().first)->second;
1780 if(currentNode->
id() == endNode)
1782 while(currentNode->
id()!=startNode)
1784 path.push_front(currentNode->
id());
1785 currentNode = &nodes.find(currentNode->
fromId())->second;
1787 path.push_front(startNode);
1792 for(std::multimap<int, Link>::const_iterator iter = links.find(currentNode->
id());
1793 iter!=links.end() && iter->first == currentNode->
id();
1796 std::map<int, Node>::iterator nodeIter = nodes.find(iter->second.to());
1798 if(!useSameCostForAllLinks)
1800 cost = iter->second.transform().getNorm();
1802 if(nodeIter == nodes.end())
1807 nodes.insert(std::make_pair(iter->second.to(), n));
1810 pqmap.insert(std::make_pair(n.totalCost(), n.id()));
1814 pq.push(
Pair(n.id(), n.totalCost()));
1817 else if(!useSameCostForAllLinks && updateNewCosts && nodeIter->second.isOpened())
1819 float newCostSoFar = currentNode->
costSoFar() + cost;
1820 if(nodeIter->second.costSoFar() > newCostSoFar)
1823 for(std::multimap<float, int>::iterator mapIter=pqmap.begin(); mapIter!=pqmap.end(); ++mapIter)
1825 if(mapIter->second == nodeIter->first)
1827 pqmap.erase(mapIter);
1828 nodeIter->second.setCostSoFar(newCostSoFar);
1829 pqmap.insert(std::make_pair(nodeIter->second.totalCost(), nodeIter->first));
1846 bool lookInDatabase,
1847 bool updateNewCosts,
1848 float linearVelocity,
1849 float angularVelocity)
1854 std::list<std::pair<int, Transform> > path;
1855 UDEBUG(
"fromId=%d, toId=%d, lookInDatabase=%d, updateNewCosts=%d, linearVelocity=%f, angularVelocity=%f",
1863 std::multimap<int, Link> allLinks;
1868 allLinks = memory->
getAllLinks(lookInDatabase,
true,
true);
1869 for(std::multimap<int, Link>::iterator iter=allLinks.begin(); iter!=allLinks.end(); ++iter)
1871 if(iter->second.to() < 0)
1873 allLinks.insert(std::make_pair(iter->second.to(), iter->second.inverse()));
1876 UINFO(
"getting all %d links time = %f s", (
int)allLinks.size(), t.
ticks());
1880 int startNode = fromId;
1882 std::map<int, Node> nodes;
1884 std::priority_queue<Pair, std::vector<Pair>,
Order> pq;
1885 std::multimap<float, int> pqmap;
1888 pqmap.insert(std::make_pair(0, startNode));
1892 pq.push(
Pair(startNode, 0));
1895 while((updateNewCosts && pqmap.size()) || (!updateNewCosts && pq.size()))
1900 currentNode = &nodes.find(pqmap.begin()->second)->second;
1901 pqmap.erase(pqmap.begin());
1905 currentNode = &nodes.find(pq.top().first)->second;
1911 if(currentNode->
id() == endNode)
1913 while(currentNode->
id()!=startNode)
1915 path.push_front(std::make_pair(currentNode->
id(), currentNode->
pose()));
1916 currentNode = &nodes.find(currentNode->
fromId())->second;
1918 path.push_front(std::make_pair(startNode, currentNode->
pose()));
1923 std::multimap<int, Link> links;
1924 if(allLinks.size() == 0)
1926 links = memory->
getLinks(currentNode->
id(), lookInDatabase,
true);
1930 for(std::multimap<int, Link>::const_iterator iter = allLinks.lower_bound(currentNode->
id());
1931 iter!=allLinks.end() && iter->first == currentNode->
id();
1934 links.insert(std::make_pair(iter->second.to(), iter->second));
1937 for(std::multimap<int, Link>::const_iterator iter = links.begin(); iter!=links.end(); ++iter)
1939 if(iter->second.from() != iter->second.to())
1941 Transform nextPose = currentNode->
pose()*iter->second.transform();
1943 if(linearVelocity <= 0.0
f && angularVelocity <= 0.0
f)
1946 cost = iter->second.transform().
getNorm();
1950 if(linearVelocity > 0.0
f)
1952 cost += iter->second.transform().getNorm()/linearVelocity;
1954 if(angularVelocity > 0.0
f)
1956 Eigen::Vector4f v1 = Eigen::Vector4f(nextPose.
x()-currentNode->
pose().
x(), nextPose.
y()-currentNode->
pose().
y(), nextPose.
z()-currentNode->
pose().
z(), 1.0f);
1958 float angle = pcl::getAngle3D(v1, v2);
1959 cost += angle / angularVelocity;
1963 std::map<int, Node>::iterator nodeIter = nodes.find(iter->first);
1964 if(nodeIter == nodes.end())
1966 Node n(iter->second.to(), currentNode->
id(), nextPose);
1969 nodes.insert(std::make_pair(iter->second.to(), n));
1972 pqmap.insert(std::make_pair(n.totalCost(), n.id()));
1976 pq.push(
Pair(n.id(), n.totalCost()));
1979 else if(updateNewCosts && nodeIter->second.isOpened())
1981 float newCostSoFar = currentNode->
costSoFar() + cost;
1982 if(nodeIter->second.costSoFar() > newCostSoFar)
1985 nodeIter->second.setPose(nextPose);
1988 for(std::multimap<float, int>::iterator mapIter=pqmap.begin(); mapIter!=pqmap.end(); ++mapIter)
1990 if(mapIter->second == nodeIter->first)
1992 pqmap.erase(mapIter);
1993 nodeIter->second.setCostSoFar(newCostSoFar);
1994 pqmap.insert(std::make_pair(nodeIter->second.totalCost(), nodeIter->first));
2007 std::stringstream stream;
2009 std::list<std::pair<int, Transform> >::const_iterator previousIter = path.end();
2011 for(std::list<std::pair<int, Transform> >::const_iterator iter=path.begin(); iter!=path.end();++iter)
2013 if(iter!=path.begin())
2018 if(previousIter!=path.end())
2023 std::multimap<int, Link>::iterator jter =
graph::findLink(allLinks, previousIter->first, iter->first);
2024 if(jter != allLinks.end())
2034 ++linkTypes[jter->second.type()];
2035 stream <<
"[" << jter->second.type() <<
"]";
2036 length += jter->second.transform().getNorm();
2041 stream << iter->first;
2045 UDEBUG(
"Path (%f m) = [%s]", length, stream.str().c_str());
2046 std::stringstream streamB;
2047 for(
unsigned int i=0; i<linkTypes.size(); ++i)
2053 streamB << i <<
"=" << linkTypes[i];
2055 UDEBUG(
"Link types = %s", streamB.str().c_str());
2062 const std::map<int, rtabmap::Transform> & nodes,
2067 std::map<int, float> nearestNodes =
findNearestNodes(nodes, targetPose, 1);
2068 if(!nearestNodes.empty())
2070 id = nearestNodes.begin()->first;
2073 *distance = nearestNodes.begin()->second;
2080 const std::map<int, rtabmap::Transform> & nodes,
2084 std::map<int, float> nearestIds;
2085 if(nodes.size() && !targetPose.
isNull())
2087 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
2088 cloud->resize(nodes.size());
2089 std::vector<int> ids(nodes.size());
2091 for(std::map<int, Transform>::const_iterator iter = nodes.begin(); iter!=nodes.end(); ++iter)
2093 (*cloud)[oi] = pcl::PointXYZ(iter->second.x(), iter->second.y(), iter->second.z());
2094 ids[oi++] = iter->first;
2097 pcl::search::KdTree<pcl::PointXYZ>::Ptr kdTree(
new pcl::search::KdTree<pcl::PointXYZ>);
2098 kdTree->setInputCloud(cloud);
2099 std::vector<int> ind;
2100 std::vector<float> dist;
2101 pcl::PointXYZ pt(targetPose.
x(), targetPose.
y(), targetPose.
z());
2102 kdTree->nearestKSearch(pt, k, ind, dist);
2104 for(
unsigned int i=0; i<ind.size(); ++i)
2106 nearestIds.insert(std::make_pair(ids[ind[i]], dist[i]));
2115 const std::map<int, Transform> & nodes,
2120 std::map<int, Transform> nodesMinusTarget = nodes;
2121 Transform targetPose = nodes.at(nodeId);
2122 nodesMinusTarget.erase(nodeId);
2129 const std::map<int, Transform> & nodes,
2132 std::map<int, float> foundNodes;
2138 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
2139 cloud->resize(nodes.size());
2140 std::vector<int> ids(nodes.size());
2142 for(std::map<int, Transform>::const_iterator iter = nodes.begin(); iter!=nodes.end(); ++iter)
2144 (*cloud)[oi] = pcl::PointXYZ(iter->second.x(), iter->second.y(), iter->second.z());
2146 ids[oi] = iter->first;
2154 pcl::search::KdTree<pcl::PointXYZ>::Ptr kdTree(
new pcl::search::KdTree<pcl::PointXYZ>);
2155 kdTree->setInputCloud(cloud);
2156 std::vector<int> ind;
2157 std::vector<float> sqrdDist;
2158 pcl::PointXYZ pt(targetPose.
x(), targetPose.
y(), targetPose.
z());
2159 kdTree->radiusSearch(pt, radius, ind, sqrdDist, 0);
2160 for(
unsigned int i=0; i<ind.size(); ++i)
2164 foundNodes.insert(std::make_pair(ids[ind[i]], sqrdDist[i]));
2168 UDEBUG(
"found nodes=%d", (
int)foundNodes.size());
2175 const std::map<int, Transform> & nodes,
2181 std::map<int, Transform> nodesMinusTarget = nodes;
2182 Transform targetPose = nodes.at(nodeId);
2183 nodesMinusTarget.erase(nodeId);
2189 const std::map<int, Transform> & nodes,
2193 std::map<int, Transform> foundNodes;
2199 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(
new pcl::PointCloud<pcl::PointXYZ>);
2200 cloud->resize(nodes.size());
2201 std::vector<int> ids(nodes.size());
2203 for(std::map<int, Transform>::const_iterator iter = nodes.begin(); iter!=nodes.end(); ++iter)
2205 (*cloud)[oi] = pcl::PointXYZ(iter->second.x(), iter->second.y(), iter->second.z());
2207 ids[oi] = iter->first;
2215 pcl::search::KdTree<pcl::PointXYZ>::Ptr kdTree(
new pcl::search::KdTree<pcl::PointXYZ>);
2216 kdTree->setInputCloud(cloud);
2217 std::vector<int> ind;
2218 std::vector<float> sqrdDist;
2219 pcl::PointXYZ pt(targetPose.
x(), targetPose.
y(), targetPose.
z());
2220 kdTree->radiusSearch(pt, radius, ind, sqrdDist, 0);
2222 Eigen::Vector3f vA = targetPose.
toEigen3f().linear()*Eigen::Vector3f(1,0,0);
2224 for(
unsigned int i=0; i<ind.size(); ++i)
2230 const Transform & checkT = nodes.at(ids[ind[i]]);
2232 Eigen::Vector3f vB = checkT.
toEigen3f().linear()*Eigen::Vector3f(1,0,0);
2233 double a = pcl::getAngle3D(Eigen::Vector4f(vA[0], vA[1], vA[2], 0), Eigen::Vector4f(vB[0], vB[1], vB[2], 0));
2236 foundNodes.insert(std::make_pair(ids[ind[i]], nodes.at(ids[ind[i]])));
2241 foundNodes.insert(std::make_pair(ids[ind[i]], nodes.at(ids[ind[i]])));
2246 UDEBUG(
"found nodes=%d", (
int)foundNodes.size());
2251 const std::vector<std::pair<int, Transform> > & path,
2252 unsigned int fromIndex,
2253 unsigned int toIndex)
2258 UASSERT(fromIndex < path.size() && toIndex < path.size() && fromIndex <= toIndex);
2259 if(fromIndex >= toIndex)
2261 toIndex = (
unsigned int)path.size()-1;
2263 float x=0, y=0, z=0;
2264 for(
unsigned int i=fromIndex; i<toIndex-1; ++i)
2266 x += fabs(path[i].second.x() - path[i+1].second.x());
2267 y += fabs(path[i].second.y() - path[i+1].second.y());
2268 z += fabs(path[i].second.z() - path[i+1].second.z());
2270 length =
sqrt(x*x + y*y + z*z);
2276 const std::map<int, Transform> & path)
2281 float x=0, y=0, z=0;
2282 std::map<int, Transform>::const_iterator iter=path.begin();
2285 for(; iter!=path.end(); ++iter)
2287 const Transform & currentPose = iter->second;
2288 x += fabs(previousPose.
x() - currentPose.
x());
2289 y += fabs(previousPose.
y() - currentPose.
y());
2290 z += fabs(previousPose.
z() - currentPose.
z());
2291 previousPose = currentPose;
2293 length =
sqrt(x*x + y*y + z*z);
2300 std::map<int, Transform> poses,
2301 const std::multimap<int, Link> & links)
2303 std::list<std::map<int, Transform> > paths;
2304 if(poses.size() && links.size())
2309 std::map<int, Transform> path;
2310 for(std::map<int, Transform>::iterator iter=poses.begin(); iter!=poses.end();)
2312 std::multimap<int, Link>::const_iterator jter =
findLink(links, path.rbegin()->first, iter->first);
2316 poses.erase(iter++);
2324 paths.push_back(path);
std::list< K > uUniqueKeys(const std::multimap< K, V > &mm)
GLM_FUNC_DECL T roll(detail::tquat< T, P > const &x)
T uVariance(const T *v, unsigned int size, T meanV)
bool RTABMAP_EXP isFinite(const cv::Point3f &pt)
void setPose(const Transform &pose)
std::list< Link > RTABMAP_EXP findLinks(const std::multimap< int, Link > &links, int from)
Transform RTABMAP_EXP transformFromXYZCorrespondencesSVD(const pcl::PointCloud< pcl::PointXYZ > &cloud1, const pcl::PointCloud< pcl::PointXYZ > &cloud2)
std::map< int, Transform > RTABMAP_EXP getPosesInRadius(int nodeId, const std::map< int, Transform > &nodes, float radius, float angle=0.0f)
bool saveGraph(const std::string &fileName, const std::map< int, Transform > &poses, const std::multimap< int, Link > &edgeConstraints)
float rotationError(const Transform &pose_error)
void reduceGraph(const std::map< int, Transform > &poses, const std::multimap< int, Link > &links, std::multimap< int, int > &hyperNodes, std::multimap< int, Link > &hyperLinks)
std::map< int, Transform > RTABMAP_EXP radiusPosesFiltering(const std::map< int, Transform > &poses, float radius, float angle, bool keepLatest=true)
GLM_FUNC_DECL genType min(genType const &x, genType const &y)
std::vector< K > uKeys(const std::multimap< K, V > &mm)
double UTILITE_EXP uStr2Double(const std::string &str)
bool RTABMAP_EXP exportGPS(const std::string &filePath, const std::map< int, GPS > &gpsValues, unsigned int rgba=0xFFFFFFFF)
GLM_FUNC_DECL vecType< T, P > sqrt(vecType< T, P > const &x)
float translationError(const Transform &pose_error)
float UTILITE_EXP uStr2Float(const std::string &str)
std::map< std::string, std::string > ParametersMap
GLM_FUNC_DECL genType::value_type distance(genType const &p0, genType const &p1)
std::multimap< int, Link > RTABMAP_EXP filterLinks(const std::multimap< int, Link > &links, Link::Type filteredType, bool inverted=false)
Basic mathematics functions.
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
rtabmap::Transform pose() const
Some conversion functions.
std::string getExtension()
GLM_FUNC_DECL T pitch(detail::tquat< T, P > const &x)
std::vector< float > trajectoryDistances(const std::vector< Transform > &poses)
std::multimap< int, Link > RTABMAP_EXP filterDuplicateLinks(const std::multimap< int, Link > &links)
int RTABMAP_EXP findNearestNode(const std::map< int, rtabmap::Transform > &nodes, const rtabmap::Transform &targetPose, float *distance=0)
void RTABMAP_EXP computeMaxGraphErrors(const std::map< int, Transform > &poses, const std::multimap< int, Link > &links, float &maxLinearErrorRatio, float &maxAngularErrorRatio, float &maxLinearError, float &maxAngularError, const Link **maxLinearErrorLink=0, const Link **maxAngularErrorLink=0)
void setDistToEnd(float distToEnd)
const Transform & transform() const
pcl::IndicesPtr RTABMAP_EXP frustumFiltering(const pcl::PointCloud< pcl::PointXYZ >::Ptr &cloud, const pcl::IndicesPtr &indices, const Transform &cameraPose, float horizontalFOV, float verticalFOV, float nearClipPlaneDistance, float farClipPlaneDistance, bool negative=false)
std::list< std::string > uSplit(const std::string &str, char separator= ' ')
#define UASSERT(condition)
Wrappers of STL for convenient functions.
std::string uJoin(const std::list< std::string > &strings, const std::string &separator="")
T uMax3(const T &a, const T &b, const T &c)
Node(int id, int fromId, const rtabmap::Transform &pose)
#define UASSERT_MSG(condition, msg_str)
std::multimap< int, Link > getAllLinks(bool lookInDatabase, bool ignoreNullLinks=true, bool withLandmarks=false) const
Transform RTABMAP_EXP calcRMSE(const std::map< int, Transform > &groundTruth, const std::map< int, Transform > &poses, float &translational_rmse, float &translational_mean, float &translational_median, float &translational_std, float &translational_min, float &translational_max, float &rotational_rmse, float &rotational_mean, float &rotational_median, float &rotational_std, float &rotational_min, float &rotational_max)
std::vector< double > RTABMAP_EXP getMaxOdomInf(const std::multimap< int, Link > &links)
void setClosed(bool closed)
std::string UTILITE_EXP uReplaceChar(const std::string &str, char before, char after)
std::list< std::pair< int, Transform > > RTABMAP_EXP computePath(const std::map< int, rtabmap::Transform > &poses, const std::multimap< int, int > &links, int from, int to, bool updateNewCosts=false)
float distFrom(const rtabmap::Transform &pose) const
static ULogger::Level level()
bool uIsNumber(const std::string &str)
GLM_FUNC_QUALIFIER T atan2(T x, T y)
Arc tangent. Returns an angle whose tangent is y/x. The signs of x and y are used to determine what q...
bool uContains(const std::list< V > &list, const V &value)
std::multimap< int, int > RTABMAP_EXP radiusPosesClustering(const std::map< int, Transform > &poses, float radius, float angle)
bool RTABMAP_EXP exportPoses(const std::string &filePath, int format, const std::map< int, Transform > &poses, const std::multimap< int, Link > &constraints=std::multimap< int, Link >(), const std::map< int, double > &stamps=std::map< int, double >(), const ParametersMap ¶meters=ParametersMap())
std::vector< V > uListToVector(const std::list< V > &list)
int32_t lastFrameFromSegmentLength(std::vector< float > &dist, int32_t first_frame, float len)
bool operator()(Pair const &a, Pair const &b) const
std::vector< V > uValues(const std::multimap< K, V > &mm)
std::pair< int, float > Pair
cv::Point3d toENU_WGS84(const GeodeticCoords &origin) const
std::map< int, float > RTABMAP_EXP getNodesInRadius(int nodeId, const std::map< int, Transform > &nodes, float radius)
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
std::multimap< int, Link > getLinks(int signatureId, bool lookInDatabase=false, bool withLandmarks=false) const
std::multimap< int, Link >::iterator RTABMAP_EXP findLink(std::multimap< int, Link > &links, int from, int to, bool checkBothWays=true)
void RTABMAP_EXP calcRelativeErrors(const std::vector< Transform > &poses_gt, const std::vector< Transform > &poses_result, float &t_err, float &r_err)
bool RTABMAP_EXP importPoses(const std::string &filePath, int format, std::map< int, Transform > &poses, std::multimap< int, Link > *constraints=0, std::map< int, double > *stamps=0)
ULogger class and convenient macros.
std::list< std::map< int, Transform > > RTABMAP_EXP getPaths(std::map< int, Transform > poses, const std::multimap< int, Link > &links)
GLM_FUNC_DECL genType acos(genType const &x)
GLM_FUNC_DECL T yaw(detail::tquat< T, P > const &x)
void setCostSoFar(float costSoFar)
static const GLushort kIndices[]
bool saveGraph(const std::string &fileName, const std::map< int, Transform > &poses, const std::multimap< int, Link > &edgeConstraints)
GLM_FUNC_DECL genType::value_type length(genType const &x)
static bool loadGraph(const std::string &fileName, std::map< int, Transform > &poses, std::multimap< int, Link > &edgeConstraints)
float RTABMAP_EXP computePathLength(const std::vector< std::pair< int, Transform > > &path, unsigned int fromIndex=0, unsigned int toIndex=0)
std::string UTILITE_EXP uFormat(const char *fmt,...)
V uValue(const std::map< K, V > &m, const K &key, const V &defaultValue=V())
void setFromId(int fromId)
std::map< int, Transform > RTABMAP_EXP frustumPosesFiltering(const std::map< int, Transform > &poses, const Transform &cameraPose, float horizontalFOV=45.0f, float verticalFOV=45.0f, float nearClipPlaneDistance=0.1f, float farClipPlaneDistance=100.0f, bool negative=false)
std::map< int, float > RTABMAP_EXP findNearestNodes(const std::map< int, rtabmap::Transform > &nodes, const rtabmap::Transform &targetPose, int k)
void RTABMAP_EXP calcKittiSequenceErrors(const std::vector< Transform > &poses_gt, const std::vector< Transform > &poses_result, float &t_err, float &r_err)
errors(int32_t first_frame, float r_err, float t_err, float len, float speed)