Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
our_cvfh.h
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 * 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: cvfh.h 4936 2012-03-07 11:12:45Z aaldoma $
38 *
39 */
40
41#pragma once
42
43#include <pcl/features/feature.h>
44#include <pcl/point_types.h> // for pcl::VFHSignature308, pcl::PointNormal
45
46namespace pcl
47{
48 /** \brief OURCVFHEstimation estimates the Oriented, Unique and Repetable Clustered Viewpoint Feature Histogram (CVFH) descriptor for a given
49 * point cloud dataset given XYZ data and normals, as presented in:
50 * - OUR-CVFH – Oriented, Unique and Repeatable Clustered Viewpoint Feature Histogram for Object Recognition and 6DOF Pose Estimation
51 * A. Aldoma, F. Tombari, R.B. Rusu and M. Vincze
52 * DAGM-OAGM 2012
53 * Graz, Austria
54 * The suggested PointOutT is pcl::VFHSignature308.
55 *
56 * \author Aitor Aldoma
57 * \ingroup features
58 */
59 template<typename PointInT, typename PointNT, typename PointOutT = pcl::VFHSignature308>
60 class OURCVFHEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
61 {
62 public:
63 using Ptr = shared_ptr<OURCVFHEstimation<PointInT, PointNT, PointOutT> >;
64 using ConstPtr = shared_ptr<const OURCVFHEstimation<PointInT, PointNT, PointOutT> >;
65 using Feature<PointInT, PointOutT>::feature_name_;
66 using Feature<PointInT, PointOutT>::getClassName;
67 using Feature<PointInT, PointOutT>::indices_;
68 using Feature<PointInT, PointOutT>::k_;
69 using Feature<PointInT, PointOutT>::search_radius_;
70 using Feature<PointInT, PointOutT>::surface_;
71 using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
72
76 /** \brief Empty constructor. */
78 cluster_tolerance_ (leaf_size_ * 3),
79 radius_normals_ (leaf_size_ * 3)
80 {
82 k_ = 1;
83 feature_name_ = "OURCVFHEstimation";
84 refine_clusters_ = 1.f;
85 min_axis_value_ = 0.925f;
86 axis_ratio_ = 0.8f;
87 }
88 ;
89
90 /** \brief Creates an affine transformation from the RF axes
91 * \param[in] evx the x-axis
92 * \param[in] evy the y-axis
93 * \param[in] evz the z-axis
94 * \param[out] transformPC the resulting transformation
95 * \param[in] center_mat 4x4 matrix concatenated to the resulting transformation
96 */
97 inline Eigen::Matrix4f
98 createTransFromAxes (Eigen::Vector3f & evx, Eigen::Vector3f & evy, Eigen::Vector3f & evz, Eigen::Affine3f & transformPC,
99 Eigen::Matrix4f & center_mat)
100 {
101 Eigen::Matrix4f trans;
102 trans.setIdentity (4, 4);
103 trans (0, 0) = evx (0, 0);
104 trans (1, 0) = evx (1, 0);
105 trans (2, 0) = evx (2, 0);
106 trans (0, 1) = evy (0, 0);
107 trans (1, 1) = evy (1, 0);
108 trans (2, 1) = evy (2, 0);
109 trans (0, 2) = evz (0, 0);
110 trans (1, 2) = evz (1, 0);
111 trans (2, 2) = evz (2, 0);
112
113 Eigen::Matrix4f homMatrix = Eigen::Matrix4f ();
114 homMatrix.setIdentity (4, 4);
115 homMatrix = transformPC.matrix ();
116
117 Eigen::Matrix4f trans_copy = trans.inverse ();
118 trans.noalias() = trans_copy * center_mat * homMatrix;
119 return trans;
120 }
121
122 /** \brief Computes SGURF and the shape distribution based on the selected SGURF
123 * \param[in] processed the input cloud
124 * \param[out] output the resulting signature
125 * \param[in] cluster_indices the indices of the stable cluster
126 */
127 void
128 computeRFAndShapeDistribution (PointInTPtr & processed, PointCloudOut &output, std::vector<pcl::PointIndices> & cluster_indices);
129
130 /** \brief Computes SGURF
131 * \param[in] centroid the centroid of the cluster
132 * \param[in] normal_centroid the average of the normals
133 * \param[in] processed the input cloud
134 * \param[out] transformations the transformations aligning the cloud to the SGURF axes
135 * \param[out] grid the cloud transformed internally
136 * \param[in] indices the indices of the stable cluster
137 */
138 bool
139 sgurf (Eigen::Vector3f & centroid, Eigen::Vector3f & normal_centroid, PointInTPtr & processed, std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > & transformations,
140 PointInTPtr & grid, pcl::PointIndices & indices);
141
142 /** \brief Removes normals with high curvature caused by real edges or noisy data
143 * \param[in] cloud pointcloud to be filtered
144 * \param[in] indices_to_use
145 * \param[out] indices_out the indices of the points with higher curvature than threshold
146 * \param[out] indices_in the indices of the remaining points after filtering
147 * \param[in] threshold threshold value for curvature
148 */
149 void
150 filterNormalsWithHighCurvature (const pcl::PointCloud<PointNT> & cloud, pcl::Indices & indices_to_use, pcl::Indices &indices_out,
151 pcl::Indices &indices_in, float threshold);
152
153 /** \brief Set the viewpoint.
154 * \param[in] vpx the X coordinate of the viewpoint
155 * \param[in] vpy the Y coordinate of the viewpoint
156 * \param[in] vpz the Z coordinate of the viewpoint
157 */
158 inline void
159 setViewPoint (float vpx, float vpy, float vpz)
160 {
161 vpx_ = vpx;
162 vpy_ = vpy;
163 vpz_ = vpz;
164 }
165
166 /** \brief Set the radius used to compute normals
167 * \param[in] radius_normals the radius
168 */
169 inline void
170 setRadiusNormals (float radius_normals)
171 {
172 radius_normals_ = radius_normals;
173 }
174
175 /** \brief Get the viewpoint.
176 * \param[out] vpx the X coordinate of the viewpoint
177 * \param[out] vpy the Y coordinate of the viewpoint
178 * \param[out] vpz the Z coordinate of the viewpoint
179 */
180 inline void
181 getViewPoint (float &vpx, float &vpy, float &vpz)
182 {
183 vpx = vpx_;
184 vpy = vpy_;
185 vpz = vpz_;
186 }
187
188 /** \brief Get the centroids used to compute different CVFH descriptors
189 * \param[out] centroids vector to hold the centroids
190 */
191 inline void
192 getCentroidClusters (std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > & centroids)
193 {
194 for (const auto & centroids_dominant_orientation : centroids_dominant_orientations_)
195 centroids.push_back (centroids_dominant_orientation);
196 }
197
198 /** \brief Get the normal centroids used to compute different CVFH descriptors
199 * \param[out] centroids vector to hold the normal centroids
200 */
201 inline void
202 getCentroidNormalClusters (std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > & centroids)
203 {
204 for (const auto & dominant_normal : dominant_normals_)
205 centroids.push_back (dominant_normal);
206 }
207
208 /** \brief Sets max. Euclidean distance between points to be added to the cluster
209 * \param[in] d the maximum Euclidean distance
210 */
211
212 inline void
214 {
215 cluster_tolerance_ = d;
216 }
217
218 /** \brief Sets max. deviation of the normals between two points so they can be clustered together
219 * \param[in] d the maximum deviation
220 */
221 inline void
223 {
224 eps_angle_threshold_ = d;
225 }
226
227 /** \brief Sets curvature threshold for removing normals
228 * \param[in] d the curvature threshold
229 */
230 inline void
232 {
233 curv_threshold_ = d;
234 }
235
236 /** \brief Set minimum amount of points for a cluster to be considered
237 * \param[in] min the minimum amount of points to be set
238 */
239 inline void
240 setMinPoints (std::size_t min)
241 {
242 min_points_ = min;
243 }
244
245 /** \brief Sets whether the signatures should be normalized or not
246 * \param[in] normalize true if normalization is required, false otherwise
247 */
248 inline void
249 setNormalizeBins (bool normalize)
250 {
251 normalize_bins_ = normalize;
252 }
253
254 /** \brief Gets the indices of the original point cloud used to compute the signatures
255 * \param[out] indices vector of point indices
256 */
257 inline void
258 getClusterIndices (std::vector<pcl::PointIndices> & indices)
259 {
260 indices = clusters_;
261 }
262
263 /** \brief Gets the number of non-disambiguable axes that correspond to each centroid
264 * \param[out] cluster_axes vector mapping each centroid to the number of signatures
265 */
266 inline void
267 getClusterAxes (std::vector<short> & cluster_axes)
268 {
269 cluster_axes = cluster_axes_;
270 }
271
272 /** \brief Sets the refinement factor for the clusters
273 * \param[in] rc the factor used to decide if a point is used to estimate a stable cluster
274 */
275 void
277 {
278 refine_clusters_ = rc;
279 }
280
281 /** \brief Returns the transformations aligning the point cloud to the corresponding SGURF
282 * \param[out] trans vector of transformations
283 */
284 void
285 getTransforms (std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > & trans)
286 {
287 trans = transforms_;
288 }
289
290 /** \brief Returns a boolean vector indicating of the transformation obtained by getTransforms() represents
291 * a valid SGURF
292 * \param[out] valid vector of booleans
293 */
294 void
295 getValidTransformsVec (std::vector<bool> & valid)
296 {
297 valid = valid_transforms_;
298 }
299
300 /** \brief Sets the min axis ratio between the SGURF axes to decide if disambiguition is feasible
301 * \param[in] f the ratio between axes
302 */
303 void
304 setAxisRatio (float f)
305 {
306 axis_ratio_ = f;
307 }
308
309 /** \brief Sets the min disambiguition axis value to generate several SGURFs for the cluster when disambiguition is difficult
310 * \param[in] f the min axis value
311 */
312 void
314 {
315 min_axis_value_ = f;
316 }
317
318 /** \brief Overloaded computed method from pcl::Feature.
319 * \param[out] output the resultant point cloud model dataset containing the estimated features
320 */
321 void
322 compute (PointCloudOut &output);
323
324 private:
325 /** \brief Values describing the viewpoint ("pinhole" camera model assumed).
326 * By default, the viewpoint is set to 0,0,0.
327 */
328 float vpx_{0.0f}, vpy_{0.0f}, vpz_{0.0f};
329
330 /** \brief Size of the voxels after voxel gridding. IMPORTANT: Must match the voxel
331 * size of the training data or the normalize_bins_ flag must be set to true.
332 */
333 float leaf_size_{0.005f};
334
335 /** \brief Whether to normalize the signatures or not. Default: false. */
336 bool normalize_bins_{false};
337
338 /** \brief Curvature threshold for removing normals. */
339 float curv_threshold_{0.03f};
340
341 /** \brief allowed Euclidean distance between points to be added to the cluster. */
342 float cluster_tolerance_;
343
344 /** \brief deviation of the normals between two points so they can be clustered together. */
345 float eps_angle_threshold_{0.125f};
346
347 /** \brief Minimum amount of points in a clustered region to be considered stable for CVFH
348 * computation.
349 */
350 std::size_t min_points_{50};
351
352 /** \brief Radius for the normals computation. */
353 float radius_normals_;
354
355 /** \brief Factor for the cluster refinement */
356 float refine_clusters_;
357
358 std::vector<Eigen::Matrix4f, Eigen::aligned_allocator<Eigen::Matrix4f> > transforms_;
359 std::vector<bool> valid_transforms_;
360
361 float axis_ratio_;
362 float min_axis_value_;
363
364 /** \brief Estimate the OUR-CVFH descriptors at
365 * a set of points given by <setInputCloud (), setIndices ()> using the surface in
366 * setSearchSurface ()
367 *
368 * \param[out] output the resultant point cloud model dataset that contains the OUR-CVFH
369 * feature estimates
370 */
371 void
372 computeFeature (PointCloudOut &output) override;
373
374 /** \brief Region growing method using Euclidean distances and neighbors normals to
375 * add points to a region.
376 * \param[in] cloud point cloud to split into regions
377 * \param[in] normals are the normals of cloud
378 * \param[in] tolerance is the allowed Euclidean distance between points to be added to
379 * the cluster
380 * \param[in] tree is the spatial search structure for nearest neighbour search
381 * \param[out] clusters vector of indices representing the clustered regions
382 * \param[in] eps_angle deviation of the normals between two points so they can be
383 * clustered together
384 * \param[in] min_pts_per_cluster minimum cluster size. (default: 1 point)
385 * \param[in] max_pts_per_cluster maximum cluster size. (default: all the points)
386 */
387 void
388 extractEuclideanClustersSmooth (const pcl::PointCloud<pcl::PointNormal> &cloud, const pcl::PointCloud<pcl::PointNormal> &normals,
389 float tolerance, const pcl::search::Search<pcl::PointNormal>::Ptr &tree,
390 std::vector<pcl::PointIndices> &clusters, double eps_angle, unsigned int min_pts_per_cluster = 1,
391 unsigned int max_pts_per_cluster = (std::numeric_limits<int>::max) ());
392
393 protected:
394 /** \brief Centroids that were used to compute different OUR-CVFH descriptors */
395 std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > centroids_dominant_orientations_;
396 /** \brief Normal centroids that were used to compute different OUR-CVFH descriptors */
397 std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > dominant_normals_;
398 /** \brief Indices to the points representing the stable clusters */
399 std::vector<pcl::PointIndices> clusters_;
400 /** \brief Mapping from clusters to OUR-CVFH descriptors */
401 std::vector<short> cluster_axes_;
402 };
403}
404
405#ifdef PCL_NO_PRECOMPILE
406#include <pcl/features/impl/our_cvfh.hpp>
407#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
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
int k_
The number of K nearest neighbors to use for each point.
Definition feature.h:240
std::string feature_name_
The feature name.
Definition feature.h:220
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation.
Definition feature.h:228
OURCVFHEstimation estimates the Oriented, Unique and Repetable Clustered Viewpoint Feature Histogram ...
Definition our_cvfh.h:61
void setClusterTolerance(float d)
Sets max.
Definition our_cvfh.h:213
void setNormalizeBins(bool normalize)
Sets whether the signatures should be normalized or not.
Definition our_cvfh.h:249
void getValidTransformsVec(std::vector< bool > &valid)
Returns a boolean vector indicating of the transformation obtained by getTransforms() represents a va...
Definition our_cvfh.h:295
bool sgurf(Eigen::Vector3f &centroid, Eigen::Vector3f &normal_centroid, PointInTPtr &processed, std::vector< Eigen::Matrix4f, Eigen::aligned_allocator< Eigen::Matrix4f > > &transformations, PointInTPtr &grid, pcl::PointIndices &indices)
Computes SGURF.
Definition our_cvfh.hpp:201
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition our_cvfh.h:73
void filterNormalsWithHighCurvature(const pcl::PointCloud< PointNT > &cloud, pcl::Indices &indices_to_use, pcl::Indices &indices_out, pcl::Indices &indices_in, float threshold)
Removes normals with high curvature caused by real edges or noisy data.
Definition our_cvfh.hpp:171
void getCentroidClusters(std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &centroids)
Get the centroids used to compute different CVFH descriptors.
Definition our_cvfh.h:192
void getViewPoint(float &vpx, float &vpy, float &vpz)
Get the viewpoint.
Definition our_cvfh.h:181
shared_ptr< const OURCVFHEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition our_cvfh.h:64
void setRadiusNormals(float radius_normals)
Set the radius used to compute normals.
Definition our_cvfh.h:170
void getTransforms(std::vector< Eigen::Matrix4f, Eigen::aligned_allocator< Eigen::Matrix4f > > &trans)
Returns the transformations aligning the point cloud to the corresponding SGURF.
Definition our_cvfh.h:285
void getCentroidNormalClusters(std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > &centroids)
Get the normal centroids used to compute different CVFH descriptors.
Definition our_cvfh.h:202
void setMinAxisValue(float f)
Sets the min disambiguition axis value to generate several SGURFs for the cluster when disambiguition...
Definition our_cvfh.h:313
shared_ptr< OURCVFHEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition our_cvfh.h:63
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
Definition our_cvfh.hpp:54
Eigen::Matrix4f createTransFromAxes(Eigen::Vector3f &evx, Eigen::Vector3f &evy, Eigen::Vector3f &evz, Eigen::Affine3f &transformPC, Eigen::Matrix4f &center_mat)
Creates an affine transformation from the RF axes.
Definition our_cvfh.h:98
typename pcl::search::Search< PointNormal >::Ptr KdTreePtr
Definition our_cvfh.h:74
void setViewPoint(float vpx, float vpy, float vpz)
Set the viewpoint.
Definition our_cvfh.h:159
void setRefineClusters(float rc)
Sets the refinement factor for the clusters.
Definition our_cvfh.h:276
OURCVFHEstimation()
Empty constructor.
Definition our_cvfh.h:77
std::vector< pcl::PointIndices > clusters_
Indices to the points representing the stable clusters.
Definition our_cvfh.h:399
std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > dominant_normals_
Normal centroids that were used to compute different OUR-CVFH descriptors.
Definition our_cvfh.h:397
std::vector< short > cluster_axes_
Mapping from clusters to OUR-CVFH descriptors.
Definition our_cvfh.h:401
std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > centroids_dominant_orientations_
Centroids that were used to compute different OUR-CVFH descriptors.
Definition our_cvfh.h:395
void setAxisRatio(float f)
Sets the min axis ratio between the SGURF axes to decide if disambiguition is feasible.
Definition our_cvfh.h:304
typename pcl::PointCloud< PointInT >::Ptr PointInTPtr
Definition our_cvfh.h:75
void setCurvatureThreshold(float d)
Sets curvature threshold for removing normals.
Definition our_cvfh.h:231
void getClusterIndices(std::vector< pcl::PointIndices > &indices)
Gets the indices of the original point cloud used to compute the signatures.
Definition our_cvfh.h:258
void getClusterAxes(std::vector< short > &cluster_axes)
Gets the number of non-disambiguable axes that correspond to each centroid.
Definition our_cvfh.h:267
void setMinPoints(std::size_t min)
Set minimum amount of points for a cluster to be considered.
Definition our_cvfh.h:240
void setEPSAngleThreshold(float d)
Sets max.
Definition our_cvfh.h:222
void computeRFAndShapeDistribution(PointInTPtr &processed, PointCloudOut &output, std::vector< pcl::PointIndices > &cluster_indices)
Computes SGURF and the shape distribution based on the selected SGURF.
Definition our_cvfh.hpp:384
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< pcl::search::Search< PointT > > Ptr
Definition search.h:81
Defines all the PCL implemented PointT point type structures.
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition types.h:133