diff options
author | Hans Goudey <h.goudey@me.com> | 2022-07-22 17:59:28 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-07-22 17:59:28 +0300 |
commit | 6bcda04d1f1cc396dcc188678997105b09231bde (patch) | |
tree | 3f83a3c86a476408f054755d651e0e6f694500cb /source/blender/blenlib/BLI_length_parameterize.hh | |
parent | 1f94b56d774440d08eb92f2a7a47b9a6a7aa7b84 (diff) |
Geometry Nodes: Port sample curves node to new data-block
Use the newer more generic sampling and interpolation functions
developed recently (ab444a80a280) instead of the `CurveEval` type.
Functions are split up a bit more internally, to allow a separate mode
for supplying the curve index directly in the future (T92474).
In one basic test, the performance seems mostly unchanged from 3.1.
Differential Revision: https://developer.blender.org/D14621
Diffstat (limited to 'source/blender/blenlib/BLI_length_parameterize.hh')
-rw-r--r-- | source/blender/blenlib/BLI_length_parameterize.hh | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/source/blender/blenlib/BLI_length_parameterize.hh b/source/blender/blenlib/BLI_length_parameterize.hh index 1b494c021a3..d81bcbe1e7a 100644 --- a/source/blender/blenlib/BLI_length_parameterize.hh +++ b/source/blender/blenlib/BLI_length_parameterize.hh @@ -6,6 +6,7 @@ * \ingroup bli */ +#include "BLI_index_mask.hh" #include "BLI_math_base.hh" #include "BLI_math_color.hh" #include "BLI_math_vector.hh" @@ -41,26 +42,38 @@ void accumulate_lengths(const Span<T> values, const bool cyclic, MutableSpan<flo } template<typename T> -inline void interpolate(const Span<T> src, - const Span<int> indices, - const Span<float> factors, - MutableSpan<T> dst) +inline void interpolate_to_masked(const Span<T> src, + const Span<int> indices, + const Span<float> factors, + const IndexMask dst_mask, + MutableSpan<T> dst) { BLI_assert(indices.size() == factors.size()); - BLI_assert(indices.size() == dst.size()); + BLI_assert(indices.size() == dst_mask.size()); const int last_src_index = src.size() - 1; - for (const int i : dst.index_range()) { - const int prev_index = indices[i]; - const float factor = factors[i]; - const bool is_cyclic_case = prev_index == last_src_index; - if (is_cyclic_case) { - dst[i] = math::interpolate(src.last(), src.first(), factor); + dst_mask.to_best_mask_type([&](auto dst_mask) { + for (const int i : IndexRange(dst_mask.size())) { + const int prev_index = indices[i]; + const float factor = factors[i]; + const bool is_cyclic_case = prev_index == last_src_index; + if (is_cyclic_case) { + dst[dst_mask[i]] = math::interpolate(src.last(), src.first(), factor); + } + else { + dst[dst_mask[i]] = math::interpolate(src[prev_index], src[prev_index + 1], factor); + } } - else { - dst[i] = math::interpolate(src[prev_index], src[prev_index + 1], factor); - } - } + }); +} + +template<typename T> +inline void interpolate(const Span<T> src, + const Span<int> indices, + const Span<float> factors, + MutableSpan<T> dst) +{ + interpolate_to_masked(src, indices, factors, dst.index_range(), dst); } /** |