Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <pcl/io/pcd_io.h>
00041 #include <pcl/point_types.h>
00042 #include <pcl/common/transforms.h>
00043 #include <pcl/registration/icp.h>
00044 #include <pcl/registration/elch.h>
00045
00046 #include <iostream>
00047 #include <string>
00048
00049 #include <vector>
00050
00051 typedef pcl::PointXYZ PointType;
00052 typedef pcl::PointCloud<PointType> Cloud;
00053 typedef Cloud::ConstPtr CloudConstPtr;
00054 typedef Cloud::Ptr CloudPtr;
00055 typedef std::pair<std::string, CloudPtr> CloudPair;
00056 typedef std::vector<CloudPair> CloudVector;
00057
00058 bool
00059 loopDetection (int end, const CloudVector &clouds, double dist, int &first, int &last)
00060 {
00061 static double min_dist = -1;
00062 int state = 0;
00063
00064 for (int i = end-1; i > 0; i--)
00065 {
00066 Eigen::Vector4f cstart, cend;
00067
00068 pcl::compute3DCentroid (*(clouds[i].second), cstart);
00069 pcl::compute3DCentroid (*(clouds[end].second), cend);
00070 Eigen::Vector4f diff = cend - cstart;
00071
00072 double norm = diff.norm ();
00073
00074
00075
00076 if (state == 0 && norm > dist)
00077 {
00078 state = 1;
00079
00080 }
00081 if (state > 0 && norm < dist)
00082 {
00083 state = 2;
00084
00085 if (min_dist < 0 || norm < min_dist)
00086 {
00087 min_dist = norm;
00088 first = i;
00089 last = end;
00090 }
00091 }
00092 }
00093
00094 if (min_dist > 0 && (state < 2 || end == int (clouds.size ()) - 1))
00095 {
00096 min_dist = -1;
00097 return true;
00098 }
00099 return false;
00100 }
00101
00102 int
00103 main (int argc, char **argv)
00104 {
00105 pcl::registration::ELCH<PointType> elch;
00106 pcl::IterativeClosestPoint<PointType, PointType>::Ptr icp (new pcl::IterativeClosestPoint<PointType, PointType>);
00107 icp->setMaximumIterations (100);
00108 icp->setMaxCorrespondenceDistance (0.1);
00109 icp->setRANSACOutlierRejectionThreshold (0.1);
00110 elch.setReg (icp);
00111
00112 CloudVector clouds;
00113 for (int i = 1; i < argc; i++)
00114 {
00115 CloudPtr pc (new Cloud);
00116 pcl::io::loadPCDFile (argv[i], *pc);
00117 clouds.push_back (CloudPair (argv[i], pc));
00118 std::cout << "loading file: " << argv[i] << " size: " << pc->size () << std::endl;
00119 elch.addPointCloud (clouds[i-1].second);
00120 }
00121
00122 int first = 0, last = 0;
00123
00124 for (size_t i = 0; i < clouds.size (); i++)
00125 {
00126
00127 if (loopDetection (int (i), clouds, 3.0, first, last))
00128 {
00129 std::cout << "Loop between " << first << " (" << clouds[first].first << ") and " << last << " (" << clouds[last].first << ")" << std::endl;
00130 elch.setLoopStart (first);
00131 elch.setLoopEnd (last);
00132 elch.compute ();
00133 }
00134 }
00135
00136 for (size_t i = 0; i < clouds.size (); i++)
00137 {
00138 std::string result_filename (clouds[i].first);
00139 result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
00140 pcl::io::savePCDFileBinary (result_filename.c_str (), *(clouds[i].second));
00141 std::cout << "saving result to " << result_filename << std::endl;
00142 }
00143
00144 return 0;
00145 }