Paralelization of filtration in AOI triangles
This commit is contained in:
parent
26eb8b02ef
commit
ded488d516
@ -28,6 +28,7 @@ using namespace Slic3r;
|
|||||||
#include <CGAL/Exact_integer.h>
|
#include <CGAL/Exact_integer.h>
|
||||||
#include <CGAL/Surface_mesh.h>
|
#include <CGAL/Surface_mesh.h>
|
||||||
#include <CGAL/Cartesian_converter.h>
|
#include <CGAL/Cartesian_converter.h>
|
||||||
|
#include <tbb/parallel_for.h>
|
||||||
|
|
||||||
// libslic3r
|
// libslic3r
|
||||||
#include "TriangleMesh.hpp" // its_merge
|
#include "TriangleMesh.hpp" // its_merge
|
||||||
@ -631,14 +632,14 @@ using PointNormals = std::array<PointNormal, 4>;
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool is_out_of(const Vec3d &v, const PointNormal &point_normal);
|
bool is_out_of(const Vec3d &v, const PointNormal &point_normal);
|
||||||
|
|
||||||
using IsOnSides = std::array<std::vector<bool>, 4>;
|
using IsOnSides = std::vector<std::array<bool, 4>>;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check if triangle t has all vertices out of any plane
|
/// Check if triangle t has all vertices out of any plane
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="t">Triangle</param>
|
/// <param name="t">Triangle</param>
|
||||||
/// <param name="is_on_sides">Flag is vertex index out of plane</param>
|
/// <param name="is_on_sides">Flag is vertex index out of plane</param>
|
||||||
/// <returns>True when triangle is out of one of plane</returns>
|
/// <returns>True when triangle is out of one of plane</returns>
|
||||||
bool is_all_on_one_side(const Vec3i &t, const IsOnSides is_on_sides);
|
bool is_all_on_one_side(const Vec3i &t, const IsOnSides& is_on_sides);
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
|
|
||||||
@ -650,11 +651,11 @@ bool priv::is_out_of(const Vec3d &v, const PointNormal &point_normal)
|
|||||||
return signed_distance > 1e-5;
|
return signed_distance > 1e-5;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool priv::is_all_on_one_side(const Vec3i &t, const IsOnSides is_on_sides) {
|
bool priv::is_all_on_one_side(const Vec3i &t, const IsOnSides& is_on_sides) {
|
||||||
for (size_t side = 0; side < 4; side++) {
|
for (size_t side = 0; side < 4; side++) {
|
||||||
bool result = true;
|
bool result = true;
|
||||||
for (auto vi : t) {
|
for (auto vi : t) {
|
||||||
if (!is_on_sides[side][vi]) {
|
if (!is_on_sides[vi][side]) {
|
||||||
result = false;
|
result = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -709,36 +710,40 @@ void priv::set_skip_for_out_of_aoi(std::vector<bool> &skip_indicies,
|
|||||||
point_normals[i] = {p1.cast<double>(), normal};
|
point_normals[i] = {p1.cast<double>(), normal};
|
||||||
}
|
}
|
||||||
// same meaning as point normal
|
// same meaning as point normal
|
||||||
IsOnSides is_on_sides;
|
IsOnSides is_on_sides(its.vertices.size(), {false,false,false,false});
|
||||||
for (size_t side = 0; side < 4; side++)
|
|
||||||
is_on_sides[side] = std::vector<bool>(its.vertices.size(), {false});
|
|
||||||
|
|
||||||
// inspect all vertices when it is out of bounding box
|
// inspect all vertices when it is out of bounding box
|
||||||
for (size_t i = 0; i < its.vertices.size(); i++) {
|
tbb::parallel_for(tbb::blocked_range<size_t>(0, its.vertices.size()),
|
||||||
Vec3d v = its.vertices[i].cast<double>();
|
[&its, &point_normals, &is_on_sides](const tbb::blocked_range<size_t> &range) {
|
||||||
// under + above
|
for (size_t i = range.begin(); i < range.end(); ++i) {
|
||||||
for (int side : {0, 2}) {
|
Vec3d v = its.vertices[i].cast<double>();
|
||||||
if (is_out_of(v, point_normals[side])) {
|
// under + above
|
||||||
is_on_sides[side][i] = true;
|
for (int side : {0, 2}) {
|
||||||
// when it is under it can't be above
|
if (is_out_of(v, point_normals[side])) {
|
||||||
break;
|
is_on_sides[i][side] = true;
|
||||||
|
// when it is under it can't be above
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// left + right
|
||||||
|
for (int side : {1, 3}) {
|
||||||
|
if (is_out_of(v, point_normals[side])) {
|
||||||
|
is_on_sides[i][side] = true;
|
||||||
|
// when it is on left side it can't be on right
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// left + right
|
}); // END parallel for
|
||||||
for (int side : {1, 3}) {
|
|
||||||
if (is_out_of(v, point_normals[side])) {
|
|
||||||
is_on_sides[side][i] = true;
|
|
||||||
// when it is on left side it can't be on right
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// inspect all triangles, when it is out of bounding box
|
// inspect all triangles, when it is out of bounding box
|
||||||
for (size_t i = 0; i < its.indices.size(); i++) {
|
tbb::parallel_for(tbb::blocked_range<size_t>(0, its.indices.size()),
|
||||||
if (is_all_on_one_side(its.indices[i], is_on_sides))
|
[&its, &is_on_sides, &skip_indicies](const tbb::blocked_range<size_t> &range) {
|
||||||
skip_indicies[i] = true;
|
for (size_t i = range.begin(); i < range.end(); ++i) {
|
||||||
}
|
if (is_all_on_one_side(its.indices[i], is_on_sides))
|
||||||
|
skip_indicies[i] = true;
|
||||||
|
}
|
||||||
|
}); // END parallel for
|
||||||
}
|
}
|
||||||
|
|
||||||
indexed_triangle_set Slic3r::its_mask(const indexed_triangle_set &its,
|
indexed_triangle_set Slic3r::its_mask(const indexed_triangle_set &its,
|
||||||
|
Loading…
Reference in New Issue
Block a user