openMP 处理for循环

//////////////////////////////////////////////////////////////////////////////////////////////
template <typename PointInT, typename PointOutT> void
pcl::MovingLeastSquares<PointInT, PointOutT>::performProcessing (PointCloudOut &output)
{
// Compute the number of coefficients
nr_coeff_ = (order_ + ) * (order_ + ) / ; size_t mls_result_index = ; #ifdef _OPENMP
// (Maximum) number of threads
const unsigned int threads = threads_ == ? : 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 = ; 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 () >= )
{
// 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]; 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 = ; 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);
}
template <typename PointT> void
pcl::FastBilateralFilterOMP<PointT>::applyFilter (PointCloud &output)
{
if (!input_->isOrganized ())
{
PCL_ERROR ("[pcl::FastBilateralFilterOMP] Input cloud needs to be organized.\n");
return;
} copyPointCloud (*input_, output);
float base_max = -std::numeric_limits<float>::max (),
base_min = std::numeric_limits<float>::max ();
bool found_finite = false;
for (size_t x = ; x < output.width; ++x)
{
for (size_t y = ; y < output.height; ++y)
{
if (pcl_isfinite (output (x, y).z))
{
if (base_max < output (x, y).z)
base_max = output (x, y).z;
if (base_min > output (x, y).z)
base_min = output (x, y).z;
found_finite = true;
}
}
}
if (!found_finite)
{
PCL_WARN ("[pcl::FastBilateralFilterOMP] Given an empty cloud. Doing nothing.\n");
return;
}
#ifdef _OPENMP
#pragma omp parallel for num_threads (threads_)
#endif
for (long int i = ; i < static_cast<long int> (output.size ()); ++i)
if (!pcl_isfinite (output.at(i).z))
output.at(i).z = base_max; const float base_delta = base_max - base_min; const size_t padding_xy = ;
const size_t padding_z = ; const size_t small_width = static_cast<size_t> (static_cast<float> (input_->width - ) / sigma_s_) + + * padding_xy;
const size_t small_height = static_cast<size_t> (static_cast<float> (input_->height - ) / sigma_s_) + + * padding_xy;
const size_t small_depth = static_cast<size_t> (base_delta / sigma_r_) + + * padding_z; Array3D data (small_width, small_height, small_depth);
#ifdef _OPENMP
#pragma omp parallel for num_threads (threads_)
#endif
for (long int i = ; i < static_cast<long int> (small_width * small_height); ++i)
{
size_t small_x = static_cast<size_t> (i % small_width);
size_t small_y = static_cast<size_t> (i / small_width);
size_t start_x = static_cast<size_t>(
std::max ((static_cast<float> (small_x) - static_cast<float> (padding_xy) - 0.5f) * sigma_s_ + , .f));
size_t end_x = static_cast<size_t>(
std::max ((static_cast<float> (small_x) - static_cast<float> (padding_xy) + 0.5f) * sigma_s_ + , .f));
size_t start_y = static_cast<size_t>(
std::max ((static_cast<float> (small_y) - static_cast<float> (padding_xy) - 0.5f) * sigma_s_ + , .f));
size_t end_y = static_cast<size_t>(
std::max ((static_cast<float> (small_y) - static_cast<float> (padding_xy) + 0.5f) * sigma_s_ + , .f));
for (size_t x = start_x; x < end_x && x < input_->width; ++x)
{
for (size_t y = start_y; y < end_y && y < input_->height; ++y)
{
const float z = output (x,y).z - base_min;
const size_t small_z = static_cast<size_t> (static_cast<float> (z) / sigma_r_ + 0.5f) + padding_z;
Eigen::Vector2f& d = data (small_x, small_y, small_z);
d[] += output (x,y).z;
d[] += 1.0f;
}
}
} std::vector<long int> offset ();
offset[] = &(data (,,)) - &(data (,,));
offset[] = &(data (,,)) - &(data (,,));
offset[] = &(data (,,)) - &(data (,,)); Array3D buffer (small_width, small_height, small_depth); for (size_t dim = ; dim < ; ++dim)
{
for (size_t n_iter = ; n_iter < ; ++n_iter)
{
Array3D* current_buffer = (n_iter % == ? &buffer : &data);
Array3D* current_data =(n_iter % == ? &data : &buffer);
#ifdef _OPENMP
#pragma omp parallel for num_threads (threads_)
#endif
for(long int i = ; i < static_cast<long int> ((small_width - )*(small_height - )); ++i)
{
size_t x = static_cast<size_t> (i % (small_width - ) + );
size_t y = static_cast<size_t> (i / (small_width - ) + );
const long int off = offset[dim];
Eigen::Vector2f* d_ptr = &(current_data->operator() (x,y,));
Eigen::Vector2f* b_ptr = &(current_buffer->operator() (x,y,)); for(size_t z = ; z < small_depth - ; ++z, ++d_ptr, ++b_ptr)
*d_ptr = (*(b_ptr - off) + *(b_ptr + off) + 2.0 * (*b_ptr)) / 4.0;
}
}
}
// Note: this works because there are an even number of iterations.
// If there were an odd number, we would need to end with a:
// std::swap (data, buffer); if (early_division_)
{
for (std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::iterator d = data.begin (); d != data.end (); ++d)
*d /= ((*d)[] != ) ? (*d)[] : ; #ifdef _OPENMP
#pragma omp parallel for num_threads (threads_)
#endif
for (long int i = ; i < static_cast<long int> (input_->size ()); ++i)
{
size_t x = static_cast<size_t> (i % input_->width);
size_t y = static_cast<size_t> (i / input_->width);
const float z = output (x,y).z - base_min;
const Eigen::Vector2f D = data.trilinear_interpolation (static_cast<float> (x) / sigma_s_ + padding_xy,
static_cast<float> (y) / sigma_s_ + padding_xy,
z / sigma_r_ + padding_z);
output(x,y).z = D[];
}
}
else
{
#ifdef _OPENMP
#pragma omp parallel for num_threads (threads_)
#endif
for (long i = ; i < static_cast<long int> (input_->size ()); ++i)
{
size_t x = static_cast<size_t> (i % input_->width);
size_t y = static_cast<size_t> (i / input_->width);
const float z = output (x,y).z - base_min;
const Eigen::Vector2f D = data.trilinear_interpolation (static_cast<float> (x) / sigma_s_ + padding_xy,
static_cast<float> (y) / sigma_s_ + padding_xy,
z / sigma_r_ + padding_z);
output (x,y).z = D[] / D[];
}
}
}
template <typename PointInT, typename PointOutT> void
pcl::NormalEstimationOMP<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
{
// Allocate enough space to hold the results
// \note This resize is irrelevant for a radiusSearch ().
std::vector<int> nn_indices (k_);
std::vector<float> nn_dists (k_); output.is_dense = true;
// Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
if (input_->is_dense)
{
#ifdef _OPENMP
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
// Iterating over the entire index vector
for (int idx = ; idx < static_cast<int> (indices_->size ()); ++idx)
{
Eigen::Vector4f n;
if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == ||
!computePointNormal (*surface_, nn_indices, n, output.points[idx].curvature))
{
output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].curvature = std::numeric_limits<float>::quiet_NaN (); output.is_dense = false;
continue;
} output.points[idx].normal_x = n[];
output.points[idx].normal_y = n[];
output.points[idx].normal_z = n[]; flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[]); }
}
else
{
#ifdef _OPENMP
#pragma omp parallel for shared (output) private (nn_indices, nn_dists) num_threads(threads_)
#endif
// Iterating over the entire index vector
for (int idx = ; idx < static_cast<int> (indices_->size ()); ++idx)
{
Eigen::Vector4f n;
if (!isFinite ((*input_)[(*indices_)[idx]]) ||
this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == ||
!computePointNormal (*surface_, nn_indices, n, output.points[idx].curvature))
{
output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].normal[] = output.points[idx].curvature = std::numeric_limits<float>::quiet_NaN (); output.is_dense = false;
continue;
} output.points[idx].normal_x = n[];
output.points[idx].normal_y = n[];
output.points[idx].normal_z = n[]; flipNormalTowardsViewpoint (input_->points[(*indices_)[idx]], vpx_, vpy_, vpz_,
output.points[idx].normal[], output.points[idx].normal[], output.points[idx].normal[]); }
}
}

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. Nginx作为静态资源web服务之跨域访问

    Nginx作为静态资源web服务之跨域访问 首先了解一下什么是跨域 跨域,指的是浏览器不能执行其他网站的脚本.它是由浏览器的同源策略造成的,是浏览器施加的安全限制. 所谓同源是指,域名,协议,端口均相 ...

  2. 盗取连接你wifi的人的qq

    #本文内容仅供个人娱乐学习 思路: 使用wireshark监听笔记本的wifi热点,拦截捕获连接你的wifi热点的人的手机qq网络数据包,从网络数据包中分析取出两个qq空间的两个coookie值,使用 ...

  3. JavaJDBC【四、存储过程的使用】

    Mysql还没学到存储过程,不过语法比较简单 此处不深究数据库中的存储过程怎么创建,后面在mysql的学习笔记里再做整理 今天只整理java中如何调用存储过程 语句 CallableStatement ...

  4. 第十五章·Kibana深入-Dev Tools及Lucene语法

    Dev Tools介绍 Dev Tools 页面包含开发工具,您可以使用这些Dev Tools与Kibana中的数据进行交互. 原先的交互式控制台Sense,使用户方便的通过浏览器直接与Elastic ...

  5. Binlog_master

    二进制日志 记录导致数据改变或潜在导致数据改变的SQL语句 记录已提交的日志 不依赖于存储引擎类型 功能:通过"重放"日志文件中的事件来生成数据副本 注意:建议二进制日志和数据文件 ...

  6. linux基础—课堂随笔_03 SHELL脚本编程基础

    shell脚本编程基础 条件选择:if语句 选择执行: 注意:if语句可嵌套 单分支 if(开头)判断条件:then条件为真的分支代码 fi(结尾) 双分支 if(开头)判断条件:then条件为真的分 ...

  7. python基础编程: 函数示例、装饰器、模块、内置函数

    目录: 函数示例 装饰器 模块 内置函数 一.函数示例: 1.为什么使用函数之模块化程序设计: 不使用模块程序设计的缺点: 1.体系结构不清晰,可主读性差: 2.可扩展性差: 3.程序冗长: 2.定义 ...

  8. 解决Zabbix某台主机突然频繁告警"Zabbix agent on xxxxxx is unreachable for x minutes"

    一.某台主机突然某一天频繁告警zabbix agent不可达 查看zabbix agent日志没有发现异常 二.查看zabbix server日志发现这台主机的日志有大量报错信息"first ...

  9. 30秒钟解决MariaDB插入汉字时出现错误

    示例: create table demo( name varchar(10), sex varchar(5) )engine=innoDB default charset=utf8; 表的后面加上指 ...

  10. PHP类知识----clone方法上机实验

    <?php class mycoach { public function __construct($name,$age) { $this->name = $name; $this-> ...