/*
Copyright 2005-2012 Intel Corporation. All Rights Reserved.
This file is part of Threading Building Blocks.
Threading Building Blocks is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
Threading Building Blocks is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Threading Building Blocks; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
As a special exception, you may use this file as part of a free software
library without restriction. Specifically, if other files instantiate
templates or use macros or inline functions from this file, or you compile
this file and link it with other files to produce an executable, this
file does not by itself cause the resulting executable to be covered by
the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
// Polygon overlay
//
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstdlib>
#include <assert.h>
#include "tbb/tick_count.h"
#include "tbb/blocked_range.h"
#include "tbb/task_scheduler_init.h"
#include "tbb/parallel_for.h"
#include "tbb/mutex.h"
#include "tbb/spin_mutex.h"
#include "polyover.h"
#include "polymain.h"
#include "pover_video.h"
using namespace std;
/*!
* @brief intersects a polygon with a map, adding any results to output map
*
* @param[out] resultMap output map (must be allocated)
* @param[in] polygon to be intersected
* @param[in] map intersected against
* @param[in] lock to use when adding output polygons to result map
*
*/
void OverlayOnePolygonWithMap(Polygon_map_t *resultMap, RPolygon *myPoly, Polygon_map_t *map2, tbb::spin_mutex *rMutex) {
int r1, g1, b1, r2, g2, b2;
int myr=0;
int myg=0;
int myb=0;
int p1Area = myPoly->area();
for(unsigned int j=1; (j < map2->size()) && (p1Area > 0); j++) {
RPolygon *p2 = &((*map2)[j]);
RPolygon *pnew;
int newxMin, newxMax, newyMin, newyMax;
myPoly->getColor(&r1, &g1, &b1);
if(PolygonsOverlap(myPoly, p2, newxMin, newyMin, newxMax, newyMax)) {
p2->getColor(&r2, &g2, &b2);
myr = r1 + r2;
myg = g1 + g2;
myb = b1 + b2;
p1Area -= (newxMax-newxMin+1)*(newyMax - newyMin + 1);
if(rMutex) {
tbb::spin_mutex::scoped_lock lock(*rMutex);
resultMap->push_back(RPolygon(newxMin, newyMin, newxMax, newyMax, myr, myg, myb));
}
else {
resultMap->push_back(RPolygon(newxMin, newyMin, newxMax, newyMax, myr, myg, myb));
}
}
}
}
/*!
* @brief Serial version of polygon overlay
* @param[out] output map
* @param[in] first map (map that individual polygons are taken from)
* @param[in] second map (map passed to OverlayOnePolygonWithMap)
*/
void SerialOverlayMaps(Polygon_map_t **resultMap, Polygon_map_t *map1, Polygon_map_t *map2) {
cout << "SerialOverlayMaps called" << std::endl;
*resultMap = new Polygon_map_t;
RPolygon *p0 = &((*map1)[0]);
int mapxSize, mapySize, ignore1, ignore2;
p0->get(&ignore1, &ignore2, &mapxSize, &mapySize);
(*resultMap)->reserve(mapxSize*mapySize); // can't be any bigger than this
// push the map size as the first polygon,
(*resultMap)->push_back(RPolygon(0,0,mapxSize, mapySize));
for(unsigned int i=1; i < map1->size(); i++) {
RPolygon *p1 = &((*map1)[i]);
OverlayOnePolygonWithMap(*resultMap, p1, map2, NULL);
}
}
/*!
* @class ApplyOverlay
* @brief Simple version of parallel overlay (make parallel on polygons in map1)
*/
class ApplyOverlay {
Polygon_map_t *m_map1, *m_map2, *m_resultMap;
tbb::spin_mutex *m_rMutex;
public:
/*!
* @brief functor to apply
* @param[in] r range of polygons to intersect from map1
*/
void operator()( const tbb::blocked_range<int> & r) const {
PRINT_DEBUG("From " << r.begin() << " to " << r.end());
for(int i=r.begin(); i != r.end(); i++) {
RPolygon *myPoly = &((*m_map1)[i]);
OverlayOnePolygonWithMap(m_resultMap, myPoly, m_map2, m_rMutex);
}
}
ApplyOverlay(Polygon_map_t *resultMap, Polygon_map_t *map1, Polygon_map_t *map2, tbb::spin_mutex *rmutex) :
m_resultMap(resultMap), m_map1(map1), m_map2(map2), m_rMutex(rmutex) {}
};
/*!
* @brief apply the parallel algorithm
* @param[out] result_map generated map
* @param[in] polymap1 first map to be applied (algorithm is parallel on this map)
* @param[in] polymap2 second map.
*/
void NaiveParallelOverlay(Polygon_map_t *&result_map, Polygon_map_t &polymap1, Polygon_map_t &polymap2) {
// -----------------------------------
bool automatic_threadcount = false;
if(gThreadsLow == THREADS_UNSET || gThreadsLow == tbb::task_scheduler_init::automatic) {
gThreadsLow = gThreadsHigh = tbb::task_scheduler_init::automatic;
automatic_threadcount = true;
}
result_map = new Polygon_map_t;
RPolygon *p0 = &(polymap1[0]);
int mapxSize, mapySize, ignore1, ignore2;
p0->get(&ignore1, &ignore2, &mapxSize, &mapySize);
result_map->reserve(mapxSize*mapySize); // can't be any bigger than this
// push the map size as the first polygon,
tbb::spin_mutex *resultMutex = new tbb::spin_mutex();
int grain_size = gGrainSize;
for(int nthreads = gThreadsLow; nthreads <= gThreadsHigh; nthreads++) {
tbb::task_scheduler_init init(nthreads);
if(gIsGraphicalVersion) {
RPolygon *xp = new RPolygon(0, 0, gMapXSize-1, gMapYSize-1, 0, 0, 0); // Clear the output space
delete xp;
}
// put size polygon in result map
result_map->push_back(RPolygon(0,0,mapxSize, mapySize));
tbb::tick_count t0 = tbb::tick_count::now();
tbb::parallel_for (tbb::blocked_range<int>(1,(int)(polymap1.size()),grain_size), ApplyOverlay(result_map, &polymap1, &polymap2, resultMutex));
tbb::tick_count t1 = tbb::tick_count::now();
double naiveParallelTime = (t1-t0).seconds() * 1000;
cout << "Naive parallel with spin lock and ";
if(automatic_threadcount) cout << "automatic";
else cout << nthreads;
cout << ((nthreads == 1) ? " thread" : " threads");
cout << " took " << naiveParallelTime << " msec : speedup over serial " << (gSerialTime / naiveParallelTime) << std::endl;
if(gCsvFile.is_open()) {
gCsvFile << "," << naiveParallelTime;
}
#if _DEBUG
CheckPolygonMap(result_map);
ComparePolygonMaps(result_map, gResultMap);
#endif
result_map->clear();
}
delete resultMutex;
if(gCsvFile.is_open()) {
gCsvFile << std::endl;
}
// -----------------------------------
}
template<typename T>
void split_at( Flagged_map_t& in_map, Flagged_map_t &left_out, Flagged_map_t &right_out, const T median) {
left_out.reserve(in_map.size());
right_out.reserve(in_map.size());
for(Flagged_map_t::iterator i = in_map.begin(); i != in_map.end(); ++i ) {
RPolygon *p = i->p();
if(p->xmax() < median) {
// in left map
left_out.push_back(*i);
}
else if(p->xmin() >= median) {
right_out.push_back(*i);
// in right map
}
else {
// in both maps.
left_out.push_back(*i);
right_out.push_back(RPolygon_flagged(p, true));
}
}
}
// range that splits the maps as well as the range. the
没有合适的资源?快使用搜索试试~ 我知道了~
tbb41_20121003oss_win.zip_TBB-41_tbb_tbb41_tbb41_20121003oss_tbb
共1005个文件
html:376个
h:154个
cpp:80个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 55 浏览量
2022-09-14
21:05:56
上传
评论
收藏 21.34MB ZIP 举报
温馨提示
opencv用到的tbb 例子,还有各种动态链接库
资源详情
资源评论
资源推荐
收起资源包目录
tbb41_20121003oss_win.zip_TBB-41_tbb_tbb41_tbb41_20121003oss_tbb (1005个子文件)
tbbvars.bat 4KB
copy_libraries.bat 3KB
dxcheck.bat 2KB
CHANGES 54KB
condition_variable 15KB
COPYING 18KB
polyover.cpp 25KB
ddvideo.cpp 24KB
test_all.cpp 23KB
polymain.cpp 23KB
convex_hull_bench.cpp 20KB
Fibonacci.cpp 20KB
parse.cpp 20KB
grid.cpp 18KB
binpack.cpp 15KB
xvideo.cpp 14KB
shortpath.cpp 13KB
Update_state.cpp 13KB
dining_philosophers.cpp 12KB
api.cpp 12KB
sudoku.cpp 12KB
primes.cpp 11KB
convex_hull_sample.cpp 11KB
count_strings.cpp 10KB
trace.tbb.cpp 10KB
objbound.cpp 10KB
square.cpp 10KB
extvol.cpp 9KB
shade.cpp 9KB
texture.cpp 9KB
vol.cpp 9KB
apigeom.cpp 8KB
fractal.cpp 8KB
main.cpp 8KB
universe.cpp 8KB
cylinder.cpp 8KB
tgafile.cpp 8KB
apitrigeom.cpp 8KB
trace.tbb1d.cpp 7KB
triangle.cpp 7KB
Evolution.cpp 7KB
d2dvideo.cpp 7KB
Game_of_life.cpp 6KB
main.cpp 6KB
trace.serial.cpp 6KB
gdivideo.cpp 6KB
bndbox.cpp 6KB
jpeg.cpp 6KB
pover_video.cpp 6KB
sub_string_finder_extended.cpp 6KB
quadric.cpp 6KB
imap.cpp 6KB
intersect.cpp 5KB
box.cpp 5KB
trace_rest.cpp 5KB
main.cpp 5KB
imageio.cpp 5KB
pthread.cpp 5KB
main.cpp 5KB
seismic_video.cpp 5KB
tachyon_video.cpp 5KB
util.cpp 5KB
camera.cpp 5KB
ppm.cpp 5KB
macvideo.cpp 5KB
ring.cpp 5KB
sphere.cpp 5KB
vector.cpp 4KB
light.cpp 4KB
main.cpp 4KB
main.cpp 4KB
ui.cpp 4KB
plane.cpp 4KB
render.cpp 4KB
coordsys.cpp 4KB
convideo.cpp 4KB
Graph.cpp 4KB
global.cpp 3KB
sub_string_finder_pretty.cpp 3KB
OptimizedParallelSumTree.cpp 3KB
sub_string_finder.cpp 3KB
SimpleParallelSumTree.cpp 3KB
AssemblyInfo.cpp 3KB
parallel_preorder.cpp 3KB
gen_input.cpp 2KB
SerialSumTree.cpp 2KB
doxygen.css 8KB
tabs.css 2KB
balls3.dat 508KB
balls.dat 508KB
teapot.dat 453KB
lattice.dat 448KB
820spheres.dat 56KB
trypsin4pti.dat 27KB
model2.dat 2KB
tbb.def 14KB
tbb.def 14KB
tbb.def 13KB
tbb.def 13KB
tbb.def 13KB
共 1005 条
- 1
- 2
- 3
- 4
- 5
- 6
- 11
JaniceLu
- 粉丝: 78
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- python tkinter-08-盒子模型.ev4.rar
- Doozy UI Manager 2023
- 基于matlab实现夜间车牌识别程序(1).rar
- 基于matlab实现无线传感器网络无需测距定位算法matlab源代码 包括apit,dv-hop,amorphous在内的共7个
- 基于python的yolov5实现的旋转目标检测
- 基于matlab实现无线传感器网络 CAB定位仿真程序 这是无线传感器节点定位CAB算法的仿真程序,由matlab完成.rar
- 基于matlab实现图像处理,本程序使用背景差分法对来往车辆进行检测和跟踪.rar
- 基于matlab实现视频监控中车型识别代码,自己写的,希望和大家多多交流.rar
- springcodespringcodespringcodespringcode
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0