template <typename PointInT, typename PointOutT> void pcl::MovingLeastSquares<PointInT, PointOutT>::performProcessing (PointCloudOut &output) { // Compute the number of coefficients nr_coeff_ = (order_ + 1) * (order_ + 2) / 2; // Allocate enough space to hold the results of nearest neighbor searches // \note resize is irrelevant for a radiusSearch (). std::vector<int> nn_indices; std::vector<float> nn_sqr_dists; // For all points for (size_t cp = 0; cp < indices_->size (); ++cp) { // Get the initial estimates of point positions and their neighborhoods if (!searchForNeighbors ((*indices_)[cp], nn_indices, nn_sqr_dists)) continue; // Check the number of nearest neighbors for normal estimation (and later // for polynomial fit as well) if (nn_indices.size () < 3) continue; PointCloudOut projected_points; 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]); // Copy all information from the input cloud to the output points (not doing any interpolation) for (size_t pp = 0; pp < projected_points.size (); ++pp) copyMissingFields (input_->points[(*indices_)[cp]], projected_points[pp]); // Append projected points to output output.insert (output.end (), projected_points.begin (), projected_points.end ()); if (compute_normals_) normals_->insert (normals_->end (), projected_points_normals.begin (), projected_points_normals.end ()); } // Perform the distinct-cloud or voxel-grid upsampling performUpsampling (output); }
void ResamplerTest::testUpsamplingTriangle() { generateTriangularSignal(); std::cout << "Test Upsampling Triangle" << std::endl; Resampler resampler(44100); performUpsampling(resampler); AudioBuffer tmpInputBuffer(TMP_LOWSMPLR_BUFFER_LENGTH, AudioFormat::MONO()); AudioBuffer tmpOutputBuffer(TMP_HIGHSMPLR_BUFFER_LENGTH, AudioFormat(16000, 1)); tmpInputBuffer.copy(inputBuffer); std::cout << "Input Buffer" << std::endl; print_buffer(*tmpInputBuffer.getChannel(0)); tmpOutputBuffer.copy(outputBuffer); std::cout << "Output Buffer" << std::endl; print_buffer(*tmpOutputBuffer.getChannel(0)); }
void ResamplerTest::testUpsamplingRamp() { // generate input samples and store them in inputBuffer generateRamp(); std::cout << "Test Upsampling Ramp" << std::endl; Resampler resampler(44100); performUpsampling(resampler); AudioBuffer tmpInputBuffer(TMP_LOWSMPLR_BUFFER_LENGTH, AudioFormat::MONO()); AudioBuffer tmpOutputBuffer(TMP_HIGHSMPLR_BUFFER_LENGTH, AudioFormat(16000, 1)); tmpInputBuffer.copy(inputBuffer); std::cout << "Input Buffer" << std::endl; print_buffer(*tmpInputBuffer.getChannel(0)); tmpOutputBuffer.copy(outputBuffer); std::cout << "Output Buffer" << std::endl; print_buffer(*tmpOutputBuffer.getChannel(0)); }
template <typename PointInT, typename PointOutT> void pcl::MovingLeastSquares<PointInT, PointOutT>::performProcessing (PointCloudOut &output) { // Compute the number of coefficients nr_coeff_ = (order_ + 1) * (order_ + 2) / 2; #ifdef _OPENMP // (Maximum) number of threads const unsigned int threads = threads_ == 0 ? 1 : threads_; // Create temporaries for each thread in order to avoid synchronization typename PointCloudOut::CloudVectorType projected_points (threads); typename NormalCloud::CloudVectorType projected_points_normals (threads); std::vector<PointIndices> corresponding_input_indices (threads); #endif // For all points #ifdef _OPENMP #pragma omp parallel for schedule (dynamic,1000) num_threads (threads) #endif for (int cp = 0; cp < static_cast<int> (indices_->size ()); ++cp) { // Allocate enough space to hold the results of nearest neighbor searches // \note resize is irrelevant for a radiusSearch (). std::vector<int> nn_indices; std::vector<float> nn_sqr_dists; // Get the initial estimates of point positions and their neighborhoods if (searchForNeighbors ((*indices_)[cp], nn_indices, nn_sqr_dists)) { // Check the number of nearest neighbors for normal estimation (and later for polynomial fit as well) if (nn_indices.size () >= 3) { // This thread's ID (range 0 to threads-1) #ifdef _OPENMP const int tn = omp_get_thread_num (); // Size of projected points before computeMLSPointNormal () adds points size_t pp_size = projected_points[tn].size (); #else PointCloudOut projected_points; NormalCloud projected_points_normals; #endif // Get a plane approximating the local surface's tangent and project point onto it const int index = (*indices_)[cp]; size_t mls_result_index = 0; if (cache_mls_results_) mls_result_index = index; // otherwise we give it a dummy location. #ifdef _OPENMP computeMLSPointNormal (index, nn_indices, projected_points[tn], projected_points_normals[tn], corresponding_input_indices[tn], 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) copyMissingFields (input_->points[(*indices_)[cp]], projected_points[tn][pp]); #else computeMLSPointNormal (index, nn_indices, projected_points, projected_points_normals, *corresponding_input_indices_, mls_results_[mls_result_index]); // Append projected points to output output.insert (output.end (), projected_points.begin (), projected_points.end ()); if (compute_normals_) normals_->insert (normals_->end (), projected_points_normals.begin (), projected_points_normals.end ()); #endif } } } #ifdef _OPENMP // Combine all threads' results into the output vectors for (unsigned int tn = 0; tn < threads; ++tn) { output.insert (output.end (), projected_points[tn].begin (), projected_points[tn].end ()); corresponding_input_indices_->indices.insert (corresponding_input_indices_->indices.end (), corresponding_input_indices[tn].indices.begin (), corresponding_input_indices[tn].indices.end ()); if (compute_normals_) normals_->insert (normals_->end (), projected_points_normals[tn].begin (), projected_points_normals[tn].end ()); } #endif // Perform the distinct-cloud or voxel-grid upsampling performUpsampling (output); }