Point Cloud Library (PCL)  1.10.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 
73  // Use the radiusSearch () function
74  search_parameter_ = search_radius_;
75  if (surface_ == input_) // if the two surfaces are the same
76  {
77  // Declare the search locator definition
78  search_method_ = [this] (int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
79  {
80  return tree_->radiusSearch (index, radius, k_indices, k_distances, 0);
81  };
82  }
83  else
84  {
85  // Declare the search locator definition
86  search_method_surface_ = [this] (const PointCloudIn &cloud, int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
87  {
88  return tree_->radiusSearch (cloud, index, radius, k_indices, k_distances, 0);
89  };
90  }
91  }
92  else
93  {
94  if (k_ != 0) // Use the nearestKSearch () function
95  {
96  search_parameter_ = k_;
97  if (surface_ == input_) // if the two surfaces are the same
98  {
99  // Declare the search locator definition
100  search_method_ = [this] (int index, int k, std::vector<int> &k_indices, std::vector<float> &k_distances)
101  {
102  return tree_->nearestKSearch (index, k, k_indices, k_distances);
103  };
104  }
105  else
106  {
107  // Declare the search locator definition
108  search_method_surface_ = [this] (const PointCloudIn &cloud, int index, int k, std::vector<int> &k_indices, std::vector<float> &k_distances)
109  {
110  return tree_->nearestKSearch (cloud, index, k, k_indices, k_distances);
111  };
112  }
113  }
114  else
115  {
116  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 ());
117  return (false);
118  }
119  }
120 
121  keypoints_indices_.reset (new pcl::PointIndices);
122  keypoints_indices_->indices.reserve (input_->size ());
123 
124  return (true);
125 }
126 
127 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
128 template <typename PointInT, typename PointOutT> inline void
130 {
131  if (!initCompute ())
132  {
133  PCL_ERROR ("[pcl::%s::compute] initCompute failed!\n", getClassName ().c_str ());
134  return;
135  }
136 
137  // Perform the actual computation
138  detectKeypoints (output);
139 
140  deinitCompute ();
141 
142  // Reset the surface
143  if (input_ == surface_)
144  surface_.reset ();
145 }
146 
147 #endif //#ifndef PCL_KEYPOINT_IMPL_H_
148 
pcl::Keypoint::initCompute
virtual bool initCompute()
Definition: keypoint.hpp:43
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::PointCloud< pcl::PointXYZ >
pcl::search::KdTree
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:61
pcl::PointIndices
Definition: PointIndices.h:12
pcl::search::OrganizedNeighbor
OrganizedNeighbor is a class for optimized nearest neigbhor search in organized point clouds.
Definition: organized.h:62
pcl::Keypoint::compute
void compute(PointCloudOut &output)
Base method for key point detection for all points given in <setInputCloud (), setIndices ()> using t...
Definition: keypoint.hpp:129