00001
00002
00003 #include <ndt_registration/ndt_matcher_d2d.h>
00004 #include <ndt_map/ndt_map.h>
00005 #include <ndt_map/pointcloud_utils.h>
00006
00007 #include "pcl/point_cloud.h"
00008 #include "pcl/io/pcd_io.h"
00009 #include <cstdio>
00010 #include <Eigen/Eigen>
00011 #include <Eigen/Geometry>
00012
00013 #include <iostream>
00014 #include <sstream>
00015
00016 using namespace std;
00017
00018 int
00019 main (int argc, char** argv)
00020 {
00021 if(argc!=9) {
00022 std::cout<<"usage "<<argv[0]<<" x y z r p t cloud1.wrl cloud2.wrl\n";
00023 return -1;
00024 }
00025
00026 istringstream roll_c(argv[4]),pitch_c(argv[5]),yaw_c(argv[6]),xoffset_c(argv[1]),yoffset_c(argv[2]),zoffset_c(argv[3]);
00027 double roll,pitch,yaw,xoffset,yoffset,zoffset;
00028 roll_c >> roll;
00029 pitch_c >> pitch;
00030 yaw_c >> yaw;
00031 xoffset_c >> xoffset;
00032 yoffset_c >> yoffset;
00033 zoffset_c >> zoffset;
00034
00035 printf("X %f Y %f Z %f Roll %f Pitch %f Yaw %f \n",xoffset,yoffset,zoffset,roll,pitch,yaw);
00036 pcl::PointCloud<pcl::PointXYZ> cloud, cloud_offset, cloud_trans;
00037 char fname[50];
00038 FILE *fout;
00039 double __res[] = {0.5, 1, 2, 4};
00040 std::vector<double> resolutions (__res, __res+sizeof(__res)/sizeof(double));
00041
00042 struct timeval tv_start,tv_end,tv_reg_start,tv_reg_end;
00043
00044 Eigen::Transform<double,3,Eigen::Affine,Eigen::ColMajor> Tout;
00045 Tout.setIdentity();
00046
00047 if(argc == 9)
00048 {
00049
00050 gettimeofday(&tv_start,NULL);
00051
00052
00053 if (pcl::io::loadPCDFile<pcl::PointXYZ> (argv[7], cloud) == -1)
00054 {
00055 std::cerr<<"Couldn't read file\n";
00056 return (-1);
00057 }
00058 if (pcl::io::loadPCDFile<pcl::PointXYZ> (argv[8], cloud_offset) == -1)
00059 {
00060 std::cerr<<"Couldn't read file\n";
00061 return (-1);
00062 }
00063
00064 Tout = Eigen::Translation<double,3>(xoffset,yoffset,zoffset)*
00065 Eigen::AngleAxis<double>(roll,Eigen::Vector3d::UnitX()) *
00066 Eigen::AngleAxis<double>(pitch,Eigen::Vector3d::UnitY()) *
00067 Eigen::AngleAxis<double>(yaw,Eigen::Vector3d::UnitZ()) ;
00068
00069
00070 lslgeneric::NDTMatcherD2D matcherD2D(false, false, resolutions);
00071 cloud_trans = cloud_offset;
00072 bool ret = matcherD2D.match(cloud,cloud_offset,Tout,true);
00073
00074 std::cout<<"Transform: \n"<<Tout.matrix()<<std::endl;
00075
00076 lslgeneric::transformPointCloudInPlace(Tout,cloud_trans);
00077 pcl::PointCloud<pcl::PointXYZRGB> cloud_comb;
00078 pcl::PointXYZRGB red(255,0,0);
00079 for(int i=0; i<cloud.points.size(); ++i ) {
00080 red.x = cloud.points[i].x;
00081 red.y = cloud.points[i].y;
00082 red.z = cloud.points[i].z;
00083 cloud_comb.points.push_back(red);
00084 }
00085 pcl::PointXYZRGB green(0,200,0);
00086 for(int i=0; i<cloud_offset.points.size(); ++i ) {
00087 green.x = cloud_offset.points[i].x;
00088 green.y = cloud_offset.points[i].y;
00089 green.z = cloud_offset.points[i].z;
00090 cloud_comb.points.push_back(green);
00091 }
00092 pcl::PointXYZRGB blue(10,20,200);
00093 for(int i=0; i<cloud_trans.points.size(); ++i ) {
00094 blue.x = cloud_trans.points[i].x;
00095 blue.y = cloud_trans.points[i].y;
00096 blue.z = cloud_trans.points[i].z;
00097 cloud_comb.points.push_back(blue);
00098 }
00099 cloud_comb.width=1;
00100 cloud_comb.height=cloud_comb.points.size();
00101 cloud_comb.is_dense = false;
00102 pcl::io::savePCDFileBinary ("test_pcd.pcd", cloud_comb);
00103
00104 }
00105 }