Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
boundary.hpp
Go to the documentation of this file.
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  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: boundary.hpp 5026 2012-03-12 02:51:44Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FEATURES_IMPL_BOUNDARY_H_
41 #define PCL_FEATURES_IMPL_BOUNDARY_H_
42 
43 #include <pcl/features/boundary.h>
44 #include <cfloat>
45 
47 template <typename PointInT, typename PointNT, typename PointOutT> bool
49  const pcl::PointCloud<PointInT> &cloud, int q_idx,
50  const std::vector<int> &indices,
51  const Eigen::Vector4f &u, const Eigen::Vector4f &v,
52  const float angle_threshold)
53 {
54  return (isBoundaryPoint (cloud, cloud.points[q_idx], indices, u, v, angle_threshold));
55 }
56 
58 template <typename PointInT, typename PointNT, typename PointOutT> bool
60  const pcl::PointCloud<PointInT> &cloud, const PointInT &q_point,
61  const std::vector<int> &indices,
62  const Eigen::Vector4f &u, const Eigen::Vector4f &v,
63  const float angle_threshold)
64 {
65  if (indices.size () < 3)
66  return (false);
67 
68  if (!pcl_isfinite (q_point.x) || !pcl_isfinite (q_point.y) || !pcl_isfinite (q_point.z))
69  return (false);
70 
71  // Compute the angles between each neighboring point and the query point itself
72  std::vector<float> angles (indices.size ());
73  float max_dif = FLT_MIN, dif;
74  int cp = 0;
75 
76  for (size_t i = 0; i < indices.size (); ++i)
77  {
78  if (!pcl_isfinite (cloud.points[indices[i]].x) ||
79  !pcl_isfinite (cloud.points[indices[i]].y) ||
80  !pcl_isfinite (cloud.points[indices[i]].z))
81  continue;
82 
83  Eigen::Vector4f delta = cloud.points[indices[i]].getVector4fMap () - q_point.getVector4fMap ();
84 
85  angles[cp++] = atan2f (v.dot (delta), u.dot (delta)); // the angles are fine between -PI and PI too
86  }
87  if (cp == 0)
88  return (false);
89 
90  angles.resize (cp);
91  std::sort (angles.begin (), angles.end ());
92 
93  // Compute the maximal angle difference between two consecutive angles
94  for (size_t i = 0; i < angles.size () - 1; ++i)
95  {
96  dif = angles[i + 1] - angles[i];
97  if (max_dif < dif)
98  max_dif = dif;
99  }
100  // Get the angle difference between the last and the first
101  dif = 2 * static_cast<float> (M_PI) - angles[angles.size () - 1] + angles[0];
102  if (max_dif < dif)
103  max_dif = dif;
104 
105  // Check results
106  if (max_dif > angle_threshold)
107  return (true);
108  else
109  return (false);
110 }
111 
113 template <typename PointInT, typename PointNT, typename PointOutT> void
115 {
116  // Allocate enough space to hold the results
117  // \note This resize is irrelevant for a radiusSearch ().
118  std::vector<int> nn_indices (k_);
119  std::vector<float> nn_dists (k_);
120 
121  Eigen::Vector4f u = Eigen::Vector4f::Zero (), v = Eigen::Vector4f::Zero ();
122 
123  output.is_dense = true;
124  // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
125  if (input_->is_dense)
126  {
127  // Iterating over the entire index vector
128  for (size_t idx = 0; idx < indices_->size (); ++idx)
129  {
130  if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
131  {
132  output.points[idx].boundary_point = std::numeric_limits<uint8_t>::quiet_NaN ();
133  output.is_dense = false;
134  continue;
135  }
136 
137  // Obtain a coordinate system on the least-squares plane
138  //v = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().unitOrthogonal ();
139  //u = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().cross3 (v);
140  getCoordinateSystemOnPlane (normals_->points[(*indices_)[idx]], u, v);
141 
142  // Estimate whether the point is lying on a boundary surface or not
143  output.points[idx].boundary_point = isBoundaryPoint (*surface_, input_->points[(*indices_)[idx]], nn_indices, u, v, angle_threshold_);
144  }
145  }
146  else
147  {
148  // Iterating over the entire index vector
149  for (size_t idx = 0; idx < indices_->size (); ++idx)
150  {
151  if (!isFinite ((*input_)[(*indices_)[idx]]) ||
152  this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
153  {
154  output.points[idx].boundary_point = std::numeric_limits<uint8_t>::quiet_NaN ();
155  output.is_dense = false;
156  continue;
157  }
158 
159  // Obtain a coordinate system on the least-squares plane
160  //v = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().unitOrthogonal ();
161  //u = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().cross3 (v);
162  getCoordinateSystemOnPlane (normals_->points[(*indices_)[idx]], u, v);
163 
164  // Estimate whether the point is lying on a boundary surface or not
165  output.points[idx].boundary_point = isBoundaryPoint (*surface_, input_->points[(*indices_)[idx]], nn_indices, u, v, angle_threshold_);
166  }
167  }
168 }
169 
171 template <typename PointInT, typename PointNT> void
173 {
174  // Allocate enough space to hold the results
175  // \note This resize is irrelevant for a radiusSearch ().
176  std::vector<int> nn_indices (k_);
177  std::vector<float> nn_dists (k_);
178 
179  Eigen::Vector4f u = Eigen::Vector4f::Zero (), v = Eigen::Vector4f::Zero ();
180 
181  output.is_dense = true;
182  output.points.resize (indices_->size (), 1);
183  // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
184  if (input_->is_dense)
185  {
186  // Iterating over the entire index vector
187  for (size_t idx = 0; idx < indices_->size (); ++idx)
188  {
189  if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
190  {
191  output.points (idx, 0) = std::numeric_limits<float>::quiet_NaN ();
192  output.is_dense = false;
193  continue;
194  }
195 
196  // Obtain a coordinate system on the least-squares plane
197  //v = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().unitOrthogonal ();
198  //u = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().cross3 (v);
199  this->getCoordinateSystemOnPlane (normals_->points[(*indices_)[idx]], u, v);
200 
201  // Estimate whether the point is lying on a boundary surface or not
202  output.points (idx, 0) = this->isBoundaryPoint (*surface_, input_->points[(*indices_)[idx]], nn_indices, u, v, angle_threshold_);
203  }
204  }
205  else
206  {
207  // Iterating over the entire index vector
208  for (size_t idx = 0; idx < indices_->size (); ++idx)
209  {
210  if (!isFinite ((*input_)[(*indices_)[idx]]) ||
211  this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
212  {
213  output.points (idx, 0) = std::numeric_limits<float>::quiet_NaN ();
214  output.is_dense = false;
215  continue;
216  }
217 
218  // Obtain a coordinate system on the least-squares plane
219  //v = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().unitOrthogonal ();
220  //u = normals_->points[(*indices_)[idx]].getNormalVector4fMap ().cross3 (v);
221  this->getCoordinateSystemOnPlane (normals_->points[(*indices_)[idx]], u, v);
222 
223  // Estimate whether the point is lying on a boundary surface or not
224  output.points (idx, 0) = this->isBoundaryPoint (*surface_, input_->points[(*indices_)[idx]], nn_indices, u, v, angle_threshold_);
225  }
226  }
227 }
228 
229 #define PCL_INSTANTIATE_BoundaryEstimation(PointInT,PointNT,PointOutT) template class PCL_EXPORTS pcl::BoundaryEstimation<PointInT, PointNT, PointOutT>;
230 
231 #endif // PCL_FEATURES_IMPL_BOUNDARY_H_
232