Point Cloud Library (PCL)  1.11.0
data_source.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * Author: Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
35  */
36 
37 
38 #ifndef _PCL_TEST_GPU_OCTREE_DATAGEN_
39 #define _PCL_TEST_GPU_OCTREE_DATAGEN_
40 
41 #include <vector>
42 #include <algorithm>
43 #include <iostream>
44 #include <Eigen/StdVector>
45 #include <cstdlib>
46 
47 
48 #if defined (_WIN32) || defined(_WIN64)
49  EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(pcl::PointXYZ)
50 #endif
51 
52 
53 namespace pcl
54 {
55 
56 namespace gpu
57 {
58 
60 {
62 
63  std::size_t data_size;
64  std::size_t tests_num;
65 
66  float cube_size;
67  float max_radius;
68 
70 
71  std::vector<PointType> points;
72  std::vector<PointType> queries;
73  std::vector<float> radiuses;
74  std::vector< std::vector<int> > bfresutls;
75 
76  std::vector<int> indices;
77 
78  DataGenerator() : data_size(871000), tests_num(10000), cube_size(1024.f)
79  {
80  max_radius = cube_size/15.f;
81  shared_radius = cube_size/20.f;
82  }
83 
84  void operator()()
85  {
86  srand (0);
87 
88  points.resize(data_size);
89  for(std::size_t i = 0; i < data_size; ++i)
90  {
91  points[i].x = ((float)rand())/RAND_MAX * cube_size;
92  points[i].y = ((float)rand())/RAND_MAX * cube_size;
93  points[i].z = ((float)rand())/RAND_MAX * cube_size;
94  }
95 
96 
97  queries.resize(tests_num);
98  radiuses.resize(tests_num);
99  for (std::size_t i = 0; i < tests_num; ++i)
100  {
101  queries[i].x = ((float)rand())/RAND_MAX * cube_size;
102  queries[i].y = ((float)rand())/RAND_MAX * cube_size;
103  queries[i].z = ((float)rand())/RAND_MAX * cube_size;
104  radiuses[i] = ((float)rand())/RAND_MAX * max_radius;
105  };
106 
107  for(std::size_t i = 0; i < tests_num/2; ++i)
108  indices.push_back(i*2);
109  }
110 
111  void bruteForceSearch(bool log = false, float radius = -1.f)
112  {
113  if (log)
114  std::cout << "BruteForceSearch";
115 
116  int value100 = std::min<int>(tests_num, 50);
117  int step = tests_num/value100;
118 
119  bfresutls.resize(tests_num);
120  for(std::size_t i = 0; i < tests_num; ++i)
121  {
122  if (log && i % step == 0)
123  {
124  std::cout << ".";
125  std::cout.flush();
126  }
127 
128  std::vector<int>& curr_res = bfresutls[i];
129  curr_res.clear();
130 
131  float query_radius = radius > 0 ? radius : radiuses[i];
132  const PointType& query = queries[i];
133 
134  for(std::size_t ind = 0; ind < points.size(); ++ind)
135  {
136  const PointType& point = points[ind];
137 
138  float dx = query.x - point.x;
139  float dy = query.y - point.y;
140  float dz = query.z - point.z;
141 
142  if (dx*dx + dy*dy + dz*dz < query_radius * query_radius)
143  curr_res.push_back(ind);
144  }
145 
146  std::sort(curr_res.begin(), curr_res.end());
147  }
148  if (log)
149  std::cout << "Done" << std::endl;
150  }
151 
152  void printParams() const
153  {
154  std::cout << "Points number = " << data_size << std::endl;
155  std::cout << "Queries number = " << tests_num << std::endl;
156  std::cout << "Cube size = " << cube_size << std::endl;
157  std::cout << "Max radius = " << max_radius << std::endl;
158  std::cout << "Shared radius = " << shared_radius << std::endl;
159  }
160 
161  template<typename Dst>
162  struct ConvPoint
163  {
164  Dst operator()(const PointType& src) const
165  {
166  Dst dst;
167  dst.x = src.x;
168  dst.y = src.y;
169  dst.z = src.z;
170  return dst;
171  }
172  };
173 };
174 
175 } // namespace gpu
176 } // namespace pcl
177 
178 #endif /* _PCL_TEST_GPU_OCTREE_DATAGEN_ */
179 
pcl::gpu::DataGenerator::queries
std::vector< PointType > queries
Definition: data_source.hpp:72
pcl
Definition: convolution.h:46
pcl::gpu::DataGenerator
Definition: data_source.hpp:60
pcl::gpu::DataGenerator::max_radius
float max_radius
Definition: data_source.hpp:67
pcl::gpu::DataGenerator::points
std::vector< PointType > points
Definition: data_source.hpp:71
pcl::gpu::DataGenerator::ConvPoint::operator()
Dst operator()(const PointType &src) const
Definition: data_source.hpp:164
pcl::gpu::DataGenerator::printParams
void printParams() const
Definition: data_source.hpp:152
pcl::gpu::DataGenerator::data_size
std::size_t data_size
Definition: data_source.hpp:63
pcl::gpu::DataGenerator::bruteForceSearch
void bruteForceSearch(bool log=false, float radius=-1.f)
Definition: data_source.hpp:111
pcl::gpu::DataGenerator::bfresutls
std::vector< std::vector< int > > bfresutls
Definition: data_source.hpp:74
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:301
pcl::gpu::DataGenerator::radiuses
std::vector< float > radiuses
Definition: data_source.hpp:73
pcl::gpu::DataGenerator::DataGenerator
DataGenerator()
Definition: data_source.hpp:78
pcl::gpu::DataGenerator::shared_radius
float shared_radius
Definition: data_source.hpp:69
pcl::gpu::Octree::PointType
pcl::PointXYZ PointType
Point typwe supported.
Definition: octree.hpp:72
pcl::gpu::DataGenerator::ConvPoint
Definition: data_source.hpp:163
pcl::gpu::DataGenerator::indices
std::vector< int > indices
Definition: data_source.hpp:76
pcl::gpu::DataGenerator::cube_size
float cube_size
Definition: data_source.hpp:66
pcl::gpu::DataGenerator::tests_num
std::size_t tests_num
Definition: data_source.hpp:64
pcl::gpu::DataGenerator::operator()
void operator()()
Definition: data_source.hpp:84