Point Cloud Library (PCL)  1.12.1-dev
boundary.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  *
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/features/feature.h>
44
45 namespace pcl
46 {
47  /** \brief BoundaryEstimation estimates whether a set of points is lying on surface boundaries using an angle
48  * criterion. The code makes use of the estimated surface normals at each point in the input dataset.
49  *
50  * Here's an example for estimating boundary points for a PointXYZ point cloud:
51  * \code
52  * pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
53  * // fill in the cloud data here
54  *
55  * pcl::PointCloud<pcl::Normal>::Ptr normals (new pcl::PointCloud<pcl::Normal>);
56  * // estimate normals and fill in \a normals
57  *
58  * pcl::PointCloud<pcl::Boundary> boundaries;
59  * pcl::BoundaryEstimation<pcl::PointXYZ, pcl::Normal, pcl::Boundary> est;
60  * est.setInputCloud (cloud);
61  * est.setInputNormals (normals);
62  * est.setRadiusSearch (0.02); // 2cm radius
63  * est.setSearchMethod (typename pcl::search::KdTree<PointXYZ>::Ptr (new pcl::search::KdTree<PointXYZ>)
64  * est.compute (boundaries);
65  * \endcode
66  *
67  * \attention
68  * The convention for Boundary features is:
69  * - if a query point's nearest neighbors cannot be estimated, the boundary feature will be set to NaN
70  * (not a number)
71  * - it is impossible to estimate a boundary property for a point that
72  * doesn't have finite 3D coordinates. Therefore, any point that contains
73  * NaN data on x, y, or z, will have its boundary feature property set to NaN.
74  *
75  * \author Radu B. Rusu
76  * \ingroup features
77  */
78  template <typename PointInT, typename PointNT, typename PointOutT>
79  class BoundaryEstimation: public FeatureFromNormals<PointInT, PointNT, PointOutT>
80  {
81  public:
82  using Ptr = shared_ptr<BoundaryEstimation<PointInT, PointNT, PointOutT> >;
83  using ConstPtr = shared_ptr<const BoundaryEstimation<PointInT, PointNT, PointOutT> >;
84
95
97
98  public:
99  /** \brief Empty constructor.
100  * The angular threshold \a angle_threshold_ is set to M_PI / 2.0
101  */
102  BoundaryEstimation () : angle_threshold_ (static_cast<float> (M_PI) / 2.0f)
103  {
104  feature_name_ = "BoundaryEstimation";
105  };
106
107  /** \brief Check whether a point is a boundary point in a planar patch of projected points given by indices.
108  * \note A coordinate system u-v-n must be computed a-priori using \a getCoordinateSystemOnPlane
109  * \param[in] cloud a pointer to the input point cloud
110  * \param[in] q_idx the index of the query point in \a cloud
111  * \param[in] indices the estimated point neighbors of the query point
112  * \param[in] u the u direction
113  * \param[in] v the v direction
114  * \param[in] angle_threshold the threshold angle (default \f$\pi / 2.0\f$)
115  */
116  bool
118  int q_idx, const pcl::Indices &indices,
119  const Eigen::Vector4f &u, const Eigen::Vector4f &v, const float angle_threshold);
120
121  /** \brief Check whether a point is a boundary point in a planar patch of projected points given by indices.
122  * \note A coordinate system u-v-n must be computed a-priori using \a getCoordinateSystemOnPlane
123  * \param[in] cloud a pointer to the input point cloud
124  * \param[in] q_point a pointer to the querry point
125  * \param[in] indices the estimated point neighbors of the query point
126  * \param[in] u the u direction
127  * \param[in] v the v direction
128  * \param[in] angle_threshold the threshold angle (default \f$\pi / 2.0\f$)
129  */
130  bool
132  const PointInT &q_point,
133  const pcl::Indices &indices,
134  const Eigen::Vector4f &u, const Eigen::Vector4f &v, const float angle_threshold);
135
136  /** \brief Set the decision boundary (angle threshold) that marks points as boundary or regular.
137  * (default \f$\pi / 2.0\f$)
138  * \param[in] angle the angle threshold
139  */
140  inline void
141  setAngleThreshold (float angle)
142  {
143  angle_threshold_ = angle;
144  }
145
146  /** \brief Get the decision boundary (angle threshold) as set by the user. */
147  inline float
149  {
150  return (angle_threshold_);
151  }
152
153  /** \brief Get a u-v-n coordinate system that lies on a plane defined by its normal
154  * \param[in] p_coeff the plane coefficients (containing the plane normal)
155  * \param[out] u the resultant u direction
156  * \param[out] v the resultant v direction
157  */
158  inline void
159  getCoordinateSystemOnPlane (const PointNT &p_coeff,
160  Eigen::Vector4f &u, Eigen::Vector4f &v)
161  {
162  pcl::Vector4fMapConst p_coeff_v = p_coeff.getNormalVector4fMap ();
163  v = p_coeff_v.unitOrthogonal ();
164  u = p_coeff_v.cross3 (v);
165  }
166
167  protected:
168  /** \brief Estimate whether a set of points is lying on surface boundaries using an angle criterion for all points
169  * given in <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
170  * setSearchMethod ()
171  * \param[out] output the resultant point cloud model dataset that contains boundary point estimates
172  */
173  void
174  computeFeature (PointCloudOut &output) override;
175
176  /** \brief The decision boundary (angle threshold) that marks points as boundary or regular. (default \f$\pi / 2.0\f$) */
178  };
179 }
180
181 #ifdef PCL_NO_PRECOMPILE
182 #include <pcl/features/impl/boundary.hpp>
183 #endif
BoundaryEstimation estimates whether a set of points is lying on surface boundaries using an angle cr...
Definition: boundary.h:80
void getCoordinateSystemOnPlane(const PointNT &p_coeff, Eigen::Vector4f &u, Eigen::Vector4f &v)
Get a u-v-n coordinate system that lies on a plane defined by its normal.
Definition: boundary.h:159
shared_ptr< BoundaryEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition: boundary.h:82
float getAngleThreshold()
Get the decision boundary (angle threshold) as set by the user.
Definition: boundary.h:148
BoundaryEstimation()
Empty constructor.
Definition: boundary.h:102
shared_ptr< const BoundaryEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition: boundary.h:83
void computeFeature(PointCloudOut &output) override
Estimate whether a set of points is lying on surface boundaries using an angle criterion for all poin...
Definition: boundary.hpp:116
void setAngleThreshold(float angle)
Set the decision boundary (angle threshold) that marks points as boundary or regular.
Definition: boundary.h:141
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: boundary.h:96
bool isBoundaryPoint(const pcl::PointCloud< PointInT > &cloud, int q_idx, const pcl::Indices &indices, const Eigen::Vector4f &u, const Eigen::Vector4f &v, const float angle_threshold)
Check whether a point is a boundary point in a planar patch of projected points given by indices.
Definition: boundary.hpp:51
float angle_threshold_
The decision boundary (angle threshold) that marks points as boundary or regular.
Definition: boundary.h:177
Feature represents the base feature class.
Definition: feature.h:107
std::string feature_name_
The feature name.
Definition: feature.h:220
const Eigen::Map< const Eigen::Vector4f, Eigen::Aligned > Vector4fMapConst
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
#define M_PI
Definition: pcl_macros.h:201