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