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