Commit 224fce4e authored by Patrik Huber's avatar Patrik Huber

Parallelised texture extraction

Wrapped the extraction of a triangle in a lambda and calling all lambdas with std::async
parent 26371d1d
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <tuple> #include <tuple>
#include <cassert> #include <cassert>
#include <future>
namespace eos { namespace eos {
namespace render { namespace render {
...@@ -112,7 +113,11 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat ...@@ -112,7 +113,11 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat
Mat isomap = Mat::zeros(isomap_resolution, isomap_resolution, CV_8UC4); // #Todo: We do want an alpha channel. Will be added soon-ish. Mat isomap = Mat::zeros(isomap_resolution, isomap_resolution, CV_8UC4); // #Todo: We do want an alpha channel. Will be added soon-ish.
// #Todo: We should handle gray images, but output a 4-channel isomap nevertheless I think. // #Todo: We should handle gray images, but output a 4-channel isomap nevertheless I think.
std::vector<std::future<void>> results;
for (const auto& triangle_indices : mesh.tvi) { for (const auto& triangle_indices : mesh.tvi) {
auto extract_triangle = [&mesh, &affine_camera_matrix, triangle_indices = triangle_indices, &depthbuffer, &isomap, &mapping_type, &image]() {
// Find out if the current triangle is visible: // Find out if the current triangle is visible:
// We do a second rendering-pass here. We use the depth-buffer of the final image, and then, here, // We do a second rendering-pass here. We use the depth-buffer of the final image, and then, here,
// check if each pixel in a triangle is visible. If the whole triangle is visible, we use it to extract // check if each pixel in a triangle is visible. If the whole triangle is visible, we use it to extract
...@@ -130,7 +135,8 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat ...@@ -130,7 +135,8 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat
if (!detail::is_triangle_visible(v0, v1, v2, depthbuffer)) if (!detail::is_triangle_visible(v0, v1, v2, depthbuffer))
{ {
continue; //continue;
return;
} }
// Todo: Documentation // Todo: Documentation
...@@ -255,7 +261,12 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat ...@@ -255,7 +261,12 @@ inline cv::Mat extract_texture(Mesh mesh, cv::Mat affine_camera_matrix, cv::Mat
} }
} }
} }
} }; // end lambda auto extract_triangle();
results.emplace_back(std::async(extract_triangle));
} // end for all mesh.tvi
// Collect all the launched tasks:
for (auto&& r : results) {
r.get();
} }
return isomap; return isomap;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment