From cf64064b553856b9ab2febeed1b782f8516f10e2 Mon Sep 17 00:00:00 2001 From: John Woods Date: Wed, 2 Jul 2014 16:07:07 -0400 Subject: [PATCH] The mls_results_ vector did not need to be allocated for most of the Moving Least Squares methods. However, a reference to an entry in this vector was needed for calls to computeMLSPointNormal, which is why it was being allocated in full. This commit causes the vector to be resized to 1 for those methods that don't need the full version, and then a reference to entry 0 is passed. The decision was made not to modify computeMLSPointNormal because it needs to be thread-safe and I do not have the means to test the OpenMP version of the code. Identical modifications were made to MovingLeastSquaresOMP::performProcessing as to MovingLeastSquares::performProcessing. Tests which do not depend on OpenMP still pass. --- surface/include/pcl/surface/impl/mls.hpp | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/surface/include/pcl/surface/impl/mls.hpp b/surface/include/pcl/surface/impl/mls.hpp index 578c0d8528f..374dc24e1e5 100644 --- a/surface/include/pcl/surface/impl/mls.hpp +++ b/surface/include/pcl/surface/impl/mls.hpp @@ -117,18 +117,23 @@ pcl::MovingLeastSquares::process (PointCloudOut &output) boost::uniform_real uniform_distrib (-tmp, tmp); rng_uniform_distribution_.reset (new boost::variate_generator > (rng_alg_, uniform_distrib)); + mls_results_.resize (1); // Need to have a reference to a single dummy result. + break; } case (VOXEL_GRID_DILATION): case (DISTINCT_CLOUD): { - break; + mls_results_.resize (input_->size ()); + break; } default: - break; + { + mls_results_.resize (1); // Need to have a reference to a single dummy result. + break; + } } - mls_results_.resize (input_->size ()); // Perform the actual surface reconstruction performProcessing (output); @@ -467,6 +472,8 @@ pcl::MovingLeastSquares::performProcessing (PointCloudOut & // \note resize is irrelevant for a radiusSearch (). std::vector nn_indices; std::vector nn_sqr_dists; + + size_t mls_result_index = 0; // For all points for (size_t cp = 0; cp < indices_->size (); ++cp) @@ -486,7 +493,11 @@ pcl::MovingLeastSquares::performProcessing (PointCloudOut & NormalCloud projected_points_normals; // Get a plane approximating the local surface's tangent and project point onto it int index = (*indices_)[cp]; - computeMLSPointNormal (index, nn_indices, nn_sqr_dists, projected_points, projected_points_normals, *corresponding_input_indices_, mls_results_[index]); + + if (upsample_method_ == VOXEL_GRID_DILATION || upsample_method_ == DISTINCT_CLOUD) + mls_result_index = index; // otherwise we give it a dummy location. + + computeMLSPointNormal (index, nn_indices, nn_sqr_dists, projected_points, projected_points_normals, *corresponding_input_indices_, mls_results_[mls_result_index]); // Copy all information from the input cloud to the output points (not doing any interpolation) @@ -544,7 +555,12 @@ pcl::MovingLeastSquaresOMP::performProcessing (PointCloudOu // Get a plane approximating the local surface's tangent and project point onto it int index = (*indices_)[cp]; - this->computeMLSPointNormal (index, nn_indices, nn_sqr_dists, projected_points[tn], projected_points_normals[tn], corresponding_input_indices[tn], this->mls_results_[index]); + size_t mls_result_index = 0; + + if (upsample_method_ == VOXEL_GRID_DILATION || upsample_method_ == DISTINCT_CLOUD) + mls_result_index = index; // otherwise we give it a dummy location. + + this->computeMLSPointNormal (index, nn_indices, nn_sqr_dists, projected_points[tn], projected_points_normals[tn], corresponding_input_indices[tn], this->mls_results_[mls_result_index]); // Copy all information from the input cloud to the output points (not doing any interpolation) for (size_t pp = pp_size; pp < projected_points[tn].size (); ++pp)