Point Cloud Library (PCL) 1.12.1
board.h
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2010-2012, 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 *
38 */
39
40#pragma once
41
42#include <pcl/point_types.h>
43#include <pcl/features/feature.h>
44
45namespace pcl
46{
47 /** \brief BOARDLocalReferenceFrameEstimation implements the BOrder Aware Repeatable Directions algorithm
48 * for local reference frame estimation as described here:
49 *
50 * - A. Petrelli, L. Di Stefano,
51 * "On the repeatability of the local reference frame for partial shape matching",
52 * 13th International Conference on Computer Vision (ICCV), 2011
53 *
54 * \author Alioscia Petrelli (original), Tommaso Cavallari (PCL port)
55 * \ingroup features
56 */
57 template<typename PointInT, typename PointNT, typename PointOutT = ReferenceFrame>
58 class BOARDLocalReferenceFrameEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
59 {
60 public:
61 using Ptr = shared_ptr<BOARDLocalReferenceFrameEstimation<PointInT, PointNT, PointOutT> >;
62 using ConstPtr = shared_ptr<const BOARDLocalReferenceFrameEstimation<PointInT, PointNT, PointOutT> >;
63
64 /** \brief Constructor. */
66 tangent_radius_ (0.0f),
67 find_holes_ (false),
68 margin_thresh_ (0.85f),
69 check_margin_array_size_ (24),
70 hole_size_prob_thresh_ (0.2f),
71 steep_thresh_ (0.1f)
72 {
73 feature_name_ = "BOARDLocalReferenceFrameEstimation";
74 setCheckMarginArraySize (check_margin_array_size_);
75 }
76
77 /** \brief Empty destructor */
79
80 //Getters/Setters
81
82 /** \brief Set the maximum distance of the points used to estimate the x_axis and y_axis of the BOARD Reference Frame for a given point.
83 *
84 * \param[in] radius The search radius for x and y axes. If not set or set to 0 the parameter given with setRadiusSearch is used.
85 */
86 inline void
87 setTangentRadius (float radius)
88 {
89 tangent_radius_ = radius;
90 }
91
92 /** \brief Get the maximum distance of the points used to estimate the x_axis and y_axis of the BOARD Reference Frame for a given point.
93 *
94 * \return The search radius for x and y axes. If set to 0 the parameter given with setRadiusSearch is used.
95 */
96 inline float
98 {
99 return (tangent_radius_);
100 }
101
102 /** \brief Sets whether holes in the margin of the support, for each point, are searched and accounted for in the estimation of the
103 * Reference Frame or not.
104 *
105 * \param[in] find_holes Enable/Disable the search for holes in the support.
106 */
107 inline void
108 setFindHoles (bool find_holes)
109 {
110 find_holes_ = find_holes;
111 }
112
113 /** \brief Gets whether holes in the margin of the support, for each point, are searched and accounted for in the estimation of the
114 * Reference Frame or not.
115 *
116 * \return The search for holes in the support is enabled/disabled.
117 */
118 inline bool
120 {
121 return (find_holes_);
122 }
123
124 /** \brief Sets the percentage of the search radius (or tangent radius if set) after which a point is considered part of the support margin.
125 *
126 * \param[in] margin_thresh the percentage of the search radius after which a point is considered a margin point.
127 */
128 inline void
129 setMarginThresh (float margin_thresh)
130 {
131 margin_thresh_ = margin_thresh;
132 }
133
134 /** \brief Gets the percentage of the search radius (or tangent radius if set) after which a point is considered part of the support margin.
135 *
136 * \return The percentage of the search radius after which a point is considered a margin point.
137 */
138 inline float
140 {
141 return (margin_thresh_);
142 }
143
144 /** \brief Sets the number of slices in which is divided the margin for the search of missing regions.
145 *
146 * \param[in] size the number of margin slices.
147 */
148 void
150 {
151 check_margin_array_size_ = size;
152
153 check_margin_array_.clear ();
154 check_margin_array_.resize (check_margin_array_size_);
155
156 margin_array_min_angle_.clear ();
157 margin_array_min_angle_.resize (check_margin_array_size_);
158
159 margin_array_max_angle_.clear ();
160 margin_array_max_angle_.resize (check_margin_array_size_);
161
162 margin_array_min_angle_normal_.clear ();
163 margin_array_min_angle_normal_.resize (check_margin_array_size_);
164
165 margin_array_max_angle_normal_.clear ();
166 margin_array_max_angle_normal_.resize (check_margin_array_size_);
167 }
168
169 /** \brief Gets the number of slices in which is divided the margin for the search of missing regions.
170 *
171 * \return the number of margin slices.
172 */
173 inline int
175 {
176 return (check_margin_array_size_);
177 }
178
179 /** \brief Given the angle width of a hole in the support margin, sets the minimum percentage of a circumference this angle
180 * must cover to be considered a missing region in the support and hence used for the estimation of the Reference Frame.
181 *
182 * \param[in] prob_thresh the minimum percentage of a circumference after which a hole is considered in the calculation
183 */
184 inline void
185 setHoleSizeProbThresh (float prob_thresh)
186 {
187 hole_size_prob_thresh_ = prob_thresh;
188 }
189
190 /** \brief Given the angle width of a hole in the support margin, gets the minimum percentage of a circumference this angle
191 * must cover to be considered a missing region in the support and hence used for the estimation of the Reference Frame.
192 *
193 * \return the minimum percentage of a circumference after which a hole is considered in the calculation
194 */
195 inline float
197 {
198 return (hole_size_prob_thresh_);
199 }
200
201 /** \brief Sets the minimum steepness that the normals of the points situated on the borders of the hole, with reference
202 * to the normal of the best point found by the algorithm, must have in order to be considered in the calculation of the Reference Frame.
203 *
204 * \param[in] steep_thresh threshold that defines if a missing region contains a point with the most different normal.
205 */
206 inline void
207 setSteepThresh (float steep_thresh)
208 {
209 steep_thresh_ = steep_thresh;
210 }
211
212 /** \brief Gets the minimum steepness that the normals of the points situated on the borders of the hole, with reference
213 * to the normal of the best point found by the algorithm, must have in order to be considered in the calculation of the Reference Frame.
214 *
215 * \return threshold that defines if a missing region contains a point with the most different normal.
216 */
217 inline float
219 {
220 return (steep_thresh_);
221 }
222
223 protected:
232
235
236 void
238 {
239 setCheckMarginArraySize (check_margin_array_size_);
240 }
241
242 /** \brief Estimate the LRF descriptor for a given point based on its spatial neighborhood of 3D points with normals
243 * \param[in] index the index of the point in input_
244 * \param[out] lrf the resultant local reference frame
245 */
246 float
247 computePointLRF (const int &index, Eigen::Matrix3f &lrf);
248
249 /** \brief Abstract feature estimation method.
250 * \param[out] output the resultant features
251 */
252 void
253 computeFeature (PointCloudOut &output) override;
254
255 /** \brief Given an axis (with origin axis_origin), return the orthogonal axis directed to point.
256 *
257 * \note axis must be normalized.
258 *
259 * \param[in] axis the axis
260 * \param[in] axis_origin the axis_origin
261 * \param[in] point the point towards which the resulting axis is directed
262 * \param[out] directed_ortho_axis the directed orthogonal axis calculated
263 */
264 void
265 directedOrthogonalAxis (Eigen::Vector3f const &axis, Eigen::Vector3f const &axis_origin,
266 Eigen::Vector3f const &point, Eigen::Vector3f &directed_ortho_axis);
267
268 /** \brief return the angle (in radians) that rotate v1 to v2 with respect to axis .
269 *
270 * \param[in] v1 the first vector
271 * \param[in] v2 the second vector
272 * \param[in] axis the rotation axis. Axis must be normalized and orthogonal to plane defined by v1 and v2.
273 * \return angle
274 */
275 float
276 getAngleBetweenUnitVectors (Eigen::Vector3f const &v1, Eigen::Vector3f const &v2, Eigen::Vector3f const &axis);
277
278 /** \brief Disambiguates a normal direction using adjacent normals
279 *
280 * \param[in] normals_cloud a cloud of normals used for the calculation
281 * \param[in] normal_indices the indices of the normals in the cloud that should to be used for the calculation
282 * \param[in,out] normal the normal to disambiguate, the calculation is performed in place
283 */
284 void
285 normalDisambiguation (pcl::PointCloud<PointNT> const &normals_cloud, pcl::Indices const &normal_indices,
286 Eigen::Vector3f &normal);
287
288 /** \brief Compute Least Square Plane Fitting in a set of 3D points
289 *
290 * \param[in] points Matrix(nPoints,3) of 3D points coordinates
291 * \param[out] center centroid of the distribution of points that belongs to the fitted plane
292 * \param[out] norm normal to the fitted plane
293 */
294 void
295 planeFitting (Eigen::Matrix<float, Eigen::Dynamic, 3> const &points, Eigen::Vector3f &center,
296 Eigen::Vector3f &norm);
297
298 /** \brief Given a plane (origin and normal) and a point, return the projection of x on plane
299 *
300 * Equivalent to vtkPlane::ProjectPoint()
301 *
302 * \param[in] point the point to project
303 * \param[in] origin_point a point belonging to the plane
304 * \param[in] plane_normal normal of the plane
305 * \param[out] projected_point the projection of the point on the plane
306 */
307 void
308 projectPointOnPlane (Eigen::Vector3f const &point, Eigen::Vector3f const &origin_point,
309 Eigen::Vector3f const &plane_normal, Eigen::Vector3f &projected_point);
310
311 /** \brief Given an axis, return a random orthogonal axis
312 *
313 * \param[in] axis input axis
314 * \param[out] rand_ortho_axis an axis orthogonal to the input axis and whose direction is random
315 */
316 void
317 randomOrthogonalAxis (Eigen::Vector3f const &axis, Eigen::Vector3f &rand_ortho_axis);
318
319 /** \brief Check if val1 and val2 are equals.
320 *
321 * \param[in] val1 first number to check.
322 * \param[in] val2 second number to check.
323 * \param[in] zero_float_eps epsilon
324 * \return true if val1 is equal to val2, false otherwise.
325 */
326 inline bool
327 areEquals (float val1, float val2, float zero_float_eps = 1E-8f) const
328 {
329 return (std::abs (val1 - val2) < zero_float_eps);
330 }
331
332 private:
333 /** \brief Radius used to find tangent axis. */
334 float tangent_radius_;
335
336 /** \brief If true, check if support is complete or has missing regions because it is too near to mesh borders. */
337 bool find_holes_;
338
339 /** \brief Threshold that define if a support point is near the margins. */
340 float margin_thresh_;
341
342 /** \brief Number of slices that divide the support in order to determine if a missing region is present. */
343 int check_margin_array_size_;
344
345 /** \brief Threshold used to determine a missing region */
346 float hole_size_prob_thresh_;
347
348 /** \brief Threshold that defines if a missing region contains a point with the most different normal. */
349 float steep_thresh_;
350
351 std::vector<bool> check_margin_array_;
352 std::vector<float> margin_array_min_angle_;
353 std::vector<float> margin_array_max_angle_;
354 std::vector<float> margin_array_min_angle_normal_;
355 std::vector<float> margin_array_max_angle_normal_;
356 };
357}
358
359#ifdef PCL_NO_PRECOMPILE
360#include <pcl/features/impl/board.hpp>
361#endif
BOARDLocalReferenceFrameEstimation implements the BOrder Aware Repeatable Directions algorithm for lo...
Definition: board.h:59
void setSteepThresh(float steep_thresh)
Sets the minimum steepness that the normals of the points situated on the borders of the hole,...
Definition: board.h:207
bool getFindHoles() const
Gets whether holes in the margin of the support, for each point, are searched and accounted for in th...
Definition: board.h:119
float getTangentRadius() const
Get the maximum distance of the points used to estimate the x_axis and y_axis of the BOARD Reference ...
Definition: board.h:97
void projectPointOnPlane(Eigen::Vector3f const &point, Eigen::Vector3f const &origin_point, Eigen::Vector3f const &plane_normal, Eigen::Vector3f &projected_point)
Given a plane (origin and normal) and a point, return the projection of x on plane.
Definition: board.hpp:66
~BOARDLocalReferenceFrameEstimation()
Empty destructor.
Definition: board.h:78
void directedOrthogonalAxis(Eigen::Vector3f const &axis, Eigen::Vector3f const &axis_origin, Eigen::Vector3f const &point, Eigen::Vector3f &directed_ortho_axis)
Given an axis (with origin axis_origin), return the orthogonal axis directed to point.
Definition: board.hpp:48
void setHoleSizeProbThresh(float prob_thresh)
Given the angle width of a hole in the support margin, sets the minimum percentage of a circumference...
Definition: board.h:185
float computePointLRF(const int &index, Eigen::Matrix3f &lrf)
Estimate the LRF descriptor for a given point based on its spatial neighborhood of 3D points with nor...
Definition: board.hpp:183
void planeFitting(Eigen::Matrix< float, Eigen::Dynamic, 3 > const &points, Eigen::Vector3f &center, Eigen::Vector3f &norm)
Compute Least Square Plane Fitting in a set of 3D points.
Definition: board.hpp:130
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: board.h:234
void setCheckMarginArraySize(int size)
Sets the number of slices in which is divided the margin for the search of missing regions.
Definition: board.h:149
void setTangentRadius(float radius)
Set the maximum distance of the points used to estimate the x_axis and y_axis of the BOARD Reference ...
Definition: board.h:87
float getMarginThresh() const
Gets the percentage of the search radius (or tangent radius if set) after which a point is considered...
Definition: board.h:139
float getAngleBetweenUnitVectors(Eigen::Vector3f const &v1, Eigen::Vector3f const &v2, Eigen::Vector3f const &axis)
return the angle (in radians) that rotate v1 to v2 with respect to axis .
Definition: board.hpp:83
void normalDisambiguation(pcl::PointCloud< PointNT > const &normals_cloud, pcl::Indices const &normal_indices, Eigen::Vector3f &normal)
Disambiguates a normal direction using adjacent normals.
Definition: board.hpp:158
BOARDLocalReferenceFrameEstimation()
Constructor.
Definition: board.h:65
void setMarginThresh(float margin_thresh)
Sets the percentage of the search radius (or tangent radius if set) after which a point is considered...
Definition: board.h:129
typename Feature< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: board.h:233
float getSteepThresh() const
Gets the minimum steepness that the normals of the points situated on the borders of the hole,...
Definition: board.h:218
int getCheckMarginArraySize() const
Gets the number of slices in which is divided the margin for the search of missing regions.
Definition: board.h:174
shared_ptr< BOARDLocalReferenceFrameEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition: board.h:61
void computeFeature(PointCloudOut &output) override
Abstract feature estimation method.
Definition: board.hpp:569
void randomOrthogonalAxis(Eigen::Vector3f const &axis, Eigen::Vector3f &rand_ortho_axis)
Given an axis, return a random orthogonal axis.
Definition: board.hpp:99
bool areEquals(float val1, float val2, float zero_float_eps=1E-8f) const
Check if val1 and val2 are equals.
Definition: board.h:327
float getHoleSizeProbThresh() const
Given the angle width of a hole in the support margin, gets the minimum percentage of a circumference...
Definition: board.h:196
void setFindHoles(bool find_holes)
Sets whether holes in the margin of the support, for each point, are searched and accounted for in th...
Definition: board.h:108
shared_ptr< const BOARDLocalReferenceFrameEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition: board.h:62
Feature represents the base feature class.
Definition: feature.h:107
std::string feature_name_
The feature name.
Definition: feature.h:223
Defines all the PCL implemented PointT point type structures.
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133