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 #include <pcl/kdtree/kdtree_flann.h>
45 
46 //////////////////////////////////////////////////////////////////////////////////////////////
47 template <typename Point1T, typename Point2T> void
49  const typename pcl::PointCloud<Point1T>::ConstPtr &cloud_in,
50  const typename pcl::PointCloud<Point2T>::ConstPtr &cloud_ref,
51  std::vector<int> &indices)
52 {
54  tree.setInputCloud (cloud_ref);
55 
56  std::vector<int> nn_idx (1);
57  std::vector<float> nn_dists (1);
58  indices.resize (cloud_in->points.size ());
59  for (size_t i = 0; i < cloud_in->points.size (); ++i)
60  {
61  tree.nearestKSearchT ((*cloud_in)[i], 1, nn_idx, nn_dists);
62  indices[i] = nn_idx[0];
63  }
64 }
65 
66 //////////////////////////////////////////////////////////////////////////////////////////////
67 template <typename PointT> void
69  const typename pcl::PointCloud<PointT>::ConstPtr &cloud_in,
70  const typename pcl::PointCloud<PointT>::ConstPtr &cloud_ref,
71  std::vector<int> &indices)
72 {
74  tree.setInputCloud (cloud_ref);
75 
76  std::vector<int> nn_idx (1);
77  std::vector<float> nn_dists (1);
78  indices.resize (cloud_in->points.size ());
79  for (size_t i = 0; i < cloud_in->points.size (); ++i)
80  {
81  tree.nearestKSearch (*cloud_in, i, 1, nn_idx, nn_dists);
82  indices[i] = nn_idx[0];
83  }
84 }
85 
86 #endif // PCL_KDTREE_IO_IMPL_H_
87 
KdTreeFLANN is a generic type of 3D spatial locator using kD-tree structures.
Definition: kdtree_flann.h:68
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:409
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Provide a pointer to the input dataset.
int nearestKSearch(const PointT &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.
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:68
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:428
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