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