78 const int verts_num = coords.
size();
82 const int segments_num = is_closed ? verts_num : verts_num - 1;
86 segment_length[i] = distances[i + 1] - distances[i];
87 if (!(segment_length[i] > 0.0f)) {
107 lower_diag[i] = segment_length[i_prev];
108 diag[i] = 2.0f * (segment_length[i_prev] + segment_length[i]);
109 upper_diag[i] = segment_length[i];
110 rhs[i] = 3.0f * (((coords[i_next] - coords[i]) / segment_length[i]) -
111 ((coords[i] - coords[i_prev]) / segment_length[i_prev]));
119 const int interior = verts_num - 2;
125 for (
const int i_curr :
IndexRange(interior)) {
126 const int i_next = i_curr + 1;
127 lower_diag[i_curr] = segment_length[i_curr];
128 diag[i_curr] = 2.0f * (segment_length[i_curr] + segment_length[i_next]);
129 upper_diag[i_curr] = segment_length[i_next];
130 rhs[i_curr] = 3.0f * (((coords[i_next + 1] - coords[i_next]) / segment_length[i_next]) -
131 ((coords[i_next] - coords[i_curr]) / segment_length[i_curr]));
142 for (
const int i :
IndexRange(segments_num)) {
145 const float coeff_a = coords[i];
146 const float coeff_b = ((coords[i_next] - coords[i]) / segment_length[i]) -
147 (segment_length[i] * (c_vals[i_next] + 2.0f * c_vals[i])) / 3.0f;
148 const float coeff_c = c_vals[i];
149 const float coeff_d = (c_vals[i_next] - c_vals[i]) / (3.0f * segment_length[i]);
150 r_coeffs.
append({coeff_a, coeff_b, coeff_c, coeff_d, distances[i]});
164 if (i % 2 == phase_index) {
167 else if (i > 0 && i < verts_num - 1) {
171 r_phases.
append(std::move(phase));
180 const bool extend = verts_num % 2 == 1 ? j == 1 : j == 0;
181 const int knot_start = !extend && j == 1 ? 1 : 0;
182 const int point_start = !extend && j == 1 ? 2 : 1;
185 const int last_vert = vert_indices.
last();
186 const int first_vert = vert_indices.
first();
187 vert_indices.
insert(0, last_vert);
188 vert_indices.
append(first_vert);
192 for (
int i = knot_start; i < vert_indices.
size(); i += 2) {
195 for (
int i = point_start; i < vert_indices.
size(); i += 2) {
196 const int val = vert_indices[i];
207 r_phases.
append(std::move(phase));
214 ListBaseT<BMEdgeLoopStore> eloops = {
nullptr};
216 .use_vert_junction =
true,
227 if (chain.
verts.size() >= 3) {
228 r_chains.
append(std::move(chain));
243 const int total = knots_num + points_num;
251 else if (i == total - 1) {
257 positions[i] = verts[vert_index]->co;
261 cumulative[0] = 0.0f;
266 if (i % 2 == 0 || i == total - 1) {
267 r_knot_distances.
append(cumulative[i]);
270 r_point_distances.
append(cumulative[i]);
276 r_point_distances.
clear();
278 r_point_distances.
append((r_knot_distances[p] + r_knot_distances[p + 1]) / 2.0f);
289 const int knots_num = knot_indices.
size();
290 const int coords_num = is_closed ? knots_num - 1 : knots_num;
296 const float *co = verts[knot_indices[i]]->co;
324 accumulated_lengths, point_distances, segment_indices, factors);
335 knot_positions, segment_indices, factors, sampled_positions);
338 std::array<Vector<SplineCoeffs>, 3> axis_coeffs;
342 const int seg = segment_indices[i];
343 const float dt = point_distances[i] - axis_coeffs[0][seg].x;
349 sampled_positions[i] =
float3(cx.
a + dt * (cx.
b + dt * (cx.
c + dt * cx.
d)),
350 cy.
a + dt * (cy.
b + dt * (cy.
c + dt * cy.
d)),
351 cz.
a + dt * (cz.
b + dt * (cz.
c + dt * cz.
d)));
357 const float3 current_pos(verts[v_index]->co);
358 const float3 final_pos = (current_pos + sampled_positions[i]) / 2.0f;
383 for (
const RelaxPhase &phase : chain.phases) {
#define BM_elem_flag_test(ele, hflag)
MutableSpan< T > as_mutable_span()
constexpr IndexRange()=default
constexpr Span drop_front(int64_t n) const
constexpr int64_t size() const
void append(const T &value)
void insert(const int64_t insert_index, const T &value)
const T & last(const int64_t n=0) const
MutableSpan< T > as_mutable_span()
void append(const T &value)
const T & last(const int64_t n=0) const
IndexRange index_range() const
void fill_index_range(MutableSpan< T > span, const T start=0)
void accumulate_lengths(const Span< T > values, const bool cyclic, MutableSpan< float > lengths)
void sample_at_lengths(Span< float > accumulated_segment_lengths, Span< float > sample_lengths, MutableSpan< int > r_segment_indices, MutableSpan< float > r_factors)
void interpolate(const Span< T > src, const Span< int > indices, const Span< float > factors, MutableSpan< T > dst)
T mod_periodic(const T &a, const T &b)
bool BLI_tridiagonal_solve_cyclic(const float *a, const float *b, const float *c, const float *d, float *r_x, int count)
Solve a possibly cyclic tridiagonal system using the Sherman-Morrison formula.
ListBaseT< LinkData > * BM_edgeloop_verts_get(BMEdgeLoopStore *el_store)
int BM_mesh_edgeloops_find(BMesh *bm, ListBaseT< BMEdgeLoopStore > *r_eloops, FunctionRef< bool(BMEdge *)> test_fn, const BMEdgeLoopFind_Params *params)
static void get_relax_input_chains(BMesh *bm, Vector< RelaxChainData > &r_chains)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
static void calculate_phase_distances(Span< BMVert * > verts, const RelaxPhase &phase, const bool regular, Vector< float > &r_knot_distances, Vector< float > &r_point_distances)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BMO_slot_buffer_hflag_enable(BMesh *bm, BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char htype, char hflag, bool do_flush)
BMO_FLAG_BUFFER.
void BM_mesh_edgeloops_free(ListBaseT< BMEdgeLoopStore > *eloops)
bool BLI_tridiagonal_solve(const float *a, const float *b, const float *c, const float *d, float *r_x, int count)
Solve a tridiagonal system of equations:
void BM_mesh_elem_hflag_disable_all(BMesh *bm, const char htype, const char hflag, const bool respecthide)
@ RELAX_EDGE_LOOPS_INTERP_LINEAR
bool BM_edgeloop_is_closed(BMEdgeLoopStore *el_store)
void bmo_relax_edge_loops_exec(BMesh *bm, BMOperator *op)
constexpr float RELAX_EPSILON
static void calculate_splines_axis(const Span< float > distances, const Span< float > coords, const bool is_closed, Array< SplineCoeffs > &r_coeffs)
bool BMO_slot_bool_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
static void build_relax_phases(int verts_num, bool is_closed, Vector< RelaxPhase > &r_phases)
VecBase< float, 3 > float3
static void execute_relax_phase(Span< BMVert * > verts, const RelaxPhase &phase, bool is_closed, int interpolation, bool regular)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static void calculate_relax_splines(Span< BMVert * > verts, Span< int > knot_indices, Span< float > t_params, bool is_closed, std::array< Vector< SplineCoeffs >, 3 > &r_coeffs)
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]
Vector< RelaxPhase > phases
Vector< int > point_indices
Vector< int > knot_indices