Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
normal_3d_omp.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: normal_3d_omp.hpp 5026 2012-03-12 02:51:44Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
41 #define PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
42 
44 
46 template <typename PointInT> void
48 {
49  float vpx, vpy, vpz;
50  getViewPoint (vpx, vpy, vpz);
51  output.is_dense = true;
52 
53  // Resize the output dataset
54  output.points.resize (indices_->size (), 4);
55 
56  // GCC 4.2.x seems to segfault with "internal compiler error" on MacOS X here
57 #if defined(_WIN32) || ((__GNUC__ > 4) && (__GNUC_MINOR__ > 2))
58 #pragma omp parallel for schedule (dynamic, threads_)
59 #endif
60  // Iterating over the entire index vector
61  for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
62  {
63  // Allocate enough space to hold the results
64  // \note This resize is irrelevant for a radiusSearch ().
65  std::vector<int> nn_indices (k_);
66  std::vector<float> nn_dists (k_);
67 
68  if (!isFinite ((*input_)[(*indices_)[idx]]) ||
69  this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
70  {
71  output.points (idx, 0) = output.points (idx, 1) = output.points (idx, 2) = output.points (idx, 3) = std::numeric_limits<float>::quiet_NaN ();
72  output.is_dense = false;
73  continue;
74  }
75 
76  // 16-bytes aligned placeholder for the XYZ centroid of a surface patch
77  Eigen::Vector4f xyz_centroid;
78  // Estimate the XYZ centroid
79  compute3DCentroid (*surface_, nn_indices, xyz_centroid);
80 
81  // Placeholder for the 3x3 covariance matrix at each surface patch
82  EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
83  // Compute the 3x3 covariance matrix
84  computeCovarianceMatrix (*surface_, nn_indices, xyz_centroid, covariance_matrix);
85 
86  // Get the plane normal and surface curvature
87  solvePlaneParameters (covariance_matrix,
88  output.points (idx, 0), output.points (idx, 1), output.points (idx, 2), output.points (idx, 3));
89 
90  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx, vpy, vpz,
91  output.points (idx, 0), output.points (idx, 1), output.points (idx, 2));
92  }
93 }
94 
96 template <typename PointInT, typename PointOutT> void
98 {
99  float vpx, vpy, vpz;
100  getViewPoint (vpx, vpy, vpz);
101 
102  output.is_dense = true;
103  // Iterating over the entire index vector
104 #pragma omp parallel for schedule (dynamic, threads_)
105  for (int idx = 0; idx < static_cast<int> (indices_->size ()); ++idx)
106  {
107  // Allocate enough space to hold the results
108  // \note This resize is irrelevant for a radiusSearch ().
109  std::vector<int> nn_indices (k_);
110  std::vector<float> nn_dists (k_);
111 
112  if (!isFinite ((*input_)[(*indices_)[idx]]) ||
113  this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
114  {
115  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 ();
116 
117  output.is_dense = false;
118  continue;
119  }
120 
121  // 16-bytes aligned placeholder for the XYZ centroid of a surface patch
122  Eigen::Vector4f xyz_centroid;
123  // Estimate the XYZ centroid
124  compute3DCentroid (*surface_, nn_indices, xyz_centroid);
125 
126  // Placeholder for the 3x3 covariance matrix at each surface patch
127  EIGEN_ALIGN16 Eigen::Matrix3f covariance_matrix;
128  // Compute the 3x3 covariance matrix
129  computeCovarianceMatrix (*surface_, nn_indices, xyz_centroid, covariance_matrix);
130 
131  // Get the plane normal and surface curvature
132  solvePlaneParameters (covariance_matrix,
133  output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2], output.points[idx].curvature);
134 
135  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx, vpy, vpz,
136  output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2]);
137  }
138 }
139 
140 #define PCL_INSTANTIATE_NormalEstimationOMP(T,NT) template class PCL_EXPORTS pcl::NormalEstimationOMP<T,NT>;
141 
142 #endif // PCL_FEATURES_IMPL_NORMAL_3D_OMP_H_
143