00001
00060 #include <gtest/gtest.h>
00061 #include <cob_3d_mapping_common/cylinder.h>
00062 #include <cob_3d_mapping_common/ros_msg_conversions.h>
00063 #include <pcl/common/eigen.h>
00064 #include <pcl/io/pcd_io.h>
00065
00066 using namespace cob_3d_mapping;
00067
00068 struct CylinderData
00069 {
00070 CylinderData(unsigned int id,
00071 std::vector<float> color,
00072 Eigen::Vector3f sym_axis,
00073 Eigen::Vector3f x_axis,
00074 Eigen::Vector3f origin,
00075 double r,
00076 std::vector<std::vector<Eigen::Vector3f> > contours,
00077 std::vector<bool> holes)
00078 {
00079 id_ = id;
00080 color_ = color;
00081 sym_axis_ = sym_axis.normalized();
00082 origin_ = origin;
00083 r_ = r;
00084 if (sym_axis_[2] < 0 )
00085 {
00086 sym_axis_ = sym_axis_ * -1;
00087 }
00088 contours_3d_cyl_ = contours;
00089 holes_ = holes;
00090 Eigen::Affine3f t;
00091 pcl::getTransformationFromTwoUnitVectorsAndOrigin(sym_axis_, x_axis.cross(sym_axis_), origin_, t);
00092 std::cout << x_axis.cross(sym_axis_) << std::endl;
00093 pose_ = t.inverse();
00094 for(unsigned int i = 0; i < contours_3d_cyl_.size(); i++)
00095 {
00096 std::vector<Eigen::Vector3f> c_3d;
00097 for(unsigned int j = 0; j < contours_3d_cyl_[i].size(); j++)
00098 {
00099 Eigen::Vector3f p_3d = pose_ * contours_3d_cyl_[i][j];
00100 c_3d.push_back(p_3d);
00101 }
00102 contours_3d_.push_back(c_3d);
00103 }
00104 }
00105
00106 unsigned int id_;
00107 std::vector<float> color_;
00108 Eigen::Vector3f sym_axis_;
00109 Eigen::Vector3f origin_;
00110 double r_;
00111 std::vector<std::vector<Eigen::Vector2f> > contours_2d_;
00112 std::vector<std::vector<Eigen::Vector3f> > contours_3d_cyl_;
00113 std::vector<std::vector<Eigen::Vector3f> > contours_3d_;
00114 std::vector<bool> holes_;
00115 Eigen::Affine3f pose_;
00116 std::vector<unsigned int> merge_candidates_;
00117 };
00118
00119
00120 class CylinderTest : public ::testing::Test
00121 {
00122 protected:
00123 virtual void
00124 SetUp ()
00125 {
00126 std::vector<std::vector<Eigen::Vector3f> > contours;
00127 Eigen::Vector3f p1(-1,-1,0), p2(0,-1,1), p3(1,-1,0), p4(1,1,0), p5(0,1,1), p6(-1,1,0);
00128 std::vector<Eigen::Vector3f> c;
00129 c.push_back(p1);
00130 c.push_back(p2);
00131 c.push_back(p3);
00132 c.push_back(p4);
00133 c.push_back(p5);
00134 c.push_back(p6);
00135 contours.push_back(c);
00136 std::vector<bool> holes;
00137 holes.push_back(false);
00138 CylinderData* cd1 = new CylinderData(0, std::vector<float>(4,1), Eigen::Vector3f(0,1,0), Eigen::Vector3f(1,0,0), Eigen::Vector3f(0,0,0), 1.0, contours, holes);
00139 cd_.push_back(cd1);
00140
00141 contours.clear();
00142 c.clear();
00143 holes.clear();
00144 p1 = Eigen::Vector3f(-0.71,-1,0.71);
00145
00146 p3 = Eigen::Vector3f(0.71,-1,0.71);
00147 p4 = Eigen::Vector3f(0.71,1,0.71);
00148
00149 p6 = Eigen::Vector3f(-0.71,1,0.71);
00150 c.push_back(p1);
00151 c.push_back(p2);
00152 c.push_back(p3);
00153 c.push_back(p4);
00154 c.push_back(p5);
00155 c.push_back(p6);
00156 contours.push_back(c);
00157 holes.push_back(false);
00158 CylinderData* cd2 = new CylinderData(0, std::vector<float>(4,1), Eigen::Vector3f(0,1,0), Eigen::Vector3f(1,0,0), Eigen::Vector3f(1,0,0), 1.0, contours, holes);
00159 cd_.push_back(cd2);
00160 }
00161
00162 std::vector<CylinderData*> cd_;
00163 };
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 TEST_F(CylinderTest, creationWorks)
00179 {
00180 for(unsigned int i = 0; i < cd_.size(); i++)
00181 {
00182 cob_3d_mapping::Cylinder c(cd_[i]->id_, cd_[i]->origin_, cd_[i]->sym_axis_, cd_[i]->r_, cd_[i]->contours_3d_, cd_[i]->holes_, cd_[i]->color_);
00183 std::cout << "Pose " << c.pose_.matrix() << std::endl;
00184 std::cout << "Pose Inverse " << c.pose_.inverse().matrix() << std::endl;
00185 std::vector<std::vector<Eigen::Vector3f> > c_3d = c.getContours3D();
00186 std::cout << "Actual 3D contours" << std::endl;
00187 for(unsigned int j = 0; j < c_3d.size(); j++)
00188 {
00189 for(unsigned int k = 0; k < c_3d[j].size(); k++)
00190 {
00191 std::cout << cd_[i]->contours_3d_[j][k](0) << "," << cd_[i]->contours_3d_[j][k](1) << "," << cd_[i]->contours_3d_[j][k](2) << std::endl;
00192 }
00193 }
00194 std::cout << "Actual 3D contours in cyl coords" << std::endl;
00195 for(unsigned int j = 0; j < c_3d.size(); j++)
00196 {
00197 for(unsigned int k = 0; k < c_3d[j].size(); k++)
00198 {
00199 std::cout << cd_[i]->contours_3d_cyl_[j][k](0) << "," << cd_[i]->contours_3d_cyl_[j][k](1) << "," << cd_[i]->contours_3d_cyl_[j][k](2) << std::endl;
00200 }
00201 }
00202 std::cout << "Computed 3D contours" << std::endl;
00203 for(unsigned int j = 0; j < c_3d.size(); j++)
00204 {
00205 for(unsigned int k = 0; k < c_3d[j].size(); k++)
00206 {
00207 std::cout << c_3d[j][k](0) << "," << c_3d[j][k](1) << "," << c_3d[j][k](2) << std::endl;
00208 }
00209 }
00210 std::cout << "Computed 2D contours" << std::endl;
00211 for(unsigned int j = 0; j < c.contours_.size(); j++)
00212 {
00213 for(unsigned int k = 0; k < c.contours_[j].size(); k++)
00214 {
00215 std::cout << c.contours_[j][k](0) << "," << c.contours_[j][k](1) << std::endl;
00216 }
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 }
00234 }
00235
00236
00237 int main(int argc, char **argv)
00238 {
00239 testing::InitGoogleTest(&argc, argv);
00240 return RUN_ALL_TESTS();
00241 }
00242