Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rsd.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage, Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id: rsd.h 6144 2012-07-04 22:06:28Z rusu $
35  *
36  */
37 
38 #ifndef PCL_RSD_H_
39 #define PCL_RSD_H_
40 
41 #include <pcl/features/feature.h>
42 
43 namespace pcl
44 {
52  template <int N> void
53  getFeaturePointCloud (const std::vector<Eigen::MatrixXf, Eigen::aligned_allocator<Eigen::MatrixXf> > &histograms2D, PointCloud<Histogram<N> > &histogramsPC)
54  {
55  histogramsPC.points.resize (histograms2D.size ());
56  histogramsPC.width = histograms2D.size ();
57  histogramsPC.height = 1;
58  histogramsPC.is_dense = true;
59 
60  const int rows = histograms2D.at(0).rows();
61  const int cols = histograms2D.at(0).cols();
62 
63  typename PointCloud<Histogram<N> >::VectorType::iterator it = histogramsPC.points.begin ();
64  BOOST_FOREACH (Eigen::MatrixXf h, histograms2D)
65  {
66  Eigen::Map<Eigen::MatrixXf> histogram (&(it->histogram[0]), rows, cols);
67  histogram = h;
68  ++it;
69  }
70  }
71 
83  template <typename PointInT, typename PointNT, typename PointOutT> Eigen::MatrixXf
84  computeRSD (boost::shared_ptr<const pcl::PointCloud<PointInT> > &surface, boost::shared_ptr<const pcl::PointCloud<PointNT> > &normals,
85  const std::vector<int> &indices, double max_dist,
86  int nr_subdiv, double plane_radius, PointOutT &radii, bool compute_histogram = false);
87 
99  template <typename PointNT, typename PointOutT> Eigen::MatrixXf
100  computeRSD (boost::shared_ptr<const pcl::PointCloud<PointNT> > &normals,
101  const std::vector<int> &indices, const std::vector<float> &sqr_dists, double max_dist,
102  int nr_subdiv, double plane_radius, PointOutT &radii, bool compute_histogram = false);
103 
126  template <typename PointInT, typename PointNT, typename PointOutT>
127  class RSDEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
128  {
129  public:
137 
140 
141  typedef typename boost::shared_ptr<RSDEstimation<PointInT, PointNT, PointOutT> > Ptr;
142  typedef typename boost::shared_ptr<const RSDEstimation<PointInT, PointNT, PointOutT> > ConstPtr;
143 
144 
146  RSDEstimation () : nr_subdiv_ (5), plane_radius_ (0.2), save_histograms_ (false)
147  {
148  feature_name_ = "RadiusSurfaceDescriptor";
149  };
150 
154  inline void
155  setNrSubdivisions (int nr_subdiv) { nr_subdiv_ = nr_subdiv; }
156 
158  inline int
159  getNrSubdivisions () const { return (nr_subdiv_); }
160 
166  inline void
167  setPlaneRadius (double plane_radius) { plane_radius_ = plane_radius; }
168 
170  inline double
171  getPlaneRadius () const { return (plane_radius_); }
172 
174  inline void
175  setKSearch (int)
176  {
177  PCL_ERROR ("[pcl::%s::setKSearch] RSD does not work with k nearest neighbor search. Use setRadiusSearch() instead!\n", getClassName ().c_str ());
178  }
179 
184  inline void
185  setSaveHistograms (bool save) { save_histograms_ = save; }
186 
188  inline bool
189  getSaveHistograms () const { return (save_histograms_); }
190 
192  inline boost::shared_ptr<std::vector<Eigen::MatrixXf, Eigen::aligned_allocator<Eigen::MatrixXf> > >
193  getHistograms () const { return (histograms_); }
194 
195  protected:
196 
202  void
203  computeFeature (PointCloudOut &output);
204 
206  boost::shared_ptr<std::vector<Eigen::MatrixXf, Eigen::aligned_allocator<Eigen::MatrixXf> > > histograms_;
207 
208  private:
210  int nr_subdiv_;
211 
213  double plane_radius_;
214 
216  bool save_histograms_;
217 
221  void
222  computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output) {}
223  public:
224  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
225  };
226 }
227 
228 #endif //#ifndef PCL_RSD_H_
229 
230