Loading...
Searching...
No Matches
octree.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
#pragma once
#include <pcl/search/search.h>
#include <pcl/octree/octree_search.h>
namespace pcl
{
namespace search
{
/** \brief @b search::Octree is a wrapper class which implements nearest neighbor search operations based on the
* pcl::octree::Octree structure.
*
* The octree pointcloud class needs to be initialized with its voxel
* resolution. Its bounding box is automatically adjusted according to the
* pointcloud dimension or it can be predefined. Note: The tree depth
* equates to the resolution and the bounding box dimensions of the
* octree.
*
* \note typename: PointT: type of point used in pointcloud
* \note typename: LeafT: leaf node class (usuallt templated with integer indices values)
* \note typename: OctreeT: octree implementation ()
*
* \author Julius Kammerl
* \ingroup search
*/
template<typename PointT,
typename LeafTWrap = pcl::octree::OctreeContainerPointIndices,
typename BranchTWrap = pcl::octree::OctreeContainerEmpty,
typename OctreeT = pcl::octree::OctreeBase<LeafTWrap, BranchTWrap > >
class Octree: public Search<PointT>
{
public:
// public typedefs
using Ptr = shared_ptr<pcl::search::Octree<PointT,LeafTWrap,BranchTWrap,OctreeT> >;
using ConstPtr = shared_ptr<const pcl::search::Octree<PointT,LeafTWrap,BranchTWrap,OctreeT> >;
using PointCloud = pcl::PointCloud<PointT>;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
// Boost shared pointers
using OctreePointCloudSearchPtr = typename pcl::octree::OctreePointCloudSearch<PointT, LeafTWrap, BranchTWrap>::Ptr;
using OctreePointCloudSearchConstPtr = typename pcl::octree::OctreePointCloudSearch<PointT, LeafTWrap, BranchTWrap>::ConstPtr;
OctreePointCloudSearchPtr tree_;
using pcl::search::Search<PointT>::input_;
using pcl::search::Search<PointT>::indices_;
using pcl::search::Search<PointT>::sorted_results_;
/** \brief Octree constructor.
* \param[in] resolution octree resolution at lowest octree level
*/
Octree (const double resolution)
: Search<PointT> ("Octree")
, tree_ (new pcl::octree::OctreePointCloudSearch<PointT, LeafTWrap, BranchTWrap> (resolution))
{
}
/** \brief Empty Destructor. */
~Octree () override = default;
/** \brief Provide a pointer to the input dataset.
* \param[in] cloud the const boost shared pointer to a PointCloud message
*/
inline void
setInputCloud (const PointCloudConstPtr &cloud)
{
tree_->deleteTree ();
tree_->setInputCloud (cloud);
tree_->addPointsFromInputCloud ();
input_ = cloud;
}
/** \brief Provide a pointer to the input dataset.
* \param[in] cloud the const boost shared pointer to a PointCloud message
* \param[in] indices the point indices subset that is to be used from \a cloud
*/
inline bool
setInputCloud (const PointCloudConstPtr &cloud, const IndicesConstPtr& indices) override
{
tree_->deleteTree ();
tree_->setInputCloud (cloud, indices);
tree_->addPointsFromInputCloud ();
input_ = cloud;
indices_ = indices;
return true;
}
/** \brief Search for the k-nearest neighbors for the given query point.
* \param[in] cloud the point cloud data
* \param[in] index the index in \a cloud representing the query point
* \param[in] k the number of neighbors to search for
* \param[out] k_indices the resultant indices of the neighboring points (must be resized to \a k a priori!)
* \param[out] k_sqr_distances the resultant squared distances to the neighboring points (must be resized to \a k
* a priori!)
* \return number of neighbors found
*/
inline int
nearestKSearch (const PointCloud &cloud, index_t index, int k, Indices &k_indices,
std::vector<float> &k_sqr_distances) const override
{
return (tree_->nearestKSearch (cloud, index, k, k_indices, k_sqr_distances));
}
/** \brief Search for the k-nearest neighbors for the given query point.
* \param[in] point the given query point
* \param[in] k the number of neighbors to search for
* \param[out] k_indices the resultant indices of the neighboring points (must be resized to \a k a priori!)
* \param[out] k_sqr_distances the resultant squared distances to the neighboring points (must be resized to \a k
* a priori!)
* \return number of neighbors found
*/
inline int
nearestKSearch (const PointT &point, int k, Indices &k_indices,
std::vector<float> &k_sqr_distances) const override
{
return (tree_->nearestKSearch (point, k, k_indices, k_sqr_distances));
}
/** \brief Search for the k-nearest neighbors for the given query point (zero-copy).
*
* \param[in] index the index representing the query point in the
* dataset given by \a setInputCloud if indices were given in
* setInputCloud, index will be the position in the indices vector
* \param[in] k the number of neighbors to search for
* \param[out] k_indices the resultant indices of the neighboring points (must be resized to \a k a priori!)
* \param[out] k_sqr_distances the resultant squared distances to the neighboring points (must be resized to \a k
* a priori!)
* \return number of neighbors found
*/
inline int
nearestKSearch (index_t index, int k, Indices &k_indices, std::vector<float> &k_sqr_distances) const override
{
return (tree_->nearestKSearch (index, k, k_indices, k_sqr_distances));
}
/** \brief search for all neighbors of query point that are within a given radius.
* \param cloud the point cloud data
* \param index the index in \a cloud representing the query point
* \param radius the radius of the sphere bounding all of p_q's neighbors
* \param k_indices the resultant indices of the neighboring points
* \param k_sqr_distances the resultant squared distances to the neighboring points
* \param max_nn if given, bounds the maximum returned neighbors to this value
* \return number of neighbors found in radius
*/
inline int
radiusSearch (const PointCloud &cloud,
index_t index,
double radius,
Indices &k_indices,
std::vector<float> &k_sqr_distances,
unsigned int max_nn = 0) const override
{
tree_->radiusSearch (cloud, index, radius, k_indices, k_sqr_distances, max_nn);
if (sorted_results_)
this->sortResults (k_indices, k_sqr_distances);
return (static_cast<int> (k_indices.size ()));
}
/** \brief search for all neighbors of query point that are within a given radius.
* \param p_q the given query point
* \param radius the radius of the sphere bounding all of p_q's neighbors
* \param k_indices the resultant indices of the neighboring points
* \param k_sqr_distances the resultant squared distances to the neighboring points
* \param max_nn if given, bounds the maximum returned neighbors to this value
* \return number of neighbors found in radius
*/
inline int
radiusSearch (const PointT &p_q,
double radius,
Indices &k_indices,
std::vector<float> &k_sqr_distances,
unsigned int max_nn = 0) const override
{
tree_->radiusSearch (p_q, radius, k_indices, k_sqr_distances, max_nn);
if (sorted_results_)
this->sortResults (k_indices, k_sqr_distances);
return (static_cast<int> (k_indices.size ()));
}
/** \brief search for all neighbors of query point that are within a given radius.
* \param index index representing the query point in the dataset given by \a setInputCloud.
* If indices were given in setInputCloud, index will be the position in the indices vector
* \param radius radius of the sphere bounding all of p_q's neighbors
* \param k_indices the resultant indices of the neighboring points
* \param k_sqr_distances the resultant squared distances to the neighboring points
* \param max_nn if given, bounds the maximum returned neighbors to this value
* \return number of neighbors found in radius
*/
inline int
radiusSearch (index_t index, double radius, Indices &k_indices,
std::vector<float> &k_sqr_distances, unsigned int max_nn = 0) const override
{
tree_->radiusSearch (index, radius, k_indices, k_sqr_distances, max_nn);
if (sorted_results_)
this->sortResults (k_indices, k_sqr_distances);
return (static_cast<int> (k_indices.size ()));
}
/** \brief Search for approximate nearest neighbor at the query point.
* \param[in] cloud the point cloud data
* \param[in] query_index the index in \a cloud representing the query point
* \param[out] result_index the resultant index of the neighbor point
* \param[out] sqr_distance the resultant squared distance to the neighboring point
* \return number of neighbors found
*/
inline void
approxNearestSearch (const PointCloudConstPtr &cloud, index_t query_index, index_t &result_index,
float &sqr_distance)
{
return (tree_->approxNearestSearch ((*cloud)[query_index], result_index, sqr_distance));
}
/** \brief Search for approximate nearest neighbor at the query point.
* \param[in] p_q the given query point
* \param[out] result_index the resultant index of the neighbor point
* \param[out] sqr_distance the resultant squared distance to the neighboring point
*/
inline void
approxNearestSearch (const PointT &p_q, index_t &result_index, float &sqr_distance)
{
return (tree_->approxNearestSearch (p_q, result_index, sqr_distance));
}
/** \brief Search for approximate nearest neighbor at the query point.
* \param query_index index representing the query point in the dataset given by \a setInputCloud.
* If indices were given in setInputCloud, index will be the position in the indices vector.
* \param result_index the resultant index of the neighbor point
* \param sqr_distance the resultant squared distance to the neighboring point
* \return number of neighbors found
*/
inline void
approxNearestSearch (index_t query_index, index_t &result_index, float &sqr_distance)
{
return (tree_->approxNearestSearch (query_index, result_index, sqr_distance));
}
/** \brief Search for points within rectangular search area
* \param[in] min_pt lower corner of search area
* \param[in] max_pt upper corner of search area
* \param[out] k_indices the resultant point indices
* \return number of points found within search area
*/
inline uindex_t
boxSearch(const Eigen::Vector3f &min_pt, const Eigen::Vector3f &max_pt, Indices &k_indices) const
{
return (tree_->boxSearch(min_pt, max_pt, k_indices));
}
};
}
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/octree/impl/octree_search.hpp>
#else
#define PCL_INSTANTIATE_Octree(T) template class PCL_EXPORTS pcl::search::Octree<T>;
#endif
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition point_cloud.h:173
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition point_cloud.h:414
pcl::octree::OctreeBase
Octree class.
Definition octree_base.h:62
pcl::octree::OctreeContainerEmpty
Octree container class that does not store any information.
Definition octree_container.h:129
pcl::octree::OctreeContainerPointIndices
Octree container class that does store a vector of point indices.
Definition octree_container.h:264
pcl::octree::OctreePointCloudSearch::ConstPtr
shared_ptr< const OctreePointCloudSearch< PointT, LeafContainerT, BranchContainerT > > ConstPtr
Definition octree_search.h:72
pcl::octree::OctreePointCloudSearch::Ptr
shared_ptr< OctreePointCloudSearch< PointT, LeafContainerT, BranchContainerT > > Ptr
Definition octree_search.h:70
pcl::search::Octree
search::Octree is a wrapper class which implements nearest neighbor search operations based on the pc...
Definition octree.h:69
pcl::search::Octree::ConstPtr
shared_ptr< const pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT > > ConstPtr
Definition octree.h:73
pcl::search::Octree::boxSearch
uindex_t boxSearch(const Eigen::Vector3f &min_pt, const Eigen::Vector3f &max_pt, Indices &k_indices) const
Search for points within rectangular search area.
Definition octree.h:284
pcl::search::Octree::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition octree.h:76
pcl::search::Octree::nearestKSearch
int nearestKSearch(index_t index, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const override
Search for the k-nearest neighbors for the given query point (zero-copy).
Definition octree.h:171
pcl::search::Octree::setInputCloud
void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition octree.h:105
pcl::search::Octree::radiusSearch
int radiusSearch(const PointT &p_q, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
search for all neighbors of query point that are within a given radius.
Definition octree.h:208
pcl::search::Octree::tree_
OctreePointCloudSearchPtr tree_
Definition octree.h:82
pcl::search::Octree::approxNearestSearch
void approxNearestSearch(const PointCloudConstPtr &cloud, index_t query_index, index_t &result_index, float &sqr_distance)
Search for approximate nearest neighbor at the query point.
Definition octree.h:248
pcl::search::Octree::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition octree.h:77
pcl::search::Octree::radiusSearch
int radiusSearch(index_t index, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
search for all neighbors of query point that are within a given radius.
Definition octree.h:230
pcl::search::Octree::OctreePointCloudSearchConstPtr
typename pcl::octree::OctreePointCloudSearch< PointT, LeafTWrap, BranchTWrap >::ConstPtr OctreePointCloudSearchConstPtr
Definition octree.h:81
pcl::search::Octree::approxNearestSearch
void approxNearestSearch(index_t query_index, index_t &result_index, float &sqr_distance)
Search for approximate nearest neighbor at the query point.
Definition octree.h:273
pcl::search::Octree::Octree
Octree(const double resolution)
Octree constructor.
Definition octree.h:91
pcl::search::Octree::radiusSearch
int radiusSearch(const PointCloud &cloud, index_t index, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
search for all neighbors of query point that are within a given radius.
Definition octree.h:186
pcl::search::Octree::OctreePointCloudSearchPtr
typename pcl::octree::OctreePointCloudSearch< PointT, LeafTWrap, BranchTWrap >::Ptr OctreePointCloudSearchPtr
Definition octree.h:80
pcl::search::Octree::Ptr
shared_ptr< pcl::search::Octree< PointT, LeafTWrap, BranchTWrap, OctreeT > > Ptr
Definition octree.h:72
pcl::search::Octree::approxNearestSearch
void approxNearestSearch(const PointT &p_q, index_t &result_index, float &sqr_distance)
Search for approximate nearest neighbor at the query point.
Definition octree.h:260
pcl::search::Octree::nearestKSearch
int nearestKSearch(const PointT &point, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const override
Search for the k-nearest neighbors for the given query point.
Definition octree.h:153
pcl::search::Octree::setInputCloud
bool setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices) override
Provide a pointer to the input dataset.
Definition octree.h:118
pcl::search::Octree::~Octree
~Octree() override=default
Empty Destructor.
pcl::search::Octree::nearestKSearch
int nearestKSearch(const PointCloud &cloud, index_t index, int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const override
Search for the k-nearest neighbors for the given query point.
Definition octree.h:138
pcl::search::Search
Generic search class.
Definition search.h:75
pcl::search::Search::input_
PointCloudConstPtr input_
Definition search.h:402
pcl::search::Search::sortResults
void sortResults(Indices &indices, std::vector< float > &distances) const
Definition search.hpp:189
pcl::search::Search::indices_
IndicesConstPtr indices_
Definition search.h:403
pcl::search::Search::IndicesConstPtr
pcl::IndicesConstPtr IndicesConstPtr
Definition search.h:85
pcl::search::Search::sorted_results_
bool sorted_results_
Definition search.h:404
pcl
Definition convolution.h:46
pcl::uindex_t
detail::int_type_t< detail::index_type_size, false > uindex_t
Type used for an unsigned index in PCL.
Definition types.h:120
pcl::index_t
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
Definition types.h:112
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition point_types.hpp:623