openMP 处理for循环

  1. //////////////////////////////////////////////////////////////////////////////////////////////
  2. template <typename PointInT, typename PointOutT> void
  3. pcl::MovingLeastSquares<PointInT, PointOutT>::performProcessing (PointCloudOut &output)
  4. {
  5. // Compute the number of coefficients
  6. nr_coeff_ = (order_ + ) * (order_ + ) / ;
  7.  
  8. size_t mls_result_index = ;
  9.  
  10. #ifdef _OPENMP
  11. // (Maximum) number of threads
  12. const unsigned int threads = threads_ == ? : threads_;
  13. // Create temporaries for each thread in order to avoid synchronization
  14. typename PointCloudOut::CloudVectorType projected_points (threads);
  15. typename NormalCloud::CloudVectorType projected_points_normals (threads);
  16. std::vector<PointIndices> corresponding_input_indices (threads);
  17. #endif
  18.  
  19. // For all points
  20. #ifdef _OPENMP
  21. #pragma omp parallel for schedule (dynamic,1000) num_threads (threads)
  22. #endif
  23. for (int cp = ; cp < static_cast<int> (indices_->size ()); ++cp)
  24. {
  25. // Allocate enough space to hold the results of nearest neighbor searches
  26. // \note resize is irrelevant for a radiusSearch ().
  27. std::vector<int> nn_indices;
  28. std::vector<float> nn_sqr_dists;
  29.  
  30. // Get the initial estimates of point positions and their neighborhoods
  31. if (searchForNeighbors ((*indices_)[cp], nn_indices, nn_sqr_dists))
  32. {
  33. // Check the number of nearest neighbors for normal estimation (and later for polynomial fit as well)
  34. if (nn_indices.size () >= )
  35. {
  36. // This thread's ID (range 0 to threads-1)
  37. #ifdef _OPENMP
  38. const int tn = omp_get_thread_num ();
  39. // Size of projected points before computeMLSPointNormal () adds points
  40. size_t pp_size = projected_points[tn].size ();
  41. #else
  42. PointCloudOut projected_points;
  43. NormalCloud projected_points_normals;
  44. #endif
  45.  
  46. // Get a plane approximating the local surface's tangent and project point onto it
  47. const int index = (*indices_)[cp];
  48.  
  49. if (cache_mls_results_)
  50. mls_result_index = index; // otherwise we give it a dummy location.
  51.  
  52. #ifdef _OPENMP
  53. computeMLSPointNormal (index, nn_indices, projected_points[tn], projected_points_normals[tn], corresponding_input_indices[tn], mls_results_[mls_result_index]);
  54.  
  55. // Copy all information from the input cloud to the output points (not doing any interpolation)
  56. for (size_t pp = pp_size; pp < projected_points[tn].size (); ++pp)
  57. copyMissingFields (input_->points[(*indices_)[cp]], projected_points[tn][pp]);
  58. #else
  59. computeMLSPointNormal (index, nn_indices, projected_points, projected_points_normals, *corresponding_input_indices_, mls_results_[mls_result_index]);
  60.  
  61. // Append projected points to output
  62. output.insert (output.end (), projected_points.begin (), projected_points.end ());
  63. if (compute_normals_)
  64. normals_->insert (normals_->end (), projected_points_normals.begin (), projected_points_normals.end ());
  65. #endif
  66. }
  67. }
  68. }
  69.  
  70. #ifdef _OPENMP
  71. // Combine all threads' results into the output vectors
  72. for (unsigned int tn = ; tn < threads; ++tn)
  73. {
  74. output.insert (output.end (), projected_points[tn].begin (), projected_points[tn].end ());
  75. corresponding_input_indices_->indices.insert (corresponding_input_indices_->indices.end (),
  76. corresponding_input_indices[tn].indices.begin (), corresponding_input_indices[tn].indices.end ());
  77. if (compute_normals_)
  78. normals_->insert (normals_->end (), projected_points_normals[tn].begin (), projected_points_normals[tn].end ());
  79. }
  80. #endif
  81.  
  82. // Perform the distinct-cloud or voxel-grid upsampling
  83. performUpsampling (output);
  84. }
  1. template <typename PointT> void
  2. pcl::FastBilateralFilterOMP<PointT>::applyFilter (PointCloud &output)
  3. {
  4. if (!input_->isOrganized ())
  5. {
  6. PCL_ERROR ("[pcl::FastBilateralFilterOMP] Input cloud needs to be organized.\n");
  7. return;
  8. }
  9.  
  10. copyPointCloud (*input_, output);
  11. float base_max = -std::numeric_limits<float>::max (),
  12. base_min = std::numeric_limits<float>::max ();
  13. bool found_finite = false;
  14. for (size_t x = ; x < output.width; ++x)
  15. {
  16. for (size_t y = ; y < output.height; ++y)
  17. {
  18. if (pcl_isfinite (output (x, y).z))
  19. {
  20. if (base_max < output (x, y).z)
  21. base_max = output (x, y).z;
  22. if (base_min > output (x, y).z)
  23. base_min = output (x, y).z;
  24. found_finite = true;
  25. }
  26. }
  27. }
  28. if (!found_finite)
  29. {
  30. PCL_WARN ("[pcl::FastBilateralFilterOMP] Given an empty cloud. Doing nothing.\n");
  31. return;
  32. }
  33. #ifdef _OPENMP
  34. #pragma omp parallel for num_threads (threads_)
  35. #endif
  36. for (long int i = ; i < static_cast<long int> (output.size ()); ++i)
  37. if (!pcl_isfinite (output.at(i).z))
  38. output.at(i).z = base_max;
  39.  
  40. const float base_delta = base_max - base_min;
  41.  
  42. const size_t padding_xy = ;
  43. const size_t padding_z = ;
  44.  
  45. const size_t small_width = static_cast<size_t> (static_cast<float> (input_->width - ) / sigma_s_) + + * padding_xy;
  46. const size_t small_height = static_cast<size_t> (static_cast<float> (input_->height - ) / sigma_s_) + + * padding_xy;
  47. const size_t small_depth = static_cast<size_t> (base_delta / sigma_r_) + + * padding_z;
  48.  
  49. Array3D data (small_width, small_height, small_depth);
  50. #ifdef _OPENMP
  51. #pragma omp parallel for num_threads (threads_)
  52. #endif
  53. for (long int i = ; i < static_cast<long int> (small_width * small_height); ++i)
  54. {
  55. size_t small_x = static_cast<size_t> (i % small_width);
  56. size_t small_y = static_cast<size_t> (i / small_width);
  57. size_t start_x = static_cast<size_t>(
  58. std::max ((static_cast<float> (small_x) - static_cast<float> (padding_xy) - 0.5f) * sigma_s_ + , .f));
  59. size_t end_x = static_cast<size_t>(
  60. std::max ((static_cast<float> (small_x) - static_cast<float> (padding_xy) + 0.5f) * sigma_s_ + , .f));
  61. size_t start_y = static_cast<size_t>(
  62. std::max ((static_cast<float> (small_y) - static_cast<float> (padding_xy) - 0.5f) * sigma_s_ + , .f));
  63. size_t end_y = static_cast<size_t>(
  64. std::max ((static_cast<float> (small_y) - static_cast<float> (padding_xy) + 0.5f) * sigma_s_ + , .f));
  65. for (size_t x = start_x; x < end_x && x < input_->width; ++x)
  66. {
  67. for (size_t y = start_y; y < end_y && y < input_->height; ++y)
  68. {
  69. const float z = output (x,y).z - base_min;
  70. const size_t small_z = static_cast<size_t> (static_cast<float> (z) / sigma_r_ + 0.5f) + padding_z;
  71. Eigen::Vector2f& d = data (small_x, small_y, small_z);
  72. d[] += output (x,y).z;
  73. d[] += 1.0f;
  74. }
  75. }
  76. }
  77.  
  78. std::vector<long int> offset ();
  79. offset[] = &(data (,,)) - &(data (,,));
  80. offset[] = &(data (,,)) - &(data (,,));
  81. offset[] = &(data (,,)) - &(data (,,));
  82.  
  83. Array3D buffer (small_width, small_height, small_depth);
  84.  
  85. for (size_t dim = ; dim < ; ++dim)
  86. {
  87. for (size_t n_iter = ; n_iter < ; ++n_iter)
  88. {
  89. Array3D* current_buffer = (n_iter % == ? &buffer : &data);
  90. Array3D* current_data =(n_iter % == ? &data : &buffer);
  91. #ifdef _OPENMP
  92. #pragma omp parallel for num_threads (threads_)
  93. #endif
  94. for(long int i = ; i < static_cast<long int> ((small_width - )*(small_height - )); ++i)
  95. {
  96. size_t x = static_cast<size_t> (i % (small_width - ) + );
  97. size_t y = static_cast<size_t> (i / (small_width - ) + );
  98. const long int off = offset[dim];
  99. Eigen::Vector2f* d_ptr = &(current_data->operator() (x,y,));
  100. Eigen::Vector2f* b_ptr = &(current_buffer->operator() (x,y,));
  101.  
  102. for(size_t z = ; z < small_depth - ; ++z, ++d_ptr, ++b_ptr)
  103. *d_ptr = (*(b_ptr - off) + *(b_ptr + off) + 2.0 * (*b_ptr)) / 4.0;
  104. }
  105. }
  106. }
  107. // Note: this works because there are an even number of iterations.
  108. // If there were an odd number, we would need to end with a:
  109. // std::swap (data, buffer);
  110.  
  111. if (early_division_)
  112. {
  113. for (std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::iterator d = data.begin (); d != data.end (); ++d)
  114. *d /= ((*d)[] != ) ? (*d)[] : ;
  115.  
  116. #ifdef _OPENMP
  117. #pragma omp parallel for num_threads (threads_)
  118. #endif
  119. for (long int i = ; i < static_cast<long int> (input_->size ()); ++i)
  120. {
  121. size_t x = static_cast<size_t> (i % input_->width);
  122. size_t y = static_cast<size_t> (i / input_->width);
  123. const float z = output (x,y).z - base_min;
  124. const Eigen::Vector2f D = data.trilinear_interpolation (static_cast<float> (x) / sigma_s_ + padding_xy,
  125. static_cast<float> (y) / sigma_s_ + padding_xy,
  126. z / sigma_r_ + padding_z);
  127. output(x,y).z = D[];
  128. }
  129. }
  130. else
  131. {
  132. #ifdef _OPENMP
  133. #pragma omp parallel for num_threads (threads_)
  134. #endif
  135. for (long i = ; i < static_cast<long int> (input_->size ()); ++i)
  136. {
  137. size_t x = static_cast<size_t> (i % input_->width);
  138. size_t y = static_cast<size_t> (i / input_->width);
  139. const float z = output (x,y).z - base_min;
  140. const Eigen::Vector2f D = data.trilinear_interpolation (static_cast<float> (x) / sigma_s_ + padding_xy,
  141. static_cast<float> (y) / sigma_s_ + padding_xy,
  142. z / sigma_r_ + padding_z);
  143. output (x,y).z = D[] / D[];
  144. }
  145. }
  146. }
  1. template <typename PointInT, typename PointOutT> void
  2. pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
  3. {
  4. // Allocate enough space to hold the results
  5. // \note This resize is irrelevant for a radiusSearch ().
  6. std::vector<int> nn_indices (k_);
  7. std::vector<float> nn_dists (k_);
  8.  
  9. output.is_dense = true;
  10. // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
  11. if (input_->is_dense)
  12. {
  13. #ifdef _OPENMP
  14. #pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
  15. #endif
  16. // Iterating over the entire index vector
  17. for (int idx = ; idx < static_cast<int> (indices_->size ()); ++idx)
  18. {
  19. Eigen::Vector4f n;
  20. if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == ||
  21. !computePointNormal (*surface_, nn_indices, n, output.points[idx].curvature))
  22. {
  23. output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].curvature = std::numeric_limits<float>::quiet_NaN ();
  24.  
  25. output.is_dense = false;
  26. continue;
  27. }
  28.  
  29. output.points[idx].normal_x = n[];
  30. output.points[idx].normal_y = n[];
  31. output.points[idx].normal_z = n[];
  32.  
  33. flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
  34. output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[]);
  35.  
  36. }
  37. }
  38. else
  39. {
  40. #ifdef _OPENMP
  41. #pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
  42. #endif
  43. // Iterating over the entire index vector
  44. for (int idx = ; idx < static_cast<int> (indices_->size ()); ++idx)
  45. {
  46. Eigen::Vector4f n;
  47. if (!isFinite ((*input_)[(*indices_)[idx]]) ||
  48. this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == ||
  49. !computePointNormal (*surface_, nn_indices, n, output.points[idx].curvature))
  50. {
  51. output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].curvature = std::numeric_limits<float>::quiet_NaN ();
  52.  
  53. output.is_dense = false;
  54. continue;
  55. }
  56.  
  57. output.points[idx].normal_x = n[];
  58. output.points[idx].normal_y = n[];
  59. output.points[idx].normal_z = n[];
  60.  
  61. flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
  62. output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[]);
  63.  
  64. }
  65. }
  66. }

openMP---第一篇的更多相关文章

  1. 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)

    从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...

  2. Python爬虫小白入门(四)PhatomJS+Selenium第一篇

    一.前言 在上一篇博文中,我们的爬虫面临着一个问题,在爬取Unsplash网站的时候,由于网站是下拉刷新,并没有分页.所以不能够通过页码获取页面的url来分别发送网络请求.我也尝试了其他方式,比如下拉 ...

  3. Three.js 第一篇:绘制一个静态的3D球体

    第一篇就画一个球体吧 首先我们知道Three.js其实是一个3D的JS引擎,其中的强大之处就在于这个JS框架并不是依托于JQUERY来写的.那么,我们在写这一篇绘制3D球体的文章的时候,应该注意哪些地 ...

  4. 深入学习jQuery选择器系列第一篇——基础选择器和层级选择器

    × 目录 [1]id选择器 [2]元素选择器 [3]类选择器[4]通配选择器[5]群组选择器[6]后代选择器[7]兄弟选择器 前面的话 选择器是jQuery的根基,在jQuery中,对事件处理.遍历D ...

  5. 【第一篇】ASP.NET MVC快速入门之数据库操作(MVC5+EF6)

    目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...

  6. Android基础学习第一篇—Project目录结构

    写在前面的话: 1. 最近在自学Android,也是边看书边写一些Demo,由于知识点越来越多,脑子越来越记不清楚,所以打算写成读书笔记,供以后查看,也算是把自己学到所理解的东西写出来,献丑,如有不对 ...

  7. 深入理解ajax系列第一篇——XHR对象

    × 目录 [1]创建对象 [2]发送请求 [3]接收响应[4]异步处理[5]实例演示 前面的话 ajax是asynchronous javascript and XML的简写,中文翻译是异步的java ...

  8. 深入理解javascript对象系列第一篇——初识对象

    × 目录 [1]定义 [2]创建 [3]组成[4]引用[5]方法 前面的话 javascript中的难点是函数.对象和继承,前面已经介绍过函数系列.从本系列开始介绍对象部分,本文是该系列的第一篇——初 ...

  9. 深入理解this机制系列第一篇——this的4种绑定规则

    × 目录 [1]默认绑定 [2]隐式绑定 [3]隐式丢失[4]显式绑定[5]new绑定[6]严格模式 前面的话 如果要问javascript中哪两个知识点容易混淆,作用域查询和this机制绝对名列前茅 ...

  10. 前端工程师技能之photoshop巧用系列第一篇——准备篇

    × 目录 [1]作用 [2]初始化 [3]常用工具[4]快捷键 前面的话 photoshop是前端工程师无法回避的一个软件,这个软件本身很强大,但我们仅仅需要通过这个工具来完成基本的切图工作即可.本文 ...

随机推荐

  1. Google 开源的 Python 命令行库:初探 fire

    作者:HelloGitHub-Prodesire HelloGitHub 的<讲解开源项目>系列,项目地址:https://github.com/HelloGitHub-Team/Arti ...

  2. zookeeper--为分布式应用提供协调服务

    1.概述 zookeeper是一个开源的.分布式的.为分布式应用提供协调服务的Apache项目 zookeeper的工作机制 zookeeper从设计模式角度来理解:是一个基于观察者模式设计的分布式服 ...

  3. 关于单机部署fastdfs遇到的问题

    查找错误日志显示:/html/group1/M00/00/00/wKjJWFzdF0qAE1pBAACmOw57Lw0520_big.jpg" failed (2: No such file ...

  4. 并发编程:协程TCP、非阻塞IO、多路复用、

    一.线程池实现阻塞IO 二.非阻塞IO模型 三.多路复用,降低CPU占用 四.模拟异步IO 一.线程池实现阻塞IO 线程阻塞IO 客户端 import socket c = socket.socket ...

  5. js失效问题

    由于有些公司设计的js文件涉及到收费问题,提供的这些js文件不能部署到线上,只能通过127.0.0.1:8080/home类似方式访问js才能生效,换作10.140.111.11:8080/home这 ...

  6. docker镜像pull不下来最终解决方法

    pull镜像wordpress下来,但是出现如下错误: # docker pull wordpress:latest Error response from daemon: Get https://r ...

  7. java 多线程,线程安全等定义

    线程安全, synchronized的使用,保证方法或代码块操作的原子性.可见性和有序性 参考这篇文章: 7张图带你轻松理解Java 线程安全 public class ThreadDemo { pr ...

  8. java线程基础巩固---同步代码块以及同步方法之间的区别和关系

    在上一次中[http://www.cnblogs.com/webor2006/p/8040369.html]采用同步代码块的方式来实现对线程的同步,如下: 对于同步方法我想都知道,就是将同步关键字声明 ...

  9. Mac常用设置备忘

    1.显示隐藏文件 1>命令行方式 显示:defaults write com.apple.finder AppleShowAllFiles -bool true 隐藏:defaults writ ...

  10. HTML5测试题整理Ⅰ

    1.在 HTML5 中,哪个元素用于组合标题元素? 答案:<hgroup>   2.HTML5 中不再支持哪个元素? 答案:<font>,<acronym>,< ...