Point Cloud Library (PCL)  1.7.1
keypoint.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  */
37 
38 #ifndef PCL_KEYPOINT_IMPL_H_
39 #define PCL_KEYPOINT_IMPL_H_
40 
41 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
42 template <typename PointInT, typename PointOutT> bool
44 {
46  return (false);
47 
48  // Initialize the spatial locator
49  if (!tree_)
50  {
51  if (input_->isOrganized ())
52  tree_.reset (new pcl::search::OrganizedNeighbor<PointInT> ());
53  else
54  tree_.reset (new pcl::search::KdTree<PointInT> (false));
55  }
56 
57  // If no search surface has been defined, use the input dataset as the search surface itself
58  if (!surface_)
59  surface_ = input_;
60 
61  // Send the surface dataset to the spatial locator
62  tree_->setInputCloud (surface_);
63 
64  // Do a fast check to see if the search parameters are well defined
65  if (search_radius_ != 0.0)
66  {
67  if (k_ != 0)
68  {
69  PCL_ERROR ("[pcl::%s::initCompute] Both radius (%f) and K (%d) defined! Set one of them to zero first and then re-run compute ().\n", getClassName ().c_str (), search_radius_, k_);
70  return (false);
71  }
72  else // Use the radiusSearch () function
73  {
74  search_parameter_ = search_radius_;
75  if (surface_ == input_) // if the two surfaces are the same
76  {
77  // Declare the search locator definition
78  int (KdTree::*radiusSearch)(int index, double radius, std::vector<int> &k_indices,
79  std::vector<float> &k_distances, unsigned int max_nn) const = &KdTree::radiusSearch;
80  search_method_ = boost::bind (radiusSearch, boost::ref (tree_), _1, _2, _3, _4, 0);
81  }
82  else
83  {
84  // Declare the search locator definition
85  int (KdTree::*radiusSearchSurface)(const PointCloudIn &cloud, int index, double radius, std::vector<int> &k_indices,
86  std::vector<float> &k_distances, unsigned int max_nn) const = &KdTree::radiusSearch;
87  search_method_surface_ = boost::bind (radiusSearchSurface, boost::ref (tree_), _1, _2, _3, _4, _5, 0);
88  }
89  }
90  }
91  else
92  {
93  if (k_ != 0) // Use the nearestKSearch () function
94  {
95  search_parameter_ = k_;
96  if (surface_ == input_) // if the two surfaces are the same
97  {
98  // Declare the search locator definition
99  int (KdTree::*nearestKSearch)(int index, int k, std::vector<int> &k_indices, std::vector<float> &k_distances) const = &KdTree::nearestKSearch;
100  search_method_ = boost::bind (nearestKSearch, boost::ref (tree_), _1, _2, _3, _4);
101  }
102  else
103  {
104  // Declare the search locator definition
105  int (KdTree::*nearestKSearchSurface)(const PointCloudIn &cloud, int index, int k, std::vector<int> &k_indices, std::vector<float> &k_distances) const = &KdTree::nearestKSearch;
106  search_method_surface_ = boost::bind (nearestKSearchSurface, boost::ref (tree_), _1, _2, _3, _4, _5);
107  }
108  }
109  else
110  {
111  PCL_ERROR ("[pcl::%s::initCompute] Neither radius nor K defined! Set one of them to a positive number first and then re-run compute ().\n", getClassName ().c_str ());
112  return (false);
113  }
114  }
115 
116  return (true);
117 }
118 
119 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
120 template <typename PointInT, typename PointOutT> inline void
122 {
123  if (!initCompute ())
124  {
125  PCL_ERROR ("[pcl::%s::compute] initCompute failed!\n", getClassName ().c_str ());
126  return;
127  }
128 
129  // Perform the actual computation
130  detectKeypoints (output);
131 
132  deinitCompute ();
133 
134  // Reset the surface
135  if (input_ == surface_)
136  surface_.reset ();
137 }
138 
139 #endif //#ifndef PCL_KEYPOINT_IMPL_H_
140