test.cpp
Go to the documentation of this file.
00001 
00064 // ROS includes
00065 #include <ros/ros.h>
00066 #include <pcl/point_types.h>
00067 #define PCL_MINOR (PCL_VERSION[2] - '0')
00068 
00069 #include <pcl_ros/transforms.h>
00070 #include <pcl_ros/point_cloud.h>
00071 #include <tf/transform_listener.h>
00072 #include <tf_conversions/tf_kdl.h>
00073 #include <pcl/io/pcd_io.h>
00074 #include <pcl/kdtree/kdtree.h>
00075 #include <pcl/kdtree/kdtree_flann.h>
00076 #include <pcl/registration/transformation_estimation_svd.h>
00077 #include <cob_3d_registration/feature_container.h>
00078 //#include <registration/registration_correspondence.h>
00079 #include <pcl/visualization/cloud_viewer.h>
00080 
00081 void
00082 show (pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud)
00083 {
00084   //... populate cloud
00085   pcl::visualization::CloudViewer viewer ("Simple Cloud Viewer");
00086   viewer.showCloud (cloud);
00087   while (!viewer.wasStopped ())
00088   {
00089   }
00090 }
00091 
00092 Eigen::Matrix4f getTransf(const Eigen::Vector3f &a, const Eigen::Vector3f &b, const Eigen::Vector3f &ap, const Eigen::Vector3f &bp)
00093 {
00094   pcl::registration::TransformationEstimationSVD<pcl::PointXYZRGB, pcl::PointXYZRGB> trans_est;
00095   pcl::PointCloud<pcl::PointXYZRGB> pc, pc2;
00096 
00097   pcl::PointXYZRGB p;
00098 
00099   p.x=a(0);
00100   p.y=a(1);
00101   p.z=a(2);
00102   pc.points.push_back(p);
00103   p.x=b(0);
00104   p.y=b(1);
00105   p.z=b(2);
00106   pc.points.push_back(p);
00107 
00108   p.x=ap(0);
00109   p.y=ap(1);
00110   p.z=ap(2);
00111   pc2.points.push_back(p);
00112   p.x=bp(0);
00113   p.y=bp(1);
00114   p.z=bp(2);
00115   pc2.points.push_back(p);
00116 
00117   Eigen::Matrix4f m=Eigen::Matrix4f::Identity();
00118   trans_est.estimateRigidTransformation (pc, pc2, m);
00119 
00120   return m;
00121 }
00122 
00123 int main(int argc, char **argv) {
00124 
00125   {
00126     pcl::PointCloud<pcl::PointXYZ> pc, pc2;
00127     pcl::PointXYZ p;
00128 
00129     p.x=0;
00130     p.y=0;
00131     p.z=0.1;
00132     pc.points.push_back(p);
00133 
00134     p.x=0;
00135     p.y=1;
00136     p.z=1;
00137     pc.points.push_back(p);
00138 
00139     Eigen::Vector3f a,b;
00140     a(0)=0;a(1)=0;a(2)=1;
00141     b(0)=0.1;a(1)=0;b(2)=1;
00142 
00143     Eigen::Quaternionf q;
00144     q.setFromTwoVectors(a,b);
00145 
00146     Eigen::Matrix4f m=Eigen::Matrix4f::Identity(), m2;
00147 
00148     for(int i=0; i<3; i++)
00149       for(int j=0; j<3; j++)
00150         m(i,j)=q.toRotationMatrix()(i,j);
00151 
00152     m(1,3)=0.5;
00153 
00154     std::cout<<m<<"\n\n";
00155 
00156     pcl::transformPointCloud(pc,pc2,m);
00157 
00158     pcl::registration::TransformationEstimationSVD<pcl::PointXYZ, pcl::PointXYZ> trans_est;
00159     trans_est.estimateRigidTransformation (pc, pc2, m2);
00160 
00161     std::cout<<m2<<"\n\n";
00162     Eigen::Vector4f t=p.getArray4fMap();
00163     std::cout<<(m*t)<<"\n\n";
00164     std::cout<<(m2*t)<<"\n\n";
00165     std::cout<<getTransf(pc[0].getVector3fMap(),pc[1].getVector3fMap(), pc2[0].getVector3fMap(),pc2[1].getVector3fMap())<<"\n\n";
00166   }
00167 
00168  /* if(argc<2)
00169     return 0;
00170 
00171   Keypoints_Segments<pcl::PointXYZRGB> seg;
00172   pcl::PointCloud<pcl::PointXYZRGB> pc,pc_out;
00173   pcl::PointCloud<PCAPoint> mids;
00174   pcl::io::loadPCDFile(argv[1],pc);
00175 
00176   //show(pc.makeShared());
00177 
00178   seg.extractFeatures(pc,pc_out,mids);
00179 
00180   pcl::io::savePCDFileBinary("a.pcd",pc_out);
00181   //pcl::io::savePCDFileBinary("b.pcd",mids);
00182   //show(pc_out.makeShared());
00183   //show(mids.makeShared());*/
00184 
00185   return 0;
00186 }


cob_3d_registration
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:02:36