Cleanup: Move offset size copying utility to generic header

This shows more clearly that there's nothing specific to curves here.
This commit is contained in:
Hans Goudey
2023-05-25 13:32:01 -04:00
parent 9c15058d0b
commit 0b0b6a687a
5 changed files with 25 additions and 15 deletions

View File

@@ -538,13 +538,6 @@ void fill_points(const OffsetIndices<int> points_by_curve,
*/
bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves);
/**
* Copy the number of points in every curve in the mask to the corresponding index in #sizes.
*/
void copy_curve_sizes(OffsetIndices<int> points_by_curve,
const IndexMask &mask,
MutableSpan<int> sizes);
/**
* Copy the number of points in every curve in #curve_ranges to the corresponding index in
* #sizes.

View File

@@ -8,13 +8,6 @@
namespace blender::bke::curves {
void copy_curve_sizes(const OffsetIndices<int> points_by_curve,
const IndexMask &mask,
MutableSpan<int> sizes)
{
mask.foreach_index(GrainSize(4096), [&](const int i) { sizes[i] = points_by_curve[i].size(); });
}
void copy_curve_sizes(const OffsetIndices<int> points_by_curve,
const Span<IndexRange> curve_ranges,
MutableSpan<int> sizes)

View File

@@ -4,6 +4,7 @@
#include <algorithm>
#include "BLI_index_mask.hh"
#include "BLI_index_range.hh"
#include "BLI_span.hh"
@@ -137,6 +138,12 @@ template<typename T> struct GroupedSpan {
OffsetIndices<int> accumulate_counts_to_offsets(MutableSpan<int> counts_to_offsets,
int start_offset = 0);
/** Copy the number of indices in every group in the mask to the corresponding index. */
void copy_group_sizes(OffsetIndices<int> offsets, const IndexMask &mask, MutableSpan<int> sizes);
/** Gather the number of indices in each indexed group to sizes. */
void gather_group_sizes(OffsetIndices<int> offsets, const IndexMask &mask, MutableSpan<int> sizes);
/**
* Create a map from indexed elements to the source indices, in other words from the larger array
* to the smaller array.

View File

@@ -19,6 +19,23 @@ OffsetIndices<int> accumulate_counts_to_offsets(MutableSpan<int> counts_to_offse
return OffsetIndices<int>(counts_to_offsets);
}
void copy_group_sizes(const OffsetIndices<int> offsets,
const IndexMask &mask,
MutableSpan<int> sizes)
{
mask.foreach_index_optimized<int64_t>(GrainSize(4096),
[&](const int64_t i) { sizes[i] = offsets[i].size(); });
}
void gather_group_sizes(const OffsetIndices<int> offsets,
const IndexMask &mask,
MutableSpan<int> sizes)
{
mask.foreach_index_optimized<int64_t>(GrainSize(4096), [&](const int64_t i, const int64_t pos) {
sizes[pos] = offsets[i].size();
});
}
void build_reverse_map(OffsetIndices<int> offsets, MutableSpan<int> r_map)
{
threading::parallel_for(offsets.index_range(), 1024, [&](const IndexRange range) {

View File

@@ -422,7 +422,7 @@ CurvesGeometry resample_to_evaluated(const CurvesGeometry &src_curves,
CurvesGeometry dst_curves = bke::curves::copy_only_curve_domain(src_curves);
dst_curves.fill_curve_types(selection, CURVE_TYPE_POLY);
MutableSpan<int> dst_offsets = dst_curves.offsets_for_write();
bke::curves::copy_curve_sizes(src_evaluated_points_by_curve, selection, dst_offsets);
offset_indices::copy_group_sizes(src_evaluated_points_by_curve, selection, dst_offsets);
bke::curves::copy_curve_sizes(src_points_by_curve, unselected_ranges, dst_offsets);
offset_indices::accumulate_counts_to_offsets(dst_offsets);
const OffsetIndices dst_points_by_curve = dst_curves.points_by_curve();