mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-06 21:44:08 -06:00
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue