From 038c6e229c4fb1518f726d7f6a828be026bae857 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Sat, 15 May 2021 17:44:33 -0500 Subject: 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. --- source/blender/blenkernel/intern/curve_eval.cc | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'source/blender/blenkernel/intern/curve_eval.cc') 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 CurveEval::control_point_offsets() const +{ + Array 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 CurveEval::evaluated_point_offsets() const +{ + Array 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) { -- cgit v1.2.3