Blender V5.3
fillet_curves.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10#include "BKE_curves.hh"
11#include "BKE_curves_utils.hh"
12
14#include "BLI_task.hh"
15
16#include "GEO_fillet_curves.hh"
17
18#include <cfloat>
19#include <numbers>
20
21namespace blender::geometry {
22
23static void duplicate_fillet_point_data(const OffsetIndices<int> src_points_by_curve,
24 const OffsetIndices<int> dst_points_by_curve,
25 const IndexMask &curve_selection,
26 const Span<int> all_point_offsets,
27 const GSpan src,
28 GMutableSpan dst)
29{
30 curve_selection.foreach_index(
31 [&](const int curve_i) {
32 const IndexRange src_points = src_points_by_curve[curve_i];
33 const IndexRange dst_points = dst_points_by_curve[curve_i];
34 const IndexRange offsets_range = bke::curves::per_curve_point_offsets_range(src_points,
35 curve_i);
36 bke::attribute_math::gather_to_groups(all_point_offsets.slice(offsets_range),
37 IndexRange(src_points.size()),
38 src.slice(src_points),
39 dst.slice(dst_points));
40 },
42}
43
44static void calculate_result_offsets(const OffsetIndices<int> src_points_by_curve,
45 const IndexMask &selection,
46 const IndexMask &unselected,
47 const VArray<float> &radii,
48 const VArray<int> &counts,
49 const Span<bool> cyclic,
50 MutableSpan<int> dst_curve_offsets,
51 MutableSpan<int> dst_point_offsets)
52{
53 /* Fill the offsets array with the curve point counts, then accumulate them to form offsets. */
54 offset_indices::copy_group_sizes(src_points_by_curve, unselected, dst_curve_offsets);
55 selection.foreach_index(
56 [&](const int curve_i) {
57 const IndexRange src_points = src_points_by_curve[curve_i];
58 const IndexRange offsets_range = bke::curves::per_curve_point_offsets_range(src_points,
59 curve_i);
60
61 MutableSpan<int> point_offsets = dst_point_offsets.slice(offsets_range);
62 MutableSpan<int> point_counts = point_offsets.drop_back(1);
63
64 counts.materialize_compressed(src_points, point_counts);
65 for (int &count : point_counts) {
66 /* Make sure the number of cuts is greater than zero and add one for the existing point.
67 */
68 count = std::max(count, 0) + 1;
69 }
70 if (!cyclic[curve_i]) {
71 /* Endpoints on non-cyclic curves cannot be filleted. */
72 point_counts.first() = 1;
73 point_counts.last() = 1;
74 }
75 /* Implicitly "deselect" points with zero radius. */
76 devirtualize_varray(radii, [&](const auto radii) {
77 for (const int i : IndexRange(src_points.size())) {
78 if (radii[src_points[i]] == 0.0f) {
79 point_counts[i] = 1;
80 }
81 }
82 });
83
85
86 dst_curve_offsets[curve_i] = point_offsets.last();
87 },
90}
91
92static void calculate_directions(const Span<float3> positions, MutableSpan<float3> directions)
93{
94 for (const int i : positions.index_range().drop_back(1)) {
95 directions[i] = math::normalize(positions[i + 1] - positions[i]);
96 }
97 directions.last() = math::normalize(positions.first() - positions.last());
98}
99
100static void calculate_angles(const Span<float3> directions, MutableSpan<float> angles)
101{
102 angles.first() = M_PI - angle_v3v3(-directions.last(), directions.first());
103 for (const int i : directions.index_range().drop_front(1)) {
104 angles[i] = M_PI - angle_v3v3(-directions[i - 1], directions[i]);
105 }
106}
107
113static void zero_degenerate_radii(const Span<float3> directions,
114 const Span<float> angles,
115 MutableSpan<float> radii)
116{
117 const int i_last = radii.index_range().last();
118 for (const int i : radii.index_range()) {
119 const int i_prev = i == 0 ? i_last : i - 1;
120 if (angles[i] >= std::numbers::pi_v<float> || math::is_zero(directions[i_prev]) ||
121 math::is_zero(directions[i]))
122 {
123 radii[i] = 0.0f;
124 }
125 }
126}
127
133static float limit_radius(const float3 &position_prev,
134 const float3 &position,
135 const float3 &position_next,
136 const float angle_prev,
137 const float angle,
138 const float angle_next,
139 const float radius_prev,
140 const float radius,
141 const float radius_next)
142{
143 const float displacement = radius * std::tan(angle / 2.0f);
144
145 const float displacement_prev = radius_prev * std::tan(angle_prev / 2.0f);
146 const float segment_length_prev = math::distance(position, position_prev);
147 const float total_displacement_prev = displacement_prev + displacement;
148 const float factor_prev = std::clamp(
149 math::safe_divide(segment_length_prev, total_displacement_prev), 0.0f, 1.0f);
150
151 const float displacement_next = radius_next * std::tan(angle_next / 2.0f);
152 const float segment_length_next = math::distance(position, position_next);
153 const float total_displacement_next = displacement_next + displacement;
154 const float factor_next = std::clamp(
155 math::safe_divide(segment_length_next, total_displacement_next), 0.0f, 1.0f);
156
157 return radius * std::min(factor_prev, factor_next);
158}
159
160static void limit_radii(const Span<float3> positions,
161 const Span<float> angles,
162 const Span<float> radii,
163 const bool cyclic,
164 MutableSpan<float> radii_clamped)
165{
166 if (cyclic) {
167 /* First point. */
168 radii_clamped.first() = limit_radius(positions.last(),
169 positions.first(),
170 positions[1],
171 angles.last(),
172 angles.first(),
173 angles[1],
174 radii.last(),
175 radii.first(),
176 radii[1]);
177 /* All middle points. */
178 for (const int i : positions.index_range().drop_back(1).drop_front(1)) {
179 const int i_prev = i - 1;
180 const int i_next = i + 1;
181 radii_clamped[i] = limit_radius(positions[i_prev],
182 positions[i],
183 positions[i_next],
184 angles[i_prev],
185 angles[i],
186 angles[i_next],
187 radii[i_prev],
188 radii[i],
189 radii[i_next]);
190 }
191 /* Last point. */
192 radii_clamped.last() = limit_radius(positions.last(1),
193 positions.last(),
194 positions.first(),
195 angles.last(1),
196 angles.last(),
197 angles.first(),
198 radii.last(1),
199 radii.last(),
200 radii.first());
201 }
202 else {
203 const int i_last = positions.index_range().last();
204 /* First point. */
205 radii_clamped.first() = 0.0f;
206 /* All middle points. */
207 for (const int i : positions.index_range().drop_back(1).drop_front(1)) {
208 const int i_prev = i - 1;
209 const int i_next = i + 1;
210 /* Use a zero radius for the first and last points, because they don't have fillets.
211 * This logic could potentially be unrolled, but it doesn't seem worth it. */
212 const float radius_prev = i_prev == 0 ? 0.0f : radii[i_prev];
213 const float radius_next = i_next == i_last ? 0.0f : radii[i_next];
214 radii_clamped[i] = limit_radius(positions[i_prev],
215 positions[i],
216 positions[i_next],
217 angles[i_prev],
218 angles[i],
219 angles[i_next],
220 radius_prev,
221 radii[i],
222 radius_next);
223 }
224 /* Last point. */
225 radii_clamped.last() = 0.0f;
226 }
227}
228
229static void calculate_fillet_positions(const Span<float3> src_positions,
230 const Span<float> angles,
231 const Span<float> radii,
232 const Span<float3> directions,
233 const OffsetIndices<int> dst_offsets,
235{
236 const int i_src_last = src_positions.index_range().last();
237 threading::parallel_for(src_positions.index_range(), 512, [&](IndexRange range) {
238 for (const int i_src : range) {
239 const IndexRange arc = dst_offsets[i_src];
240 const float3 &src = src_positions[i_src];
241 if (arc.size() == 1) {
242 dst[arc.first()] = src;
243 continue;
244 }
245
246 const int i_src_prev = i_src == 0 ? i_src_last : i_src - 1;
247 const float angle = angles[i_src];
248 const float radius = radii[i_src];
249 const float displacement = radius * std::tan(angle / 2.0f);
250 const float3 prev_dir = -directions[i_src_prev];
251 const float3 &next_dir = directions[i_src];
252 const float3 arc_start = src + prev_dir * displacement;
253 const float3 arc_end = src + next_dir * displacement;
254
255 dst[arc.first()] = arc_start;
256 dst[arc.last()] = arc_end;
257
258 const IndexRange middle = arc.drop_front(1).drop_back(1);
259 if (middle.is_empty()) {
260 continue;
261 }
262
263 const float3 axis = -math::normalize(math::cross(prev_dir, next_dir));
264 const float3 center_direction = math::normalize(math::midpoint(next_dir, prev_dir));
265 const float distance_to_center = std::sqrt(pow2f(radius) + pow2f(displacement));
266 const float3 center = src + center_direction * distance_to_center;
267
268 /* Rotate each middle fillet point around the center. */
269 const float segment_angle = angle / (middle.size() + 1);
270 for (const int i : IndexRange(middle.size())) {
271 const int point_i = middle[i];
272 dst[point_i] = math::rotate_around_axis(arc_start, center, axis, segment_angle * (i + 1));
273 }
274 }
275 });
276}
277
284 const float3 &handle,
285 const float3 &other_handle)
286{
287 const float3 handle_offset = handle - position;
288 const float3 other_direction = math::normalize(other_handle - position);
289 if (math::is_zero(other_direction) || math::is_zero(handle_offset)) {
290 return BEZIER_HANDLE_ALIGN;
291 }
292 if (math::dot(handle_offset, other_direction) >= 0.0f) {
293 return BEZIER_HANDLE_FREE;
294 }
295 const float length = math::length(handle_offset);
296 const float3 aligned_handle = position - other_direction * length;
297 /* Allow rounding when reconstructing the handle, including cancellation near zero after
298 * translation. Use a floating-point error bound rather than a scene-space epsilon.
299 * gamma(12) bounds the accumulated relative error of the reconstruction operations. */
300 constexpr double unit_roundoff = FLT_EPSILON / 2.0;
301 constexpr double relative_error = 12 * unit_roundoff / (1 - 12 * unit_roundoff);
302 /* All components must agree within the rounding bound to preserve the handle's 3D position.
303 * A mismatch on any axis means alignment would change the circular arc. */
304 for (const int axis : IndexRange(3)) {
305 const double rounding_bound = relative_error * length +
306 unit_roundoff * (std::abs(double(position[axis])) +
307 std::abs(double(handle[axis])));
308 if (std::abs(double(aligned_handle[axis]) - handle[axis]) > rounding_bound) {
309 return BEZIER_HANDLE_FREE;
310 }
311 }
312 return BEZIER_HANDLE_ALIGN;
313}
314
321 const Span<float3> src_handles_r,
322 const Span<int8_t> src_types_l,
323 const Span<int8_t> src_types_r,
324 const Span<float> angles,
325 const Span<float> radii,
326 const Span<float3> directions,
327 const OffsetIndices<int> dst_offsets,
328 const Span<float3> dst_positions,
329 MutableSpan<float3> dst_handles_l,
330 MutableSpan<float3> dst_handles_r,
331 MutableSpan<int8_t> dst_types_l,
332 MutableSpan<int8_t> dst_types_r)
333{
334 const int i_src_last = src_handles_l.index_range().last();
335 const int i_dst_last = dst_positions.index_range().last();
336 threading::parallel_for(src_handles_l.index_range(), 512, [&](IndexRange range) {
337 for (const int i_src : range) {
338 const IndexRange arc = dst_offsets[i_src];
339 if (arc.size() == 1) {
340 dst_handles_l[arc.first()] = src_handles_l[i_src];
341 dst_handles_r[arc.first()] = src_handles_r[i_src];
342 dst_types_l[arc.first()] = src_types_l[i_src];
343 dst_types_r[arc.first()] = src_types_r[i_src];
344 continue;
345 }
346 BLI_assert(arc.size() == 2);
347 const int i_dst_a = arc.first();
348 const int i_dst_b = arc.last();
349
350 const int i_src_prev = i_src == 0 ? i_src_last : i_src - 1;
351 const float angle = angles[i_src];
352 const float radius = radii[i_src];
353 const float3 prev_dir = -directions[i_src_prev];
354 const float3 &next_dir = directions[i_src];
355
356 const float3 &arc_start = dst_positions[arc.first()];
357 const float3 &arc_end = dst_positions[arc.last()];
358
359 /* Calculate the point's handles on the outside of the fillet segment,
360 * connecting to the next or previous result points. */
361 const int i_dst_prev = i_dst_a == 0 ? i_dst_last : i_dst_a - 1;
362 const int i_dst_next = i_dst_b == i_dst_last ? 0 : i_dst_b + 1;
363 dst_handles_l[i_dst_a] = bke::curves::bezier::calculate_vector_handle(
364 dst_positions[i_dst_a], dst_positions[i_dst_prev]);
365 dst_handles_r[i_dst_b] = bke::curves::bezier::calculate_vector_handle(
366 dst_positions[i_dst_b], dst_positions[i_dst_next]);
367 dst_types_l[i_dst_a] = BEZIER_HANDLE_VECTOR;
368 dst_types_r[i_dst_b] = BEZIER_HANDLE_VECTOR;
369
370 /* Preserve the original corner's arc tangents. Alignment is only valid when the outer
371 * vector handles provide the opposite direction (or no direction for coincident points). */
372 const float handle_length = (4.0f / 3.0f) * radius * std::tan(angle / 4.0f);
373 dst_handles_r[i_dst_a] = arc_start - prev_dir * handle_length;
374 dst_handles_l[i_dst_b] = arc_end - next_dir * handle_length;
375 dst_types_r[i_dst_a] = fillet_handle_type(
376 arc_start, dst_handles_r[i_dst_a], dst_handles_l[i_dst_a]);
377 dst_types_l[i_dst_b] = fillet_handle_type(
378 arc_end, dst_handles_l[i_dst_b], dst_handles_r[i_dst_b]);
379 }
380 });
381}
382
387static void calculate_bezier_handles_poly_mode(const Span<float3> src_handles_l,
388 const Span<float3> src_handles_r,
389 const Span<int8_t> src_types_l,
390 const Span<int8_t> src_types_r,
391 const OffsetIndices<int> dst_offsets,
392 const Span<float3> dst_positions,
393 MutableSpan<float3> dst_handles_l,
394 MutableSpan<float3> dst_handles_r,
395 MutableSpan<int8_t> dst_types_l,
396 MutableSpan<int8_t> dst_types_r)
397{
398 const int i_dst_last = dst_positions.index_range().last();
399 threading::parallel_for(src_handles_l.index_range(), 512, [&](IndexRange range) {
400 for (const int i_src : range) {
401 const IndexRange arc = dst_offsets[i_src];
402 if (arc.size() == 1) {
403 dst_handles_l[arc.first()] = src_handles_l[i_src];
404 dst_handles_r[arc.first()] = src_handles_r[i_src];
405 dst_types_l[arc.first()] = src_types_l[i_src];
406 dst_types_r[arc.first()] = src_types_r[i_src];
407 continue;
408 }
409
410 /* The fillet's next and previous handles are vector handles, as are the inner handles. */
411 dst_types_l.slice(arc).fill(BEZIER_HANDLE_VECTOR);
412 dst_types_r.slice(arc).fill(BEZIER_HANDLE_VECTOR);
413
414 /* Calculate the point's handles on the outside of the fillet segment. This point
415 * won't be selected for a fillet if it is the first or last in a non-cyclic curve. */
416
417 const int i_dst_prev = arc.first() == 0 ? i_dst_last : arc.one_before_start();
418 const int i_dst_next = arc.last() == i_dst_last ? 0 : arc.one_after_last();
419 dst_handles_l[arc.first()] = bke::curves::bezier::calculate_vector_handle(
420 dst_positions[arc.first()], dst_positions[i_dst_prev]);
421 dst_handles_r[arc.last()] = bke::curves::bezier::calculate_vector_handle(
422 dst_positions[arc.last()], dst_positions[i_dst_next]);
423
424 /* Set the values for the inner handles. */
425 const IndexRange middle = arc.drop_front(1).drop_back(1);
426 for (const int i : middle) {
427 dst_handles_r[i] = bke::curves::bezier::calculate_vector_handle(dst_positions[i],
428 dst_positions[i - 1]);
429 dst_handles_l[i] = bke::curves::bezier::calculate_vector_handle(dst_positions[i],
430 dst_positions[i + 1]);
431 }
432 }
433 });
434}
435
437 const IndexMask &curve_selection,
438 const VArray<float> &radius_input,
439 const VArray<int> &counts,
440 const bool limit_radius,
441 const bool use_bezier_mode,
442 const bke::AttributeFilter &attribute_filter)
443{
444 if (src_curves.is_empty()) {
445 return src_curves;
446 }
447 const OffsetIndices src_points_by_curve = src_curves.points_by_curve();
448 const Span<float3> positions = src_curves.positions();
449 const VArraySpan<bool> cyclic{src_curves.cyclic()};
450 const bke::AttributeAccessor src_attributes = src_curves.attributes();
451 IndexMaskMemory memory;
452 const IndexMask unselected = curve_selection.complement(src_curves.curves_range(), memory);
453
455 /* Stores the offset of every result point for every original point.
456 * The extra length is used in order to store an extra zero for every curve. */
457 Array<int> dst_point_offsets(src_curves.points_num() + src_curves.curves_num());
458 calculate_result_offsets(src_points_by_curve,
459 curve_selection,
460 unselected,
461 radius_input,
462 counts,
463 cyclic,
464 dst_curves.offsets_for_write(),
465 dst_point_offsets);
466 const OffsetIndices dst_points_by_curve = dst_curves.points_by_curve();
467 const Span<int> all_point_offsets = dst_point_offsets.as_span();
468
469 dst_curves.resize(dst_curves.offsets().last(), dst_curves.curves_num());
470 bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write();
471 MutableSpan<float3> dst_positions = dst_curves.positions_for_write();
472
473 VArraySpan<int8_t> src_types_l;
474 VArraySpan<int8_t> src_types_r;
475 Span<float3> src_handles_l;
476 Span<float3> src_handles_r;
477 MutableSpan<int8_t> dst_types_l;
478 MutableSpan<int8_t> dst_types_r;
479 MutableSpan<float3> dst_handles_l;
480 MutableSpan<float3> dst_handles_r;
481 if (src_curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
482 src_types_l = src_curves.handle_types_left();
483 src_types_r = src_curves.handle_types_right();
484 src_handles_l = *src_curves.handle_positions_left();
485 src_handles_r = *src_curves.handle_positions_right();
486
487 dst_types_l = dst_curves.handle_types_left_for_write();
488 dst_types_r = dst_curves.handle_types_right_for_write();
489 dst_handles_l = dst_curves.handle_positions_left_for_write();
490 dst_handles_r = dst_curves.handle_positions_right_for_write();
491 }
492
493 curve_selection.foreach_segment(
494 [&](const IndexMaskSegment segment) {
495 Array<float3> directions;
496 Array<float> angles;
497 Array<float> radii;
498 Array<float> input_radii_buffer;
499
500 for (const int curve_i : segment) {
501 const IndexRange src_points = src_points_by_curve[curve_i];
502 const IndexRange offsets_range = bke::curves::per_curve_point_offsets_range(src_points,
503 curve_i);
504 const OffsetIndices<int> offsets(all_point_offsets.slice(offsets_range));
505 const IndexRange dst_points = dst_points_by_curve[curve_i];
506 const Span<float3> src_positions = positions.slice(src_points);
507
508 directions.reinitialize(src_points.size());
509 calculate_directions(src_positions, directions);
510
511 angles.reinitialize(src_points.size());
512 calculate_angles(directions, angles);
513
514 radii.reinitialize(src_points.size());
515 if (limit_radius) {
516 input_radii_buffer.reinitialize(src_points.size());
517 radius_input.materialize_compressed(src_points, input_radii_buffer);
518 zero_degenerate_radii(directions, angles, input_radii_buffer);
519 limit_radii(src_positions, angles, input_radii_buffer, cyclic[curve_i], radii);
520 }
521 else {
522 radius_input.materialize_compressed(src_points, radii);
523 zero_degenerate_radii(directions, angles, radii);
524 }
525
526 calculate_fillet_positions(positions.slice(src_points),
527 angles,
528 radii,
529 directions,
530 offsets,
531 dst_positions.slice(dst_points));
532
533 if (src_curves.has_curve_with_type(CURVE_TYPE_BEZIER)) {
534 if (use_bezier_mode) {
535 calculate_bezier_handles_bezier_mode(src_handles_l.slice(src_points),
536 src_handles_r.slice(src_points),
537 src_types_l.slice(src_points),
538 src_types_r.slice(src_points),
539 angles,
540 radii,
541 directions,
542 offsets,
543 dst_positions.slice(dst_points),
544 dst_handles_l.slice(dst_points),
545 dst_handles_r.slice(dst_points),
546 dst_types_l.slice(dst_points),
547 dst_types_r.slice(dst_points));
548 }
549 else {
550 calculate_bezier_handles_poly_mode(src_handles_l.slice(src_points),
551 src_handles_r.slice(src_points),
552 src_types_l.slice(src_points),
553 src_types_r.slice(src_points),
554 offsets,
555 dst_positions.slice(dst_points),
556 dst_handles_l.slice(dst_points),
557 dst_handles_r.slice(dst_points),
558 dst_types_l.slice(dst_points),
559 dst_types_r.slice(dst_points));
560 }
561 }
562 }
563 },
565
567 src_attributes,
568 dst_attributes,
571 {"position",
572 "handle_type_left",
573 "handle_type_right",
574 "handle_right",
575 "handle_left"})))
576 {
577 duplicate_fillet_point_data(src_points_by_curve,
578 dst_points_by_curve,
579 curve_selection,
580 all_point_offsets,
581 attribute.src,
582 attribute.dst.span);
583 attribute.dst.finish();
584 }
585
589 attribute_filter,
590 src_points_by_curve,
591 dst_points_by_curve,
592 unselected,
593 dst_attributes);
594 if (src_curves.nurbs_has_custom_knots()) {
597 }
599 return dst_curves;
600}
601
603 const IndexMask &curve_selection,
604 const VArray<float> &radius,
605 const VArray<int> &count,
606 const bool limit_radius,
607 const bke::AttributeFilter &attribute_filter)
608{
609 return fillet_curves(
610 src_curves, curve_selection, radius, count, limit_radius, false, attribute_filter);
611}
612
614 const IndexMask &curve_selection,
615 const VArray<float> &radius,
616 const bool limit_radius,
617 const bke::AttributeFilter &attribute_filter)
618{
619 return fillet_curves(src_curves,
620 curve_selection,
621 radius,
622 VArray<int>::from_single(1, src_curves.points_num()),
624 true,
625 attribute_filter);
626}
627
628} // namespace blender::geometry
Low-level operations for curves.
Low-level operations for curves.
#define M_PI
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
Span< T > as_span() const
Definition BLI_array.hh:254
void reinitialize(const int64_t new_size)
Definition BLI_array.hh:430
GMutableSpan slice(const int64_t start, int64_t size) const
GSpan slice(const int64_t start, int64_t size) const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr IndexRange drop_front(int64_t n) const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
Definition BLI_span.hh:579
constexpr MutableSpan drop_back(const int64_t n) const
Definition BLI_span.hh:624
constexpr T & first() const
Definition BLI_span.hh:685
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr T & last(const int64_t n=0) const
Definition BLI_span.hh:695
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr const T & first() const
Definition BLI_span.hh:319
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
static VArray from_single(T value, const int64_t size)
MutableSpan< int8_t > handle_types_left_for_write()
MutableSpan< float3 > positions_for_write()
MutableSpan< int8_t > handle_types_right_for_write()
std::optional< Span< float3 > > handle_positions_right() const
void resize(int points_num, int curves_num)
VArray< bool > cyclic() const
AttributeAccessor attributes() const
Span< float3 > positions() const
MutableSpan< float3 > handle_positions_right_for_write()
std::optional< Span< float3 > > handle_positions_left() const
IndexRange curves_range() const
VArray< int8_t > handle_types_left() const
MutableSpan< float3 > handle_positions_left_for_write()
bool has_curve_with_type(CurveType type) const
MutableSpan< int > offsets_for_write()
VArray< int8_t > handle_types_right() const
OffsetIndices< int > points_by_curve() const
MutableAttributeAccessor attributes_for_write()
constexpr Span slice(int64_t start, int64_t size) const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
#define FLT_EPSILON
#define position
#define attribute(slot)
float length(VecOp< float, D >) RET
void gather_to_groups(OffsetIndices< int > dst_offsets, const IndexMask &src_selection, GSpan src, GMutableSpan dst)
void update_custom_knot_modes(const IndexMask &mask, const KnotsMode mode_for_regular, const KnotsMode mode_for_cyclic, bke::CurvesGeometry &curves)
bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves)
IndexRange per_curve_point_offsets_range(const IndexRange points, const int curve_index)
auto attribute_filter_with_skip_ref(const AttributeFilter &filter, const Span< StringRef > skip)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
void copy_attributes_group_to_group(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
constexpr ParallelGrainSize grain_size(int grain_size)
static void calculate_bezier_handles_poly_mode(const Span< float3 > src_handles_l, const Span< float3 > src_handles_r, const Span< int8_t > src_types_l, const Span< int8_t > src_types_r, const OffsetIndices< int > dst_offsets, const Span< float3 > dst_positions, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r)
bke::CurvesGeometry fillet_curves_bezier(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius, bool limit_radius, const bke::AttributeFilter &attribute_filter)
static void calculate_result_offsets(const OffsetIndices< int > src_points_by_curve, const IndexMask &selection, const IndexMask &unselected, const VArray< float > &radii, const VArray< int > &counts, const Span< bool > cyclic, MutableSpan< int > dst_curve_offsets, MutableSpan< int > dst_point_offsets)
static HandleType fillet_handle_type(const float3 &position, const float3 &handle, const float3 &other_handle)
static void limit_radii(const Span< float3 > positions, const Span< float > angles, const Span< float > radii, const bool cyclic, MutableSpan< float > radii_clamped)
static void calculate_angles(const Span< float3 > directions, MutableSpan< float > angles)
static float limit_radius(const float3 &position_prev, const float3 &position, const float3 &position_next, const float angle_prev, const float angle, const float angle_next, const float radius_prev, const float radius, const float radius_next)
bke::CurvesGeometry fillet_curves_poly(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius, const VArray< int > &counts, bool limit_radius, const bke::AttributeFilter &attribute_filter)
static void calculate_fillet_positions(const Span< float3 > src_positions, const Span< float > angles, const Span< float > radii, const Span< float3 > directions, const OffsetIndices< int > dst_offsets, MutableSpan< float3 > dst)
static bke::CurvesGeometry fillet_curves(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius_input, const VArray< int > &counts, const bool limit_radius, const bool use_bezier_mode, const bke::AttributeFilter &attribute_filter)
static void calculate_directions(const Span< float3 > positions, MutableSpan< float3 > directions)
static void zero_degenerate_radii(const Span< float3 > directions, const Span< float > angles, MutableSpan< float > radii)
static void calculate_bezier_handles_bezier_mode(const Span< float3 > src_handles_l, const Span< float3 > src_handles_r, const Span< int8_t > src_types_l, const Span< int8_t > src_types_r, const Span< float > angles, const Span< float > radii, const Span< float3 > directions, const OffsetIndices< int > dst_offsets, const Span< float3 > dst_positions, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r)
static void duplicate_fillet_point_data(const OffsetIndices< int > src_points_by_curve, const OffsetIndices< int > dst_points_by_curve, const IndexMask &curve_selection, const Span< int > all_point_offsets, const GSpan src, GMutableSpan dst)
T safe_divide(const T &a, const T &b)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
bool is_zero(const T &a)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void copy_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask, MutableSpan< int > sizes)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:69
void devirtualize_varray(const VArray< T > &varray, const Func &func, bool enable=true)
float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
@ NURBS_KNOT_MODE_NORMAL
VecBase< float, 3 > float3