Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
normal_3d.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.hpp 5026 2012-03-12 02:51:44Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FEATURES_IMPL_NORMAL_3D_H_
41 #define PCL_FEATURES_IMPL_NORMAL_3D_H_
42 
43 #include <pcl/features/normal_3d.h>
44 
46 template <typename PointInT, typename PointOutT> void
48 {
49  // Allocate enough space to hold the results
50  // \note This resize is irrelevant for a radiusSearch ().
51  std::vector<int> nn_indices (k_);
52  std::vector<float> nn_dists (k_);
53 
54  output.is_dense = true;
55  // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
56  if (input_->is_dense)
57  {
58  // Iterating over the entire index vector
59  for (size_t idx = 0; idx < indices_->size (); ++idx)
60  {
61  if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
62  {
63  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 ();
64 
65  output.is_dense = false;
66  continue;
67  }
68 
69  computePointNormal (*surface_, nn_indices,
70  output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2], output.points[idx].curvature);
71 
72  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
73  output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2]);
74 
75  }
76  }
77  else
78  {
79  // Iterating over the entire index vector
80  for (size_t idx = 0; idx < indices_->size (); ++idx)
81  {
82  if (!isFinite ((*input_)[(*indices_)[idx]]) ||
83  this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
84  {
85  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 ();
86 
87  output.is_dense = false;
88  continue;
89  }
90 
91  computePointNormal (*surface_, nn_indices,
92  output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2], output.points[idx].curvature);
93 
94  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
95  output.points[idx].normal[0], output.points[idx].normal[1], output.points[idx].normal[2]);
96 
97  }
98  }
99 }
100 
102 template <typename PointInT> void
104 {
105  // Resize the output dataset
106  output.points.resize (indices_->size (), 4);
107 
108  // Allocate enough space to hold the results
109  // \note This resize is irrelevant for a radiusSearch ().
110  std::vector<int> nn_indices (k_);
111  std::vector<float> nn_dists (k_);
112 
113  output.is_dense = true;
114  // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
115  if (input_->is_dense)
116  {
117  // Iterating over the entire index vector
118  for (size_t idx = 0; idx < indices_->size (); ++idx)
119  {
120  if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
121  {
122  output.points (idx, 0) = output.points (idx, 1) = output.points (idx, 2) = output.points (idx, 3) = std::numeric_limits<float>::quiet_NaN ();
123  output.is_dense = false;
124  continue;
125  }
126 
127  computePointNormal (*surface_, nn_indices,
128  output.points (idx, 0), output.points (idx, 1), output.points (idx, 2), output.points (idx, 3));
129 
130  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
131  output.points (idx, 0), output.points (idx, 1), output.points (idx, 2));
132 
133  }
134  }
135  else
136  {
137  // Iterating over the entire index vector
138  for (size_t idx = 0; idx < indices_->size (); ++idx)
139  {
140  if (!isFinite ((*input_)[(*indices_)[idx]]) ||
141  this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
142  {
143  output.points (idx, 0) = output.points (idx, 1) = output.points (idx, 2) = output.points (idx, 3) = std::numeric_limits<float>::quiet_NaN ();
144  output.is_dense = false;
145  continue;
146  }
147 
148  computePointNormal (*surface_, nn_indices,
149  output.points (idx, 0), output.points (idx, 1), output.points (idx, 2), output.points (idx, 3));
150 
151  flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
152  output.points (idx, 0), output.points (idx, 1), output.points (idx, 2));
153 
154  }
155  }
156 }
157 
158 #define PCL_INSTANTIATE_NormalEstimation(T,NT) template class PCL_EXPORTS pcl::NormalEstimation<T,NT>;
159 
160 #endif // PCL_FEATURES_IMPL_NORMAL_3D_H_