performance_raycast.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 <cstddef>
00031 #include <cmath>
00032 #include <vector>
00033 
00034 #include <boost/chrono.hpp>
00035 
00036 #include <mcl_3dl/chunked_kdtree.h>
00037 #include <mcl_3dl/raycast.h>
00038 
00039 void performanceTestRaycast(const float chunk_size)
00040 {
00041   std::cerr << "## Chunk size: " << chunk_size << std::endl;
00042   const auto ts = boost::chrono::high_resolution_clock::now();
00043   pcl::PointCloud<pcl::PointXYZ> pc;
00044   for (float y = -50.0; y < 50.0; y += 0.1)
00045   {
00046     for (float z = -50.0; z < 50.0; z += 0.1)
00047     {
00048       pc.push_back(pcl::PointXYZ(5.0, y, z));
00049       pc.push_back(pcl::PointXYZ(y + 10.0, 1.5, z));
00050     }
00051   }
00052   mcl_3dl::ChunkedKdtree<pcl::PointXYZ>::Ptr kdtree(
00053       new mcl_3dl::ChunkedKdtree<pcl::PointXYZ>(chunk_size, 0.1));
00054   kdtree->setInputCloud(pc.makeShared());
00055   const auto tnow = boost::chrono::high_resolution_clock::now();
00056   std::cerr << "- Generate kdtree: "
00057             << boost::chrono::duration<float>(tnow - ts).count()
00058             << " sec" << std::endl;
00059 
00060   const auto ts2 = boost::chrono::high_resolution_clock::now();
00061   size_t collision_cnt = 0;
00062   size_t cnt = 0;
00063   for (float y = -50.0; y < 50.0; y += 1.2)
00064   {
00065     for (float z = -50.0; z < 50.0; z += 1.1)
00066     {
00067       cnt++;
00068       mcl_3dl::Raycast<pcl::PointXYZ> ray(
00069           kdtree,
00070           mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(1.0, y * 2.0, z * 2.0), 0.1, 0.1);
00071       for (auto point : ray)
00072       {
00073         if (point.collision_)
00074         {
00075           collision_cnt++;
00076           break;
00077         }
00078       }
00079     }
00080   }
00081   std::cerr << "- Collisions: " << collision_cnt << "/" << cnt << std::endl;
00082   const auto tnow2 = boost::chrono::high_resolution_clock::now();
00083   std::cerr << "- mcl_3dl::Raycast: "
00084             << boost::chrono::duration<float>(tnow2 - ts2).count()
00085             << " sec" << std::endl;
00086   std::cerr << std::endl;
00087 }
00088 
00089 int main(int argc, char** argv)
00090 {
00091   performanceTestRaycast(1.0);
00092   performanceTestRaycast(2.0);
00093   performanceTestRaycast(5.0);
00094   performanceTestRaycast(10.0);
00095   performanceTestRaycast(20.0);
00096   performanceTestRaycast(50.0);
00097   performanceTestRaycast(100.0);
00098 
00099   return 0;
00100 }


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