1
1

Cleanup: Deduplicate OffsetIndices utility for meshes and curves

The "reverse map" of corners to faces and points to curves is the same
for meshes and curves now. Move it to the offset indices header to
reflect this.

This unification can go further in the future, but I'd rather wait
until the design is clearer for now.

Pull Request: blender/blender#106570
This commit is contained in:
2023-04-04 22:12:17 +02:00
committed by Hans Goudey
parent 8d0920ec6d
commit 4b2ea18ec9
4 changed files with 18 additions and 11 deletions

View File

@@ -549,13 +549,8 @@ IndexMask CurvesGeometry::indices_for_curve_type(const CurveType type,
Array<int> CurvesGeometry::point_to_curve_map() const
{
const OffsetIndices points_by_curve = this->points_by_curve();
Array<int> map(this->points_num());
threading::parallel_for(this->curves_range(), 1024, [&](const IndexRange range) {
for (const int i_curve : range) {
map.as_mutable_span().slice(points_by_curve[i_curve]).fill(i_curve);
}
});
offset_indices::build_reverse_map(this->points_by_curve(), map);
return map;
}

View File

@@ -526,11 +526,7 @@ namespace blender::bke::mesh_topology {
Array<int> build_loop_to_poly_map(const OffsetIndices<int> polys)
{
Array<int> map(polys.total_size());
threading::parallel_for(polys.index_range(), 1024, [&](IndexRange range) {
for (const int64_t poly_i : range) {
map.as_mutable_span().slice(polys[poly_i]).fill(int(poly_i));
}
});
offset_indices::build_reverse_map(polys, map);
return map;
}

View File

@@ -97,6 +97,12 @@ template<typename T> class OffsetIndices {
*/
void accumulate_counts_to_offsets(MutableSpan<int> counts_to_offsets, int start_offset = 0);
/**
* Create a map from indexed elements to the source indices, in other words from the larger array
* to the smaller array.
*/
void build_reverse_map(OffsetIndices<int> offsets, MutableSpan<int> r_map);
} // namespace blender::offset_indices
namespace blender {

View File

@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_offset_indices.hh"
#include "BLI_task.hh"
namespace blender::offset_indices {
@@ -16,4 +17,13 @@ void accumulate_counts_to_offsets(MutableSpan<int> counts_to_offsets, const int
counts_to_offsets.last() = offset;
}
void build_reverse_map(OffsetIndices<int> offsets, MutableSpan<int> r_map)
{
threading::parallel_for(offsets.index_range(), 1024, [&](const IndexRange range) {
for (const int64_t i : range) {
r_map.slice(offsets[i]).fill(i);
}
});
}
} // namespace blender::offset_indices