Point Cloud Library (PCL)  1.11.0
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 
39 #ifndef PCL_KEYPOINT_IMPL_H_
40 #define PCL_KEYPOINT_IMPL_H_
41 
42 
43 namespace pcl
44 {
45 
46 template <typename PointInT, typename PointOutT> bool
48 {
50  return (false);
51 
52  // Initialize the spatial locator
53  if (!tree_)
54  {
55  if (input_->isOrganized ())
56  tree_.reset (new pcl::search::OrganizedNeighbor<PointInT> ());
57  else
58  tree_.reset (new pcl::search::KdTree<PointInT> (false));
59  }
60 
61  // If no search surface has been defined, use the input dataset as the search surface itself
62  if (!surface_)
63  surface_ = input_;
64 
65  // Send the surface dataset to the spatial locator
66  tree_->setInputCloud (surface_);
67 
68  // Do a fast check to see if the search parameters are well defined
69  if (search_radius_ != 0.0)
70  {
71  if (k_ != 0)
72  {
73  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_);
74  return (false);
75  }
76 
77  // Use the radiusSearch () function
78  search_parameter_ = search_radius_;
79  if (surface_ == input_) // if the two surfaces are the same
80  {
81  // Declare the search locator definition
82  search_method_ = [this] (int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
83  {
84  return tree_->radiusSearch (index, radius, k_indices, k_distances, 0);
85  };
86  }
87  else
88  {
89  // Declare the search locator definition
90  search_method_surface_ = [this] (const PointCloudIn &cloud, int index, double radius, std::vector<int> &k_indices, std::vector<float> &k_distances)
91  {
92  return tree_->radiusSearch (cloud, index, radius, k_indices, k_distances, 0);
93  };
94  }
95  }
96  else
97  {
98  if (k_ != 0) // Use the nearestKSearch () function
99  {
100  search_parameter_ = k_;
101  if (surface_ == input_) // if the two surfaces are the same
102  {
103  // Declare the search locator definition
104  search_method_ = [this] (int index, int k, std::vector<int> &k_indices, std::vector<float> &k_distances)
105  {
106  return tree_->nearestKSearch (index, k, k_indices, k_distances);
107  };
108  }
109  else
110  {
111  // Declare the search locator definition
112  search_method_surface_ = [this] (const PointCloudIn &cloud, int index, int k, std::vector<int> &k_indices, std::vector<float> &k_distances)
113  {
114  return tree_->nearestKSearch (cloud, index, k, k_indices, k_distances);
115  };
116  }
117  }
118  else
119  {
120  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 ());
121  return (false);
122  }
123  }
124 
125  keypoints_indices_.reset (new pcl::PointIndices);
126  keypoints_indices_->indices.reserve (input_->size ());
127 
128  return (true);
129 }
130 
131 
132 template <typename PointInT, typename PointOutT> inline void
134 {
135  if (!initCompute ())
136  {
137  PCL_ERROR ("[pcl::%s::compute] initCompute failed!\n", getClassName ().c_str ());
138  return;
139  }
140 
141  // Perform the actual computation
142  detectKeypoints (output);
143 
144  deinitCompute ();
145 
146  // Reset the surface
147  if (input_ == surface_)
148  surface_.reset ();
149 }
150 
151 } // namespace pcl
152 
153 #endif //#ifndef PCL_KEYPOINT_IMPL_H_
154 
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition: kdtree.h:61
Keypoint represents the base class for key points.
Definition: keypoint.h:49
PCL base class.
Definition: pcl_base.h:69
virtual bool initCompute()
Definition: keypoint.hpp:47
OrganizedNeighbor is a class for optimized nearest neigbhor search in organized point clouds...
Definition: organized.h:63