[Bf-blender-cvs] [038c6e229c4] master: Splines: Convenience methods for point offsets of multiple splines
Hans Goudey
noreply at git.blender.org
Sun May 16 00:44:41 CEST 2021
Commit: 038c6e229c4fb1518f726d7f6a828be026bae857
Author: Hans Goudey
Date: Sat May 15 17:44:33 2021 -0500
Branches: master
https://developer.blender.org/rB038c6e229c4fb1518f726d7f6a828be026bae857
Splines: Convenience methods for point offsets of multiple splines
Since spline data is stored separately for each spline, the data often
needs to be flattened into a separate array. It's helpful to have the
necessarily-sequential part of that split off into a separate method.
I've found myself using functions like these in quite a few places.
===================================================================
M source/blender/blenkernel/BKE_spline.hh
M source/blender/blenkernel/intern/curve_eval.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index acff2843806..35f21ccb897 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -493,6 +493,9 @@ class CurveEval {
void translate(const blender::float3 &translation);
void transform(const blender::float4x4 &matrix);
void bounds_min_max(blender::float3 &min, blender::float3 &max, const bool use_evaluated) const;
+
+ blender::Array<int> control_point_offsets() const;
+ blender::Array<int> evaluated_point_offsets() const;
};
std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &curve);
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 882fdbc0ec6..86ae70399db 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -23,6 +23,7 @@
#include "BKE_curve.h"
#include "BKE_spline.hh"
+using blender::Array;
using blender::float3;
using blender::float4x4;
using blender::Span;
@@ -82,6 +83,40 @@ void CurveEval::bounds_min_max(float3 &min, float3 &max, const bool use_evaluate
}
}
+/**
+ * Return the start indices for each of the curve spline's evaluated points, as if they were part
+ * of a flattened array. This can be used to facilitate parallelism by avoiding the need to
+ * accumulate an offset while doing more complex calculations.
+ *
+ * \note The result array is one longer than the spline count; the last element is the total size.
+ */
+blender::Array<int> CurveEval::control_point_offsets() const
+{
+ Array<int> offsets(splines_.size() + 1);
+ int offset = 0;
+ for (const int i : splines_.index_range()) {
+ offsets[i] = offset;
+ offset += splines_[i]->size();
+ }
+ offsets.last() = offset;
+ return offsets;
+}
+
+/**
+ * Exactly like #control_point_offsets, but uses the number of evaluated points instead.
+ */
+blender::Array<int> CurveEval::evaluated_point_offsets() const
+{
+ Array<int> offsets(splines_.size() + 1);
+ int offset = 0;
+ for (const int i : splines_.index_range()) {
+ offsets[i] = offset;
+ offset += splines_[i]->evaluated_points_size();
+ }
+ offsets.last() = offset;
+ return offsets;
+}
+
static BezierSpline::HandleType handle_type_from_dna_bezt(const eBezTriple_Handle dna_handle_type)
{
switch (dna_handle_type) {
More information about the Bf-blender-cvs
mailing list