size_t operator()(size_t key){ static tbb::mutex mtx; if (use_serial_initiation_function){ mtx.lock(); } micro_benchmarking::utils::busy_wait(m_weight_of_initiation_call_usec); if (use_serial_initiation_function){ mtx.unlock(); } return key; }
void operator()( DVertex_handle vh ) const { //std::cout << "TBBVoronoiCell::operator()" << std::endl; mutexforDelaunayVoronoiTbb.lock(); //The direct assign of cutMeshTriangles = meshData->first causes a crash on multiple calls of voronoiShatter, // due to the copy of the Triangle. In order to work correctly, the Triangle are recreated //std::list<Triangle> cutMeshTriangles = meshData->first; std::list<TriangleInfo> cutInfo = meshData->second; std::list<Triangle> cutMeshTriangles; //std::list<TriangleInfo> cutInfo; std::list<Triangle>::iterator triangleIter; for(triangleIter=meshData->first.begin(); triangleIter!= meshData->first.end(); ++triangleIter) { Triangle t = *triangleIter; cutMeshTriangles.push_back(Triangle(t.vertex(0),t.vertex(1),t.vertex(2))); //See the comment above } //std::list<TriangleInfo>::iterator triangleInfoIter; //for(triangleInfoIter=meshData->second.begin(); triangleInfoIter!= meshData->second.end(); ++triangleInfoIter) //{ // TriangleInfo ti = *triangleInfoIter; // cutInfo.push_back(ti); //} std::list<DEdge> segs; T->finite_incident_edges(vh, std::back_inserter(segs)); mutexforDelaunayVoronoiTbb.unlock(); std::cout << " num edges: " << segs.size() << std::endl; std::list<DEdge>::iterator segsIter; for(segsIter=segs.begin(); segsIter!= segs.end(); ++segsIter) { DEdge edg = *segsIter; mutexforDelaunayVoronoiTbb.lock(); DSegment_3 segment = T->segment(edg); mutexforDelaunayVoronoiTbb.unlock(); KDVector vect = segment.to_vector(); KDPoint p1 = segment.source(); KDPoint p2 = segment.target(); //KDPoint mp( (p1.x() + p2.x())/2.0, (p1.y() + p2.y())/2.0, (p1.z() + p2.z())/2.0); //Plane planeCutter_voronoi(PointCGAL(mp.x(), mp.y(), mp.z()), Vector(-vect.x(), -vect.y(), -vect.z())); //TODO: potrebbe esserci un errore a causa dei punti non esatti p1 e p2 PointCGAL mp( (p1.x() + p2.x())/2.0, (p1.y() + p2.y())/2.0, (p1.z() + p2.z())/2.0); Plane planeCutter_voronoi(mp, Vector(-vect.x(), -vect.y(), -vect.z())); MeshData cutData = cutMesh(cutMeshTriangles, planeCutter_voronoi, cutInfo, useDelaunay, bCriteria, sCriteria); cutMeshTriangles = cutData.first; cutInfo = cutData.second; //std::cout << " temp mesh size: " << cutMeshTriangles.size() << std::endl; } mutexforDelaunayVoronoiTbb.lock(); if (cutMeshTriangles.size() > 0) { //concurrentResultMeshdata->push_back(MeshData(cutMeshTriangles, cutInfo)); resultMeshdata->push_back(MeshData(cutMeshTriangles, cutInfo)); } else { std::cout << " Warning: Final Voronoi mesh size empty!!" << std::endl; } mutexforDelaunayVoronoiTbb.unlock(); }