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