Point Cloud Library (PCL)  1.10.1
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 #ifndef _PCL_TEST_GPU_OCTREE_DATAGEN_
38 #define _PCL_TEST_GPU_OCTREE_DATAGEN_
39 
40 #include <vector>
41 #include <algorithm>
42 #include <iostream>
43 #include <Eigen/StdVector>
44 #include <cstdlib>
45 
46 
47 #if defined (_WIN32) || defined(_WIN64)
48  EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(pcl::PointXYZ)
49 #endif
50 
52 {
54 
55  std::size_t data_size;
56  std::size_t tests_num;
57 
58  float cube_size;
59  float max_radius;
60 
62 
63  std::vector<PointType> points;
64  std::vector<PointType> queries;
65  std::vector<float> radiuses;
66  std::vector< std::vector<int> > bfresutls;
67 
68  std::vector<int> indices;
69 
70  DataGenerator() : data_size(871000), tests_num(10000), cube_size(1024.f)
71  {
72  max_radius = cube_size/15.f;
73  shared_radius = cube_size/20.f;
74  }
75 
76  void operator()()
77  {
78  srand (0);
79 
80  points.resize(data_size);
81  for(std::size_t i = 0; i < data_size; ++i)
82  {
83  points[i].x = ((float)rand())/RAND_MAX * cube_size;
84  points[i].y = ((float)rand())/RAND_MAX * cube_size;
85  points[i].z = ((float)rand())/RAND_MAX * cube_size;
86  }
87 
88 
89  queries.resize(tests_num);
90  radiuses.resize(tests_num);
91  for (std::size_t i = 0; i < tests_num; ++i)
92  {
93  queries[i].x = ((float)rand())/RAND_MAX * cube_size;
94  queries[i].y = ((float)rand())/RAND_MAX * cube_size;
95  queries[i].z = ((float)rand())/RAND_MAX * cube_size;
96  radiuses[i] = ((float)rand())/RAND_MAX * max_radius;
97  };
98 
99  for(std::size_t i = 0; i < tests_num/2; ++i)
100  indices.push_back(i*2);
101  }
102 
103  void bruteForceSearch(bool log = false, float radius = -1.f)
104  {
105  if (log)
106  std::cout << "BruteForceSearch";
107 
108  int value100 = std::min<int>(tests_num, 50);
109  int step = tests_num/value100;
110 
111  bfresutls.resize(tests_num);
112  for(std::size_t i = 0; i < tests_num; ++i)
113  {
114  if (log && i % step == 0)
115  {
116  std::cout << ".";
117  std::cout.flush();
118  }
119 
120  std::vector<int>& curr_res = bfresutls[i];
121  curr_res.clear();
122 
123  float query_radius = radius > 0 ? radius : radiuses[i];
124  const PointType& query = queries[i];
125 
126  for(std::size_t ind = 0; ind < points.size(); ++ind)
127  {
128  const PointType& point = points[ind];
129 
130  float dx = query.x - point.x;
131  float dy = query.y - point.y;
132  float dz = query.z - point.z;
133 
134  if (dx*dx + dy*dy + dz*dz < query_radius * query_radius)
135  curr_res.push_back(ind);
136  }
137 
138  std::sort(curr_res.begin(), curr_res.end());
139  }
140  if (log)
141  std::cout << "Done" << std::endl;
142  }
143 
144  void printParams() const
145  {
146  std::cout << "Points number = " << data_size << std::endl;
147  std::cout << "Queries number = " << tests_num << std::endl;
148  std::cout << "Cube size = " << cube_size << std::endl;
149  std::cout << "Max radius = " << max_radius << std::endl;
150  std::cout << "Shared radius = " << shared_radius << std::endl;
151  }
152 
153  template<typename Dst>
154  struct ConvPoint
155  {
156  Dst operator()(const PointType& src) const
157  {
158  Dst dst;
159  dst.x = src.x;
160  dst.y = src.y;
161  dst.z = src.z;
162  return dst;
163  }
164  };
165 
166 };
167 
168 #endif /* _PCL_TEST_GPU_OCTREE_DATAGEN_ */
169 
170 
171 
DataGenerator::operator()
void operator()()
Definition: data_source.hpp:76
DataGenerator::printParams
void printParams() const
Definition: data_source.hpp:144
DataGenerator::tests_num
std::size_t tests_num
Definition: data_source.hpp:56
DataGenerator::cube_size
float cube_size
Definition: data_source.hpp:58
DataGenerator::DataGenerator
DataGenerator()
Definition: data_source.hpp:70
pcl::PointXYZ
A point structure representing Euclidean xyz coordinates.
Definition: point_types.hpp:292
DataGenerator::ConvPoint::operator()
Dst operator()(const PointType &src) const
Definition: data_source.hpp:156
DataGenerator::ConvPoint
Definition: data_source.hpp:154
DataGenerator::radiuses
std::vector< float > radiuses
Definition: data_source.hpp:65
DataGenerator::max_radius
float max_radius
Definition: data_source.hpp:59
pcl::gpu::Octree::PointType
pcl::PointXYZ PointType
Point typwe supported.
Definition: octree.hpp:71
DataGenerator::queries
std::vector< PointType > queries
Definition: data_source.hpp:64
DataGenerator::bfresutls
std::vector< std::vector< int > > bfresutls
Definition: data_source.hpp:66
DataGenerator::indices
std::vector< int > indices
Definition: data_source.hpp:68
DataGenerator::data_size
std::size_t data_size
Definition: data_source.hpp:55
DataGenerator::shared_radius
float shared_radius
Definition: data_source.hpp:61
DataGenerator::bruteForceSearch
void bruteForceSearch(bool log=false, float radius=-1.f)
Definition: data_source.hpp:103
DataGenerator
Definition: data_source.hpp:51
DataGenerator::points
std::vector< PointType > points
Definition: data_source.hpp:63