performance_raycast.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, the mcl_3dl authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <cstddef>
31 #include <cmath>
32 #include <vector>
33 
34 #include <boost/chrono.hpp>
35 
36 #include <mcl_3dl/chunked_kdtree.h>
37 #include <mcl_3dl/raycast.h>
38 
39 void performanceTestRaycast(const float chunk_size)
40 {
41  std::cerr << "## Chunk size: " << chunk_size << std::endl;
42  const auto ts = boost::chrono::high_resolution_clock::now();
43  pcl::PointCloud<pcl::PointXYZ> pc;
44  for (float y = -50.0; y < 50.0; y += 0.1)
45  {
46  for (float z = -50.0; z < 50.0; z += 0.1)
47  {
48  pc.push_back(pcl::PointXYZ(5.0, y, z));
49  pc.push_back(pcl::PointXYZ(y + 10.0, 1.5, z));
50  }
51  }
53  new mcl_3dl::ChunkedKdtree<pcl::PointXYZ>(chunk_size, 0.1));
54  kdtree->setInputCloud(pc.makeShared());
55  const auto tnow = boost::chrono::high_resolution_clock::now();
56  std::cerr << "- Generate kdtree: "
57  << boost::chrono::duration<float>(tnow - ts).count()
58  << " sec" << std::endl;
59 
60  const auto ts2 = boost::chrono::high_resolution_clock::now();
61  size_t collision_cnt = 0;
62  size_t cnt = 0;
63  for (float y = -50.0; y < 50.0; y += 1.2)
64  {
65  for (float z = -50.0; z < 50.0; z += 1.1)
66  {
67  cnt++;
69  kdtree,
70  mcl_3dl::Vec3(0.0, 0.0, 0.0), mcl_3dl::Vec3(1.0, y * 2.0, z * 2.0), 0.1, 0.1);
71  for (auto point : ray)
72  {
73  if (point.collision_)
74  {
75  collision_cnt++;
76  break;
77  }
78  }
79  }
80  }
81  std::cerr << "- Collisions: " << collision_cnt << "/" << cnt << std::endl;
82  const auto tnow2 = boost::chrono::high_resolution_clock::now();
83  std::cerr << "- mcl_3dl::Raycast: "
84  << boost::chrono::duration<float>(tnow2 - ts2).count()
85  << " sec" << std::endl;
86  std::cerr << std::endl;
87 }
88 
89 int main(int argc, char** argv)
90 {
98 
99  return 0;
100 }
std::shared_ptr< ChunkedKdtree > Ptr
TFSIMD_FORCE_INLINE const tfScalar & y() const
int main(int argc, char **argv)
void setInputCloud(const typename pcl::PointCloud< POINT_TYPE >::ConstPtr cloud)
TFSIMD_FORCE_INLINE const tfScalar & z() const
void performanceTestRaycast(const float chunk_size)


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Mon Jul 8 2019 03:32:36