39 #ifndef PCL_FEATURES_LINEAR_LEAST_SQUARES_NORMAL_HPP_
40 #define PCL_FEATURES_LINEAR_LEAST_SQUARES_NORMAL_HPP_
41 #define EIGEN_II_METHOD 1
43 #include <pcl/features/linear_least_squares_normal.h>
46 template <
typename Po
intInT,
typename Po
intOutT>
50 template <
typename Po
intInT,
typename Po
intOutT>
void
52 const int pos_x,
const int pos_y, PointOutT &normal)
54 const float bad_point = std::numeric_limits<float>::quiet_NaN ();
56 const int width = input_->width;
57 const int height = input_->height;
62 const int index = y * width + x;
64 const float px = (*input_)[index].x;
65 const float py = (*input_)[index].y;
66 const float pz = (*input_)[index].z;
70 normal.normal_x = bad_point;
71 normal.normal_y = bad_point;
72 normal.normal_z = bad_point;
73 normal.curvature = bad_point;
78 float smoothingSize = normal_smoothing_size_;
79 if (use_depth_dependent_smoothing_) smoothingSize = smoothingSize*(pz+0.5f);
81 const int smoothingSizeInt =
static_cast<int> (smoothingSize);
90 for (
int v = y - smoothingSizeInt; v <= y + smoothingSizeInt; v += smoothingSizeInt)
92 for (
int u = x - smoothingSizeInt; u <= x + smoothingSizeInt; u += smoothingSizeInt)
94 if (u < 0 || u >= width || v < 0 || v >= height)
continue;
96 const int index2 = v * width + u;
98 const float qx = (*input_)[index2].x;
99 const float qy = (*input_)[index2].y;
100 const float qz = (*input_)[index2].z;
102 if (std::isnan (qx))
continue;
104 const float delta = qz - pz;
105 const float i = qx - px;
106 const float j = qy - py;
108 float depthChangeThreshold = pz*pz * 0.05f * max_depth_change_factor_;
109 if (use_depth_dependent_smoothing_) depthChangeThreshold *= pz;
111 const float f = std::fabs (delta) > depthChangeThreshold ? 0 : 1;
116 vecb0 += f * i * delta;
117 vecb1 += f * j * delta;
121 const float det = matA0 * matA3 - matA1 * matA1;
122 const float ddx = matA3 * vecb0 - matA1 * vecb1;
123 const float ddy = -matA1 * vecb0 + matA0 * vecb1;
125 const float nx = ddx;
126 const float ny = ddy;
127 const float nz = -det * pz;
129 const float length = nx * nx + ny * ny + nz * nz;
133 normal.normal_x = bad_point;
134 normal.normal_y = bad_point;
135 normal.normal_z = bad_point;
136 normal.curvature = bad_point;
140 const float normInv = 1.0f / std::sqrt (length);
142 normal.normal_x = -nx * normInv;
143 normal.normal_y = -ny * normInv;
144 normal.normal_z = -nz * normInv;
145 normal.curvature = bad_point;
152 template <
typename Po
intInT,
typename Po
intOutT>
void
155 const float bad_point = std::numeric_limits<float>::quiet_NaN ();
157 const int width = input_->width;
158 const int height = input_->height;
173 for (
int y = 0; y < height; ++y)
175 for (
int x = 0; x < width; ++x)
177 const int index = y * width + x;
179 const float px = (*input_)[index].x;
180 const float py = (*input_)[index].y;
181 const float pz = (*input_)[index].z;
183 if (std::isnan(px))
continue;
187 float smoothingSize = normal_smoothing_size_;
192 const int smoothingSizeInt =
static_cast<int>(smoothingSize);
201 for (
int v = y - smoothingSizeInt; v <= y + smoothingSizeInt; v += smoothingSizeInt)
203 for (
int u = x - smoothingSizeInt; u <= x + smoothingSizeInt; u += smoothingSizeInt)
205 if (u < 0 || u >= width || v < 0 || v >= height)
continue;
207 const int index2 = v * width + u;
209 const float qx = (*input_)[index2].x;
210 const float qy = (*input_)[index2].y;
211 const float qz = (*input_)[index2].z;
213 if (std::isnan(qx))
continue;
215 const float delta = qz - pz;
216 const float i = qx - px;
217 const float j = qy - py;
219 const float depthDependendDepthChange = (max_depth_change_factor_ * (std::abs (pz) + 1.0f) * 2.0f);
220 const float f = std::fabs(delta) > depthDependendDepthChange ? 0 : 1;
229 vecb0 += f * i * delta;
230 vecb1 += f * j * delta;
234 const float det = matA0 * matA3 - matA1 * matA1;
235 const float ddx = matA3 * vecb0 - matA1 * vecb1;
236 const float ddy = -matA1 * vecb0 + matA0 * vecb1;
238 const float nx = ddx;
239 const float ny = ddy;
240 const float nz = -det * pz;
242 const float length = nx * nx + ny * ny + nz * nz;
246 output[index].normal_x = bad_point;
247 output[index].normal_y = bad_point;
248 output[index].normal_z = bad_point;
249 output[index].curvature = bad_point;
253 const float normInv = 1.0f / std::sqrt (length);
255 output[index].normal_x = nx * normInv;
256 output[index].normal_y = ny * normInv;
257 output[index].normal_z = nz * normInv;
258 output[index].curvature = bad_point;
264 #define PCL_INSTANTIATE_LinearLeastSquaresNormalEstimation(T,NT) template class PCL_EXPORTS pcl::LinearLeastSquaresNormalEstimation<T,NT>;
void computePointNormal(const int pos_x, const int pos_y, PointOutT &normal)
Computes the normal at the specified position.
~LinearLeastSquaresNormalEstimation() override
Destructor.
void computeFeature(PointCloudOut &output) override
Computes the normal for the complete cloud.