Skip to content

Instantly share code, notes, and snippets.

@soulslicer
Last active June 19, 2017 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soulslicer/d6a1de900b90fd03deef2c2a6fa01b5a to your computer and use it in GitHub Desktop.
Save soulslicer/d6a1de900b90fd03deef2c2a6fa01b5a to your computer and use it in GitHub Desktop.
PCL Surface OpenMP speedup patch
diff --git a/surface/include/pcl/surface/impl/poisson.hpp b/surface/include/pcl/surface/impl/poisson.hpp
index 97848d3..4f824fd 100644
--- a/surface/include/pcl/surface/impl/poisson.hpp
+++ b/surface/include/pcl/surface/impl/poisson.hpp
@@ -102,6 +102,7 @@ pcl::Poisson<PointNT>::execute (poisson::CoredVectorMeshData &mesh,
/// TODO OPENMP stuff
// tree.threads = Threads.value;
+ tree.threads = 16;
center.coords[0] = center.coords[1] = center.coords[2] = 0;
diff --git a/surface/include/pcl/surface/impl/texture_mapping.hpp b/surface/include/pcl/surface/impl/texture_mapping.hpp
index ed7bd50..d2076d3 100644
--- a/surface/include/pcl/surface/impl/texture_mapping.hpp
+++ b/surface/include/pcl/surface/impl/texture_mapping.hpp
@@ -752,6 +752,7 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras (pcl::TextureMesh
std::vector<pcl::Vertices> faces;
+ //#pragma omp parallel for shared(mesh)
for (int current_cam = 0; current_cam < static_cast<int> (cameras.size ()); ++current_cam)
{
PCL_INFO ("Processing camera %d of %d.\n", current_cam+1, cameras.size ());
@@ -837,16 +838,18 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras (pcl::TextureMesh
pcl::KdTreeFLANN<pcl::PointXY> kdtree;
kdtree.setInputCloud (projections);
- std::vector<int> idxNeighbors;
- std::vector<float> neighborsSquaredDistance;
+
// af first (idx_pcan < current_cam), check if some of the faces attached to previous cameras occlude the current faces
// then (idx_pcam == current_cam), check for self occlusions. At this stage, we skip faces that were already marked as occluded
cpt_invisible = 0;
for (int idx_pcam = 0 ; idx_pcam <= current_cam ; ++idx_pcam)
{
// project all faces
+ #pragma omp parallel for shared(visibility,cpt_invisible)
for (int idx_face = 0; idx_face < static_cast<int> (mesh.tex_polygons[idx_pcam].size ()); ++idx_face)
{
+ std::vector<int> idxNeighbors;
+ std::vector<float> neighborsSquaredDistance;
if (idx_pcam == current_cam && !visibility[idx_face])
{
@@ -891,8 +894,11 @@ pcl::TextureMapping<PointInT>::textureMeshwithMultipleCameras (pcl::TextureMesh
if (checkPointInsideTriangle(uv_coord1, uv_coord2, uv_coord3, projections->points[idxNeighbors[i]]))
{
// current neighbor is inside triangle and is closer => the corresponding face
+ #pragma omp critical(dataupdate)
+ {
visibility[indexes_uv_to_points[idxNeighbors[i]].idx_face] = false;
cpt_invisible++;
+ }
//TODO we could remove the projections of this face from the kd-tree cloud, but I fond it slower, and I need the point to keep ordered to querry UV coordinates later
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment