Skip to content

Commit

Permalink
make icp tool use IncrementalICP
Browse files Browse the repository at this point in the history
This simplifies the code and gives a good example for using the class
  • Loading branch information
Michael Görner authored and v4hn committed Apr 13, 2015
1 parent 7a45f4c commit a0d306d
Showing 1 changed file with 23 additions and 40 deletions.
63 changes: 23 additions & 40 deletions tools/icp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <pcl/point_types.h>
#include <pcl/registration/icp.h>
#include <pcl/registration/icp_nl.h>
#include <pcl/registration/incremental_icp.h>

#include <string>
#include <iostream>
Expand Down Expand Up @@ -71,62 +72,44 @@ main (int argc, char **argv)
std::vector<int> pcd_indices;
pcd_indices = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");

CloudPtr model (new Cloud);
if (pcl::io::loadPCDFile (argv[pcd_indices[0]], *model) == -1)
pcl::IterativeClosestPoint<PointType, PointType>::Ptr icp;
if (nonLinear)
{
std::cout << "Could not read file" << std::endl;
return -1;
std::cout << "Using IterativeClosestPointNonLinear" << std::endl;
icp.reset (new pcl::IterativeClosestPointNonLinear<PointType, PointType> ());
}
std::cout << argv[pcd_indices[0]] << " width: " << model->width << " height: " << model->height << std::endl;

std::string result_filename (argv[pcd_indices[0]]);
result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
pcl::io::savePCDFile (result_filename.c_str (), *model);
std::cout << "saving first model to " << result_filename << std::endl;
else
{
std::cout << "Using IterativeClosestPoint" << std::endl;
icp.reset (new pcl::IterativeClosestPoint<PointType, PointType> ());
}
icp->setMaximumIterations (iter);
icp->setMaxCorrespondenceDistance (dist);
icp->setRANSACOutlierRejectionThreshold (rans);

Eigen::Matrix4f t (Eigen::Matrix4f::Identity ());
pcl::registration::IncrementalICP<PointType> iicp;
iicp.setICP (icp);

for (size_t i = 1; i < pcd_indices.size (); i++)
for (size_t i = 0; i < pcd_indices.size (); i++)
{
CloudPtr data (new Cloud);
if (pcl::io::loadPCDFile (argv[pcd_indices[i]], *data) == -1)
{
std::cout << "Could not read file" << std::endl;
return -1;
}
std::cout << argv[pcd_indices[i]] << " width: " << data->width << " height: " << data->height << std::endl;

pcl::IterativeClosestPoint<PointType, PointType> *icp;

if (nonLinear)
if (!iicp.registerCloud (data))
{
std::cout << "Using IterativeClosestPointNonLinear" << std::endl;
icp = new pcl::IterativeClosestPointNonLinear<PointType, PointType>();
}
else
{
std::cout << "Using IterativeClosestPoint" << std::endl;
icp = new pcl::IterativeClosestPoint<PointType, PointType>();
}

icp->setMaximumIterations (iter);
icp->setMaxCorrespondenceDistance (dist);
icp->setRANSACOutlierRejectionThreshold (rans);

icp->setInputTarget (model);

icp->setInputSource (data);
std::cout << "Registration failed. Resetting transform" << std::endl;
iicp.reset ();
iicp.registerCloud (data);
};

CloudPtr tmp (new Cloud);
icp->align (*tmp);

t = t * icp->getFinalTransformation ();

pcl::transformPointCloud (*data, *tmp, t);

std::cout << icp->getFinalTransformation () << std::endl;
pcl::transformPointCloud (*data, *tmp, iicp.getAbsoluteTransform ());

*model = *data;
std::cout << iicp.getAbsoluteTransform () << std::endl;

std::string result_filename (argv[pcd_indices[i]]);
result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
Expand Down

0 comments on commit a0d306d

Please sign in to comment.