61 const int verts_num = coords.
size();
65 const int segments_num = is_closed ? verts_num : verts_num - 1;
69 segment_length[i] = distances[i + 1] - distances[i];
70 if (!(segment_length[i] > 0.0f)) {
87 lower_diag[i] = segment_length[i_prev];
88 diag[i] = 2.0f * (segment_length[i_prev] + segment_length[i]);
89 upper_diag[i] = segment_length[i];
90 rhs[i] = 3.0f * (((coords[i_next] - coords[i]) / segment_length[i]) -
91 ((coords[i] - coords[i_prev]) / segment_length[i_prev]));
97 const int interior = verts_num - 2;
104 for (
const int i_curr :
IndexRange(interior)) {
105 const int i_next = i_curr + 1;
106 lower_diag[i_curr] = segment_length[i_curr];
107 diag[i_curr] = 2.0f * (segment_length[i_curr] + segment_length[i_next]);
108 upper_diag[i_curr] = segment_length[i_next];
109 rhs[i_curr] = 3.0f * (((coords[i_next + 1] - coords[i_next]) / segment_length[i_next]) -
110 ((coords[i_next] - coords[i_curr]) / segment_length[i_curr]));
123 for (
const int i :
IndexRange(segments_num)) {
125 const float coeff_a = coords[i];
126 const float coeff_b = ((coords[i_next] - coords[i]) / segment_length[i]) -
127 (segment_length[i] * (c_vals[i_next] + 2.0f * c_vals[i])) / 3.0f;
128 const float coeff_c = c_vals[i];
129 const float coeff_d = (c_vals[i_next] - c_vals[i]) / (3.0f * segment_length[i]);
130 r_coeffs[i] = {coeff_a, coeff_b, coeff_c, coeff_d, distances[i]};
147 visited_edges.
add(e_curr);
153 if (v_next == v_start) {
177 if (edge_count != 2) {
183 if (edge_count < 3 || edge_count > 4) {
206 visited_edges.
add(e_curr);
220 bool is_forward_circular =
false;
223 if (is_forward_circular) {
225 chain.
verts.append(e_start->
v1);
226 chain.
verts.extend(forward_trace);
230 bool is_backward_circular =
false;
233 std::ranges::reverse(backward_trace);
234 chain.
verts.extend(backward_trace);
235 chain.
verts.extend(forward_trace);
253 r_chains.
append(std::move(perp_chain));
271 for (
BMVert *v_start : tag_verts) {
278 if (visited_edges.
contains(e_start)) {
284 if (chain.
verts.size() < 3) {
297 if (tag_count == chain.
verts.size()) {
300 else if (tag_count >= 1) {
301 r_chains.
append(std::move(chain));
313 int &r_best_gap_start)
315 const int verts_num = verts.
size();
320 selected_indices.
append(i);
325 r_longest_gap = verts_num;
326 r_best_gap_start = 0;
330 int longest_gap = -1;
331 int best_gap_start = -1;
333 for (
const int i : selected_indices.
index_range()) {
334 int i_curr = selected_indices[i];
338 if (gap_size > longest_gap) {
339 longest_gap = gap_size;
344 r_longest_gap = longest_gap;
345 r_best_gap_start = best_gap_start;
351 if (chain.is_closed) {
352 int longest_gap, best_gap_start;
355 if (longest_gap > 0) {
357 int(chain.verts.size()));
359 std::rotate(chain.verts.begin(), chain.verts.begin() + new_start_index, chain.verts.end());
361 chain.is_closed =
false;
364 int first_selected = -1;
365 int last_selected = -1;
366 for (
const int i : chain.verts.index_range()) {
368 if (first_selected == -1) {
375 if (first_selected > 0 || last_selected < chain.verts.size() - 1) {
377 for (
int i = first_selected; i <= last_selected; i++) {
378 trimmed.
append(chain.verts[i]);
380 chain.verts = std::move(trimmed);
389 const bool is_closed,
394 const int verts_num = verts.
size();
398 positions[i] =
float3(verts[i]->co);
400 const int cumulative_array_size = verts_num + (is_closed ? 1 : 0);
402 cumulative[0] = 0.0f;
412 if (knot_index < knot_indices.
size() && knot_indices[knot_index] == i) {
413 r_knot_distances[knot_index] = cumulative[i];
417 r_point_distances[point_index] = cumulative[i];
423 const float total_length = cumulative.last();
424 r_knot_distances[knot_index++] = total_length;
428 const float total = cumulative.last();
430 const float spacing = total /
float(is_closed ? verts_num : verts_num - 1);
432 const int v_index = point_indices[i];
433 r_point_distances[i] =
float(v_index) * spacing;
436 r_knot_distances[ki] =
float(knot_indices[ki]) * spacing;
439 r_knot_distances[knot_indices.
size()] = total;
447 const bool is_closed,
450 const int knots_num = knot_positions.
size();
456 coords_x[i] = knot_positions[i].x;
457 coords_y[i] = knot_positions[i].y;
458 coords_z[i] = knot_positions[i].z;
476 int verts_num = input_chain.
size();
477 int new_start_index = 0;
480 int longest_gap, best_gap_start;
483 int offset = verts_num / 4;
488 if (longest_gap > 2 * offset) {
491 int trim_start =
math::mod_periodic(best_gap_start + longest_gap - offset, verts_num);
494 new_start_index = trim_start;
521 knot_indices.
insert(0, 0);
523 if (knot_indices.
last() != verts_num - 1) {
524 knot_indices.
append(verts_num - 1);
530 knot_positions[ki] =
float3(verts[knot_indices[ki]]->co);
540 knot_indices.
data() + knot_indices.
size(),
541 point_indices.
data());
544 verts, knot_indices, point_indices, is_closed, regular, knot_distances, point_distances);
550 const int points_num = point_indices.
size();
556 knot_distances.
as_span().drop_front(1), point_distances, segment_indices, factors);
559 std::array<Array<SplineCoeffs>, 3> axis_coeffs;
563 const int seg = segment_indices[i];
564 const float dt = point_distances[i] - axis_coeffs[0][seg].x;
570 new_positions[i] =
float3(cx.
a + dt * (cx.
b + dt * (cx.
c + dt * cx.
d)),
571 cy.
a + dt * (cy.
b + dt * (cy.
c + dt * cy.
d)),
572 cz.
a + dt * (cz.
b + dt * (cz.
c + dt * cz.
d)));
577 knot_positions, segment_indices, factors, new_positions);
581 const int v_index = point_indices[i];
582 BMVert *vert = verts[v_index];
583 float3 new_pos = new_positions[i];
585 const float3 old_pos(vert->co);
586 const float3 delta = new_pos - old_pos;
591 const float3 normal(vert->no);
592 const float dot_val =
math::dot(delta, normal);
608 new_pos.x = old_pos.x;
611 new_pos.y = old_pos.y;
614 new_pos.z = old_pos.z;
#define BM_elem_flag_test(ele, hflag)
#define BM_ITER_ELEM(ele, iter, data, itype)
#define BM_ITER_MESH(ele, iter, bm, itype)
Span< T > as_span() const
MutableSpan< T > as_mutable_span()
Array(Allocator allocator={}) noexcept
IndexRange index_range() const
constexpr IndexRange()=default
bool contains(const Key &key) const
constexpr int64_t size() const
constexpr IndexRange index_range() 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
IndexRange index_range() const
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 length_squared(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T interpolate(const T &a, const T &b, const FactorT &t)
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.
static void calc_curve_input_chains_from_bm(BMesh *bm, Vector< CurveChainData > &r_chains)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int BMO_slot_int_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
BLI_INLINE bool BM_edge_is_wire(const BMEdge *e) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static void get_perpendicular_chains(const CurveChainData &chain, Vector< CurveChainData > &r_chains, Set< BMEdge * > &visited_edges)
constexpr float CURVE_EPSILON
static void traverse_edge_loop(BMVert *v_start, BMEdge *e_start, Set< BMEdge * > &visited_edges, Vector< BMVert * > &r_loop, bool &r_circular)
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.
static void execute_curve_chain(const Span< BMVert * > input_chain, bool is_closed, const CurveInterpolation interpolation, const CurveClampElevation clamp_elevation, const bool regular, const float factor, const bool lock_x, const bool lock_y, const bool lock_z)
bool BM_vert_is_wire(const BMVert *v)
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:
float BMO_slot_float_get(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name)
ATTR_WARN_UNUSED_RESULT const BMVert * v
BLI_INLINE BMVert * BM_edge_other_vert(BMEdge *e, const BMVert *v) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
static CurveChainData build_curve_chain_from_edge(BMEdge *e_start, Set< BMEdge * > &visited_edges)
@ CURVE_CLAMP_ELEVATION_RAISE
@ CURVE_CLAMP_ELEVATION_LOWER
@ CURVE_CLAMP_ELEVATION_NONE
static void trim_chains_to_boundaries(Vector< CurveChainData > &chains)
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 find_longest_unselected_gap(const Span< BMVert * > verts, int &r_longest_gap, int &r_best_gap_start)
bool BM_edge_share_quad_check(BMEdge *e1, BMEdge *e2)
static void calculate_curve_splines(const Span< float3 > knot_positions, const Span< float > knot_distances, const bool is_closed, std::array< Array< SplineCoeffs >, 3 > &r_coeffs)
VecBase< float, 3 > float3
void bmo_curve_edge_loops_between_selected_exec(BMesh *bm, BMOperator *op)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static void calculate_curve_distances(const Span< BMVert * > verts, const Span< int > knot_indices, const Span< int > point_indices, const bool is_closed, const bool regular, Array< float > &r_knot_distances, Array< float > &r_point_distances)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
struct BMOpSlot slots_in[BMO_OP_MAX_SLOTS]