diff options
author | Hans Goudey <h.goudey@me.com> | 2022-03-25 17:00:30 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-03-25 17:00:30 +0300 |
commit | c0016d85b2a62858229d31bd97399fbe2608f99d (patch) | |
tree | 9ccabf7543a5c7043d85a55f37c42c403e6b6013 /source/blender/blenkernel/intern/curves_geometry.cc | |
parent | 59de9ceda05c84670d27fcb526d513e30a8e29b4 (diff) |
Curves: Add a utility to count curves of each type
This commit adds a utility that returns an array with the number
of curves of every type. One use case for this is detecting whether
to remove handle or NURBS attributes when changing curve types.
It's best to avoid using this when it's not necessary, but sometimes
it can't really be avoided, and having a utility at least makes using
an optimized version simple.
In the future, this information can be cached in the curves runtime.
Differential Revision: https://developer.blender.org/D14448
Diffstat (limited to 'source/blender/blenkernel/intern/curves_geometry.cc')
-rw-r--r-- | source/blender/blenkernel/intern/curves_geometry.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc index 5bb6a97fa49..207d0d173ac 100644 --- a/source/blender/blenkernel/intern/curves_geometry.cc +++ b/source/blender/blenkernel/intern/curves_geometry.cc @@ -277,6 +277,40 @@ bool CurvesGeometry::has_curve_with_type(const CurveType type) const return false; } +std::array<int, CURVE_TYPES_NUM> CurvesGeometry::count_curve_types() const +{ + using CountsType = std::array<int, CURVE_TYPES_NUM>; + + CountsType identity; + identity.fill(0); + + const VArray<int8_t> types = this->curve_types(); + if (types.is_single()) { + identity[types.get_internal_single()] = this->curves_num(); + return identity; + } + + Span<int8_t> types_span = types.get_internal_span(); + return threading::parallel_reduce( + this->curves_range(), + 2048, + identity, + [&](const IndexRange curves_range, const CountsType &init) { + CountsType result = init; + for (const int curve_index : curves_range) { + result[types_span[curve_index]]++; + } + return result; + }, + [](const CountsType &a, const CountsType &b) { + CountsType result = a; + for (const int i : IndexRange(CURVE_TYPES_NUM)) { + result[i] += b[i]; + } + return result; + }); +} + MutableSpan<float3> CurvesGeometry::positions() { this->position = (float(*)[3])CustomData_duplicate_referenced_layer_named( |