diff options
author | Hans Goudey <h.goudey@me.com> | 2021-05-16 01:44:33 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-05-16 01:44:33 +0300 |
commit | 038c6e229c4fb1518f726d7f6a828be026bae857 (patch) | |
tree | 1b46ee9a0e24ce5bce72584499960daee9df3c37 /source/blender/blenkernel | |
parent | cb12fb78cad4be5fa18edf0de1f8891cd97a9bed (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_spline.hh | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/curve_eval.cc | 35 |
2 files changed, 38 insertions, 0 deletions
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) { |