Point Cloud Library (PCL)  1.7.2
normal_3d_omp.hpp
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 #ifndef PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
42 #define PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
43 
44 #include <pcl/features/normal_3d_omp.h>
45 
46 ///////////////////////////////////////////////////////////////////////////////////////////
47 template <typename PointInT, typename PointOutT> void
49 {
50  // Allocate enough space to hold the results
51  // \note This resize is irrelevant for a radiusSearch ().
52  std::vector<int> nn_indices (k_);
53  std::vector<float> nn_dists (k_);
54 
55  output.is_dense = true;
56 
57  // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
58  if (input_->is_dense)
59  {
60 #ifdef _OPENMP
61 #pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
62 #endif
63  // Iterating over the entire index vector
64  for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
65  {
66  if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
67  {
68  output.points[idx].normal[0] = output.points[idx].normal[1] = output.points[idx].normal[2] = output.points[idx].curvature = std::numeric_limits<float>::quiet_NaN ();
69 
70  output.is_dense = false;
71  continue;
72  }
73 
74  Eigen::Vector4f n;
75  pcl::computePointNormal<PointInT> (*surface_, nn_indices,
76  n,
77  output.points[idx].curvature);
78 
79  output.points[idx].normal_x = n[0];
80  output.points[idx].normal_y = n[1];
81  output.points[idx].normal_z = n[2];
82 
83  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
84  output.points[idx].normal[0],
85  output.points[idx].normal[1],
86  output.points[idx].normal[2]);
87  }
88  }
89  else
90  {
91 #ifdef _OPENMP
92 #pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
93 #endif
94  // Iterating over the entire index vector
95  for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
96  {
97  if (!isFinite ((*input_)[(*indices_)[idx]]) ||
98  this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
99  {
100  output.points[idx].normal[0] = output.points[idx].normal[1] = output.points[idx].normal[2] = output.points[idx].curvature = std::numeric_limits<float>::quiet_NaN ();
101 
102  output.is_dense = false;
103  continue;
104  }
105 
106  Eigen::Vector4f n;
107  pcl::computePointNormal<PointInT> (*surface_, nn_indices,
108  n,
109  output.points[idx].curvature);
110 
111  output.points[idx].normal_x = n[0];
112  output.points[idx].normal_y = n[1];
113  output.points[idx].normal_z = n[2];
114 
115  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
116  output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2]);
117  }
118  }
119 }
120 
121 #define PCL_INSTANTIATE_NormalEstimationOMP(T,NT) template class PCL_EXPORTS pcl::NormalEstimationOMP<T,NT>;
122 
123 #endif // PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
124 
NormalEstimationOMP estimates local surface properties at each 3D point, such as surface normals and ...
Definition: normal_3d_omp.h:54
void flipNormalTowardsViewpoint(const PointT &point, float vp_x, float vp_y, float vp_z, Eigen::Matrix< Scalar, 4, 1 > &normal)
Flip (in place) the estimated normal of a point towards a given viewpoint.
Definition: normal_3d.h:119