Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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 }