Point Cloud Library (PCL)  1.11.1-dev
octree_search.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  */
38 
39 #pragma once
40 
41 #include <pcl/octree/octree_pointcloud.h>
42 #include <pcl/point_cloud.h>
43 
44 namespace pcl {
45 namespace octree {
46 
47 /** \brief @b Octree pointcloud search class
48  * \note This class provides several methods for spatial neighbor search based on octree
49  * structure
50  * \tparam PointT type of point used in pointcloud
51  * \ingroup octree
52  * \author Julius Kammerl (julius@kammerl.de)
53  */
54 template <typename PointT,
55  typename LeafContainerT = OctreeContainerPointIndices,
56  typename BranchContainerT = OctreeContainerEmpty>
58 : public OctreePointCloud<PointT, LeafContainerT, BranchContainerT> {
59 public:
60  // public typedefs
61  using IndicesPtr = shared_ptr<std::vector<int>>;
62  using IndicesConstPtr = shared_ptr<const std::vector<int>>;
63 
65  using PointCloudPtr = typename PointCloud::Ptr;
67 
68  // Boost shared pointers
69  using Ptr =
70  shared_ptr<OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>>;
71  using ConstPtr = shared_ptr<
73 
74  // Eigen aligned allocator
75  using AlignedPointTVector = std::vector<PointT, Eigen::aligned_allocator<PointT>>;
76 
78  using LeafNode = typename OctreeT::LeafNode;
79  using BranchNode = typename OctreeT::BranchNode;
80 
81  /** \brief Constructor.
82  * \param[in] resolution octree resolution at lowest octree level
83  */
84  OctreePointCloudSearch(const double resolution)
85  : OctreePointCloud<PointT, LeafContainerT, BranchContainerT>(resolution)
86  {}
87 
88  /** \brief Search for neighbors within a voxel at given point
89  * \param[in] point point addressing a leaf node voxel
90  * \param[out] point_idx_data the resultant indices of the neighboring voxel points
91  * \return "true" if leaf node exist; "false" otherwise
92  */
93  bool
94  voxelSearch(const PointT& point, std::vector<int>& point_idx_data);
95 
96  /** \brief Search for neighbors within a voxel at given point referenced by a point
97  * index
98  * \param[in] index the index in input cloud defining the query point
99  * \param[out] point_idx_data the resultant indices of the neighboring voxel points
100  * \return "true" if leaf node exist; "false" otherwise
101  */
102  bool
103  voxelSearch(const int index, std::vector<int>& point_idx_data);
104 
105  /** \brief Search for k-nearest neighbors at the query point.
106  * \param[in] cloud the point cloud data
107  * \param[in] index the index in \a cloud representing the query point
108  * \param[in] k the number of neighbors to search for
109  * \param[out] k_indices the resultant indices of the neighboring points (must be
110  * resized to \a k a priori!)
111  * \param[out] k_sqr_distances the resultant squared distances to the neighboring
112  * points (must be resized to \a k a priori!)
113  * \return number of neighbors found
114  */
115  inline int
117  int index,
118  int k,
119  std::vector<int>& k_indices,
120  std::vector<float>& k_sqr_distances)
121  {
122  return (nearestKSearch(cloud[index], k, k_indices, k_sqr_distances));
123  }
124 
125  /** \brief Search for k-nearest neighbors at given query point.
126  * \param[in] p_q the given query point
127  * \param[in] k the number of neighbors to search for
128  * \param[out] k_indices the resultant indices of the neighboring points (must be
129  * resized to k a priori!)
130  * \param[out] k_sqr_distances the resultant squared distances to the neighboring
131  * points (must be resized to k a priori!)
132  * \return number of neighbors found
133  */
134  int
135  nearestKSearch(const PointT& p_q,
136  int k,
137  std::vector<int>& k_indices,
138  std::vector<float>& k_sqr_distances);
139 
140  /** \brief Search for k-nearest neighbors at query point
141  * \param[in] index index representing the query point in the dataset given by \a
142  * setInputCloud. If indices were given in setInputCloud, index will be the position
143  * in the indices vector.
144  * \param[in] k the number of neighbors to search for
145  * \param[out] k_indices the resultant indices of the neighboring points (must be
146  * resized to \a k a priori!)
147  * \param[out] k_sqr_distances the resultant squared distances to the neighboring
148  * points (must be resized to \a k a priori!)
149  * \return number of neighbors found
150  */
151  int
152  nearestKSearch(int index,
153  int k,
154  std::vector<int>& k_indices,
155  std::vector<float>& k_sqr_distances);
156 
157  /** \brief Search for approx. nearest neighbor at the query point.
158  * \param[in] cloud the point cloud data
159  * \param[in] query_index the index in \a cloud representing the query point
160  * \param[out] result_index the resultant index of the neighbor point
161  * \param[out] sqr_distance the resultant squared distance to the neighboring point
162  * \return number of neighbors found
163  */
164  inline void
166  int query_index,
167  int& result_index,
168  float& sqr_distance)
169  {
170  return (approxNearestSearch(cloud[query_index], result_index, sqr_distance));
171  }
172 
173  /** \brief Search for approx. nearest neighbor at the query point.
174  * \param[in] p_q the given query point
175  * \param[out] result_index the resultant index of the neighbor point
176  * \param[out] sqr_distance the resultant squared distance to the neighboring point
177  */
178  void
179  approxNearestSearch(const PointT& p_q, int& result_index, float& sqr_distance);
180 
181  /** \brief Search for approx. nearest neighbor at the query point.
182  * \param[in] query_index index representing the query point in the dataset given by
183  * \a setInputCloud. If indices were given in setInputCloud, index will be the
184  * position in the indices vector.
185  * \param[out] result_index the resultant index of the neighbor point
186  * \param[out] sqr_distance the resultant squared distance to the neighboring point
187  * \return number of neighbors found
188  */
189  void
190  approxNearestSearch(int query_index, int& result_index, float& sqr_distance);
191 
192  /** \brief Search for all neighbors of query point that are within a given radius.
193  * \param[in] cloud the point cloud data
194  * \param[in] index the index in \a cloud representing the query point
195  * \param[in] radius the radius of the sphere bounding all of p_q's neighbors
196  * \param[out] k_indices the resultant indices of the neighboring points
197  * \param[out] k_sqr_distances the resultant squared distances to the neighboring
198  * points
199  * \param[in] max_nn if given, bounds the maximum returned neighbors to this value
200  * \return number of neighbors found in radius
201  */
202  int
203  radiusSearch(const PointCloud& cloud,
204  int index,
205  double radius,
206  std::vector<int>& k_indices,
207  std::vector<float>& k_sqr_distances,
208  unsigned int max_nn = 0)
209  {
210  return (radiusSearch(cloud[index], radius, k_indices, k_sqr_distances, max_nn));
211  }
212 
213  /** \brief Search for all neighbors of query point that are within a given radius.
214  * \param[in] p_q the given query point
215  * \param[in] radius the radius of the sphere bounding all of p_q's neighbors
216  * \param[out] k_indices the resultant indices of the neighboring points
217  * \param[out] k_sqr_distances the resultant squared distances to the neighboring
218  * points
219  * \param[in] max_nn if given, bounds the maximum returned neighbors to this value
220  * \return number of neighbors found in radius
221  */
222  int
223  radiusSearch(const PointT& p_q,
224  const double radius,
225  std::vector<int>& k_indices,
226  std::vector<float>& k_sqr_distances,
227  unsigned int max_nn = 0) const;
228 
229  /** \brief Search for all neighbors of query point that are within a given radius.
230  * \param[in] index index representing the query point in the dataset given by \a
231  * setInputCloud. If indices were given in setInputCloud, index will be the position
232  * in the indices vector
233  * \param[in] radius radius of the sphere bounding all of p_q's neighbors
234  * \param[out] k_indices the resultant indices of the neighboring points
235  * \param[out] k_sqr_distances the resultant squared distances to the neighboring
236  * points
237  * \param[in] max_nn if given, bounds the maximum returned neighbors to this value
238  * \return number of neighbors found in radius
239  */
240  int
241  radiusSearch(int index,
242  const double radius,
243  std::vector<int>& k_indices,
244  std::vector<float>& k_sqr_distances,
245  unsigned int max_nn = 0) const;
246 
247  /** \brief Get a PointT vector of centers of all voxels that intersected by a ray
248  * (origin, direction).
249  * \param[in] origin ray origin
250  * \param[in] direction ray direction vector
251  * \param[out] voxel_center_list results are written to this vector of PointT elements
252  * \param[in] max_voxel_count stop raycasting when this many voxels intersected (0:
253  * disable)
254  * \return number of intersected voxels
255  */
256  int
257  getIntersectedVoxelCenters(Eigen::Vector3f origin,
258  Eigen::Vector3f direction,
259  AlignedPointTVector& voxel_center_list,
260  int max_voxel_count = 0) const;
261 
262  /** \brief Get indices of all voxels that are intersected by a ray (origin,
263  * direction).
264  * \param[in] origin ray origin \param[in] direction ray direction vector
265  * \param[out] k_indices resulting point indices from intersected voxels
266  * \param[in] max_voxel_count stop raycasting when this many voxels intersected (0:
267  * disable)
268  * \return number of intersected voxels
269  */
270  int
271  getIntersectedVoxelIndices(Eigen::Vector3f origin,
272  Eigen::Vector3f direction,
273  std::vector<int>& k_indices,
274  int max_voxel_count = 0) const;
275 
276  /** \brief Search for points within rectangular search area
277  * Points exactly on the edges of the search rectangle are included.
278  * \param[in] min_pt lower corner of search area
279  * \param[in] max_pt upper corner of search area
280  * \param[out] k_indices the resultant point indices
281  * \return number of points found within search area
282  */
283  int
284  boxSearch(const Eigen::Vector3f& min_pt,
285  const Eigen::Vector3f& max_pt,
286  std::vector<int>& k_indices) const;
287 
288 protected:
289  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
290  // Octree-based search routines & helpers
291  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
292  /** \brief @b Priority queue entry for branch nodes
293  * \note This class defines priority queue entries for the nearest neighbor search.
294  * \author Julius Kammerl (julius@kammerl.de)
295  */
297  public:
298  /** \brief Empty constructor */
300 
301  /** \brief Constructor for initializing priority queue entry.
302  * \param _node pointer to octree node
303  * \param _key octree key addressing voxel in octree structure
304  * \param[in] _point_distance distance of query point to voxel center
305  */
306  prioBranchQueueEntry(OctreeNode* _node, OctreeKey& _key, float _point_distance)
307  : node(_node), point_distance(_point_distance), key(_key)
308  {}
309 
310  /** \brief Operator< for comparing priority queue entries with each other.
311  * \param[in] rhs the priority queue to compare this against
312  */
313  bool
315  {
316  return (this->point_distance > rhs.point_distance);
317  }
318 
319  /** \brief Pointer to octree node. */
320  const OctreeNode* node;
321 
322  /** \brief Distance to query point. */
324 
325  /** \brief Octree key. */
327  };
328 
329  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
330  /** \brief @b Priority queue entry for point candidates
331  * \note This class defines priority queue entries for the nearest neighbor point
332  * candidates.
333  * \author Julius Kammerl (julius@kammerl.de)
334  */
336  public:
337  /** \brief Empty constructor */
339 
340  /** \brief Constructor for initializing priority queue entry.
341  * \param[in] point_idx index for a dataset point given by \a setInputCloud
342  * \param[in] point_distance distance of query point to voxel center
343  */
344  prioPointQueueEntry(unsigned int& point_idx, float point_distance)
345  : point_idx_(point_idx), point_distance_(point_distance)
346  {}
347 
348  /** \brief Operator< for comparing priority queue entries with each other.
349  * \param[in] rhs priority queue to compare this against
350  */
351  bool
352  operator<(const prioPointQueueEntry& rhs) const
353  {
354  return (this->point_distance_ < rhs.point_distance_);
355  }
356 
357  /** \brief Index representing a point in the dataset given by \a setInputCloud. */
359 
360  /** \brief Distance to query point. */
362  };
363 
364  /** \brief Helper function to calculate the squared distance between two points
365  * \param[in] point_a point A
366  * \param[in] point_b point B
367  * \return squared distance between point A and point B
368  */
369  float
370  pointSquaredDist(const PointT& point_a, const PointT& point_b) const;
371 
372  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
373  // Recursive search routine methods
374  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
375 
376  /** \brief Recursive search method that explores the octree and finds neighbors within
377  * a given radius
378  * \param[in] point query point \param[in] radiusSquared squared search radius
379  * \param[in] node current octree node to be explored
380  * \param[in] key octree key addressing a leaf node.
381  * \param[in] tree_depth current depth/level in the octree
382  * \param[out] k_indices vector of indices found to be neighbors of query point
383  * \param[out] k_sqr_distances squared distances of neighbors to query point
384  * \param[in] max_nn maximum of neighbors to be found
385  */
386  void
388  const double radiusSquared,
389  const BranchNode* node,
390  const OctreeKey& key,
391  unsigned int tree_depth,
392  std::vector<int>& k_indices,
393  std::vector<float>& k_sqr_distances,
394  unsigned int max_nn) const;
395 
396  /** \brief Recursive search method that explores the octree and finds the K nearest
397  * neighbors
398  * \param[in] point query point
399  * \param[in] K amount of nearest neighbors to be found
400  * \param[in] node current octree node to be explored
401  * \param[in] key octree key addressing a leaf node.
402  * \param[in] tree_depth current depth/level in the octree
403  * \param[in] squared_search_radius squared search radius distance
404  * \param[out] point_candidates priority queue of nearest neigbor point candidates
405  * \return squared search radius based on current point candidate set found
406  */
407  double
409  const PointT& point,
410  unsigned int K,
411  const BranchNode* node,
412  const OctreeKey& key,
413  unsigned int tree_depth,
414  const double squared_search_radius,
415  std::vector<prioPointQueueEntry>& point_candidates) const;
416 
417  /** \brief Recursive search method that explores the octree and finds the approximate
418  * nearest neighbor
419  * \param[in] point query point
420  * \param[in] node current octree node to be explored
421  * \param[in] key octree key addressing a leaf node.
422  * \param[in] tree_depth current depth/level in the octree
423  * \param[out] result_index result index is written to this reference
424  * \param[out] sqr_distance squared distance to search
425  */
426  void
428  const BranchNode* node,
429  const OctreeKey& key,
430  unsigned int tree_depth,
431  int& result_index,
432  float& sqr_distance);
433 
434  /** \brief Recursively search the tree for all intersected leaf nodes and return a
435  * vector of voxel centers. This algorithm is based off the paper An Efficient
436  * Parametric Algorithm for Octree Traversal:
437  * http://wscg.zcu.cz/wscg2000/Papers_2000/X31.pdf
438  * \param[in] min_x octree nodes X coordinate of lower bounding box corner
439  * \param[in] min_y octree nodes Y coordinate of lower bounding box corner
440  * \param[in] min_z octree nodes Z coordinate of lower bounding box corner
441  * \param[in] max_x octree nodes X coordinate of upper bounding box corner
442  * \param[in] max_y octree nodes Y coordinate of upper bounding box corner
443  * \param[in] max_z octree nodes Z coordinate of upper bounding box corner
444  * \param[in] a
445  * \param[in] node current octree node to be explored
446  * \param[in] key octree key addressing a leaf node.
447  * \param[out] voxel_center_list results are written to this vector of PointT elements
448  * \param[in] max_voxel_count stop raycasting when this many voxels intersected (0:
449  * disable)
450  * \return number of voxels found
451  */
452  int
454  double min_y,
455  double min_z,
456  double max_x,
457  double max_y,
458  double max_z,
459  unsigned char a,
460  const OctreeNode* node,
461  const OctreeKey& key,
462  AlignedPointTVector& voxel_center_list,
463  int max_voxel_count) const;
464 
465  /** \brief Recursive search method that explores the octree and finds points within a
466  * rectangular search area
467  * \param[in] min_pt lower corner of search area
468  * \param[in] max_pt upper corner of search area
469  * \param[in] node current octree node to be explored
470  * \param[in] key octree key addressing a leaf node.
471  * \param[in] tree_depth current depth/level in the octree
472  * \param[out] k_indices the resultant point indices
473  */
474  void
475  boxSearchRecursive(const Eigen::Vector3f& min_pt,
476  const Eigen::Vector3f& max_pt,
477  const BranchNode* node,
478  const OctreeKey& key,
479  unsigned int tree_depth,
480  std::vector<int>& k_indices) const;
481 
482  /** \brief Recursively search the tree for all intersected leaf nodes and return a
483  * vector of indices. This algorithm is based off the paper An Efficient Parametric
484  * Algorithm for Octree Traversal: http://wscg.zcu.cz/wscg2000/Papers_2000/X31.pdf
485  * \param[in] min_x octree nodes X coordinate of lower bounding box corner
486  * \param[in] min_y octree nodes Y coordinate of lower bounding box corner
487  * \param[in] min_z octree nodes Z coordinate of lower bounding box corner
488  * \param[in] max_x octree nodes X coordinate of upper bounding box corner
489  * \param[in] max_y octree nodes Y coordinate of upper bounding box corner
490  * \param[in] max_z octree nodes Z coordinate of upper bounding box corner
491  * \param[in] a
492  * \param[in] node current octree node to be explored
493  * \param[in] key octree key addressing a leaf node.
494  * \param[out] k_indices resulting indices
495  * \param[in] max_voxel_count stop raycasting when this many voxels intersected (0:
496  * disable)
497  * \return number of voxels found
498  */
499  int
501  double min_y,
502  double min_z,
503  double max_x,
504  double max_y,
505  double max_z,
506  unsigned char a,
507  const OctreeNode* node,
508  const OctreeKey& key,
509  std::vector<int>& k_indices,
510  int max_voxel_count) const;
511 
512  /** \brief Initialize raytracing algorithm
513  * \param origin
514  * \param direction
515  * \param[in] min_x octree nodes X coordinate of lower bounding box corner
516  * \param[in] min_y octree nodes Y coordinate of lower bounding box corner
517  * \param[in] min_z octree nodes Z coordinate of lower bounding box corner
518  * \param[in] max_x octree nodes X coordinate of upper bounding box corner
519  * \param[in] max_y octree nodes Y coordinate of upper bounding box corner
520  * \param[in] max_z octree nodes Z coordinate of upper bounding box corner
521  * \param a
522  */
523  inline void
524  initIntersectedVoxel(Eigen::Vector3f& origin,
525  Eigen::Vector3f& direction,
526  double& min_x,
527  double& min_y,
528  double& min_z,
529  double& max_x,
530  double& max_y,
531  double& max_z,
532  unsigned char& a) const
533  {
534  // Account for division by zero when direction vector is 0.0
535  const float epsilon = 1e-10f;
536  if (direction.x() == 0.0)
537  direction.x() = epsilon;
538  if (direction.y() == 0.0)
539  direction.y() = epsilon;
540  if (direction.z() == 0.0)
541  direction.z() = epsilon;
542 
543  // Voxel childIdx remapping
544  a = 0;
545 
546  // Handle negative axis direction vector
547  if (direction.x() < 0.0) {
548  origin.x() = static_cast<float>(this->min_x_) + static_cast<float>(this->max_x_) -
549  origin.x();
550  direction.x() = -direction.x();
551  a |= 4;
552  }
553  if (direction.y() < 0.0) {
554  origin.y() = static_cast<float>(this->min_y_) + static_cast<float>(this->max_y_) -
555  origin.y();
556  direction.y() = -direction.y();
557  a |= 2;
558  }
559  if (direction.z() < 0.0) {
560  origin.z() = static_cast<float>(this->min_z_) + static_cast<float>(this->max_z_) -
561  origin.z();
562  direction.z() = -direction.z();
563  a |= 1;
564  }
565  min_x = (this->min_x_ - origin.x()) / direction.x();
566  max_x = (this->max_x_ - origin.x()) / direction.x();
567  min_y = (this->min_y_ - origin.y()) / direction.y();
568  max_y = (this->max_y_ - origin.y()) / direction.y();
569  min_z = (this->min_z_ - origin.z()) / direction.z();
570  max_z = (this->max_z_ - origin.z()) / direction.z();
571  }
572 
573  /** \brief Find first child node ray will enter
574  * \param[in] min_x octree nodes X coordinate of lower bounding box corner
575  * \param[in] min_y octree nodes Y coordinate of lower bounding box corner
576  * \param[in] min_z octree nodes Z coordinate of lower bounding box corner
577  * \param[in] mid_x octree nodes X coordinate of bounding box mid line
578  * \param[in] mid_y octree nodes Y coordinate of bounding box mid line
579  * \param[in] mid_z octree nodes Z coordinate of bounding box mid line
580  * \return the first child node ray will enter
581  */
582  inline int
584  double min_y,
585  double min_z,
586  double mid_x,
587  double mid_y,
588  double mid_z) const
589  {
590  int currNode = 0;
591 
592  if (min_x > min_y) {
593  if (min_x > min_z) {
594  // max(min_x, min_y, min_z) is min_x. Entry plane is YZ.
595  if (mid_y < min_x)
596  currNode |= 2;
597  if (mid_z < min_x)
598  currNode |= 1;
599  }
600  else {
601  // max(min_x, min_y, min_z) is min_z. Entry plane is XY.
602  if (mid_x < min_z)
603  currNode |= 4;
604  if (mid_y < min_z)
605  currNode |= 2;
606  }
607  }
608  else {
609  if (min_y > min_z) {
610  // max(min_x, min_y, min_z) is min_y. Entry plane is XZ.
611  if (mid_x < min_y)
612  currNode |= 4;
613  if (mid_z < min_y)
614  currNode |= 1;
615  }
616  else {
617  // max(min_x, min_y, min_z) is min_z. Entry plane is XY.
618  if (mid_x < min_z)
619  currNode |= 4;
620  if (mid_y < min_z)
621  currNode |= 2;
622  }
623  }
624 
625  return currNode;
626  }
627 
628  /** \brief Get the next visited node given the current node upper
629  * bounding box corner. This function accepts three float values, and
630  * three int values. The function returns the ith integer where the
631  * ith float value is the minimum of the three float values.
632  * \param[in] x current nodes X coordinate of upper bounding box corner
633  * \param[in] y current nodes Y coordinate of upper bounding box corner
634  * \param[in] z current nodes Z coordinate of upper bounding box corner
635  * \param[in] a next node if exit Plane YZ
636  * \param[in] b next node if exit Plane XZ
637  * \param[in] c next node if exit Plane XY
638  * \return the next child node ray will enter or 8 if exiting
639  */
640  inline int
641  getNextIntersectedNode(double x, double y, double z, int a, int b, int c) const
642  {
643  if (x < y) {
644  if (x < z)
645  return a;
646  return c;
647  }
648  if (y < z)
649  return b;
650  return c;
651  }
652 };
653 } // namespace octree
654 } // namespace pcl
655 
656 #ifdef PCL_NO_PRECOMPILE
657 #include <pcl/octree/impl/octree_search.hpp>
658 #endif
pcl
Definition: convolution.h:46
pcl::K
@ K
Definition: norms.h:54
pcl::octree::OctreePointCloudSearch::prioPointQueueEntry::prioPointQueueEntry
prioPointQueueEntry()
Empty constructor
Definition: octree_search.h:338
pcl::octree::OctreePointCloudSearch::getIntersectedVoxelIndicesRecursive
int getIntersectedVoxelIndicesRecursive(double min_x, double min_y, double min_z, double max_x, double max_y, double max_z, unsigned char a, const OctreeNode *node, const OctreeKey &key, std::vector< int > &k_indices, int max_voxel_count) const
Recursively search the tree for all intersected leaf nodes and return a vector of indices.
Definition: octree_search.hpp:861
pcl::octree::OctreePointCloudSearch::getIntersectedVoxelIndices
int getIntersectedVoxelIndices(Eigen::Vector3f origin, Eigen::Vector3f direction, std::vector< int > &k_indices, int max_voxel_count=0) const
Get indices of all voxels that are intersected by a ray (origin, direction).
Definition: octree_search.hpp:631
pcl::octree::OctreePointCloudSearch::AlignedPointTVector
std::vector< PointT, Eigen::aligned_allocator< PointT > > AlignedPointTVector
Definition: octree_search.h:75
pcl::octree::OctreePointCloudSearch::prioBranchQueueEntry::prioBranchQueueEntry
prioBranchQueueEntry(OctreeNode *_node, OctreeKey &_key, float _point_distance)
Constructor for initializing priority queue entry.
Definition: octree_search.h:306
pcl::octree::OctreePointCloudSearch::getKNearestNeighborRecursive
double getKNearestNeighborRecursive(const PointT &point, unsigned int K, const BranchNode *node, const OctreeKey &key, unsigned int tree_depth, const double squared_search_radius, std::vector< prioPointQueueEntry > &point_candidates) const
Recursive search method that explores the octree and finds the K nearest neighbors.
Definition: octree_search.hpp:224
pcl::octree::OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: octree_pointcloud.h:90
pcl::octree::OctreePointCloud
Octree pointcloud class
Definition: octree_pointcloud.h:72
pcl::octree::OctreePointCloudSearch::prioBranchQueueEntry::node
const OctreeNode * node
Pointer to octree node.
Definition: octree_search.h:320
pcl::octree::OctreePointCloudSearch::prioPointQueueEntry::operator<
bool operator<(const prioPointQueueEntry &rhs) const
Operator< for comparing priority queue entries with each other.
Definition: octree_search.h:352
pcl::octree::OctreePointCloudSearch::boxSearchRecursive
void boxSearchRecursive(const Eigen::Vector3f &min_pt, const Eigen::Vector3f &max_pt, const BranchNode *node, const OctreeKey &key, unsigned int tree_depth, std::vector< int > &k_indices) const
Recursive search method that explores the octree and finds points within a rectangular search area.
Definition: octree_search.hpp:519
pcl::octree::OctreePointCloudSearch::voxelSearch
bool voxelSearch(const PointT &point, std::vector< int > &point_idx_data)
Search for neighbors within a voxel at given point.
Definition: octree_search.hpp:50
pcl::octree::OctreePointCloudSearch::nearestKSearch
int nearestKSearch(const PointCloud &cloud, int index, int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances)
Search for k-nearest neighbors at the query point.
Definition: octree_search.h:116
pcl::octree::OctreePointCloudSearch::getNeighborsWithinRadiusRecursive
void getNeighborsWithinRadiusRecursive(const PointT &point, const double radiusSquared, const BranchNode *node, const OctreeKey &key, unsigned int tree_depth, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn) const
Recursive search method that explores the octree and finds neighbors within a given radius.
Definition: octree_search.hpp:336
pcl::octree::OctreePointCloudSearch::getIntersectedVoxelCenters
int getIntersectedVoxelCenters(Eigen::Vector3f origin, Eigen::Vector3f direction, AlignedPointTVector &voxel_center_list, int max_voxel_count=0) const
Get a PointT vector of centers of all voxels that intersected by a ray (origin, direction).
Definition: octree_search.hpp:595
pcl::octree::OctreeKey
Octree key class
Definition: octree_key.h:52
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::octree::OctreePointCloudSearch::radiusSearch
int radiusSearch(const PointCloud &cloud, int index, double radius, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0)
Search for all neighbors of query point that are within a given radius.
Definition: octree_search.h:203
pcl::octree::OctreePointCloudSearch::approxNearestSearch
void approxNearestSearch(const PointCloud &cloud, int query_index, int &result_index, float &sqr_distance)
Search for approx.
Definition: octree_search.h:165
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:628
pcl::octree::OctreeNode
Abstract octree node class
Definition: octree_nodes.h:58
pcl::octree::OctreePointCloud< PointT, OctreeContainerPointIndices, OctreeContainerEmpty >::min_y_
double min_y_
Definition: octree_pointcloud.h:587
pcl::octree::OctreePointCloudSearch::prioPointQueueEntry
Priority queue entry for point candidates
Definition: octree_search.h:335
pcl::octree::OctreeLeafNode
Abstract octree leaf class
Definition: octree_nodes.h:80
pcl::octree::OctreePointCloudSearch::prioPointQueueEntry::point_idx_
int point_idx_
Index representing a point in the dataset given by setInputCloud.
Definition: octree_search.h:358
pcl::octree::OctreePointCloudSearch::prioPointQueueEntry::point_distance_
float point_distance_
Distance to query point.
Definition: octree_search.h:361
pcl::octree::OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >::ConstPtr
shared_ptr< const OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty, OctreeBase< pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty > > > ConstPtr
Definition: octree_pointcloud.h:104
pcl::octree::OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >::IndicesConstPtr
shared_ptr< const std::vector< int > > IndicesConstPtr
Definition: octree_pointcloud.h:86
pcl::octree::OctreeBase< pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >
pcl::octree::OctreePointCloudSearch::prioBranchQueueEntry::key
OctreeKey key
Octree key.
Definition: octree_search.h:326
pcl::octree::OctreePointCloudSearch::OctreePointCloudSearch
OctreePointCloudSearch(const double resolution)
Constructor.
Definition: octree_search.h:84
pcl::octree::OctreeBranchNode
Abstract octree branch class
Definition: octree_nodes.h:179
pcl::octree::OctreePointCloudSearch::prioBranchQueueEntry::point_distance
float point_distance
Distance to query point.
Definition: octree_search.h:323
pcl::octree::OctreePointCloudSearch::getNextIntersectedNode
int getNextIntersectedNode(double x, double y, double z, int a, int b, int c) const
Get the next visited node given the current node upper bounding box corner.
Definition: octree_search.h:641
pcl::octree::OctreePointCloudSearch::prioBranchQueueEntry
Priority queue entry for branch nodes
Definition: octree_search.h:296
pcl::octree::OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: octree_pointcloud.h:89
pcl::octree::OctreePointCloud< PointT, OctreeContainerPointIndices, OctreeContainerEmpty >::min_z_
double min_z_
Definition: octree_pointcloud.h:590
pcl::octree::OctreePointCloud< PointT, OctreeContainerPointIndices, OctreeContainerEmpty >::max_x_
double max_x_
Definition: octree_pointcloud.h:585
pcl::octree::OctreePointCloud::BranchNode
typename OctreeT::BranchNode BranchNode
Definition: octree_pointcloud.h:77
pcl::octree::OctreePointCloudSearch::approxNearestSearchRecursive
void approxNearestSearchRecursive(const PointT &point, const BranchNode *node, const OctreeKey &key, unsigned int tree_depth, int &result_index, float &sqr_distance)
Recursive search method that explores the octree and finds the approximate nearest neighbor.
Definition: octree_search.hpp:423
pcl::octree::OctreePointCloudSearch::initIntersectedVoxel
void initIntersectedVoxel(Eigen::Vector3f &origin, Eigen::Vector3f &direction, double &min_x, double &min_y, double &min_z, double &max_x, double &max_y, double &max_z, unsigned char &a) const
Initialize raytracing algorithm.
Definition: octree_search.h:524
pcl::octree::OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >::Ptr
shared_ptr< OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty, OctreeBase< pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty > > > Ptr
Definition: octree_pointcloud.h:102
pcl::octree::OctreePointCloud< PointT, OctreeContainerPointIndices, OctreeContainerEmpty >::max_z_
double max_z_
Definition: octree_pointcloud.h:591
pcl::octree::OctreePointCloud< PointT, OctreeContainerPointIndices, OctreeContainerEmpty >::max_y_
double max_y_
Definition: octree_pointcloud.h:588
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:406
pcl::octree::OctreePointCloudSearch::pointSquaredDist
float pointSquaredDist(const PointT &point_a, const PointT &point_b) const
Helper function to calculate the squared distance between two points.
Definition: octree_search.hpp:511
pcl::octree::OctreePointCloudSearch::prioBranchQueueEntry::operator<
bool operator<(const prioBranchQueueEntry rhs) const
Operator< for comparing priority queue entries with each other.
Definition: octree_search.h:314
pcl::octree::OctreePointCloudSearch::prioPointQueueEntry::prioPointQueueEntry
prioPointQueueEntry(unsigned int &point_idx, float point_distance)
Constructor for initializing priority queue entry.
Definition: octree_search.h:344
pcl::octree::OctreePointCloudSearch::getIntersectedVoxelCentersRecursive
int getIntersectedVoxelCentersRecursive(double min_x, double min_y, double min_z, double max_x, double max_y, double max_z, unsigned char a, const OctreeNode *node, const OctreeKey &key, AlignedPointTVector &voxel_center_list, int max_voxel_count) const
Recursively search the tree for all intersected leaf nodes and return a vector of voxel centers.
Definition: octree_search.hpp:665
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:407
pcl::octree::OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >::IndicesPtr
shared_ptr< std::vector< int > > IndicesPtr
Definition: octree_pointcloud.h:85
pcl::octree::OctreePointCloudSearch::getFirstIntersectedNode
int getFirstIntersectedNode(double min_x, double min_y, double min_z, double mid_x, double mid_y, double mid_z) const
Find first child node ray will enter.
Definition: octree_search.h:583
pcl::octree::OctreePointCloudSearch::prioBranchQueueEntry::prioBranchQueueEntry
prioBranchQueueEntry()
Empty constructor
Definition: octree_search.h:299
pcl::octree::OctreePointCloudSearch
Octree pointcloud search class
Definition: octree_search.h:57
pcl::octree::OctreePointCloud< PointT, pcl::octree::OctreeContainerPointIndices, pcl::octree::OctreeContainerEmpty >::AlignedPointTVector
std::vector< PointT, Eigen::aligned_allocator< PointT > > AlignedPointTVector
Definition: octree_pointcloud.h:107
pcl::octree::OctreePointCloudSearch::boxSearch
int boxSearch(const Eigen::Vector3f &min_pt, const Eigen::Vector3f &max_pt, std::vector< int > &k_indices) const
Search for points within rectangular search area Points exactly on the edges of the search rectangle ...
Definition: octree_search.hpp:205
pcl::octree::OctreePointCloudSearch::BranchNode
typename OctreeT::BranchNode BranchNode
Definition: octree_search.h:79
pcl::octree::OctreePointCloud::LeafNode
typename OctreeT::LeafNode LeafNode
Definition: octree_pointcloud.h:76
pcl::octree::OctreePointCloud< PointT, OctreeContainerPointIndices, OctreeContainerEmpty >::min_x_
double min_x_
Definition: octree_pointcloud.h:584