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.
This commit is contained in:
Hans Goudey 2021-05-15 17:44:33 -05:00
parent cb12fb78ca
commit 038c6e229c
2 changed files with 38 additions and 0 deletions

View File

@ -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);

View File

@ -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) {