Blender V5.3
curves_edit.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
9#include "BLI_array_utils.hh"
10
12#include "BKE_attribute.hh"
13#include "BKE_curves.hh"
14#include "BKE_curves_utils.hh"
15#include "BKE_deform.hh"
16
17#include "GEO_reorder.hh"
18
19#include "ED_curves.hh"
20
21namespace blender::ed::curves {
22
24{
25 const bke::AttributeAccessor attributes = curves.attributes();
26 const VArray<bool> selection = *attributes.lookup_or_default<bool>(
27 ".selection", selection_domain, true);
28 const int domain_size_orig = attributes.domain_size(selection_domain);
29 IndexMaskMemory memory;
30 const IndexMask mask = IndexMask::from_bools(selection, memory);
31 switch (selection_domain) {
33 curves.remove_points(mask, {});
34 break;
36 curves.remove_curves(mask, {});
37 break;
38 default:
40 }
41
42 return attributes.domain_size(selection_domain) != domain_size_orig;
43}
44
45static void curve_offsets_from_selection(const Span<IndexRange> selected_points,
46 const IndexRange points,
47 const int curve,
48 const bool cyclic,
49 Vector<int> &r_new_curve_offsets,
50 Vector<bool> &r_new_cyclic,
51 Vector<IndexRange> &r_src_ranges,
52 Vector<int> &r_dst_offsets,
53 Vector<int> &r_dst_to_src_curve)
54{
55 if (selected_points.is_empty()) {
56 return;
57 }
58 const bool merge_loop = cyclic && selected_points.first().size() < points.size() &&
59 selected_points.first().first() == points.first() &&
60 selected_points.last().last() == points.last();
61
62 int last_dst_offset = r_dst_offsets.last();
63 int last_curve_offset = r_new_curve_offsets.last();
64 for (const IndexRange range : selected_points.drop_front(merge_loop)) {
65 r_src_ranges.append(range);
66 last_dst_offset += range.size();
67 r_dst_offsets.append(last_dst_offset);
68 last_curve_offset += range.size();
69 r_new_curve_offsets.append(last_curve_offset);
70 };
71 if (merge_loop) {
72 const IndexRange merge_to_end = selected_points.first();
73 r_src_ranges.append(merge_to_end);
74 r_dst_offsets.append(last_dst_offset + merge_to_end.size());
75 r_new_curve_offsets.last() += merge_to_end.size();
76 }
77 const int curves_added = selected_points.size() - merge_loop;
78 r_dst_to_src_curve.append_n_times(curve, curves_added);
79 r_new_cyclic.append_n_times(cyclic && selected_points.first().size() == points.size(),
80 curves_added);
81}
82
83static void append_point_knots(const Span<IndexRange> src_ranges,
84 const OffsetIndices<int> dst_offsets,
85 const Span<int> dst_to_src_curve,
86 const bke::CurvesGeometry &src_curves,
88{
89 curves.nurbs_custom_knots_update_size();
90
91 const Span<int> src_points_by_curve = src_curves.points_by_curve().data();
92 const Span<int> src_knots_by_curve = src_curves.nurbs_custom_knots_by_curve().data();
93 const VArray<int8_t> src_orders = src_curves.nurbs_orders();
94 const VArray<int8_t> knot_modes = curves.nurbs_knots_modes();
95 const OffsetIndices<int> points_by_curve = curves.points_by_curve();
96 const OffsetIndices<int> knots_by_curve = curves.nurbs_custom_knots_by_curve();
97 MutableSpan<float> dst_knots = curves.nurbs_custom_knots_for_write();
98 /* Source knots must be defined after destination knots, because when `src_curves` == `curves`
99 * call to `nurbs_custom_knots_for_write()` might invalidate the result of previously called
100 * `nurbs_custom_knots()`. */
101 const Span<float> src_knots = src_curves.nurbs_custom_knots();
102
103 const int old_curves_num = curves.curves_num() - dst_to_src_curve.size();
104
105 int range = 0;
106 for (const int appended_curve : dst_to_src_curve.index_range()) {
107 const int dst_curve = appended_curve + old_curves_num;
108 if (knot_modes[dst_curve] != NURBS_KNOT_MODE_CUSTOM) {
109 range++;
110 continue;
111 }
112 const int src_curve = dst_to_src_curve[appended_curve];
113 const int order = src_orders[src_curve];
114 const int first_curve_point = src_points_by_curve[src_curve];
115 const int first_curve_knot = src_knots_by_curve[src_curve];
116 const int point_to_knot = -first_curve_point + first_curve_knot;
117 const IndexRange src_range = src_ranges[range];
118 const IndexRange src_knot_range = IndexRange::from_begin_size(
119 src_range.first() + point_to_knot, src_range.size() + order);
120 const IndexRange dst_knot_range = knots_by_curve[dst_curve];
121 dst_knots.slice(dst_knot_range.take_front(src_knot_range.size()))
122 .copy_from(src_knots.slice(src_knot_range));
123 if (dst_offsets[range].size() != points_by_curve[dst_curve].size()) {
124 range++;
125 const IndexRange merged_tail = src_ranges[range];
126 const IndexRange src_tail_knots = merged_tail.shift(point_to_knot + order);
127 const IndexRange dst_tail_knots = dst_knot_range.take_back(src_tail_knots.size());
128 const float knot_shift = dst_knots[dst_tail_knots.one_before_start()] -
129 src_knots[src_tail_knots.one_before_start()];
130 for (const int i : src_tail_knots.index_range()) {
131 dst_knots[dst_tail_knots[i]] = src_knots[src_tail_knots[i]] + knot_shift;
132 }
133 }
134 range++;
135 }
136}
137
139{
140 if (curves.is_empty()) {
141 return;
142 }
143 const OffsetIndices<int> points_by_curve = curves.points_by_curve();
144 const VArray<bool> src_cyclic = curves.cyclic();
145
146 Vector<int> dst_to_src_curve;
147 Vector<int> new_curve_offsets({points_by_curve.data().last()});
148 Vector<IndexRange> src_ranges;
149 Vector<int> dst_offsets({0});
150 Vector<bool> dst_cyclic;
151 dst_to_src_curve.reserve(curves.curves_num());
152 new_curve_offsets.reserve(curves.curves_num() + 1);
153 src_ranges.reserve(curves.curves_num());
154 dst_offsets.reserve(curves.curves_num() + 1);
155 dst_cyclic.reserve(curves.curves_num());
156
157 /* Add the duplicated curves and points. */
159 mask,
160 points_by_curve,
161 [&](const int curve, const IndexRange points, Span<IndexRange> ranges_to_duplicate) {
162 curve_offsets_from_selection(ranges_to_duplicate,
163 points,
164 curve,
165 src_cyclic[curve],
166 new_curve_offsets,
167 dst_cyclic,
168 src_ranges,
169 dst_offsets,
170 dst_to_src_curve);
171 });
172
173 const int old_curves_num = curves.curves_num();
174 const int old_points_num = curves.points_num();
175 const int num_curves_to_add = dst_to_src_curve.size();
176 const int num_points_to_add = mask.size();
177
178 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
179
180 /* Delete selection attribute so that it will not have to be resized. */
181 remove_selection_attributes(attributes);
182
183 curves.resize(old_points_num + num_points_to_add, old_curves_num + num_curves_to_add);
184
185 array_utils::copy(new_curve_offsets.as_span(),
186 curves.offsets_for_write().drop_front(old_curves_num));
187
188 /* Transfer curve and point attributes. */
189 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
191 return;
192 }
194 if (!attribute) {
195 return;
196 }
197
198 switch (iter.domain) {
200 if (iter.name == "cyclic") {
201 attribute.finish();
202 return;
203 }
205 attribute.span,
206 dst_to_src_curve,
207 attribute.span.slice(IndexRange(old_curves_num, num_curves_to_add)));
208 break;
209 }
212 src_ranges.as_span(),
213 dst_offsets.as_span(),
214 attribute.span,
215 attribute.span.slice(IndexRange(old_points_num, num_points_to_add)));
216 break;
217 }
218 default: {
219 attribute.finish();
221 return;
222 }
223 }
224
225 attribute.finish();
226 });
227
228 if (!(src_cyclic.is_single() && !src_cyclic.get_internal_single())) {
229 array_utils::copy(dst_cyclic.as_span(), curves.cyclic_for_write().drop_front(old_curves_num));
230 }
231
232 curves.update_curve_types();
233 curves.tag_topology_changed();
234
235 if (curves.nurbs_has_custom_knots()) {
236 append_point_knots(src_ranges, dst_offsets.as_span(), dst_to_src_curve, curves, curves);
237 }
238
239 for (const StringRef selection_name : get_curves_selection_attribute_names(curves)) {
241 selection_name, bke::AttrDomain::Point);
242 selection.span.take_back(num_points_to_add).fill(true);
243 selection.finish();
244 }
245}
246
248{
249 curves.nurbs_custom_knots_update_size();
250 const int old_curves_num = curves.curves_num() - mask.size();
252}
253
255{
256 const int orig_points_num = curves.points_num();
257 const int orig_curves_num = curves.curves_num();
258 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
259
260 /* Delete selection attribute so that it will not have to be resized. */
261 remove_selection_attributes(attributes);
262
263 /* Resize the curves and copy the offsets of duplicated curves into the new offsets. */
264 curves.resize(curves.points_num(), orig_curves_num + mask.size());
265 const IndexRange orig_curves_range = curves.curves_range().take_front(orig_curves_num);
266 const IndexRange new_curves_range = curves.curves_range().drop_front(orig_curves_num);
267
268 MutableSpan<int> offset_data = curves.offsets_for_write();
270 OffsetIndices<int>(offset_data.take_front(orig_curves_num + 1)),
271 mask,
272 orig_points_num,
273 offset_data.drop_front(orig_curves_num));
274 const OffsetIndices<int> points_by_curve = curves.points_by_curve();
275
276 /* Resize the points array to match the new total point count. */
277 curves.resize(points_by_curve.total_size(), curves.curves_num());
278
279 attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
281 return;
282 }
284 switch (iter.domain) {
286 bke::attribute_math::gather_group_to_group(points_by_curve.slice(orig_curves_range),
287 points_by_curve.slice(new_curves_range),
288 mask,
289 attribute.span,
290 attribute.span);
291 break;
293 array_utils::gather(attribute.span, mask, attribute.span.take_back(mask.size()));
294 break;
295 default:
297 return;
298 }
299 attribute.finish();
300 });
301
302 curves.update_curve_types();
303 curves.tag_topology_changed();
304
305 if (curves.nurbs_has_custom_knots()) {
307 }
308
309 for (const StringRef selection_name : get_curves_selection_attribute_names(curves)) {
311 selection_name, bke::AttrDomain::Curve);
312 selection.span.take_back(mask.size()).fill(true);
313 selection.finish();
314 }
315}
316
317static void invert_ranges(const IndexRange universe,
318 const Span<IndexRange> ranges,
320{
321 const bool contains_first = ranges.first().first() == universe.first();
322 const bool contains_last = ranges.last().last() == universe.last();
323 inverted.reinitialize(ranges.size() - 1 + !contains_first + !contains_last);
324
325 int64_t start = contains_first ? ranges.first().one_after_last() : universe.first();
326 int i = 0;
327 for (const IndexRange range : ranges.drop_front(contains_first)) {
328 inverted[i++] = IndexRange::from_begin_end(start, range.first());
329 start = range.one_after_last();
330 }
331 if (!contains_last) {
332 inverted.last() = IndexRange::from_begin_end(start, universe.one_after_last());
333 }
334}
335
336static IndexRange extend_range(const IndexRange range, const IndexRange universe)
337{
338 return IndexRange::from_begin_end_inclusive(math::max(range.start() - 1, universe.start()),
339 math::min(range.one_after_last(), universe.last()));
340}
341
347 const bool cyclic,
348 const Span<IndexRange> ranges,
349 Vector<IndexRange> &extended_ranges)
350{
351 extended_ranges.clear();
352 if (ranges.is_empty()) {
353 return;
354 }
355
356 const bool first_match = ranges.first().first() == universe.first();
357 const bool last_match = ranges.last().last() == universe.last();
358 const bool add_first = cyclic && last_match && !first_match;
359 const bool add_last = cyclic && first_match && !last_match;
360
361 IndexRange current = add_first ? IndexRange::from_single(universe.first()) :
362 extend_range(ranges.first(), universe);
363 for (const IndexRange range : ranges.drop_front(!add_first)) {
364 const IndexRange extended = extend_range(range, universe);
365 if (extended.first() <= current.last()) {
366 current = IndexRange::from_begin_end_inclusive(current.start(), extended.last());
367 }
368 else {
369 extended_ranges.append(current);
370 current = extended;
371 }
372 }
373 extended_ranges.append(current);
374 if (add_last) {
375 extended_ranges.append(IndexRange::from_single(universe.last()));
376 }
377}
378
380 const Span<int> dst_to_src_curve,
381 const Span<int> offsets,
382 const Span<bool> cyclic,
383 const Span<IndexRange> src_ranges,
384 const OffsetIndices<int> dst_offsets)
385{
386 bke::CurvesGeometry dst_curves(offsets.last(), dst_to_src_curve.size());
388
389 if (!dst_curves.is_empty()) {
390 array_utils::copy(offsets, dst_curves.offsets_for_write());
391 }
392 dst_curves.cyclic_for_write().copy_from(cyclic);
393
394 const bke::AttributeAccessor src_attributes = src_curves.attributes();
395 bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write();
396
397 bke::gather_attributes(src_attributes,
401 dst_to_src_curve,
402 dst_attributes);
403
405 src_attributes,
406 dst_attributes,
410 {
412 src_ranges, dst_offsets, attribute.src, attribute.dst.span);
413 attribute.dst.finish();
414 };
415
416 dst_curves.update_curve_types();
417
418 if (src_curves.nurbs_has_custom_knots()) {
419 append_point_knots(src_ranges, dst_offsets, dst_to_src_curve, src_curves, dst_curves);
420 }
421 return dst_curves;
422}
423
425 const IndexMask &points_to_split)
426{
427 const OffsetIndices points_by_curve = curves.points_by_curve();
428 const VArray<bool> cyclic = curves.cyclic();
429
430 Vector<int> curve_map;
431 Vector<int> new_offsets({0});
432
433 Vector<IndexRange> src_ranges;
434 Vector<int> dst_offsets({0});
435 Vector<bool> new_cyclic;
436
437 Vector<IndexRange> deselect;
438
439 Array<IndexRange> unselected_curve_points;
440 Vector<IndexRange> curve_points_to_preserve;
441
443 points_to_split,
444 points_by_curve,
445 [&](const int curve, const IndexRange points, const Span<IndexRange> selected_curve_points) {
446 curve_offsets_from_selection(selected_curve_points,
447 points,
448 curve,
449 cyclic[curve],
450 new_offsets,
451 new_cyclic,
452 src_ranges,
453 dst_offsets,
454 curve_map);
455 /* Invert ranges to get non selected points. */
456 invert_ranges(points, selected_curve_points, unselected_curve_points);
457 /* Extended every range to left and right by one point. Any resulting intersection is
458 * merged. */
460 points, cyclic[curve], unselected_curve_points, curve_points_to_preserve);
461 const int size_before = curve_map.size();
462 /* Unselected part can contain all points from original curve, but have cuts. This happens
463 * when pairs of adjacent points are selected. To prevent loop merge and result curve from
464 * cyclic additional condition is checked. */
465 const bool can_merge_loop = !unselected_curve_points.is_empty() &&
466 (unselected_curve_points.first().first() == points.first() ||
467 unselected_curve_points.last().last() == points.last());
468 curve_offsets_from_selection(curve_points_to_preserve,
469 points,
470 curve,
471 cyclic[curve] && can_merge_loop,
472 new_offsets,
473 new_cyclic,
474 src_ranges,
475 dst_offsets,
476 curve_map);
477 deselect.append(IndexRange::from_begin_end(size_before, curve_map.size()));
478 },
479 [&](const IndexRange curves, const IndexRange /*unselected_points*/) {
480 deselect.append(IndexRange::from_begin_size(curve_map.size(), curves.size()));
481 int last_offset = new_offsets.last();
482 int last_dst_offset = dst_offsets.last();
483 for (const int curve : curves) {
484 /* Point ranges to `src_ranges` and `dst_offsets` have to be appended curve by curve to
485 * ease custom knots copying. It gives better mapping between `src_ranges` and
486 * `curve_map`. */
487 const IndexRange points = points_by_curve[curve];
488 src_ranges.append(points);
489 last_dst_offset += points.size();
490 dst_offsets.append(last_dst_offset);
491
492 last_offset += points.size();
493 new_offsets.append(last_offset);
494 curve_map.append(curve);
495 new_cyclic.append(cyclic[curve]);
496 }
497 });
498
500 curves, curve_map, new_offsets, new_cyclic, src_ranges, dst_offsets.as_span());
501
502 const OffsetIndices<int> new_points_by_curve = new_curves.points_by_curve();
504 new_curves, bke::AttrDomain::Point, [&](bke::GSpanAttributeWriter &selection) {
505 for (const IndexRange curves : deselect) {
506 for (const int curve : curves) {
507 fill_selection_false(selection.span.slice(new_points_by_curve[curve]));
508 }
509 }
510 });
511
512 return new_curves;
513}
514
516 const IndexMask &points_to_separate,
517 bke::CurvesGeometry &separated,
518 bke::CurvesGeometry &retained)
519{
520 const OffsetIndices points_by_curve = curves.points_by_curve();
521 const VArray<bool> cyclic = curves.cyclic();
522
523 Vector<int> separated_curve_map;
524 Vector<int> separated_offsets({0});
525 Vector<IndexRange> separated_src_ranges;
526 Vector<int> separated_dst_offsets({0});
527 Vector<bool> separated_cyclic;
528
529 Vector<int> retained_curve_map;
530 Vector<int> retained_offsets({0});
531 Vector<IndexRange> retained_src_ranges;
532 Vector<int> retained_dst_offsets({0});
533 Vector<bool> retained_cyclic;
534
535 Array<IndexRange> unselected_curve_points;
536 Vector<IndexRange> curve_points_to_retain;
537
539 points_to_separate,
540 points_by_curve,
541 [&](const int curve, const IndexRange points, const Span<IndexRange> selected_curve_points) {
542 curve_offsets_from_selection(selected_curve_points,
543 points,
544 curve,
545 cyclic[curve],
546 separated_offsets,
547 separated_cyclic,
548 separated_src_ranges,
549 separated_dst_offsets,
550 separated_curve_map);
551 /* Invert ranges to get non selected points. */
552 invert_ranges(points, selected_curve_points, unselected_curve_points);
553 /* Extended every range to left and right by one point. Any resulting intersection is
554 * merged. */
556 points, cyclic[curve], unselected_curve_points, curve_points_to_retain);
557 /* Unselected part can contain all points from original curve, but have cuts. This happens
558 * when pairs of adjacent points are selected. To prevent loop merge and result curve from
559 * cyclic additional condition is checked. */
560 const bool can_merge_loop = !unselected_curve_points.is_empty() &&
561 (unselected_curve_points.first().first() == points.first() ||
562 unselected_curve_points.last().last() == points.last());
563 curve_offsets_from_selection(curve_points_to_retain,
564 points,
565 curve,
566 cyclic[curve] && can_merge_loop,
567 retained_offsets,
568 retained_cyclic,
569 retained_src_ranges,
570 retained_dst_offsets,
571 retained_curve_map);
572 },
573 [&](const IndexRange curves, const IndexRange /*unselected_points*/) {
574 int last_offset = retained_offsets.last();
575 int last_dst_offset = retained_dst_offsets.last();
576 for (const int curve : curves) {
577 /* Point ranges to `retained_src_ranges` and `retained_dst_offsets` have to be appended
578 * curve by curve to ease custom knots copying. It gives better mapping between
579 * `retained_src_ranges` and `retained_curve_map`. */
580 const IndexRange points = points_by_curve[curve];
581 retained_src_ranges.append(points);
582 last_dst_offset += points.size();
583 retained_dst_offsets.append(last_dst_offset);
584
585 last_offset += points.size();
586 retained_offsets.append(last_offset);
587 retained_curve_map.append(curve);
588 retained_cyclic.append(cyclic[curve]);
589 }
590 });
591 {
593 remove_selection_attributes(attributes);
594
595 separated = copy_data_to_geometry(curves,
596 separated_curve_map,
597 separated_offsets,
598 separated_cyclic,
599 separated_src_ranges,
600 separated_dst_offsets.as_span());
601 }
602 {
604 remove_selection_attributes(attributes);
605
606 retained = copy_data_to_geometry(curves,
607 retained_curve_map,
608 retained_offsets,
609 retained_cyclic,
610 retained_src_ranges,
611 retained_dst_offsets.as_span());
612 }
613
615 retained, bke::AttrDomain::Point, [&](bke::GSpanAttributeWriter &selection) {
616 fill_selection_false(selection.span);
617 });
618}
619
621{
622 const int orig_points_num = curves.points_num();
623 const int orig_curves_num = curves.curves_num();
624 curves.resize(orig_points_num, orig_curves_num + new_sizes.size());
625
626 /* Find the final number of points by accumulating the new */
627 MutableSpan<int> new_offsets = curves.offsets_for_write().drop_front(orig_curves_num);
628 new_offsets.drop_back(1).copy_from(new_sizes);
629 offset_indices::accumulate_counts_to_offsets(new_offsets, orig_points_num);
630 /* First, resize the curve domain. */
631 curves.resize(curves.offsets().last(), curves.curves_num());
632
633 /* Initialize new attribute values, since #CurvesGeometry::resize() doesn't do that. */
634 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
636 attributes, bke::AttrDomain::Point, {}, curves.points_range().drop_front(orig_points_num));
638 attributes, bke::AttrDomain::Curve, {}, curves.curves_range().drop_front(orig_curves_num));
639
640 curves.update_curve_types();
641}
642
644 const IndexMask &curves_to_resize,
645 const Span<int> new_sizes)
646{
647 if (curves_to_resize.is_empty()) {
648 return;
649 }
650 BLI_assert(curves_to_resize.size() == new_sizes.size());
652
653 IndexMaskMemory memory;
654 IndexMask curves_to_copy;
655 std::optional<IndexRange> range = curves_to_resize.to_range();
656 /* Check if we need to copy some curves over. Write the new sizes into the offsets. */
657 if (range && curves.curves_range() == *range) {
658 curves_to_copy = {};
659 dst_curves.offsets_for_write().drop_back(1).copy_from(new_sizes);
660 }
661 else {
662 curves_to_copy = curves_to_resize.complement(curves.curves_range(), memory);
664 curves.offsets(), curves_to_copy, dst_curves.offsets_for_write());
665 array_utils::scatter(new_sizes, curves_to_resize, dst_curves.offsets_for_write());
666 }
667 /* Accumulate the sizes written from `new_sizes` into offsets. */
669
670 /* Resize the points domain. */
671 dst_curves.resize(dst_curves.offsets().last(), dst_curves.curves_num());
672
673 /* Copy point attributes and default initialize newly added point ranges. */
674 const OffsetIndices<int> src_offsets = curves.points_by_curve();
675 const OffsetIndices<int> dst_offsets = dst_curves.points_by_curve();
676 const bke::AttributeAccessor src_attributes = curves.attributes();
677 bke::MutableAttributeAccessor dst_attributes = dst_curves.attributes_for_write();
678 src_attributes.foreach_attribute([&](const bke::AttributeIter &iter) {
679 if (iter.domain != bke::AttrDomain::Point) {
680 return;
681 }
682 const GVArray src = *iter.get();
683 const CPPType &type = src.type();
684 const CommonVArrayInfo info = src.common_info();
686 const bke::AttributeInitValue init(GPointer(type, info.data));
687 if (dst_attributes.add(iter.name, iter.domain, iter.data_type, init)) {
688 return;
689 }
690 }
692 iter.name, iter.domain, iter.data_type);
693 if (!dst) {
694 return;
695 }
696 const GVArraySpan src_span(src);
697 curves_to_resize.foreach_index(
698 [&](const int curve_i) {
699 const IndexRange src_points = src_offsets[curve_i];
700 const IndexRange dst_points = dst_offsets[curve_i];
701 if (dst_points.size() < src_points.size()) {
702 const int src_excees = src_points.size() - dst_points.size();
703 dst.span.slice(dst_points).copy_from(src_span.slice(src_points.drop_back(src_excees)));
704 }
705 else {
706 const int dst_excees = dst_points.size() - src_points.size();
707 dst.span.slice(dst_points.drop_back(dst_excees)).copy_from(src_span.slice(src_points));
708 GMutableSpan dst_end_slice = dst.span.slice(dst_points.take_back(dst_excees));
709 type.value_initialize_n(dst_end_slice.data(), dst_end_slice.size());
710 }
711 },
713 array_utils::copy_group_to_group(src_offsets, dst_offsets, curves_to_copy, src_span, dst.span);
714 dst.finish();
715 });
716
717 dst_curves.update_curve_types();
718 if (dst_curves.nurbs_has_custom_knots()) {
721 }
722
723 /* Move the result into `curves`. */
724 curves = std::move(dst_curves);
725 curves.tag_topology_changed();
726}
727
728void reorder_curves(bke::CurvesGeometry &curves, const Span<int> old_by_new_indices_map)
729{
730 curves = blender::geometry::reorder_curves_geometry(curves, old_by_new_indices_map, {});
731}
732
733} // namespace blender::ed::curves
Low-level operations for curves.
Low-level operations for curves.
support for deformation groups and hooks.
#define BLI_assert_unreachable()
const T & last(const int64_t n=0) const
Definition BLI_array.hh:307
const T & first() const
Definition BLI_array.hh:292
bool is_empty() const
Definition BLI_array.hh:275
void value_initialize_n(void *ptr, int64_t n) const
void copy_from(GSpan values)
GMutableSpan slice(const int64_t start, int64_t size) const
GPointer()=default
GSpan slice(const int64_t start, int64_t size) const
CommonVArrayInfo common_info() const
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
constexpr int64_t one_before_start() const
constexpr int64_t first() const
constexpr int64_t one_after_last() const
constexpr IndexRange shift(int64_t n) const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
static constexpr IndexRange from_begin_size(const int64_t begin, const int64_t size)
constexpr int64_t start() const
constexpr IndexRange take_back(int64_t n) const
static constexpr IndexRange from_single(const int64_t index)
constexpr IndexRange index_range() const
constexpr IndexRange take_front(int64_t n) const
static constexpr IndexRange from_begin_end_inclusive(const int64_t begin, const int64_t last)
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 MutableSpan drop_front(const int64_t n) const
Definition BLI_span.hh:613
constexpr void copy_from(Span< T > values) const
Definition BLI_span.hh:745
constexpr MutableSpan take_front(const int64_t n) const
Definition BLI_span.hh:635
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:175
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 int64_t size() const
Definition BLI_span.hh:256
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
constexpr bool is_empty() const
Definition BLI_span.hh:264
int64_t size() const
void append(const T &value)
const T & last(const int64_t n=0) const
void reserve(const int64_t min_capacity)
Span< T > as_span() const
void append_n_times(const T &value, const int64_t n)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
int domain_size(const AttrDomain domain) const
std::optional< AttrStorageType > storage_type
GAttributeReader get() const
VArray< int8_t > nurbs_orders() const
Span< float > nurbs_custom_knots() const
void resize(int points_num, int curves_num)
OffsetIndices< int > nurbs_custom_knots_by_curve() const
AttributeAccessor attributes() const
IndexRange curves_range() const
MutableSpan< int > offsets_for_write()
MutableSpan< bool > cyclic_for_write()
OffsetIndices< int > points_by_curve() const
MutableAttributeAccessor attributes_for_write()
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
GSpanAttributeWriter lookup_for_write_span(StringRef name)
std::optional< IndexRange > to_range() const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
OffsetIndices slice(const IndexRange range) const
#define attribute(slot)
ccl_device_inline float3x3 inverted(const float3x3 m)
void gather(const GVArray &src, const IndexMask &indices, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void copy_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void scatter(const Span< T > src, const Span< IndexT > indices, MutableSpan< T > dst, const Mode mode={})
void copy(const GVArray &src, GMutableSpan dst, exec_mode::Mode mode=exec_mode::parallel)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void gather_ranges_to_groups(Span< IndexRange > src_ranges, OffsetIndices< int > dst_offsets, GSpan src, GMutableSpan dst)
void gather_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void gather_custom_knots(const bke::CurvesGeometry &src, const IndexMask &src_curves, int dst_curve_offset, bke::CurvesGeometry &dst)
void update_custom_knot_modes(const IndexMask &mask, const KnotsMode mode_for_regular, const KnotsMode mode_for_cyclic, bke::CurvesGeometry &curves)
void foreach_selected_point_ranges_per_curve(const IndexMask &mask, OffsetIndices< int > points_by_curve, SelectedCallback selected_fn)
bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves)
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void fill_attribute_range_default(MutableAttributeAccessor dst_attributes, AttrDomain domain, const AttributeFilter &attribute_filter, IndexRange range)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
void gather_attributes(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
bool remove_selection(bke::CurvesGeometry &curves, const bke::AttrDomain selection_domain)
static bke::CurvesGeometry copy_data_to_geometry(const bke::CurvesGeometry &src_curves, const Span< int > dst_to_src_curve, const Span< int > offsets, const Span< bool > cyclic, const Span< IndexRange > src_ranges, const OffsetIndices< int > dst_offsets)
void resize_curves(bke::CurvesGeometry &curves, const IndexMask &curves_to_resize, const Span< int > new_sizes)
void remove_selection_attributes(bke::MutableAttributeAccessor &attributes, Span< StringRef > selection_attribute_names)
static void append_point_knots(const Span< IndexRange > src_ranges, const OffsetIndices< int > dst_offsets, const Span< int > dst_to_src_curve, const bke::CurvesGeometry &src_curves, bke::CurvesGeometry &curves)
void duplicate_curves(bke::CurvesGeometry &curves, const IndexMask &mask)
void duplicate_points(bke::CurvesGeometry &curves, const IndexMask &mask)
static IndexRange extend_range(const IndexRange range, const IndexRange universe)
void foreach_selection_attribute_writer(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, FunctionRef< void(bke::GSpanAttributeWriter &selection)> fn)
static void curve_offsets_from_selection(const Span< IndexRange > selected_points, const IndexRange points, const int curve, const bool cyclic, Vector< int > &r_new_curve_offsets, Vector< bool > &r_new_cyclic, Vector< IndexRange > &r_src_ranges, Vector< int > &r_dst_offsets, Vector< int > &r_dst_to_src_curve)
void separate_points(const bke::CurvesGeometry &curves, const IndexMask &points_to_separate, bke::CurvesGeometry &separated, bke::CurvesGeometry &retained)
bke::CurvesGeometry split_points(const bke::CurvesGeometry &curves, const IndexMask &points_to_split)
void fill_selection_false(GMutableSpan selection)
void add_curves(bke::CurvesGeometry &curves, const Span< int > new_sizes)
static void invert_ranges(const IndexRange universe, const Span< IndexRange > ranges, Array< IndexRange > &inverted)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
static void append_curve_knots(const IndexMask &mask, bke::CurvesGeometry &curves)
static void extend_range_by_1_within_bounds(const IndexRange universe, const bool cyclic, const Span< IndexRange > ranges, Vector< IndexRange > &extended_ranges)
void reorder_curves(bke::CurvesGeometry &curves, const Span< int > old_by_new_indices_map)
constexpr ParallelGrainSize grain_size(int grain_size)
bke::CurvesGeometry reorder_curves_geometry(const bke::CurvesGeometry &src_curves, Span< int > old_by_new_map, const bke::AttributeFilter &attribute_filter)
Definition reorder.cc:368
T min(const T &a, const T &b)
T max(const T &a, const T &b)
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)
OffsetIndices< int > gather_selected_offsets(OffsetIndices< int > src_offsets, const IndexMask &selection, int start_offset, MutableSpan< int > dst_offsets)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
@ NURBS_KNOT_MODE_NORMAL
@ NURBS_KNOT_MODE_CUSTOM
void BKE_defgroup_copy_list(ListBaseT< bDeformGroup > *outbase, const ListBaseT< bDeformGroup > *inbase)
Definition deform.cc:75
ListBaseT< struct bDeformGroup > vertex_group_names