43 #include <pcl/features/intensity_gradient.h>
45 #include <pcl/common/point_tests.h>
49 template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT,
typename IntensitySelectorT>
void
52 const Eigen::Vector3f &point,
float mean_intensity,
const Eigen::Vector3f &normal, Eigen::Vector3f &gradient)
54 if (indices.size () < 3)
56 gradient[0] = gradient[1] = gradient[2] = std::numeric_limits<float>::quiet_NaN ();
60 Eigen::Matrix3f A = Eigen::Matrix3f::Zero ();
61 Eigen::Vector3f b = Eigen::Vector3f::Zero ();
63 for (
const auto &nn_index : indices)
65 PointInT p = cloud[nn_index];
66 if (!std::isfinite (p.x) ||
67 !std::isfinite (p.y) ||
68 !std::isfinite (p.z) ||
69 !std::isfinite (intensity_ (p)))
75 intensity_.demean (p, mean_intensity);
77 A (0, 0) += p.x * p.x;
78 A (0, 1) += p.x * p.y;
79 A (0, 2) += p.x * p.z;
81 A (1, 1) += p.y * p.y;
82 A (1, 2) += p.y * p.z;
84 A (2, 2) += p.z * p.z;
86 b[0] += p.x * intensity_ (p);
87 b[1] += p.y * intensity_ (p);
88 b[2] += p.z * intensity_ (p);
97 Eigen::Vector3f eigen_values;
98 Eigen::Matrix3f eigen_vectors;
99 eigen33 (A, eigen_vectors, eigen_values);
101 b = eigen_vectors.transpose () * b;
103 if ( eigen_values (0) != 0)
104 b (0) /= eigen_values (0);
108 if ( eigen_values (1) != 0)
109 b (1) /= eigen_values (1);
113 if ( eigen_values (2) != 0)
114 b (2) /= eigen_values (2);
119 Eigen::Vector3f x = eigen_vectors * b;
138 gradient = (Eigen::Matrix3f::Identity () - normal*normal.transpose ()) * x;
142 template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT,
typename IntensitySelectorT>
void
148 std::vector<float> nn_dists (k_);
153 threads_ = omp_get_num_procs();
154 PCL_DEBUG (
"[pcl::IntensityGradientEstimation::computeFeature] Setting number of threads to %u.\n", threads_);
159 if (surface_->is_dense)
161 #pragma omp parallel for \
164 firstprivate(nn_indices, nn_dists) \
165 num_threads(threads_)
167 for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
169 PointOutT &p_out = output[idx];
171 if (!this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists))
173 p_out.gradient[0] = p_out.gradient[1] = p_out.gradient[2] = std::numeric_limits<float>::quiet_NaN ();
178 Eigen::Vector3f centroid;
179 float mean_intensity = 0;
182 for (
const auto &nn_index : nn_indices)
184 centroid += (*surface_)[nn_index].getVector3fMap ();
185 mean_intensity += intensity_ ((*surface_)[nn_index]);
187 centroid /=
static_cast<float> (nn_indices.size ());
188 mean_intensity /=
static_cast<float> (nn_indices.size ());
190 Eigen::Vector3f normal = Eigen::Vector3f::Map ((*normals_)[(*indices_) [idx]].normal);
191 Eigen::Vector3f gradient;
192 computePointIntensityGradient (*surface_, nn_indices, centroid, mean_intensity, normal, gradient);
194 p_out.gradient[0] = gradient[0];
195 p_out.gradient[1] = gradient[1];
196 p_out.gradient[2] = gradient[2];
201 #pragma omp parallel for \
204 firstprivate(nn_indices, nn_dists) \
205 num_threads(threads_)
207 for (std::ptrdiff_t idx = 0; idx < static_cast<std::ptrdiff_t> (indices_->size ()); ++idx)
209 PointOutT &p_out = output[idx];
210 if (!
isFinite ((*surface_) [(*indices_)[idx]]) ||
211 !this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists))
213 p_out.gradient[0] = p_out.gradient[1] = p_out.gradient[2] = std::numeric_limits<float>::quiet_NaN ();
217 Eigen::Vector3f centroid;
218 float mean_intensity = 0;
222 for (
const auto &nn_index : nn_indices)
225 if (!
isFinite ((*surface_) [nn_index]))
228 centroid += surface_->points [nn_index].getVector3fMap ();
229 mean_intensity += intensity_ (surface_->points [nn_index]);
232 centroid /=
static_cast<float> (cp);
233 mean_intensity /=
static_cast<float> (cp);
234 Eigen::Vector3f normal = Eigen::Vector3f::Map ((*normals_)[(*indices_) [idx]].normal);
235 Eigen::Vector3f gradient;
236 computePointIntensityGradient (*surface_, nn_indices, centroid, mean_intensity, normal, gradient);
238 p_out.gradient[0] = gradient[0];
239 p_out.gradient[1] = gradient[1];
240 p_out.gradient[2] = gradient[2];
245 #define PCL_INSTANTIATE_IntensityGradientEstimation(InT,NT,OutT) template class PCL_EXPORTS pcl::IntensityGradientEstimation<InT,NT,OutT>;
IntensityGradientEstimation estimates the intensity gradient for a point cloud that contains position...
void computeFeature(PointCloudOut &output) override
Estimate the intensity gradients for a set of points given in <setInputCloud (), setIndices ()> using...
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
void eigen33(const Matrix &mat, typename Matrix::Scalar &eigenvalue, Vector &eigenvector)
determines the eigenvector and eigenvalue of the smallest eigenvalue of the symmetric positive semi d...
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...
IndicesAllocator<> Indices
Type used for indices in PCL.