Listing the "Blender Foundation" as copyright holder implied the Blender Foundation holds copyright to files which may include work from many developers. While keeping copyright on headers makes sense for isolated libraries, Blender's own code may be refactored or moved between files in a way that makes the per file copyright holders less meaningful. Copyright references to the "Blender Foundation" have been replaced with "Blender Authors", with the exception of `./extern/` since these this contains libraries which are more isolated, any changed to license headers there can be handled on a case-by-case basis. Some directories in `./intern/` have also been excluded: - `./intern/cycles/` it's own `AUTHORS` file is planned. - `./intern/opensubdiv/`. An "AUTHORS" file has been added, using the chromium projects authors file as a template. Design task: #110784 Ref !110783.
61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#include "BLI_length_parameterize.hh"
|
|
#include "BLI_task.hh"
|
|
|
|
namespace blender::length_parameterize {
|
|
|
|
void sample_uniform(const Span<float> lengths,
|
|
const bool include_last_point,
|
|
MutableSpan<int> r_segment_indices,
|
|
MutableSpan<float> r_factors)
|
|
{
|
|
const int count = r_segment_indices.size();
|
|
BLI_assert(count > 0);
|
|
BLI_assert(lengths.size() >= 1);
|
|
BLI_assert(std::is_sorted(lengths.begin(), lengths.end()));
|
|
|
|
if (count == 1) {
|
|
r_segment_indices[0] = 0;
|
|
r_factors[0] = 0.0f;
|
|
return;
|
|
}
|
|
const float total_length = lengths.last();
|
|
const float step_length = total_length / (count - include_last_point);
|
|
threading::parallel_for(IndexRange(count), 512, [&](const IndexRange range) {
|
|
SampleSegmentHint hint;
|
|
for (const int i : range) {
|
|
/* Use minimum to avoid issues with floating point accuracy. */
|
|
const float sample_length = std::min(total_length, i * step_length);
|
|
sample_at_length(lengths, sample_length, r_segment_indices[i], r_factors[i], &hint);
|
|
}
|
|
});
|
|
}
|
|
|
|
void sample_at_lengths(const Span<float> accumulated_segment_lengths,
|
|
const Span<float> sample_lengths,
|
|
MutableSpan<int> r_segment_indices,
|
|
MutableSpan<float> r_factors)
|
|
{
|
|
BLI_assert(
|
|
std::is_sorted(accumulated_segment_lengths.begin(), accumulated_segment_lengths.end()));
|
|
BLI_assert(std::is_sorted(sample_lengths.begin(), sample_lengths.end()));
|
|
|
|
const int count = sample_lengths.size();
|
|
BLI_assert(count == r_segment_indices.size());
|
|
BLI_assert(count == r_factors.size());
|
|
|
|
threading::parallel_for(IndexRange(count), 512, [&](const IndexRange range) {
|
|
SampleSegmentHint hint;
|
|
for (const int i : range) {
|
|
const float sample_length = sample_lengths[i];
|
|
sample_at_length(
|
|
accumulated_segment_lengths, sample_length, r_segment_indices[i], r_factors[i], &hint);
|
|
}
|
|
});
|
|
}
|
|
|
|
} // namespace blender::length_parameterize
|