00001 #include <agile_grasp/quadric.h>
00002
00003 #include <pcl/io/pcd_io.h>
00004 #include <pcl/point_types.h>
00005 #include <pcl/search/organized.h>
00006 #include <pcl/kdtree/kdtree_flann.h>
00007 #include <set>
00008
00009 typedef pcl::PointCloud<pcl::PointXYZRGBA> PointCloud;
00010
00011 struct VectorComparator
00012 {
00013 bool operator ()(const Eigen::Vector3i& a, const Eigen::Vector3i& b)
00014 {
00015 return a(0) != b(0) || a(1) != b(1) || a(2) != b(2);
00016 }
00017 };
00018
00019 int main(int argc, char** argv)
00020 {
00021 double taubin_radius = 0.03;
00022
00023 std::string file = "/home/andreas/data/mlaffordance/round21l_reg.pcd";
00024 PointCloud::Ptr cloud(new PointCloud);
00025 if (pcl::io::loadPCDFile<pcl::PointXYZRGBA>(file, *cloud) == -1)
00026 {
00027 PCL_ERROR("Couldn't read input PCD file\n");
00028 return (-1);
00029 }
00030
00031 pcl::search::OrganizedNeighbor<pcl::PointXYZRGBA>::Ptr organized_neighbor(
00032 new pcl::search::OrganizedNeighbor<pcl::PointXYZRGBA>());
00033 std::vector<int> nn_outer_indices;
00034 std::vector<float> nn_outer_dists;
00035 pcl::KdTreeFLANN<pcl::PointXYZRGBA>::Ptr tree(new pcl::KdTreeFLANN<pcl::PointXYZRGBA>());
00036
00037 int sample_index = 0;
00038 if (cloud->isOrganized())
00039 {
00040 organized_neighbor->setInputCloud(cloud);
00041 organized_neighbor->radiusSearch(cloud->points[sample_index], taubin_radius, nn_outer_indices, nn_outer_dists);
00042 }
00043 else
00044 {
00045 tree->setInputCloud(cloud);
00046 tree->radiusSearch(cloud->points[sample_index], taubin_radius, nn_outer_indices, nn_outer_dists);
00047 }
00048
00049 Eigen::Matrix4d T_base, T_sqrt;
00050 T_base << 0, 0.445417, 0.895323, 0.22, 1, 0, 0, -0.02, 0, 0.895323, -0.445417, 0.24, 0, 0, 0, 1;
00051
00052 T_sqrt << 0.9366, -0.0162, 0.3500, -0.2863, 0.0151, 0.9999, 0.0058, 0.0058, -0.3501, -0.0002, 0.9367, 0.0554, 0, 0, 0, 1;
00053
00054 std::vector<Eigen::Matrix4d, Eigen::aligned_allocator<Eigen::Matrix4d> > T_cams;
00055 T_cams.push_back(T_base * T_sqrt.inverse());
00056
00057 Eigen::Vector3d sample = cloud->points[sample_index].getVector3fMap().cast<double>();
00058 Quadric quadric(T_cams, cloud, sample, true);
00059 quadric.fitQuadric(nn_outer_indices);
00060
00061 Eigen::MatrixXi cam_source = Eigen::MatrixXi::Zero(1, cloud->points.size());
00062 quadric.findTaubinNormalAxis(nn_outer_indices, cam_source);
00063
00064 quadric.print();
00065
00066 std::set<Eigen::Vector3i, VectorComparator> s;
00067 Eigen::Matrix3i M;
00068 M << 1,1,1,2,3,4,1,1,1;
00069 for (int i=0; i < M.rows(); i++)
00070 s.insert(M.row(i));
00071 std::cout << "M:" << std::endl;
00072 std::cout << M << std::endl;
00073 Eigen::Matrix<int, Eigen::Dynamic, 3> N(s.size(), 3);
00074 int i = 0;
00075 for (std::set<Eigen::Vector3i, VectorComparator>::iterator it=s.begin(); it!=s.end(); ++it)
00076 {
00077 N.row(i) = *it;
00078 i++;
00079 }
00080 std::cout << "N:" << std::endl;
00081 std::cout << N << std::endl;
00082
00083 return 0;
00084 }