Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
rsd.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2009, Willow Garage, Inc.
6 * Copyright (c) 2012-, Open Perception, Inc.
7 *
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials provided
19 * with the distribution.
20 * * Neither the name of the copyright holder(s) nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 * $Id$
38 *
39 */
40
41#pragma once
42
43#include <pcl/memory.h>
44#include <pcl/pcl_macros.h>
45#include <pcl/features/feature.h>
46#include <pcl/point_types.h> // for Histogram
47
48namespace pcl
49{
50 /** \brief Transform a list of 2D matrices into a point cloud containing the values in a vector (Histogram<N>).
51 * Can be used to transform the 2D histograms obtained in \ref RSDEstimation into a point cloud.
52 * @note The template parameter N should be (greater or) equal to the product of the number of rows and columns.
53 * \param[in] histograms2D the list of neighborhood 2D histograms
54 * \param[out] histogramsPC the dataset containing the linearized matrices
55 * \ingroup features
56 */
57 template <int N> void
58 getFeaturePointCloud (const std::vector<Eigen::MatrixXf, Eigen::aligned_allocator<Eigen::MatrixXf> > &histograms2D, PointCloud<Histogram<N> > &histogramsPC)
59 {
60 histogramsPC.resize (histograms2D.size ());
61 histogramsPC.width = histograms2D.size ();
62 histogramsPC.height = 1;
63 histogramsPC.is_dense = true;
64
65 const int rows = histograms2D.at(0).rows();
66 const int cols = histograms2D.at(0).cols();
67
68 typename PointCloud<Histogram<N> >::VectorType::iterator it = histogramsPC.begin ();
69 for (const Eigen::MatrixXf& h : histograms2D)
70 {
71 Eigen::Map<Eigen::MatrixXf> histogram (&(it->histogram[0]), rows, cols);
72 histogram = h;
73 ++it;
74 }
75 }
76
77 /** \brief Estimate the Radius-based Surface Descriptor (RSD) for a given point based on its spatial neighborhood of 3D points with normals
78 * \param[in] surface the dataset containing the XYZ points
79 * \param[in] normals the dataset containing the surface normals at each point in the dataset
80 * \param[in] indices the neighborhood point indices in the dataset (first point is used as the reference)
81 * \param[in] max_dist the upper bound for the considered distance interval
82 * \param[in] nr_subdiv the number of subdivisions for the considered distance interval
83 * \param[in] plane_radius maximum radius, above which everything can be considered planar
84 * \param[in] radii the output point of a type that should have r_min and r_max fields
85 * \param[in] compute_histogram if not false, the full neighborhood histogram is provided, usable as a point signature
86 * \ingroup features
87 */
88 template <typename PointInT, typename PointNT, typename PointOutT> Eigen::MatrixXf
90 const pcl::Indices &indices, double max_dist,
91 int nr_subdiv, double plane_radius, PointOutT &radii, bool compute_histogram = false);
92
93 /** \brief Estimate the Radius-based Surface Descriptor (RSD) for a given point based on its spatial neighborhood of 3D points with normals
94 * \param[in] normals the dataset containing the surface normals at each point in the dataset
95 * \param[in] indices the neighborhood point indices in the dataset (first point is used as the reference)
96 * \param[in] sqr_dists the squared distances from the first to all points in the neighborhood
97 * \param[in] max_dist the upper bound for the considered distance interval
98 * \param[in] nr_subdiv the number of subdivisions for the considered distance interval
99 * \param[in] plane_radius maximum radius, above which everything can be considered planar
100 * \param[in] radii the output point of a type that should have r_min and r_max fields
101 * \param[in] compute_histogram if not false, the full neighborhood histogram is provided, usable as a point signature
102 * \ingroup features
103 */
104 template <typename PointNT, typename PointOutT> Eigen::MatrixXf
105 computeRSD (const pcl::PointCloud<PointNT> &normals,
106 const pcl::Indices &indices, const std::vector<float> &sqr_dists, double max_dist,
107 int nr_subdiv, double plane_radius, PointOutT &radii, bool compute_histogram = false);
108
109 /** \brief @b RSDEstimation estimates the Radius-based Surface Descriptor (minimal and maximal radius of the local surface's curves)
110 * for a given point cloud dataset containing points and normals.
111 *
112 * @note If you use this code in any academic work, please cite:
113 *
114 * <ul>
115 * <li> Z.C. Marton , D. Pangercic , N. Blodow , J. Kleinehellefort, M. Beetz
116 * General 3D Modelling of Novel Objects from a Single View
117 * In Proceedings of the 2010 IEEE/RSJ International Conference on Intelligent Robots and Systems (IROS)
118 * Taipei, Taiwan, October 18-22, 2010
119 * </li>
120 * <li> Z.C. Marton, D. Pangercic, N. Blodow, Michael Beetz.
121 * Combined 2D-3D Categorization and Classification for Multimodal Perception Systems.
122 * In The International Journal of Robotics Research, Sage Publications
123 * pages 1378--1402, Volume 30, Number 11, September 2011.
124 * </li>
125 * </ul>
126 *
127 * @note The code is stateful as we do not expect this class to be multicore parallelized.
128 * \author Zoltan-Csaba Marton
129 * \ingroup features
130 * \tparam PointOutT Suggested type is `pcl::PrincipalRadiiRSD`
131 */
132 template <typename PointInT, typename PointNT, typename PointOutT>
133 class RSDEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
134 {
135 public:
136 using Feature<PointInT, PointOutT>::feature_name_;
137 using Feature<PointInT, PointOutT>::getClassName;
138 using Feature<PointInT, PointOutT>::indices_;
139 using Feature<PointInT, PointOutT>::search_radius_;
140 using Feature<PointInT, PointOutT>::search_parameter_;
141 using Feature<PointInT, PointOutT>::surface_;
142 using Feature<PointInT, PointOutT>::tree_;
143 using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
144
147
148 using Ptr = shared_ptr<RSDEstimation<PointInT, PointNT, PointOutT> >;
149 using ConstPtr = shared_ptr<const RSDEstimation<PointInT, PointNT, PointOutT> >;
150
151
152 /** \brief Empty constructor. */
154 {
155 feature_name_ = "RadiusSurfaceDescriptor";
156 }
157
158 /** \brief Set the number of subdivisions for the considered distance interval.
159 * \param[in] nr_subdiv the number of subdivisions
160 */
161 inline void
162 setNrSubdivisions (int nr_subdiv) { nr_subdiv_ = nr_subdiv; }
163
164 /** \brief Get the number of subdivisions for the considered distance interval.
165 * \return the number of subdivisions
166 */
167 inline int
168 getNrSubdivisions () const { return (nr_subdiv_); }
169
170 /** \brief Set the maximum radius, above which everything can be considered planar.
171 * \note the order of magnitude should be around 10-20 times the search radius (0.2 works well for typical datasets).
172 * \note on accurate 3D data (e.g. openni sensors) a search radius as low as 0.01 still gives good results.
173 * \param[in] plane_radius the new plane radius
174 */
175 inline void
176 setPlaneRadius (double plane_radius) { plane_radius_ = plane_radius; }
177
178 /** \brief Get the maximum radius, above which everything can be considered planar.
179 * \return the plane_radius used
180 */
181 inline double
182 getPlaneRadius () const { return (plane_radius_); }
183
184 /** \brief Disables the setting of the number of k nearest neighbors to use for the feature estimation. */
185 inline void
187 {
188 PCL_ERROR ("[pcl::%s::setKSearch] RSD does not work with k nearest neighbor search. Use setRadiusSearch() instead!\n", getClassName ().c_str ());
189 }
190
191 /** \brief Set whether the full distance-angle histograms should be saved.
192 * @note Obtain the list of histograms by getHistograms ()
193 * \param[in] save set to true if histograms should be saved
194 */
195 inline void
196 setSaveHistograms (bool save) { save_histograms_ = save; }
197
198 /** \brief Returns whether the full distance-angle histograms are being saved.
199 * \return true if the histograms are being be saved
200 */
201 inline bool
202 getSaveHistograms () const { return (save_histograms_); }
203
204 /** \brief Returns a pointer to the list of full distance-angle histograms for all points.
205 * \return the histogram being saved when computing RSD
206 */
207 inline shared_ptr<std::vector<Eigen::MatrixXf, Eigen::aligned_allocator<Eigen::MatrixXf> > >
208 getHistograms () const { return (histograms_); }
209
210 protected:
211
212 /** \brief Estimate the estimates the Radius-based Surface Descriptor (RSD) at a set of points given by
213 * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
214 * setSearchMethod ()
215 * \param output the resultant point cloud model dataset that contains the RSD feature estimates (r_min and r_max values)
216 */
217 void
218 computeFeature (PointCloudOut &output) override;
219
220 /** \brief The list of full distance-angle histograms for all points. */
221 shared_ptr<std::vector<Eigen::MatrixXf, Eigen::aligned_allocator<Eigen::MatrixXf> > > histograms_;
222
223 private:
224 /** \brief The number of subdivisions for the considered distance interval. */
225 int nr_subdiv_{5};
226
227 /** \brief The maximum radius, above which everything can be considered planar. */
228 double plane_radius_{0.2};
229
230 /** \brief Signals whether the full distance-angle histograms are being saved. */
231 bool save_histograms_{false};
232
233 public:
235 };
236}
237
238#ifdef PCL_NO_PRECOMPILE
239#include <pcl/features/impl/rsd.hpp>
240#endif
PointCloudNConstPtr normals_
A pointer to the input dataset that contains the point normals of the XYZ dataset.
Definition feature.h:349
Feature represents the base feature class.
Definition feature.h:107
double search_parameter_
The actual search parameter (from either search_radius_ or k_).
Definition feature.h:234
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition feature.h:244
double search_radius_
The nearest neighbors search radius for each point.
Definition feature.h:237
std::string feature_name_
The feature name.
Definition feature.h:220
KdTreePtr tree_
A pointer to the spatial search object.
Definition feature.h:231
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation.
Definition feature.h:228
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
PointCloud represents the base class in PCL for storing collections of 3D points.
iterator begin() noexcept
RSDEstimation estimates the Radius-based Surface Descriptor (minimal and maximal radius of the local ...
Definition rsd.h:134
void setNrSubdivisions(int nr_subdiv)
Set the number of subdivisions for the considered distance interval.
Definition rsd.h:162
shared_ptr< std::vector< Eigen::MatrixXf, Eigen::aligned_allocator< Eigen::MatrixXf > > > getHistograms() const
Returns a pointer to the list of full distance-angle histograms for all points.
Definition rsd.h:208
shared_ptr< const RSDEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition rsd.h:149
void setKSearch(int)
Disables the setting of the number of k nearest neighbors to use for the feature estimation.
Definition rsd.h:186
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition rsd.h:145
int getNrSubdivisions() const
Get the number of subdivisions for the considered distance interval.
Definition rsd.h:168
typename Feature< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition rsd.h:146
void computeFeature(PointCloudOut &output) override
Estimate the estimates the Radius-based Surface Descriptor (RSD) at a set of points given by <setInpu...
Definition rsd.hpp:248
RSDEstimation()
Empty constructor.
Definition rsd.h:153
bool getSaveHistograms() const
Returns whether the full distance-angle histograms are being saved.
Definition rsd.h:202
double getPlaneRadius() const
Get the maximum radius, above which everything can be considered planar.
Definition rsd.h:182
shared_ptr< RSDEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition rsd.h:148
void setSaveHistograms(bool save)
Set whether the full distance-angle histograms should be saved.
Definition rsd.h:196
shared_ptr< std::vector< Eigen::MatrixXf, Eigen::aligned_allocator< Eigen::MatrixXf > > > histograms_
The list of full distance-angle histograms for all points.
Definition rsd.h:221
void setPlaneRadius(double plane_radius)
Set the maximum radius, above which everything can be considered planar.
Definition rsd.h:176
Defines all the PCL implemented PointT point type structures.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition memory.h:86
void getFeaturePointCloud(const std::vector< Eigen::MatrixXf, Eigen::aligned_allocator< Eigen::MatrixXf > > &histograms2D, PointCloud< Histogram< N > > &histogramsPC)
Transform a list of 2D matrices into a point cloud containing the values in a vector (Histogram<N>).
Definition rsd.h:58
Eigen::MatrixXf computeRSD(const pcl::PointCloud< PointInT > &surface, const pcl::PointCloud< PointNT > &normals, const pcl::Indices &indices, double max_dist, int nr_subdiv, double plane_radius, PointOutT &radii, bool compute_histogram=false)
Estimate the Radius-based Surface Descriptor (RSD) for a given point based on its spatial neighborhoo...
Definition rsd.hpp:49
Defines functions, macros and traits for allocating and using memory.
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133
Defines all the PCL and non-PCL macros used.
A point structure representing an N-D histogram.