Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfh.h
Go to the documentation of this file.
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  * $Id: pfh.h 4961 2012-03-07 23:44:07Z rusu $
37  *
38  */
39 
40 #ifndef PCL_PFH_H_
41 #define PCL_PFH_H_
42 
43 #include <pcl/point_types.h>
44 #include <pcl/features/feature.h>
45 #include <map>
46 
47 namespace pcl
48 {
65  PCL_EXPORTS bool
66  computePairFeatures (const Eigen::Vector4f &p1, const Eigen::Vector4f &n1,
67  const Eigen::Vector4f &p2, const Eigen::Vector4f &n2,
68  float &f1, float &f2, float &f3, float &f4);
69 
100  template <typename PointInT, typename PointNT, typename PointOutT = pcl::PFHSignature125>
101  class PFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
102  {
103  public:
112 
115 
120  nr_subdiv_ (5),
121  pfh_histogram_ (),
122  pfh_tuple_ (),
123  d_pi_ (1.0f / (2.0f * static_cast<float> (M_PI))),
124  feature_map_ (),
125  key_list_ (),
126  // Default 1GB memory size. Need to set it to something more conservative.
127  max_cache_size_ ((1ul*1024ul*1024ul*1024ul) / sizeof (std::pair<std::pair<int, int>, Eigen::Vector4f>)),
128  use_cache_ (false)
129  {
130  feature_name_ = "PFHEstimation";
131  };
132 
136  inline void
137  setMaximumCacheSize (unsigned int cache_size)
138  {
139  max_cache_size_ = cache_size;
140  }
141 
143  inline unsigned int
145  {
146  return (max_cache_size_);
147  }
148 
160  inline void
161  setUseInternalCache (bool use_cache)
162  {
163  use_cache_ = use_cache;
164  }
165 
167  inline bool
169  {
170  return (use_cache_);
171  }
172 
187  bool
189  int p_idx, int q_idx, float &f1, float &f2, float &f3, float &f4);
190 
199  void
201  const std::vector<int> &indices, int nr_split, Eigen::VectorXf &pfh_histogram);
202 
203  protected:
209  void
210  computeFeature (PointCloudOut &output);
211 
213  int nr_subdiv_;
214 
216  Eigen::VectorXf pfh_histogram_;
217 
219  Eigen::Vector4f pfh_tuple_;
220 
222  int f_index_[3];
223 
225  float d_pi_;
226 
228  std::map<std::pair<int, int>, Eigen::Vector4f, std::less<std::pair<int, int> >, Eigen::aligned_allocator<Eigen::Vector4f> > feature_map_;
229 
231  std::queue<std::pair<int, int> > key_list_;
232 
234  unsigned int max_cache_size_;
235 
237  bool use_cache_;
238  private:
242  void
243  computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &) {}
244  };
245 
274  template <typename PointInT, typename PointNT>
275  class PFHEstimation<PointInT, PointNT, Eigen::MatrixXf> : public PFHEstimation<PointInT, PointNT, pcl::PFHSignature125>
276  {
277  public:
290 
291  private:
297  void
298  computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output);
299 
303  void
305  };
306 }
307 
308 #endif //#ifndef PCL_PFH_H_
309 
310