Point Cloud Library (PCL)  1.9.1-dev
io.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, 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 
40 #ifndef PCL_KDTREE_IO_IMPL_HPP_
41 #define PCL_KDTREE_IO_IMPL_HPP_
42 
43 #include <pcl/kdtree/io.h>
44 
45 //////////////////////////////////////////////////////////////////////////////////////////////
46 template <typename Point1T, typename Point2T> void
48  const typename pcl::PointCloud<Point1T>::ConstPtr &cloud_in,
49  const typename pcl::PointCloud<Point2T>::ConstPtr &cloud_ref,
50  std::vector<int> &indices)
51 {
53  tree.setInputCloud (cloud_ref);
54 
55  std::vector<int> nn_idx (1);
56  std::vector<float> nn_dists (1);
57  indices.resize (cloud_in->points.size ());
58  for (size_t i = 0; i < cloud_in->points.size (); ++i)
59  {
60  tree.nearestKSearchT ((*cloud_in)[i], 1, nn_idx, nn_dists);
61  indices[i] = nn_idx[0];
62  }
63 }
64 
65 //////////////////////////////////////////////////////////////////////////////////////////////
66 template <typename PointT> void
68  const typename pcl::PointCloud<PointT>::ConstPtr &cloud_in,
69  const typename pcl::PointCloud<PointT>::ConstPtr &cloud_ref,
70  std::vector<int> &indices)
71 {
73  tree.setInputCloud (cloud_ref);
74 
75  std::vector<int> nn_idx (1);
76  std::vector<float> nn_dists (1);
77  indices.resize (cloud_in->points.size ());
78  for (size_t i = 0; i < cloud_in->points.size (); ++i)
79  {
80  tree.nearestKSearch (*cloud_in, i, 1, nn_idx, nn_dists);
81  indices[i] = nn_idx[0];
82  }
83 }
84 
85 #endif // PCL_KDTREE_IO_IMPL_H_
86 
KdTreeFLANN is a generic type of 3D spatial locator using kD-tree structures.
Definition: kdtree_flann.h:67
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:423
void getApproximateIndices(const typename pcl::PointCloud< PointT >::ConstPtr &cloud_in, const typename pcl::PointCloud< PointT >::ConstPtr &cloud_ref, std::vector< int > &indices)
Get a set of approximate indices for a given point cloud into a reference point cloud.
Definition: io.hpp:67
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input dataset.
int nearestKSearchT(const PointTDiff &point, int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances) const
Search for k-nearest neighbors for the given query point.
Definition: kdtree.h:174
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:442
int nearestKSearch(const PointT &point, int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances) const override
Search for k-nearest neighbors for the given query point.