Add parallel version of neighbors index creation, make it default
This commit is contained in:
parent
b4d540ec4c
commit
97529ff6b7
6 changed files with 112 additions and 116 deletions
|
@ -4,6 +4,8 @@
|
|||
#include <map>
|
||||
|
||||
#include "ItsNeighborIndex.hpp"
|
||||
#include "libslic3r/Execution/ExecutionTBB.hpp"
|
||||
#include "libslic3r/Execution/ExecutionSeq.hpp"
|
||||
|
||||
#include "tbb/parallel_sort.h"
|
||||
|
||||
|
@ -343,20 +345,20 @@ std::vector<std::vector<size_t>> create_vertex_faces_index(const indexed_triangl
|
|||
return index;
|
||||
}
|
||||
|
||||
static int get_vertex_index(size_t vertex_index, const stl_triangle_vertex_indices &triangle_indices) {
|
||||
if (vertex_index == triangle_indices[0]) return 0;
|
||||
if (vertex_index == triangle_indices[1]) return 1;
|
||||
if (vertex_index == triangle_indices[2]) return 2;
|
||||
return -1;
|
||||
}
|
||||
//static int get_vertex_index(size_t vertex_index, const stl_triangle_vertex_indices &triangle_indices) {
|
||||
// if (vertex_index == triangle_indices[0]) return 0;
|
||||
// if (vertex_index == triangle_indices[1]) return 1;
|
||||
// if (vertex_index == triangle_indices[2]) return 2;
|
||||
// return -1;
|
||||
//}
|
||||
|
||||
static Vec2crd get_edge_indices(int edge_index, const stl_triangle_vertex_indices &triangle_indices)
|
||||
{
|
||||
int next_edge_index = (edge_index == 2) ? 0 : edge_index + 1;
|
||||
coord_t vi0 = triangle_indices[edge_index];
|
||||
coord_t vi1 = triangle_indices[next_edge_index];
|
||||
return Vec2crd(vi0, vi1);
|
||||
}
|
||||
//static Vec2crd get_edge_indices(int edge_index, const stl_triangle_vertex_indices &triangle_indices)
|
||||
//{
|
||||
// int next_edge_index = (edge_index == 2) ? 0 : edge_index + 1;
|
||||
// coord_t vi0 = triangle_indices[edge_index];
|
||||
// coord_t vi1 = triangle_indices[next_edge_index];
|
||||
// return Vec2crd(vi0, vi1);
|
||||
//}
|
||||
|
||||
static std::vector<std::vector<size_t>> create_vertex_faces_index(
|
||||
const std::vector<stl_triangle_vertex_indices>& indices, size_t count_vertices)
|
||||
|
@ -600,42 +602,12 @@ FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its)
|
|||
|
||||
std::vector<Vec3crd> its_create_neighbors_index_9(const indexed_triangle_set &its)
|
||||
{
|
||||
const std::vector<stl_triangle_vertex_indices> &indices = its.indices;
|
||||
size_t vertices_size = its.vertices.size();
|
||||
return create_neighbors_index(ex_seq, its);
|
||||
}
|
||||
|
||||
if (indices.empty() || vertices_size == 0) return {};
|
||||
// std::vector<std::vector<size_t>> vertex_triangles = create_vertex_faces_index(indices, vertices_size);
|
||||
auto vertex_triangles = VertexFaceIndex{its};
|
||||
coord_t no_value = -1;
|
||||
std::vector<Vec3crd> neighbors(indices.size(), Vec3crd(no_value, no_value, no_value));
|
||||
for (const stl_triangle_vertex_indices& triangle_indices : indices) {
|
||||
coord_t index = &triangle_indices - &indices.front();
|
||||
Vec3crd& neighbor = neighbors[index];
|
||||
for (int edge_index = 0; edge_index < 3; ++edge_index) {
|
||||
// check if done
|
||||
coord_t& neighbor_edge = neighbor[edge_index];
|
||||
if (neighbor_edge != no_value) continue;
|
||||
Vec2crd edge_indices = get_edge_indices(edge_index, triangle_indices);
|
||||
// IMPROVE: use same vector for 2 sides of triangle
|
||||
const auto &faces_range = vertex_triangles[edge_indices[0]];
|
||||
for (const size_t &face : faces_range) {
|
||||
if (face <= index) continue;
|
||||
const stl_triangle_vertex_indices &face_indices = indices[face];
|
||||
int vertex_index = get_vertex_index(edge_indices[1], face_indices);
|
||||
// NOT Contain second vertex?
|
||||
if (vertex_index < 0) continue;
|
||||
// Has NOT oposit direction?
|
||||
if (edge_indices[0] != face_indices[(vertex_index + 1) % 3]) continue;
|
||||
neighbor_edge = face;
|
||||
neighbors[face][vertex_index] = index;
|
||||
break;
|
||||
}
|
||||
// must be paired
|
||||
assert(neighbor_edge != no_value);
|
||||
}
|
||||
}
|
||||
|
||||
return neighbors;
|
||||
std::vector<Vec3i> its_create_neighbors_index_10(const indexed_triangle_set &its)
|
||||
{
|
||||
return create_neighbors_index(ex_tbb, its);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "libslic3r/MeshSplitImpl.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
using FaceNeighborIndex = std::vector<std::array<size_t, 3>>;
|
||||
FaceNeighborIndex its_create_neighbors_index_1(const indexed_triangle_set &its);
|
||||
std::vector<Vec3i> its_create_neighbors_index_2(const indexed_triangle_set &its);
|
||||
std::vector<Vec3i> its_create_neighbors_index_3(const indexed_triangle_set &its);
|
||||
|
@ -12,6 +13,7 @@ std::vector<std::array<size_t, 3>> its_create_neighbors_index_6(const indexed_tr
|
|||
std::vector<std::array<size_t, 3>> its_create_neighbors_index_7(const indexed_triangle_set &its);
|
||||
FaceNeighborIndex its_create_neighbors_index_8(const indexed_triangle_set &its);
|
||||
std::vector<Vec3crd> its_create_neighbors_index_9(const indexed_triangle_set &its);
|
||||
std::vector<Vec3i> its_create_neighbors_index_10(const indexed_triangle_set &its);
|
||||
|
||||
std::vector<std::vector<size_t>> create_vertex_faces_index(const indexed_triangle_set &its);
|
||||
}
|
||||
|
|
|
@ -138,18 +138,18 @@ static const std::pair<const std::string, indexed_triangle_set> ToMeasure[] = {
|
|||
{"two_spheres_64x", two_spheres(8. * 60.)},
|
||||
{"two_spheres_128x", two_spheres(sq2 * 8. * 60.)},
|
||||
{"two_spheres_256x", two_spheres(16. * 60.)},
|
||||
{"two_spheres_512x", two_spheres(sq2 * 16. * 60.)}
|
||||
{"two_spheres_512x", two_spheres(sq2 * 16. * 60.)},
|
||||
|
||||
// {"2_spheres", make_spheres(2, 60.)},
|
||||
// {"4_spheres", make_spheres(4, 60.)},
|
||||
// {"8_spheres", make_spheres(8, 60.)},
|
||||
// {"16_spheres", make_spheres(16, 60.)},
|
||||
// {"32_spheres", make_spheres(32, 60.)},
|
||||
// {"64_spheres", make_spheres(64, 60.)},
|
||||
// {"128_spheres", make_spheres(128, 60.)},
|
||||
// {"256_spheres", make_spheres(256, 60.)},
|
||||
// {"512_spheres", make_spheres(512, 60.)},
|
||||
// {"1024_spheres", make_spheres(1024, 60.)}
|
||||
{"2_spheres", make_spheres(2, 60.)},
|
||||
{"4_spheres", make_spheres(4, 60.)},
|
||||
{"8_spheres", make_spheres(8, 60.)},
|
||||
{"16_spheres", make_spheres(16, 60.)},
|
||||
{"32_spheres", make_spheres(32, 60.)},
|
||||
{"64_spheres", make_spheres(64, 60.)},
|
||||
{"128_spheres", make_spheres(128, 60.)},
|
||||
{"256_spheres", make_spheres(256, 60.)},
|
||||
{"512_spheres", make_spheres(512, 60.)},
|
||||
{"1024_spheres", make_spheres(1024, 60.)}
|
||||
};
|
||||
|
||||
static const auto IndexFunctions = std::make_tuple(
|
||||
|
@ -158,6 +158,7 @@ static const auto IndexFunctions = std::make_tuple(
|
|||
std::make_pair("vojta tbb::parallel_sort based", [](const auto &its) { return measure_index(its, its_create_neighbors_index_3); }),
|
||||
std::make_pair("filip's vertex->face based", [](const auto &its) { return measure_index(its, its_create_neighbors_index_5); }),
|
||||
std::make_pair("vojta's vertex->face", [](const auto &its) { return measure_index(its, its_create_neighbors_index_9); }),
|
||||
std::make_pair("vojta's vertex->face parallel", [](const auto &its) { return measure_index(its, its_create_neighbors_index_10); }),
|
||||
std::make_pair("tamas's std::sort based", [](const auto &its) { return measure_index(its, its_create_neighbors_index_6); }),
|
||||
std::make_pair("tamas's tbb::parallel_sort based", [](const auto &its) { return measure_index(its, its_create_neighbors_index_7); }),
|
||||
std::make_pair("tamas's map based", [](const auto &its) { return measure_index(its, its_create_neighbors_index_8); }),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue