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