[Bf-blender-cvs] [7fc395354cd] master: Cleanup: Use offset indices arguments for curves utilities

Hans Goudey noreply at git.blender.org
Mon Jan 23 21:58:43 CET 2023


Commit: 7fc395354cd1049157096ac97bee3a2745045624
Author: Hans Goudey
Date:   Mon Jan 23 14:41:40 2023 -0600
Branches: master
https://developer.blender.org/rB7fc395354cd1049157096ac97bee3a2745045624

Cleanup: Use offset indices arguments for curves utilities

Make the functions more flexible and more generic by changing the curves
arguments to the curve offsets. This way, theoretically they could become
normal utility functions in the future. Also do a consistency pass over
the algorithms that generate new curves geometry for naming and
code ordering, and use of utility functions. The functions are really
quite similar, and it's much easier to tell this way.

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

M	source/blender/blenkernel/BKE_curves_utils.hh
M	source/blender/blenkernel/intern/curves_utils.cc
M	source/blender/geometry/intern/add_curves_on_mesh.cc
M	source/blender/geometry/intern/fillet_curves.cc
M	source/blender/geometry/intern/resample_curves.cc
M	source/blender/geometry/intern/set_curve_type.cc
M	source/blender/geometry/intern/subdivide_curves.cc
M	source/blender/geometry/intern/trim_curves.cc

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

diff --git a/source/blender/blenkernel/BKE_curves_utils.hh b/source/blender/blenkernel/BKE_curves_utils.hh
index 6caf716c063..9549a643c05 100644
--- a/source/blender/blenkernel/BKE_curves_utils.hh
+++ b/source/blender/blenkernel/BKE_curves_utils.hh
@@ -471,54 +471,58 @@ class IndexRangeCyclic {
  * ranges, assuming that all curves have the same number of control points in #src_curves
  * and #dst_curves.
  */
-void copy_point_data(const CurvesGeometry &src_curves,
-                     const CurvesGeometry &dst_curves,
+void copy_point_data(OffsetIndices<int> src_points_by_curve,
+                     OffsetIndices<int> dst_points_by_curve,
                      Span<IndexRange> curve_ranges,
                      GSpan src,
                      GMutableSpan dst);
 
-void copy_point_data(const CurvesGeometry &src_curves,
-                     const CurvesGeometry &dst_curves,
+void copy_point_data(OffsetIndices<int> src_points_by_curve,
+                     OffsetIndices<int> dst_points_by_curve,
                      IndexMask src_curve_selection,
                      GSpan src,
                      GMutableSpan dst);
 
 template<typename T>
-void copy_point_data(const CurvesGeometry &src_curves,
-                     const CurvesGeometry &dst_curves,
+void copy_point_data(OffsetIndices<int> src_points_by_curve,
+                     OffsetIndices<int> dst_points_by_curve,
                      IndexMask src_curve_selection,
                      Span<T> src,
                      MutableSpan<T> dst)
 {
-  copy_point_data(src_curves, dst_curves, src_curve_selection, GSpan(src), GMutableSpan(dst));
+  copy_point_data(src_points_by_curve,
+                  dst_points_by_curve,
+                  src_curve_selection,
+                  GSpan(src),
+                  GMutableSpan(dst));
 }
 
-void fill_points(const CurvesGeometry &curves,
+void fill_points(OffsetIndices<int> points_by_curve,
                  IndexMask curve_selection,
                  GPointer value,
                  GMutableSpan dst);
 
 template<typename T>
-void fill_points(const CurvesGeometry &curves,
+void fill_points(const OffsetIndices<int> points_by_curve,
                  IndexMask curve_selection,
                  const T &value,
                  MutableSpan<T> dst)
 {
-  fill_points(curves, curve_selection, &value, dst);
+  fill_points(points_by_curve, curve_selection, &value, dst);
 }
 
-void fill_points(const CurvesGeometry &curves,
+void fill_points(const OffsetIndices<int> points_by_curve,
                  Span<IndexRange> curve_ranges,
                  GPointer value,
                  GMutableSpan dst);
 
 template<typename T>
-void fill_points(const CurvesGeometry &curves,
+void fill_points(const OffsetIndices<int> points_by_curve,
                  Span<IndexRange> curve_ranges,
                  const T &value,
                  MutableSpan<T> dst)
 {
-  fill_points(curves, curve_ranges, &value, dst);
+  fill_points(points_by_curve, curve_ranges, &value, dst);
 }
 
 /**
@@ -533,9 +537,15 @@ void fill_points(const CurvesGeometry &curves,
 bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves);
 
 /**
- * Copy the number of points in every curve in #curve_ranges to the corresponding index in #sizes.
+ * Copy the number of points in every curve in the mask to the corresponding index in #sizes.
  */
-void copy_curve_sizes(const bke::CurvesGeometry &curves,
+void copy_curve_sizes(OffsetIndices<int> points_by_curve, IndexMask mask, MutableSpan<int> sizes);
+
+/**
+ * Copy the number of points in every curve in #curve_ranges to the corresponding index in
+ * #sizes.
+ */
+void copy_curve_sizes(OffsetIndices<int> points_by_curve,
                       Span<IndexRange> curve_ranges,
                       MutableSpan<int> sizes);
 
diff --git a/source/blender/blenkernel/intern/curves_utils.cc b/source/blender/blenkernel/intern/curves_utils.cc
index ef2518cbc3f..55f41e412a6 100644
--- a/source/blender/blenkernel/intern/curves_utils.cc
+++ b/source/blender/blenkernel/intern/curves_utils.cc
@@ -10,11 +10,21 @@
 
 namespace blender::bke::curves {
 
-void copy_curve_sizes(const bke::CurvesGeometry &curves,
+void copy_curve_sizes(const OffsetIndices<int> points_by_curve,
+                      const IndexMask mask,
+                      MutableSpan<int> sizes)
+{
+  threading::parallel_for(mask.index_range(), 4096, [&](IndexRange ranges_range) {
+    for (const int64_t i : mask.slice(ranges_range)) {
+      sizes[i] = points_by_curve.size(i);
+    }
+  });
+}
+
+void copy_curve_sizes(const OffsetIndices<int> points_by_curve,
                       const Span<IndexRange> curve_ranges,
                       MutableSpan<int> sizes)
 {
-  const OffsetIndices points_by_curve = curves.points_by_curve();
   threading::parallel_for(curve_ranges.index_range(), 512, [&](IndexRange ranges_range) {
     for (const IndexRange curves_range : curve_ranges.slice(ranges_range)) {
       threading::parallel_for(curves_range, 4096, [&](IndexRange range) {
@@ -26,14 +36,12 @@ void copy_curve_sizes(const bke::CurvesGeometry &curves,
   });
 }
 
-void copy_point_data(const CurvesGeometry &src_curves,
-                     const CurvesGeometry &dst_curves,
+void copy_point_data(const OffsetIndices<int> src_points_by_curve,
+                     const OffsetIndices<int> dst_points_by_curve,
                      const Span<IndexRange> curve_ranges,
                      const GSpan src,
                      GMutableSpan dst)
 {
-  const OffsetIndices src_points_by_curve = src_curves.points_by_curve();
-  const OffsetIndices dst_points_by_curve = dst_curves.points_by_curve();
   threading::parallel_for(curve_ranges.index_range(), 512, [&](IndexRange range) {
     for (const IndexRange range : curve_ranges.slice(range)) {
       const IndexRange src_points = src_points_by_curve[range];
@@ -44,14 +52,12 @@ void copy_point_data(const CurvesGeometry &src_curves,
   });
 }
 
-void copy_point_data(const CurvesGeometry &src_curves,
-                     const CurvesGeometry &dst_curves,
+void copy_point_data(const OffsetIndices<int> src_points_by_curve,
+                     const OffsetIndices<int> dst_points_by_curve,
                      const IndexMask src_curve_selection,
                      const GSpan src,
                      GMutableSpan dst)
 {
-  const OffsetIndices src_points_by_curve = src_curves.points_by_curve();
-  const OffsetIndices dst_points_by_curve = dst_curves.points_by_curve();
   threading::parallel_for(src_curve_selection.index_range(), 512, [&](IndexRange range) {
     for (const int i : src_curve_selection.slice(range)) {
       const IndexRange src_points = src_points_by_curve[i];
@@ -62,14 +68,13 @@ void copy_point_data(const CurvesGeometry &src_curves,
   });
 }
 
-void fill_points(const CurvesGeometry &curves,
+void fill_points(const OffsetIndices<int> points_by_curve,
                  const IndexMask curve_selection,
                  const GPointer value,
                  GMutableSpan dst)
 {
   BLI_assert(*value.type() == dst.type());
   const CPPType &type = dst.type();
-  const OffsetIndices points_by_curve = curves.points_by_curve();
   threading::parallel_for(curve_selection.index_range(), 512, [&](IndexRange range) {
     for (const int i : curve_selection.slice(range)) {
       const IndexRange points = points_by_curve[i];
@@ -78,14 +83,13 @@ void fill_points(const CurvesGeometry &curves,
   });
 }
 
-void fill_points(const CurvesGeometry &curves,
+void fill_points(const OffsetIndices<int> points_by_curve,
                  Span<IndexRange> curve_ranges,
                  GPointer value,
                  GMutableSpan dst)
 {
   BLI_assert(*value.type() == dst.type());
   const CPPType &type = dst.type();
-  const OffsetIndices points_by_curve = curves.points_by_curve();
   threading::parallel_for(curve_ranges.index_range(), 512, [&](IndexRange range) {
     for (const IndexRange range : curve_ranges.slice(range)) {
       const IndexRange points = points_by_curve[range];
diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc
index e0f5076021b..2ef51867e07 100644
--- a/source/blender/geometry/intern/add_curves_on_mesh.cc
+++ b/source/blender/geometry/intern/add_curves_on_mesh.cc
@@ -286,7 +286,7 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
 
   /* Compute new curve offsets. */
   MutableSpan<int> curve_offsets = curves.offsets_for_write();
-  MutableSpan<int> new_point_counts_per_curve = curve_offsets.take_back(added_curves_num);
+  MutableSpan<int> new_point_counts_per_curve = curve_offsets.drop_front(old_curves_num);
   if (inputs.interpolate_point_count) {
     interpolate_from_neighbors<int>(
         neighbors_per_curve,
@@ -297,9 +297,8 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves,
   else {
     new_point_counts_per_curve.fill(inputs.fallback_point_count);
   }
-  for (const int i : new_curves_range) {
-    curve_offsets[i + 1] += curve_offsets[i];
-  }
+  offset_indices::accumulate_counts_to_offsets(curve_offsets.drop_front(old_curves_num),
+                                               old_points_num);
 
   const int new_points_num = curves.offsets().last();
   curves.resize(new_points_num, new_curves_num);
diff --git a/source/blender/geometry/intern/fillet_curves.cc b/source/blender/geometry/intern/fillet_curves.cc
index 0107eafba9d..e43960db1e7 100644
--- a/source/blender/geometry/intern/fillet_curves.cc
+++ b/source/blender/geometry/intern/fillet_curves.cc
@@ -26,15 +26,13 @@ static void threaded_slice_fill(const Span<T> src,
 }
 
 template<typename T>
-static void duplicate_fillet_point_data(const bke::CurvesGeometry &src_curves,
-                                        const bke::CurvesGeometry &dst_curves,
+static void duplicate_fillet_point_data(const OffsetIndices<int> src_points_by_curve,
+                                        const OffsetIndices<int> dst_points_by_curve,
                                         const IndexMask curve_selection,
                                         const Span<int> all_point_offsets,
                                         const Span<T> src,
       

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list