1 #ifndef PCL_FEATURES_IMPL_CURVATURE_ESTIMATION_TAUBIN_HPP_ 2 #define PCL_FEATURES_IMPL_CURVATURE_ESTIMATION_TAUBIN_HPP_ 9 const double MIN_NEIGHBORS = 10;
11 this->time_taubin = 0.0;
12 this->time_curvature = 0.0;
15 std::vector<int> nn_indices;
16 std::vector<float> nn_dists;
19 output.is_dense =
true;
22 output.resize(samples.cols());
25 neighborhoods_.resize(samples.cols());
26 neighborhood_centroids_.resize(samples.cols());
29 if (input_->isOrganized())
31 pcl::search::OrganizedNeighbor<PointXYZRGBA>::Ptr organized_neighbor(
32 new pcl::search::OrganizedNeighbor<PointXYZRGBA>());
33 organized_neighbor->setInputCloud(input_);
34 pcl::PointXYZRGBA search_point;
38 #pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(num_threads_) 41 for (
int i = 0; i < samples.cols(); i++)
43 search_point.x = samples(0, i);
44 search_point.y = samples(1, i);
45 search_point.z = samples(2, i);
49 if (organized_neighbor->radiusSearch(search_point, search_radius_, nn_indices, nn_dists) < MIN_NEIGHBORS)
51 output.points[i].normal[0] = output.points[i].normal[1] = output.points[i].normal[2] =
52 std::numeric_limits<float>::quiet_NaN();
53 output.points[i].curvature_axis[0] = output.points[i].curvature_axis[1] = output.points[i].curvature_axis[2] =
54 output.points[i].normal[0];
55 output.points[i].curvature_centroid[0] = output.points[i].curvature_centroid[1] =
56 output.points[i].curvature_centroid[2] = output.points[i].normal[0];
57 output.points[i].median_curvature = output.points[i].normal[0];
59 output.is_dense =
false;
66 computeFeature(nn_indices, i, output);
69 neighborhoods_[i] = nn_indices;
70 neighborhood_centroids_[i] = i;
76 pcl::KdTreeFLANN<pcl::PointXYZRGBA>::Ptr tree(
new pcl::KdTreeFLANN<pcl::PointXYZRGBA>());
77 tree->setInputCloud(input_);
78 pcl::PointXYZRGBA search_point;
82 #pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(num_threads_) 85 for (
int i = 0; i < samples.cols(); i++)
87 search_point.x = samples(0, i);
88 search_point.y = samples(1, i);
89 search_point.z = samples(2, i);
93 if (tree->radiusSearch(search_point, search_radius_, nn_indices, nn_dists) < MIN_NEIGHBORS)
95 output.points[i].normal[0] = output.points[i].normal[1] = output.points[i].normal[2] =
96 std::numeric_limits<float>::quiet_NaN();
97 output.points[i].curvature_axis[0] = output.points[i].curvature_axis[1] = output.points[i].curvature_axis[2] =
98 output.points[i].normal[0];
99 output.points[i].curvature_centroid[0] = output.points[i].curvature_centroid[1] =
100 output.points[i].curvature_centroid[2] = output.points[i].normal[0];
101 output.points[i].median_curvature = output.points[i].normal[0];
103 output.is_dense =
false;
110 computeFeature(nn_indices, i, output);
113 neighborhoods_[i] = nn_indices;
114 neighborhood_centroids_[i] = i;
120 for (
int i = 0; i < samples.cols(); i++)
122 if (neighborhoods_[i].size() >= MIN_NEIGHBORS)
125 printf(
" Taubin fitting: %.3f sec\n", this->time_taubin);
126 printf(
" Curvature estimation: %.3f sec\n", this->time_curvature);
133 std::vector<int> nn_indices(k_);
134 std::vector<float> nn_dists(k_);
137 output.is_dense =
true;
140 output.resize(num_samples_);
143 if (input_->is_dense)
146 if (indices_->size() != num_samples_)
148 std::srand(std::time(0));
149 indices_->resize(num_samples_);
151 for (
int i = 0; i < num_samples_; i++)
153 (*indices_)[i] = std::rand() % input_->points.size();
160 if (indices_->size() != num_samples_)
162 std::srand(std::time(0));
163 indices_->resize(num_samples_);
165 for (
int i = 0; i < num_samples_; i++)
167 int r = std::rand() % input_->points.size();
169 while (!isFinite((*input_)[r]))
170 r = std::rand() % input_->points.size();
178 neighborhoods_.resize(indices_->size());
179 neighborhood_centroids_.resize(indices_->size());
183 #pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(num_threads_) 187 for (std::size_t idx = 0; idx < indices_->size(); ++idx)
189 if (this->searchForNeighbors((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
191 output.points[idx].normal[0] = output.points[idx].normal[1] = output.points[idx].normal[2] = std::numeric_limits<
193 output.points[idx].curvature_axis[0] = output.points[idx].curvature_axis[1] =
194 output.points[idx].curvature_axis[2] = output.points[idx].normal[0];
195 output.points[idx].curvature_centroid[0] = output.points[idx].curvature_centroid[1] =
196 output.points[idx].curvature_centroid[2] = output.points[idx].normal[0];
197 output.points[idx].median_curvature = output.points[idx].normal[0];
199 output.is_dense =
false;
204 computeFeature(nn_indices, idx, output);
207 neighborhoods_[idx] = nn_indices;
208 neighborhood_centroids_[idx] = (*indices_)[idx];
213 const std::vector<int> &nn_indices,
int index,
PointCloudOut &output)
216 double t0 = omp_get_wtime();
217 Eigen::VectorXd quadric_parameters(10);
218 Eigen::Vector3d quadric_centroid;
219 Eigen::Matrix3d quadric_covariance_matrix;
220 this->fitQuadric(nn_indices, quadric_parameters, quadric_centroid, quadric_covariance_matrix);
221 this->time_taubin += omp_get_wtime() - t0;
224 t0 = omp_get_wtime();
225 double median_curvature;
226 Eigen::Vector3d normal;
227 Eigen::Vector3d curvature_axis;
228 Eigen::Vector3d curvature_centroid;
229 this->estimateMedianCurvature(nn_indices, quadric_parameters, median_curvature, normal, curvature_axis,
231 this->time_curvature += omp_get_wtime() - t0;
234 output[index].normal[0] = normal[0];
235 output[index].normal[1] = normal[1];
236 output[index].normal[2] = normal[2];
237 output[index].curvature_axis[0] = curvature_axis[0];
238 output[index].curvature_axis[1] = curvature_axis[1];
239 output[index].curvature_axis[2] = curvature_axis[2];
240 output[index].curvature_centroid[0] = curvature_centroid[0];
241 output[index].curvature_centroid[1] = curvature_centroid[1];
242 output[index].curvature_centroid[2] = curvature_centroid[2];
243 output[index].median_curvature = median_curvature;
246 #endif // PCL_FEATURES_IMPL_CURVATURE_ESTIMATION_TAUBIN_HPP_ void computeFeature(const Eigen::MatrixXd &samples, PointCloudOut &output)
Estimate the curvature for a set of point neighborhoods with given centroids.
Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut