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/console/parse.h>
00041 #include <pcl/io/pcd_io.h>
00042 #include <pcl/point_types.h>
00043 #include <pcl/common/transforms.h>
00044 #include <pcl/registration/lum.h>
00045 #include <pcl/registration/correspondence_estimation.h>
00046
00047 #include <iostream>
00048 #include <string>
00049
00050 #include <vector>
00051
00052 typedef pcl::PointXYZ PointType;
00053 typedef pcl::PointCloud<PointType> Cloud;
00054 typedef Cloud::ConstPtr CloudConstPtr;
00055 typedef Cloud::Ptr CloudPtr;
00056 typedef std::pair<std::string, CloudPtr> CloudPair;
00057 typedef std::vector<CloudPair> CloudVector;
00058
00059 int
00060 main (int argc, char **argv)
00061 {
00062 double dist = 2.5;
00063 pcl::console::parse_argument (argc, argv, "-d", dist);
00064
00065 int iter = 10;
00066 pcl::console::parse_argument (argc, argv, "-i", iter);
00067
00068 int lumIter = 1;
00069 pcl::console::parse_argument (argc, argv, "-l", lumIter);
00070
00071 pcl::registration::LUM<PointType> lum;
00072 lum.setMaxIterations (lumIter);
00073 lum.setConvergenceThreshold (0.001f);
00074
00075 std::vector<int> pcd_indices;
00076 pcd_indices = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");
00077
00078 CloudVector clouds;
00079 for (size_t i = 0; i < pcd_indices.size (); i++)
00080 {
00081 CloudPtr pc (new Cloud);
00082 pcl::io::loadPCDFile (argv[pcd_indices[i]], *pc);
00083 clouds.push_back (CloudPair (argv[pcd_indices[i]], pc));
00084 std::cout << "loading file: " << argv[pcd_indices[i]] << " size: " << pc->size () << std::endl;
00085 lum.addPointCloud (clouds[i].second);
00086 }
00087
00088 for (int i = 0; i < iter; i++)
00089 {
00090 for (size_t i = 1; i < clouds.size (); i++)
00091 for (size_t j = 0; j < i; j++)
00092 {
00093 Eigen::Vector4f ci, cj;
00094 pcl::compute3DCentroid (*(clouds[i].second), ci);
00095 pcl::compute3DCentroid (*(clouds[j].second), cj);
00096 Eigen::Vector4f diff = ci - cj;
00097
00098
00099
00100 if(diff.norm () < 5.0 && (i - j == 1 || i - j > 20))
00101 {
00102 if(i - j > 20)
00103 std::cout << "add connection between " << i << " (" << clouds[i].first << ") and " << j << " (" << clouds[j].first << ")" << std::endl;
00104 pcl::registration::CorrespondenceEstimation<PointType, PointType> ce;
00105 ce.setInputTarget (clouds[i].second);
00106 ce.setInputSource (clouds[j].second);
00107 pcl::CorrespondencesPtr corr (new pcl::Correspondences);
00108 ce.determineCorrespondences (*corr, dist);
00109 if (corr->size () > 2)
00110 lum.setCorrespondences (j, i, corr);
00111 }
00112 }
00113
00114 lum.compute ();
00115
00116 for(int i = 0; i < lum.getNumVertices (); i++)
00117 {
00118
00119 clouds[i].second = lum.getTransformedCloud (i);
00120 }
00121 }
00122
00123 for(int i = 0; i < lum.getNumVertices (); i++)
00124 {
00125 std::string result_filename (clouds[i].first);
00126 result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
00127 pcl::io::savePCDFileBinary (result_filename.c_str (), *(clouds[i].second));
00128
00129 }
00130
00131 return 0;
00132 }