[Bf-blender-cvs] [9ee9dd257fa] master: Curves: Add method to find indices for curve type in a selection

Hans Goudey noreply at git.blender.org
Wed May 4 13:55:27 CEST 2022


Commit: 9ee9dd257faeeab85ba98e2d54ac2d2d9f9f389b
Author: Hans Goudey
Date:   Wed May 4 13:55:08 2022 +0200
Branches: master
https://developer.blender.org/rB9ee9dd257faeeab85ba98e2d54ac2d2d9f9f389b

Curves: Add method to find indices for curve type in a selection

For example, this can be used to find the indices of all Bezier curves
inside an existing selection. The important part is that it is optimized
for the case when all curves have the same type.

===================================================================

M	source/blender/blenkernel/BKE_curves.hh
M	source/blender/blenkernel/intern/curves_geometry.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_curves.hh b/source/blender/blenkernel/BKE_curves.hh
index c125c347071..bf2d50f63be 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -181,11 +181,18 @@ class CurvesGeometry : public ::CurvesGeometry {
   /** Update the cached count of curves of each type, necessary after #curve_types_for_write. */
   void update_curve_types();
 
-  bool has_curve_with_type(const CurveType type) const;
+  bool has_curve_with_type(CurveType type) const;
   /** Return true if all of the curves have the provided type. */
   bool is_single_type(CurveType type) const;
   /** Return the number of curves with each type. */
   const std::array<int, CURVE_TYPES_NUM> &curve_type_counts() const;
+  /**
+   * All of the curve indices for curves with a specific type.
+   */
+  IndexMask indices_for_curve_type(CurveType type, Vector<int64_t> &r_indices) const;
+  IndexMask indices_for_curve_type(CurveType type,
+                                   IndexMask selection,
+                                   Vector<int64_t> &r_indices) const;
 
   Span<float3> positions() const;
   MutableSpan<float3> positions_for_write();
@@ -283,11 +290,6 @@ class CurvesGeometry : public ::CurvesGeometry {
   bool bounds_min_max(float3 &min, float3 &max) const;
 
  private:
-  /**
-   * All of the curve indices for curves with a specific type.
-   */
-  IndexMask indices_for_curve_type(CurveType type, Vector<int64_t> &r_indices) const;
-
   /* --------------------------------------------------------------------
    * Evaluation.
    */
diff --git a/source/blender/blenkernel/intern/curves_geometry.cc b/source/blender/blenkernel/intern/curves_geometry.cc
index 36ea7a3888f..e7337d5c012 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -531,19 +531,19 @@ Span<int> CurvesGeometry::evaluated_offsets() const
 IndexMask CurvesGeometry::indices_for_curve_type(const CurveType type,
                                                  Vector<int64_t> &r_indices) const
 {
+  return this->indices_for_curve_type(type, this->curves_range(), r_indices);
+}
 
-  VArray<int8_t> types = this->curve_types();
-  if (types.is_single()) {
-    if (types.get_internal_single() == type) {
-      return IndexMask(types.size());
-    }
-    return {};
+IndexMask CurvesGeometry::indices_for_curve_type(const CurveType type,
+                                                 const IndexMask selection,
+                                                 Vector<int64_t> &r_indices) const
+{
+  if (this->curve_type_counts()[type] == this->curves_num()) {
+    return selection;
   }
-  Span<int8_t> types_span = types.get_internal_span();
+  Span<int8_t> types_span = this->curve_types().get_internal_span();
   return index_mask_ops::find_indices_based_on_predicate(
-      IndexMask(types.size()), 1024, r_indices, [&](const int index) {
-        return types_span[index] == type;
-      });
+      selection, 1024, r_indices, [&](const int index) { return types_span[index] == type; });
 }
 
 void CurvesGeometry::ensure_nurbs_basis_cache() const
@@ -1196,6 +1196,8 @@ static CurvesGeometry copy_with_removed_curves(const CurvesGeometry &curves,
         }
       });
 
+  new_curves.update_curve_types();
+
   return new_curves;
 }



More information about the Bf-blender-cvs mailing list