test_shot_lrf_estimation.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the copyright holder(s) nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id$
00037  *
00038  */
00039 
00040 #include <gtest/gtest.h>
00041 #include <pcl/point_cloud.h>
00042 #include <pcl/pcl_tests.h>
00043 #include <pcl/io/pcd_io.h>
00044 #include <pcl/features/shot_lrf.h>
00045 
00046 using namespace pcl;
00047 using namespace pcl::test;
00048 using namespace pcl::io;
00049 using namespace std;
00050 
00051 typedef search::KdTree<PointXYZ>::Ptr KdTreePtr;
00052 
00053 PointCloud<PointXYZ> cloud;
00054 vector<int> indices;
00055 KdTreePtr tree;
00056 
00058 TEST (PCL, SHOTLocalReferenceFrameEstimation)
00059 {
00060   PointCloud<ReferenceFrame> bunny_LRF;
00061 
00062   boost::shared_ptr<vector<int> > indicesptr (new vector<int> (indices));
00063 
00064   // Compute SHOT LRF
00065   SHOTLocalReferenceFrameEstimation<PointXYZ, ReferenceFrame> lrf_estimator;
00066 
00067   float radius = 0.01f;
00068 
00069   lrf_estimator.setRadiusSearch (radius);
00070 
00071   lrf_estimator.setInputCloud (cloud.makeShared ());
00072   lrf_estimator.setSearchMethod (tree);
00073   lrf_estimator.setIndices (indicesptr);
00074 
00075   lrf_estimator.compute (bunny_LRF);
00076 
00077   // TESTS
00078   EXPECT_EQ (indices.size (), bunny_LRF.size ());
00079 
00080   EXPECT_FALSE (bunny_LRF.is_dense);
00081 
00082   // NaN result for point 24
00083   //EXPECT_EQ (numeric_limits<float>::max (), bunny_LRF.at (24).confidence);
00084   EXPECT_TRUE (pcl_isnan (bunny_LRF.at (24).x_axis[0]));
00085 
00086   // Expected Results
00087   // point 15: tanget disambiguation
00088   //float point_15_conf = 0;
00089   Eigen::Vector3f point_15_x (-0.849213f, 0.528016f, 0.00593846f);
00090   Eigen::Vector3f point_15_y (0.274564f, 0.451135f, -0.849171f);
00091   Eigen::Vector3f point_15_z (-0.451055f, -0.719497f, -0.528084f);
00092 
00093   //float point_45_conf = 0;
00094   Eigen::Vector3f point_45_x (0.950556f, 0.0673042f, 0.303171f);
00095   Eigen::Vector3f point_45_y (0.156242f, -0.947328f, -0.279569f);
00096   Eigen::Vector3f point_45_z (0.268386f, 0.313114f, -0.911004f);
00097 
00098   //float point_163_conf = 0;
00099   Eigen::Vector3f point_163_x (0.816369f, 0.309943f, -0.487317f);
00100   Eigen::Vector3f point_163_y (0.235273f, -0.949082f, -0.209498f);
00101   Eigen::Vector3f point_163_z (-0.527436f, 0.0563754f, -0.847722f);
00102 
00103   // point 311: normal disambiguation
00104   //float point_311_conf = 0;
00105   Eigen::Vector3f point_311_x (0.77608663f, -0.60673451f, 0.17193851f);
00106   Eigen::Vector3f point_311_y (0.49546647f, 0.75532055f, 0.42895663f);
00107   Eigen::Vector3f point_311_z (-0.39013144f, -0.24771771f, 0.88681078f);
00108 
00109   //Test Results
00110   //EXPECT_NEAR (point_15_conf,bunny_LRF.at (15).confidence, 1E-3);
00111   for (int d = 0; d < 3; ++d)
00112   {
00113     EXPECT_NEAR (point_15_x[d], bunny_LRF.at (15).x_axis[d], 1E-3);
00114     EXPECT_NEAR (point_15_y[d], bunny_LRF.at (15).y_axis[d], 1E-3);
00115     EXPECT_NEAR (point_15_z[d], bunny_LRF.at (15).z_axis[d], 1E-3);
00116 
00117     EXPECT_NEAR (point_45_x[d], bunny_LRF.at (45).x_axis[d], 1E-3);
00118     EXPECT_NEAR (point_45_y[d], bunny_LRF.at (45).y_axis[d], 1E-3);
00119     EXPECT_NEAR (point_45_z[d], bunny_LRF.at (45).z_axis[d], 1E-3);
00120 
00121     EXPECT_NEAR (point_163_x[d], bunny_LRF.at (163).x_axis[d], 1E-3);
00122     EXPECT_NEAR (point_163_y[d], bunny_LRF.at (163).y_axis[d], 1E-3);
00123     EXPECT_NEAR (point_163_z[d], bunny_LRF.at (163).z_axis[d], 1E-3);
00124 
00125     EXPECT_NEAR (point_311_x[d], bunny_LRF.at (311).x_axis[d], 1E-3);
00126     EXPECT_NEAR (point_311_y[d], bunny_LRF.at (311).y_axis[d], 1E-3);
00127     EXPECT_NEAR (point_311_z[d], bunny_LRF.at (311).z_axis[d], 1E-3);
00128   }
00129 }
00130 
00131 /* ---[ */
00132 int
00133 main (int argc, char** argv)
00134 {
00135   if (argc < 2)
00136   {
00137     std::cerr << "No test file given. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00138     return (-1);
00139   }
00140 
00141   if (loadPCDFile<PointXYZ> (argv[1], cloud) < 0)
00142   {
00143     std::cerr << "Failed to read test file. Please download `bun0.pcd` and pass its path to the test." << std::endl;
00144     return (-1);
00145   }
00146 
00147   indices.resize (cloud.points.size ());
00148   for (size_t i = 0; i < indices.size (); ++i)
00149     indices[i] = static_cast<int> (i);
00150 
00151   tree.reset (new search::KdTree<PointXYZ> (true));
00152   tree->setInputCloud (cloud.makeShared ());
00153 
00154   testing::InitGoogleTest (&argc, argv);
00155   return (RUN_ALL_TESTS ());
00156 }
00157 /* ]--- */


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:36:13