diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-28 22:31:32 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-28 22:31:32 +0300 |
commit | 25533dbe219f8bbcb3f04ffe2ff1e57599addf3f (patch) | |
tree | fd4d4260fbb807d3d0484d2c4259b43378390875 /source/blender/blenkernel/intern/mesh_mapping.cc | |
parent | 878dea4e0fcca68ba3ad93edeae22114e1252f9e (diff) |
Mesh: Add C++ implementaiton of topology mappings
Because they are friendlier to use in C++ code than the existing mesh
mapping API, these mappings from one domain to another were often
reimplemented in separate files. This commit moves some basic
implementations to a `mesh_topology` namespace in the existing
mesh mapping header file. These is plenty of room for performance
improvement here, particularly by not using an array of Vectors, but
that can come later.
Split from D16029
Diffstat (limited to 'source/blender/blenkernel/intern/mesh_mapping.cc')
-rw-r--r-- | source/blender/blenkernel/intern/mesh_mapping.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/mesh_mapping.cc b/source/blender/blenkernel/intern/mesh_mapping.cc index 2db0adce033..c1523f0a525 100644 --- a/source/blender/blenkernel/intern/mesh_mapping.cc +++ b/source/blender/blenkernel/intern/mesh_mapping.cc @@ -16,6 +16,7 @@ #include "BLI_bitmap.h" #include "BLI_buffer.h" #include "BLI_math.h" +#include "BLI_task.hh" #include "BLI_utildefines.h" #include "BKE_customdata.h" @@ -552,6 +553,41 @@ void BKE_mesh_origindex_map_create_looptri(MeshElemMap **r_map, *r_mem = indices; } +namespace blender::mesh_topology { + +Array<int> build_corner_to_poly_map(const Span<MPoly> polys, const int loops_num) +{ + Array<int> map(loops_num); + threading::parallel_for(polys.index_range(), 1024, [&](IndexRange range) { + for (const int64_t poly_i : range) { + const MPoly &poly = polys[poly_i]; + map.as_mutable_span().slice(poly.loopstart, poly.totloop).fill(int(poly_i)); + } + }); + return map; +} + +Array<Vector<int>> build_vert_to_edge_map(const Span<MEdge> edges, const int verts_num) +{ + Array<Vector<int>> map(verts_num); + for (const int64_t i : edges.index_range()) { + map[edges[i].v1].append(int(i)); + map[edges[i].v2].append(int(i)); + } + return map; +} + +Array<Vector<int>> build_vert_to_corner_map(const Span<MLoop> loops, const int verts_num) +{ + Array<Vector<int>> map(verts_num); + for (const int64_t i : loops.index_range()) { + map[loops[i].v].append(int(i)); + } + return map; +} + +} // namespace blender::mesh_topology + /** \} */ /* -------------------------------------------------------------------- */ |