Point Cloud Library (PCL)  1.9.1-dev
octree.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_GPU_OCTREE_
38 #define _PCL_GPU_OCTREE_
39 
40 #include <vector>
41 
42 #include <pcl/point_types.h>
43 #include <pcl/pcl_macros.h>
44 #include <pcl/gpu/containers/device_array.h>
45 #include <pcl/gpu/octree/device_format.hpp>
46 
47 namespace pcl
48 {
49  namespace gpu
50  {
51  /**
52  * \brief Octree implementation on GPU. It suppors parallel building and parallel batch search as well .
53  * \author Anaoly Baksheev, Itseez, myname.mysurname@mycompany.com
54  */
55 
57  {
58  public:
59 
60  /** \brief Default constructor.*/
61  Octree();
62 
63  /** \brief Denstructor.*/
64  virtual ~Octree();
65 
66  /** \brief Types */
67  using Ptr = boost::shared_ptr<Octree>;
68 
69  /** \brief Point typwe supported */
71 
72  /** \brief Point cloud supported */
74 
75  /** \brief Point Batch query cloud type */
77 
78  /** \brief Point Radiuses for batch query */
80 
81  /** \brief Point Indices for batch query */
83 
84  /** \brief Point Sqrt distances array type */
86 
88 
89  /** \brief Sets cloud for which octree is built */
90  void setCloud(const PointCloud& cloud_arg);
91 
92  /** \brief Performs parallel octree building */
93  void build();
94 
95  /** \brief Returns true if tree has been built */
96  bool isBuilt();
97 
98  /** \brief Downloads Octree from GPU to search using CPU function. It use useful for single (not-batch) search */
99  void internalDownload();
100 
101  /** \brief Performs search of all points within given radius on CPU. It call \a internalDownload if necessary
102  * \param[in] center center of sphere
103  * \param[in] radius radious of sphere
104  * \param[out] out indeces of points within give sphere
105  * \param[in] max_nn maximum numver of results returned
106  */
107  void radiusSearchHost(const PointType& center, float radius, std::vector<int>& out, int max_nn = INT_MAX);
108 
109  /** \brief Performs approximate nearest neighbor search on CPU. It call \a internalDownload if necessary
110  * \param[in] query 3D point for which neighbour is be fetched
111  * \param[out] out_index neighbour index
112  * \param[out] sqr_dist square distance to the neighbour returned
113  */
114  void approxNearestSearchHost(const PointType& query, int& out_index, float& sqr_dist);
115 
116  /** \brief Performs batch radius search on GPU
117  * \param[in] centers array of centers
118  * \param[in] radius radius for all queries
119  * \param[in] max_results max number of returned points for each querey
120  * \param[out] result results packed to single array
121  */
122  void radiusSearch(const Queries& centers, float radius, int max_results, NeighborIndices& result) const;
123 
124  /** \brief Performs batch radius search on GPU
125  * \param[in] centers array of centers
126  * \param[in] radiuses array of radiuses
127  * \param[in] max_results max number of returned points for each querey
128  * \param[out] result results packed to single array
129  */
130  void radiusSearch(const Queries& centers, const Radiuses& radiuses, int max_results, NeighborIndices& result) const;
131 
132  /** \brief Performs batch radius search on GPU
133  * \param[in] centers array of centers
134  * \param[in] indices indices for centers array (only for these points search is performed)
135  * \param[in] radius radius for all queries
136  * \param[in] max_results max number of returned points for each querey
137  * \param[out] result results packed to single array
138  */
139  void radiusSearch(const Queries& centers, const Indices& indices, float radius, int max_results, NeighborIndices& result) const;
140 
141  /** \brief Batch approximate nearest search on GPU
142  * \param[in] queries array of centers
143  * \param[out] result array of results ( one index for each query )
144  */
145  void approxNearestSearch(const Queries& queries, NeighborIndices& result) const;
146 
147  /** \brief Batch exact k-nearest search on GPU for k == 1 only!
148  * \param[in] queries array of centers
149  * \param[in] k number of neighbors (only k == 1 is supported)
150  * \param[out] results array of results
151  */
152  void nearestKSearchBatch(const Queries& queries, int k, NeighborIndices& results) const;
153 
154  /** \brief Desroys octree and release all resources */
155  void clear();
156  private:
157  void *impl;
158  bool built_;
159  };
160 
161  /** \brief Performs brute force radius search on GPU
162  * \param[in] cloud cloud where to search
163  * \param[in] query query point
164  * \param[in] radius radius
165  * \param[out] result indeces of points within give sphere
166  * \param[in] buffer buffer for intermediate results. Keep reference to it between calls to eliminate internal allocations
167  */
168  PCL_EXPORTS void bruteForceRadiusSearchGPU(const Octree::PointCloud& cloud, const Octree::PointType& query, float radius, DeviceArray<int>& result, DeviceArray<int>& buffer);
169  }
170 }
171 
172 #endif /* _PCL_GPU_OCTREE_ */
PCL_EXPORTS void bruteForceRadiusSearchGPU(const Octree::PointCloud &cloud, const Octree::PointType &query, float radius, DeviceArray< int > &result, DeviceArray< int > &buffer)
Performs brute force radius search on GPU.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
Octree implementation on GPU.
Definition: octree.hpp:56
boost::shared_ptr< Octree > Ptr
Types.
Definition: octree.hpp:67
Defines all the PCL implemented PointT point type structures.
A point structure representing Euclidean xyz coordinates.
const PointCloud * cloud_
Definition: octree.hpp:87
#define PCL_EXPORTS
Definition: pcl_macros.h:227
Defines all the PCL and non-PCL macros used.