Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
feature.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: feature.h 6453 2012-07-17 23:09:54Z svn $
37  *
38  */
39 
40 #ifndef PCL_FEATURE_H_
41 #define PCL_FEATURE_H_
42 
43 #include <boost/function.hpp>
44 #include <boost/bind.hpp>
45 #include <boost/mpl/size.hpp>
46 
47 // PCL includes
48 #include <pcl/pcl_base.h>
49 #include <pcl/common/eigen.h>
50 #include <pcl/common/centroid.h>
51 #include <pcl/search/search.h>
52 
53 namespace pcl
54 {
66  inline void
67  solvePlaneParameters (const Eigen::Matrix3f &covariance_matrix,
68  const Eigen::Vector4f &point,
69  Eigen::Vector4f &plane_parameters, float &curvature);
70 
83  inline void
84  solvePlaneParameters (const Eigen::Matrix3f &covariance_matrix,
85  float &nx, float &ny, float &nz, float &curvature);
86 
90 
103  template <typename PointInT, typename PointOutT>
104  class Feature : public PCLBase<PointInT>
105  {
106  public:
109 
111 
112  typedef boost::shared_ptr< Feature<PointInT, PointOutT> > Ptr;
113  typedef boost::shared_ptr< const Feature<PointInT, PointOutT> > ConstPtr;
114 
117 
121 
123 
124  typedef boost::function<int (size_t, double, std::vector<int> &, std::vector<float> &)> SearchMethod;
125  typedef boost::function<int (const PointCloudIn &cloud, size_t index, double, std::vector<int> &, std::vector<float> &)> SearchMethodSurface;
126 
127  public:
129  Feature () :
130  feature_name_ (), search_method_surface_ (),
131  surface_(), tree_(),
132  search_parameter_(0), search_radius_(0), k_(0),
133  fake_surface_(false)
134  {}
135 
143  inline void
145  {
146  surface_ = cloud;
147  fake_surface_ = false;
148  //use_surface_ = true;
149  }
150 
152  inline PointCloudInConstPtr
154  {
155  return (surface_);
156  }
157 
161  inline void
162  setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
163 
165  inline KdTreePtr
167  {
168  return (tree_);
169  }
170 
172  inline double
174  {
175  return (search_parameter_);
176  }
177 
181  inline void
182  setKSearch (int k) { k_ = k; }
183 
185  inline int
186  getKSearch () const
187  {
188  return (k_);
189  }
190 
195  inline void
196  setRadiusSearch (double radius)
197  {
198  search_radius_ = radius;
199  }
200 
202  inline double
204  {
205  return (search_radius_);
206  }
207 
213  void
214  compute (PointCloudOut &output);
215 
221  void
223 
224  protected:
226  std::string feature_name_;
227 
229  SearchMethodSurface search_method_surface_;
230 
234  PointCloudInConstPtr surface_;
235 
237  KdTreePtr tree_;
238 
240  double search_parameter_;
241 
243  double search_radius_;
244 
246  int k_;
247 
249  inline const std::string&
250  getClassName () const { return (feature_name_); }
251 
253  virtual bool
254  initCompute ();
255 
257  virtual bool
258  deinitCompute ();
259 
261  bool fake_surface_;
262 
273  inline int
274  searchForNeighbors (size_t index, double parameter,
275  std::vector<int> &indices, std::vector<float> &distances) const
276  {
277  return (search_method_surface_ (*input_, index, parameter, indices, distances));
278  }
279 
291  inline int
292  searchForNeighbors (const PointCloudIn &cloud, size_t index, double parameter,
293  std::vector<int> &indices, std::vector<float> &distances) const
294  {
295  return (search_method_surface_ (cloud, index, parameter, indices, distances));
296  }
297 
298  private:
302  virtual void
303  computeFeature (PointCloudOut &output) = 0;
304 
308  virtual void
309  computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output) = 0;
310 
311  public:
312  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
313  };
314 
315 
319  template <typename PointInT, typename PointNT, typename PointOutT>
320  class FeatureFromNormals : public Feature<PointInT, PointOutT>
321  {
323  typedef typename PointCloudIn::Ptr PointCloudInPtr;
326 
327  public:
331 
332  typedef boost::shared_ptr< FeatureFromNormals<PointInT, PointNT, PointOutT> > Ptr;
333  typedef boost::shared_ptr< const FeatureFromNormals<PointInT, PointNT, PointOutT> > ConstPtr;
334 
335  // Members derived from the base class
339 
341  FeatureFromNormals () : normals_ () {}
342 
350  inline void
351  setInputNormals (const PointCloudNConstPtr &normals) { normals_ = normals; }
352 
354  inline PointCloudNConstPtr
355  getInputNormals () const { return (normals_); }
356 
357  protected:
361  PointCloudNConstPtr normals_;
362 
364  virtual bool
365  initCompute ();
366 
367  public:
368  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
369  };
370 
374  template <typename PointInT, typename PointLT, typename PointOutT>
375  class FeatureFromLabels : public Feature<PointInT, PointOutT>
376  {
378  typedef typename PointCloudIn::Ptr PointCloudInPtr;
380 
381  typedef typename pcl::PointCloud<PointLT> PointCloudL;
382  typedef typename PointCloudL::Ptr PointCloudNPtr;
383  typedef typename PointCloudL::ConstPtr PointCloudLConstPtr;
384 
386 
387  public:
388  typedef boost::shared_ptr< FeatureFromLabels<PointInT, PointLT, PointOutT> > Ptr;
389  typedef boost::shared_ptr< const FeatureFromLabels<PointInT, PointLT, PointOutT> > ConstPtr;
390 
391  // Members derived from the base class
396 
398  FeatureFromLabels () : labels_ ()
399  {
400  k_ = 1; // Search tree is not always used here.
401  }
402 
409  inline void
410  setInputLabels (const PointCloudLConstPtr &labels)
411  {
412  labels_ = labels;
413  }
414 
416  inline PointCloudLConstPtr
417  getInputLabels () const
418  {
419  return (labels_);
420  }
421 
422  protected:
426  PointCloudLConstPtr labels_;
427 
429  virtual bool
430  initCompute ();
431 
432  public:
433  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
434  };
435 
439 
450  template <typename PointInT, typename PointRFT>
452  {
453  public:
457 
459  FeatureWithLocalReferenceFrames () : frames_ (), frames_never_defined_ (true) {}
460 
463 
470  inline void
472  {
473  frames_ = frames;
474  frames_never_defined_ = false;
475  }
476 
478  inline PointCloudLRFConstPtr
480  {
481  return (frames_);
482  }
483 
484  protected:
486  PointCloudLRFConstPtr frames_;
488  bool frames_never_defined_;
489 
495  typedef typename Feature<PointInT, PointRFT>::Ptr LRFEstimationPtr;
496  virtual bool
497  initLocalReferenceFrames (const size_t& indices_size,
498  const LRFEstimationPtr& lrf_estimation = LRFEstimationPtr());
499  };
500 }
501 
503 
504 #endif //#ifndef PCL_FEATURE_H_