test_point_cloud_random_sampler.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2018, the mcl_3dl authors
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the copyright holder nor the names of its 
00014  *       contributors may be used to endorse or promote products derived from 
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <pcl/point_types.h>
00031 #include <pcl_ros/point_cloud.h>
00032 
00033 #include <mcl_3dl/point_cloud_random_sampler.h>
00034 
00035 #include <gtest/gtest.h>
00036 
00037 TEST(PointCloudRandomSampler, Sampling)
00038 {
00039   pcl::PointCloud<pcl::PointXYZ>::Ptr pc_input(new pcl::PointCloud<pcl::PointXYZ>);
00040   pc_input->width = 1;
00041   pc_input->height = 0;
00042   pc_input->header.frame_id = "frame0";
00043   pc_input->header.stamp = 12345;
00044 
00045   const float points_ref[][3] =
00046       {
00047         { 10, 11, 12 },
00048         { 20, 21, 22 },
00049         { 30, 31, 32 }
00050       };
00051   for (const auto& p_ref : points_ref)
00052   {
00053     pc_input->push_back(pcl::PointXYZ(p_ref[0], p_ref[1], p_ref[2]));
00054   }
00055 
00056   mcl_3dl::PointCloudRandomSampler sampler;
00057 
00058   for (size_t num = 1; num < 4; num++)
00059   {
00060     pcl::PointCloud<pcl::PointXYZ>::Ptr pc_output = sampler.sample<pcl::PointXYZ>(pc_input, num);
00061 
00062     // Check header and number of the points
00063     ASSERT_EQ(pc_output->header.frame_id, pc_input->header.frame_id);
00064     ASSERT_EQ(pc_output->header.stamp, pc_input->header.stamp);
00065     ASSERT_EQ(pc_output->height, 1u);
00066     ASSERT_EQ(pc_output->width, num);
00067 
00068     // Check that the all sampled points are in the original point array
00069     for (const pcl::PointXYZ& p : *pc_output)
00070     {
00071       bool found = false;
00072       for (const auto& p_ref : points_ref)
00073       {
00074         if (p_ref[0] == p.x && p_ref[1] == p.y && p_ref[2] == p.z)
00075         {
00076           found = true;
00077           break;
00078         }
00079       }
00080       ASSERT_TRUE(found) << "A sampled point is not in the original points array";
00081     }
00082   }
00083 
00084   // Make sure that the sampler returns 0 point output for 0 point input
00085   pcl::PointCloud<pcl::PointXYZ>::Ptr pc_output0 = sampler.sample<pcl::PointXYZ>(pc_input, 0);
00086   ASSERT_EQ(pc_output0->points.size(), 0u);
00087 }
00088 
00089 int main(int argc, char** argv)
00090 {
00091   testing::InitGoogleTest(&argc, argv);
00092 
00093   return RUN_ALL_TESTS();
00094 }


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Thu Jun 20 2019 20:04:43