Blender V5.3
curves_selection.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#include "BLI_assert.hh"
11#include "BLI_index_mask.hh"
12#include "BLI_lasso_2d.hh"
13#include "BLI_math_geom_c.hh"
14#include "BLI_rect.hh"
15
16#include "BKE_attribute.hh"
17#include "BKE_crazyspace.hh"
18#include "BKE_curves.hh"
19#include "BKE_curves_utils.hh"
20
21#include "ED_curves.hh"
22#include "ED_select_utils.hh"
23#include "ED_view3d.hh"
24#include <optional>
25
26namespace blender::ed::curves {
27
29{
31 const IndexRange curves_range = curves.curves_range();
32 const VArray<int8_t> curve_types = curves.curve_types();
33 const bke::AttributeAccessor attributes = curves.attributes();
34
35 /* Interpolate from points to curves manually as a performance improvement, since we are only
36 * interested in whether any point in each curve is selected. Retrieve meta data since
37 * #lookup_or_default from the attribute API doesn't give the domain of the attribute. */
38 std::optional<bke::AttributeMetaData> meta_data = attributes.lookup_meta_data(".selection");
39 if (meta_data && meta_data->domain == bke::AttrDomain::Point) {
40 /* Avoid the interpolation from interpolating the attribute to the
41 * curve domain by retrieving the point domain values directly. */
42 const VArray<bool> selection = *attributes.lookup_or_default<bool>(
43 ".selection", bke::AttrDomain::Point, true);
44 const VArray<bool> selection_left = *attributes.lookup_or_default<bool>(
45 ".selection_handle_left", bke::AttrDomain::Point, true);
46 const VArray<bool> selection_right = *attributes.lookup_or_default<bool>(
47 ".selection_handle_right", bke::AttrDomain::Point, true);
48
49 if (selection.is_single() && curves.is_single_type(CURVE_TYPE_POLY)) {
50 return selection.get_internal_single() ? IndexMask(curves_range) : IndexMask();
51 }
52
53 const OffsetIndices points_by_curve = curves.points_by_curve();
54 return IndexMask::from_predicate(curves_range, memory, [&](const int64_t curve) {
55 const IndexRange points = points_by_curve[curve];
56 /* The curve is selected if any of its points are selected. */
57 Array<bool, 32> point_selection(points.size());
58 selection.materialize_compressed(points, point_selection);
59 bool is_selected = point_selection.as_span().contains(true);
60 if (curve_types[curve] == CURVE_TYPE_BEZIER) {
61 selection_left.materialize_compressed(points, point_selection);
62 is_selected |= point_selection.as_span().contains(true);
63 selection_right.materialize_compressed(points, point_selection);
64 is_selected |= point_selection.as_span().contains(true);
65 }
66 return is_selected;
67 });
68 }
69 const VArray<bool> selection = *attributes.lookup_or_default<bool>(
70 ".selection", bke::AttrDomain::Curve, true);
71 return IndexMask::from_bools(curves_range, selection, memory);
72}
73
75{
76 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
77 return retrieve_selected_curves(curves, memory);
78}
79
81{
83 *curves.attributes().lookup_or_default<bool>(".selection", bke::AttrDomain::Point, true),
84 memory);
85}
86
88 const int handle_display,
89 LinearAllocator<> &memory)
90{
92 curves, CURVE_TYPE_BEZIER, memory);
93
94 Vector<IndexMask> selection_by_attribute;
96 if (selection_name != ".selection" && handle_display == CURVE_HANDLE_NONE) {
97 continue;
98 }
99
100 selection_by_attribute.append(
101 ed::curves::retrieve_selected_points(curves, selection_name, bezier_points, memory));
102 }
103 return IndexMask::from_union(selection_by_attribute, memory);
104}
105
107 StringRef attribute_name,
108 const IndexMask &bezier_points,
109 LinearAllocator<> &memory)
110{
112 const VArray<bool> selected = *curves.attributes().lookup_or_default<bool>(
113 attribute_name, bke::AttrDomain::Point, true);
114
115 if (attribute_name == ".selection") {
116 return IndexMask::from_bools(selected, memory);
117 }
118
119 return IndexMask::from_bools(bezier_points, selected, memory);
120}
121
123{
124 const bke::CurvesGeometry &curves = curves_id.geometry.wrap();
125 return retrieve_selected_points(curves, memory);
126}
127
129{
130 static const std::array<StringRef, 1> selection_attribute_names{".selection"};
131 return curves.has_curve_with_type(CURVE_TYPE_BEZIER) ?
133 selection_attribute_names;
134}
135
137{
138 static const std::array<StringRef, 3> selection_attribute_names{
139 ".selection", ".selection_handle_left", ".selection_handle_right"};
140 return selection_attribute_names;
141}
142
144{
145 static const std::array<StringRef, 2> selection_attribute_names{".selection_handle_left",
146 ".selection_handle_right"};
147 const bke::AttributeAccessor attributes = curves.attributes();
148 return (attributes.contains("handle_type_left") && attributes.contains("handle_type_right")) ?
149 selection_attribute_names :
151}
152
154 Span<StringRef> selection_attribute_names)
155{
156 for (const StringRef selection_name : selection_attribute_names) {
157 attributes.remove(selection_name);
158 }
159}
160
161std::optional<Span<float3>> get_selection_attribute_positions(
163 const bke::crazyspace::GeometryDeformation &deformation,
164 const StringRef attribute_name)
165{
166 if (attribute_name == ".selection") {
167 return deformation.positions;
168 }
169 if (attribute_name == ".selection_handle_left") {
170 return curves.handle_positions_left();
171 }
172 if (attribute_name == ".selection_handle_right") {
173 return curves.handle_positions_right();
174 }
176 return {};
177}
178
180 bke::AttrDomain selection_domain)
181{
182 const bke::AttrType create_type = bke::AttrType::Bool;
185 for (const int i : selection_attribute_names.index_range()) {
187 curves, selection_domain, create_type, selection_attribute_names[i]));
188 };
189 return writers;
190}
191
193{
194 for (auto &attribute_writer : attribute_writers) {
195 attribute_writer.finish();
196 }
197}
198
200 MutableSpan<bke::GSpanAttributeWriter> selections, StringRef attribute_name)
201{
202 Span<StringRef> selection_attribute_names = get_curves_all_selection_attribute_names();
203
204 BLI_assert(selection_attribute_names.contains(attribute_name));
205
206 for (const int index : selections.index_range()) {
207 if (attribute_name.size() == selection_attribute_names[index].size()) {
208 return selections[index];
209 }
210 }
212 return selections[0];
213}
214
216 bke::AttrDomain selection_domain,
217 FunctionRef<void(bke::GSpanAttributeWriter &selection)> fn)
218{
220 selection_domain);
221 for (bke::GSpanAttributeWriter &selection_writer : selection_writers) {
222 fn(selection_writer);
223 }
224 finish_attribute_writers(selection_writers);
225}
226
229 const bke::crazyspace::GeometryDeformation &deformation,
230 eHandleDisplay handle_display,
231 Span<StringRef> &r_bezier_attribute_names,
232 Span<float3> &r_positions,
233 std::optional<std::array<Span<float3>, 2>> &r_bezier_handle_positions,
234 IndexMaskMemory &r_memory,
235 IndexMask &r_bezier_curves)
236{
237 r_bezier_attribute_names = get_curves_bezier_selection_attribute_names(curves);
238 r_positions = deformation.positions;
239 if (handle_display != eHandleDisplay::CURVE_HANDLE_NONE && r_bezier_attribute_names.size() > 0) {
240 r_bezier_handle_positions = {*curves.handle_positions_left(),
241 *curves.handle_positions_right()};
242 r_bezier_curves = curves.indices_for_curve_type(CURVE_TYPE_BEZIER, r_memory);
243 }
244 else {
245 r_bezier_handle_positions = std::nullopt;
246 }
247}
248
250 const bke::crazyspace::GeometryDeformation &deformation,
251 eHandleDisplay handle_display,
252 SelectionRangeFn range_consumer)
253{
254 Span<StringRef> bezier_attribute_names;
255 Span<float3> positions;
256 std::optional<std::array<Span<float3>, 2>> bezier_handle_positions;
257 IndexMaskMemory memory;
258 IndexMask bezier_curves;
260 deformation,
261 handle_display,
262 bezier_attribute_names,
263 positions,
264 bezier_handle_positions,
265 memory,
266 bezier_curves);
267
268 range_consumer(curves.points_range(), positions, ".selection");
269
270 if (handle_display == eHandleDisplay::CURVE_HANDLE_NONE) {
271 return;
272 }
273
274 OffsetIndices<int> points_by_curve = curves.points_by_curve();
275 for (const int attribute_i : bezier_attribute_names.index_range()) {
276 bezier_curves.foreach_index(
277 [&](const int64_t curve) {
278 range_consumer(points_by_curve[curve],
279 (*bezier_handle_positions)[attribute_i],
280 bezier_attribute_names[attribute_i]);
281 },
283 }
284}
285
287 const bke::crazyspace::GeometryDeformation &deformation,
288 eHandleDisplay handle_display,
289 SelectionRangeFn range_consumer)
290{
291 Span<StringRef> bezier_attribute_names;
292 Span<float3> positions;
293 std::optional<std::array<Span<float3>, 2>> bezier_handle_positions;
294 IndexMaskMemory memory;
295 IndexMask bezier_curves;
297 deformation,
298 handle_display,
299 bezier_attribute_names,
300 positions,
301 bezier_handle_positions,
302 memory,
303 bezier_curves);
304
305 range_consumer(curves.curves_range(), positions, ".selection");
306 if (handle_display == eHandleDisplay::CURVE_HANDLE_NONE) {
307 return;
308 }
309
310 for (const int attribute_i : bezier_attribute_names.index_range()) {
311 bezier_curves.foreach_range([&](const IndexRange curves_range) {
312 range_consumer(curves_range,
313 (*bezier_handle_positions)[attribute_i],
314 bezier_attribute_names[attribute_i]);
315 });
316 }
317}
318
320 bke::AttrDomain selection_domain,
321 bke::AttrType create_type,
322 StringRef attribute_name)
323{
324 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
325 if (attributes.contains(attribute_name)) {
326 bke::GSpanAttributeWriter selection_attr = attributes.lookup_for_write_span(attribute_name);
327 /* Check domain type. */
328 if (selection_attr.domain == selection_domain) {
329 return selection_attr;
330 }
331 selection_attr.finish();
332 attributes.remove(attribute_name);
333 }
334 switch (create_type) {
336 attributes.add(
337 attribute_name, selection_domain, bke::AttrType::Bool, bke::AttributeInitValue(true));
338 break;
340 attributes.add(
341 attribute_name, selection_domain, bke::AttrType::Float, bke::AttributeInitValue(1.0f));
342 break;
343 default:
345 }
346 return attributes.lookup_for_write_span(attribute_name);
347}
348
350{
351 if (selection.type().is<bool>()) {
352 selection.typed<bool>().fill(false);
353 }
354 else if (selection.type().is<float>()) {
355 selection.typed<float>().fill(0.0f);
356 }
357}
358
360{
361 if (selection.type().is<bool>()) {
362 selection.typed<bool>().fill(true);
363 }
364 else if (selection.type().is<float>()) {
365 selection.typed<float>().fill(1.0f);
366 }
367}
368
369void fill_selection(GMutableSpan selection, bool value)
370{
371 if (selection.type().is<bool>()) {
372 selection.typed<bool>().fill(value);
373 }
374 else if (selection.type().is<float>()) {
375 selection.typed<float>().fill(value ? 1.0f : 0.0f);
376 }
377}
378
380{
381 if (selection.type().is<bool>()) {
382 index_mask::masked_fill(selection.typed<bool>(), false, mask);
383 }
384 else if (selection.type().is<float>()) {
385 index_mask::masked_fill(selection.typed<float>(), 0.0f, mask);
386 }
387}
388
390{
391 if (selection.type().is<bool>()) {
392 index_mask::masked_fill(selection.typed<bool>(), true, mask);
393 }
394 else if (selection.type().is<float>()) {
395 index_mask::masked_fill(selection.typed<float>(), 1.0f, mask);
396 }
397}
398
399bool has_anything_selected(const VArray<bool> &varray, const IndexRange range_to_check)
400{
401 return array_utils::contains(varray, range_to_check, true);
402}
403
404bool has_anything_selected(const VArray<bool> &varray, const IndexMask &indices_to_check)
405{
406 return array_utils::contains(varray, indices_to_check, true);
407}
408
410{
411 const VArray<bool> selection = *curves.attributes().lookup<bool>(".selection");
412 return !selection || array_utils::contains(selection, selection.index_range(), true);
413}
414
416{
418 curves, selection_domain, IndexRange(curves.attributes().domain_size(selection_domain)));
419}
420
422 bke::AttrDomain selection_domain,
423 const IndexMask &mask)
424{
425 for (const StringRef selection_name : get_curves_selection_attribute_names(curves)) {
426 const VArray<bool> selection = *curves.attributes().lookup<bool>(selection_name,
427 selection_domain);
428 if (!selection || array_utils::contains(selection, mask, true)) {
429 return true;
430 }
431 }
432 return false;
433}
434
435bool has_anything_selected(const GSpan selection)
436{
437 if (selection.type().is<bool>()) {
438 return selection.typed<bool>().contains(true);
439 }
440 if (selection.type().is<float>()) {
441 for (const float elem : selection.typed<float>()) {
442 if (elem > 0.0f) {
443 return true;
444 }
445 }
446 }
447 return false;
448}
449
450static void invert_selection(MutableSpan<float> selection, const IndexMask &mask)
451{
452 mask.foreach_index_optimized<int64_t>(
453 [&](const int64_t i) { selection[i] = 1.0f - selection[i]; }, exec_mode::grain_size(4096));
454}
455
456static void invert_selection(GMutableSpan selection, const IndexMask &mask)
457{
458 if (selection.type().is<bool>()) {
459 array_utils::invert_booleans(selection.typed<bool>(), mask);
460 }
461 else if (selection.type().is<float>()) {
462 invert_selection(selection.typed<float>(), mask);
463 }
464}
465
466static void invert_selection(GMutableSpan selection)
467{
468 invert_selection(selection, IndexRange(selection.size()));
469}
470
472 const IndexMask &mask,
473 const bke::AttrDomain selection_domain,
474 int action)
475{
476 if (action == SEL_SELECT) {
477 std::optional<IndexRange> range = mask.to_range();
478 if (range.has_value() &&
479 (*range == IndexRange(curves.attributes().domain_size(selection_domain))))
480 {
481 bke::MutableAttributeAccessor attributes = curves.attributes_for_write();
482 /* As an optimization, just remove the selection attributes when everything is selected. */
483 remove_selection_attributes(attributes);
484 return;
485 }
486 }
488 curves, selection_domain, [&](bke::GSpanAttributeWriter &selection) {
489 if (action == SEL_SELECT) {
490 fill_selection_true(selection.span, mask);
491 }
492 else if (action == SEL_DESELECT) {
493 fill_selection_false(selection.span, mask);
494 }
495 else if (action == SEL_INVERT) {
496 invert_selection(selection.span, mask);
497 }
498 });
499}
500
501void select_all(bke::CurvesGeometry &curves, const bke::AttrDomain selection_domain, int action)
502{
503 const IndexRange selection(curves.attributes().domain_size(selection_domain));
504 select_all(curves, selection, selection_domain, action);
505}
506
507static bool is_everything_selected(GMutableSpan &selection_curve)
508{
509 if (selection_curve.type().is<bool>()) {
510 return !selection_curve.typed<bool>().contains(false);
511 }
512
513 if (selection_curve.type().is<float>()) {
514 return !selection_curve.typed<float>().contains(0.0f);
515 }
516
517 return false;
518}
519
520void select_linked(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool unselect)
521{
522 const OffsetIndices points_by_curve = curves.points_by_curve();
523 const VArray<int8_t> curve_types = curves.curve_types();
524 const IndexRange all_writers = get_curves_all_selection_attribute_names().index_range();
525 const IndexRange selection_writer = IndexRange(1);
526
529
530 curves_mask.foreach_index(
531 [&](const int64_t curve) {
532 /* For Bezier curves check all three selection layers ".selection",
533 * ".selection_handle_left",
534 * ".selection_handle_right". For other curves only ".selection". */
535 const IndexRange curve_writers = curve_types[curve] == CURVE_TYPE_BEZIER ?
536 all_writers :
537 selection_writer;
538 const IndexRange points = points_by_curve[curve];
539 for (const int i : curve_writers) {
540 bke::GSpanAttributeWriter &selection = selection_writers[i];
541 GMutableSpan selection_curve = selection.span.slice(points);
542
543 const bool all_points_selected = is_everything_selected(selection_curve);
544 if (has_anything_selected(selection_curve)) {
545 if (unselect == all_points_selected) {
546 fill_selection(selection_curve, !unselect);
547 }
548
549 for (const int j : curve_writers) {
550 if (j == i) {
551 continue;
552 }
553 if (unselect == all_points_selected) {
554 fill_selection(selection_curve, !unselect);
555 }
556 }
557 return;
558 }
559 }
560 },
562 finish_attribute_writers(selection_writers);
563}
564
565void select_linked(bke::CurvesGeometry &curves, const bool unselect)
566{
567 select_linked(curves, curves.curves_range(), unselect);
568}
569
571 const IndexMask &curves_mask,
572 const bool deselect_ends)
573{
575 return;
576 }
577
578 const OffsetIndices points_by_curve = curves.points_by_curve();
579 const VArray<bool> cyclic = curves.cyclic();
582
583 curves_mask.foreach_index([&](const int64_t curve) {
584 const IndexRange points = points_by_curve[curve];
585
586 bool anything_selected = false;
587
588 for (bke::GSpanAttributeWriter &writer : selection_writers) {
589 const bool writer_has_anything_selected = has_anything_selected(writer.span.slice(points));
590 anything_selected = anything_selected || writer_has_anything_selected;
591 }
592 if (!anything_selected) {
593 return;
594 }
595
596 for (bke::GSpanAttributeWriter &writer : selection_writers) {
597 MutableSpan<bool> selection_typed = writer.span.typed<bool>();
598
599 const int half_of_size = points.size() / 2;
600 const IndexRange selected = points.shift(deselect_ends ? 1 : 0);
601 const IndexRange deselected = points.shift(deselect_ends ? 0 : 1);
602 for (const int i : IndexRange(half_of_size)) {
603 const int index = i * 2;
604 selection_typed[selected[index]] = true;
605 selection_typed[deselected[index]] = false;
606 }
607
608 selection_typed[points.first()] = !deselect_ends;
609 const bool end_parity_to_selected = bool(points.size() % 2);
610 const bool selected_end = cyclic[curve] || end_parity_to_selected;
611 selection_typed[points.last()] = !deselect_ends && selected_end;
612 /* Selected last one require to deselect pre-last one point which is not first. */
613 const IndexRange curve_body = points.drop_front(1).drop_back(1);
614 if (!deselect_ends && cyclic[curve] && !curve_body.is_empty()) {
615 selection_typed[curve_body.last()] = false;
616 }
617 }
618 });
619
620 finish_attribute_writers(selection_writers);
621}
622
623void select_alternate(bke::CurvesGeometry &curves, const bool deselect_ends)
624{
625 select_alternate(curves, curves.curves_range(), deselect_ends);
626}
627
629 const IndexMask &curves_mask,
630 const bool deselect)
631{
632 const OffsetIndices points_by_curve = curves.points_by_curve();
635 const VArray<bool> cyclic = curves.cyclic();
636
637 if (deselect) {
638 invert_selection(selection.span);
639 }
640
641 if (selection.span.type().is<bool>()) {
642 MutableSpan<bool> selection_typed = selection.span.typed<bool>();
643 curves_mask.foreach_index([&](const int64_t curve) {
644 const IndexRange points = points_by_curve[curve];
645 const int first_point = points.first();
646 const int last_point = points.last();
647
648 /* Handle all cases in the forward direction. */
649 for (int point = first_point; point < last_point; point++) {
650 if (!selection_typed[point] && selection_typed[point + 1]) {
651 selection_typed[point] = true;
652 }
653 }
654
655 /* Handle all cases in the backwards direction. */
656 for (int point = last_point; point > first_point; point--) {
657 if (!selection_typed[point] && selection_typed[point - 1]) {
658 selection_typed[point] = true;
659 }
660 }
661 if (deselect) {
662 if (!selection_typed[first_point]) {
663 selection_typed[first_point] = true;
664 }
665 if (!selection_typed[last_point]) {
666 selection_typed[last_point] = true;
667 }
668 }
669 /* Handle cyclic curve case. */
670 if (cyclic[curve]) {
671 if (selection_typed[first_point] != selection_typed[last_point]) {
672 selection_typed[first_point] = true;
673 selection_typed[last_point] = true;
674 }
675 }
676 });
677 }
678 else if (selection.span.type().is<float>()) {
679 MutableSpan<float> selection_typed = selection.span.typed<float>();
680 curves_mask.foreach_index([&](const int64_t curve) {
681 const IndexRange points = points_by_curve[curve];
682 const int first_point = points.first();
683 const int last_point = points.last();
684
685 /* Handle all cases in the forward direction. */
686 for (int point_i = first_point; point_i < last_point; point_i++) {
687 if ((selection_typed[point_i] == 0.0f) && (selection_typed[point_i + 1] > 0.0f)) {
688 selection_typed[point_i] = 1.0f;
689 }
690 }
691
692 /* Handle all cases in the backwards direction. */
693 for (int point_i = last_point; point_i > first_point; point_i--) {
694 if ((selection_typed[point_i] == 0.0f) && (selection_typed[point_i - 1] > 0.0f)) {
695 selection_typed[point_i] = 1.0f;
696 }
697 }
698
699 /* Handle cyclic curve case. */
700 if (cyclic[curve]) {
701 if (selection_typed[first_point] != selection_typed[last_point]) {
702 selection_typed[first_point] = 1.0f;
703 selection_typed[last_point] = 1.0f;
704 }
705 }
706 });
707 }
708
709 if (deselect) {
710 invert_selection(selection.span);
711 }
712
713 selection.finish();
714}
715
716void select_adjacent(bke::CurvesGeometry &curves, const bool deselect)
717{
718 select_adjacent(curves, curves.curves_range(), deselect);
719}
720
722 const int index,
723 const eSelectOp sel_op)
724{
725 if (selection.type().is<bool>()) {
726 MutableSpan<bool> selection_typed = selection.typed<bool>();
727 switch (sel_op) {
728 case SEL_OP_ADD:
729 case SEL_OP_SET:
730 selection_typed[index] = true;
731 break;
732 case SEL_OP_SUB:
733 selection_typed[index] = false;
734 break;
735 case SEL_OP_XOR:
736 selection_typed[index] = !selection_typed[index];
737 break;
738 default:
739 break;
740 }
741 }
742 else if (selection.type().is<float>()) {
743 MutableSpan<float> selection_typed = selection.typed<float>();
744 switch (sel_op) {
745 case SEL_OP_ADD:
746 case SEL_OP_SET:
747 selection_typed[index] = 1.0f;
748 break;
749 case SEL_OP_SUB:
750 selection_typed[index] = 0.0f;
751 break;
752 case SEL_OP_XOR:
753 selection_typed[index] = 1.0f - selection_typed[index];
754 break;
755 default:
756 break;
757 }
758 }
759}
760
762{
763 if (a.distance_sq < b.distance_sq) {
764 return a;
765 }
766 return b;
767}
768
769static std::optional<FindClosestData> find_closest_point_to_screen_co(
770 const ARegion *region,
771 const Span<float3> positions,
772 const float4x4 &projection,
773 const IndexMask &points_mask,
774 const float2 mouse_pos,
775 const float radius,
776 const FindClosestData &initial_closest)
777{
779 const float radius_sq = pow2f(radius);
780 const FindClosestData new_closest_data = threading::parallel_reduce(
781 points_mask.index_range(),
782 1024,
783 initial_closest,
784 [&](const IndexRange range, const FindClosestData &init) {
785 FindClosestData best_match = init;
786 points_mask.slice(range).foreach_index([&](const int point) {
787 const float3 &pos = positions[point];
788 const float2 pos_proj = ED_view3d_project_float_v2_m4(region, pos, projection);
789
790 const float distance_proj_sq = math::distance_squared(pos_proj, mouse_pos);
791 if (distance_proj_sq > radius_sq || distance_proj_sq > best_match.distance_sq) {
792 return;
793 }
794
795 best_match = {point, distance_proj_sq};
796 });
797 return best_match;
798 },
800
801 if (new_closest_data.distance_sq < initial_closest.distance_sq) {
802 return new_closest_data;
803 }
804
805 return {};
806}
807
808static std::optional<FindClosestData> find_closest_curve_to_screen_co(
809 const ARegion *region,
810 const OffsetIndices<int> points_by_curve,
811 const Span<float3> positions,
812 const VArray<bool> &cyclic,
813 const float4x4 &projection,
814 const IndexMask &curves_mask,
815 const float2 mouse_pos,
816 float radius,
817 const FindClosestData &initial_closest)
818{
820 const float radius_sq = pow2f(radius);
821
822 const FindClosestData new_closest_data = threading::parallel_reduce(
823 curves_mask.index_range(),
824 256,
825 initial_closest,
826 [&](const IndexRange range, const FindClosestData &init) {
827 FindClosestData best_match = init;
828 curves_mask.slice(range).foreach_index([&](const int curve) {
829 const IndexRange points = points_by_curve[curve];
830
831 if (points.size() == 1) {
832 const float3 &pos = positions[points.first()];
833 const float2 pos_proj = ED_view3d_project_float_v2_m4(region, pos, projection);
834
835 const float distance_proj_sq = math::distance_squared(pos_proj, mouse_pos);
836 if (distance_proj_sq > radius_sq || distance_proj_sq > best_match.distance_sq) {
837 return;
838 }
839
840 best_match = {curve, distance_proj_sq};
841 return;
842 }
843
844 auto process_segment = [&](const int segment_i, const int next_i) {
845 const float3 &pos1 = positions[segment_i];
846 const float3 &pos2 = positions[next_i];
847 const float2 pos1_proj = ED_view3d_project_float_v2_m4(region, pos1, projection);
848 const float2 pos2_proj = ED_view3d_project_float_v2_m4(region, pos2, projection);
849
850 const float distance_proj_sq = dist_squared_to_line_segment_v2(
851 mouse_pos, pos1_proj, pos2_proj);
852 if (distance_proj_sq > radius_sq || distance_proj_sq > best_match.distance_sq) {
853 return;
854 }
855
856 best_match = {curve, distance_proj_sq};
857 };
858 for (const int segment_i : points.drop_back(1)) {
859 process_segment(segment_i, segment_i + 1);
860 }
861 if (cyclic[curve]) {
862 process_segment(points.last(), points.first());
863 }
864 });
865 return best_match;
866 },
867 closer_elem);
868
869 if (new_closest_data.distance_sq < initial_closest.distance_sq) {
870 return new_closest_data;
871 }
872
873 return {};
874}
875
876std::optional<FindClosestData> closest_elem_find_screen_space(
877 const ViewContext &vc,
878 const OffsetIndices<int> points_by_curve,
879 const Span<float3> positions,
880 const VArray<bool> &cyclic,
881 const float4x4 &projection,
882 const IndexMask &mask,
883 const bke::AttrDomain domain,
884 const int2 coord,
885 const FindClosestData &initial_closest)
886{
887 switch (domain) {
890 positions,
891 projection,
892 mask,
893 float2(coord),
895 initial_closest);
898 points_by_curve,
899 positions,
900 cyclic,
901 projection,
902 mask,
903 float2(coord),
905 initial_closest);
906 default:
908 return {};
909 }
910}
911
912bool select_box(const ViewContext &vc,
914 const bke::crazyspace::GeometryDeformation &deformation,
915 const float4x4 &projection,
916 const IndexMask &selection_mask,
917 const IndexMask &bezier_mask,
918 const bke::AttrDomain selection_domain,
919 const rcti &rect,
920 const eSelectOp sel_op)
921{
923 selection_domain);
924
925 bool changed = false;
926 if (sel_op == SEL_OP_SET) {
927 for (bke::GSpanAttributeWriter &selection : selection_writers) {
928 fill_selection_false(selection.span, selection_mask);
929 };
930 changed = true;
931 }
932
933 if (selection_domain == bke::AttrDomain::Point) {
935 curves,
936 deformation,
938 [&](IndexRange range, Span<float3> positions, StringRef selection_attribute_name) {
939 const IndexMask &mask = (selection_attribute_name == ".selection") ? selection_mask :
940 bezier_mask;
941 mask.slice_content(range).foreach_index(
942 [&](const int point) {
943 const float2 pos_proj = ED_view3d_project_float_v2_m4(
944 vc.region, positions[point], projection);
945 if (BLI_rcti_isect_pt_v(&rect, int2(pos_proj))) {
946 apply_selection_operation_at_index(
947 selection_attribute_writer_by_name(selection_writers,
948 selection_attribute_name)
949 .span,
950 point,
951 sel_op);
952 changed = true;
953 }
954 },
956 });
957 }
958 else if (selection_domain == bke::AttrDomain::Curve) {
959 const OffsetIndices points_by_curve = curves.points_by_curve();
960 const VArray<bool> cyclic = curves.cyclic();
961 foreach_selectable_curve_range(
962 curves,
963 deformation,
964 eHandleDisplay(vc.v3d->overlay.handle_display),
965 [&](const IndexRange range,
966 const Span<float3> positions,
967 StringRef /* selection_attribute_name */) {
968 const IndexMask &mask = selection_mask;
969 mask.slice_content(range).foreach_index(
970 [&](const int curve) {
971 const IndexRange points = points_by_curve[curve];
972 if (points.size() == 1) {
973 const float2 pos_proj = ED_view3d_project_float_v2_m4(
974 vc.region, positions[points.first()], projection);
975 if (BLI_rcti_isect_pt_v(&rect, int2(pos_proj))) {
976 for (bke::GSpanAttributeWriter &selection : selection_writers) {
977 apply_selection_operation_at_index(selection.span, curve, sel_op);
978 };
979 changed = true;
980 }
981 return;
982 }
983 auto process_segment = [&](const int segment_i, const int next_i) {
984 const float3 &pos1 = positions[segment_i];
985 const float3 &pos2 = positions[next_i];
986 const float2 pos1_proj = ED_view3d_project_float_v2_m4(
987 vc.region, pos1, projection);
988 const float2 pos2_proj = ED_view3d_project_float_v2_m4(
989 vc.region, pos2, projection);
990
991 if (BLI_rcti_isect_segment(&rect, int2(pos1_proj), int2(pos2_proj))) {
992 for (bke::GSpanAttributeWriter &selection : selection_writers) {
993 apply_selection_operation_at_index(selection.span, curve, sel_op);
994 };
995 changed = true;
996 return true;
997 }
998 return false;
999 };
1000 bool segment_selected = false;
1001 for (const int segment_i : points.drop_back(1)) {
1002 if (process_segment(segment_i, segment_i + 1)) {
1003 segment_selected = true;
1004 break;
1005 }
1006 }
1007 if (!segment_selected && cyclic[curve]) {
1008 process_segment(points.last(), points.first());
1009 }
1010 },
1012 });
1013 }
1014 finish_attribute_writers(selection_writers);
1015 return changed;
1016}
1017
1020 const bke::crazyspace::GeometryDeformation &deformation,
1021 const float4x4 &projection,
1022 const IndexMask &selection_mask,
1023 const IndexMask &bezier_mask,
1024 const bke::AttrDomain selection_domain,
1025 const Span<int2> lasso_coords,
1026 const eSelectOp sel_op)
1027{
1028 rcti bbox;
1029 BLI_lasso_boundbox(&bbox, lasso_coords);
1031 selection_domain);
1032 bool changed = false;
1033 if (sel_op == SEL_OP_SET) {
1034 for (bke::GSpanAttributeWriter &selection : selection_writers) {
1035 fill_selection_false(selection.span, selection_mask);
1036 };
1037 changed = true;
1038 }
1039
1040 if (selection_domain == bke::AttrDomain::Point) {
1042 curves,
1043 deformation,
1045 [&](IndexRange range, Span<float3> positions, StringRef selection_attribute_name) {
1046 const IndexMask &mask = (selection_attribute_name == ".selection") ? selection_mask :
1047 bezier_mask;
1048 mask.slice_content(range).foreach_index(
1049 [&](const int point) {
1050 const float2 pos_proj = ED_view3d_project_float_v2_m4(
1051 vc.region, positions[point], projection);
1052 /* Check the lasso bounding box first as an optimization. */
1053 if (BLI_rcti_isect_pt_v(&bbox, int2(pos_proj)) &&
1054 BLI_lasso_is_point_inside(
1055 lasso_coords, int(pos_proj.x), int(pos_proj.y), IS_CLIPPED))
1056 {
1057 apply_selection_operation_at_index(
1058 selection_attribute_writer_by_name(selection_writers,
1059 selection_attribute_name)
1060 .span,
1061 point,
1062 sel_op);
1063 changed = true;
1064 }
1065 },
1066 exec_mode::grain_size(1024));
1067 });
1068 }
1069 else if (selection_domain == bke::AttrDomain::Curve) {
1070 const OffsetIndices points_by_curve = curves.points_by_curve();
1071 const VArray<bool> cyclic = curves.cyclic();
1072 foreach_selectable_curve_range(
1073 curves,
1074 deformation,
1075 eHandleDisplay(vc.v3d->overlay.handle_display),
1076 [&](const IndexRange range,
1077 const Span<float3> positions,
1078 StringRef /* selection_attribute_name */) {
1079 const IndexMask &mask = selection_mask;
1080 mask.slice_content(range).foreach_index(
1081 [&](const int curve) {
1082 const IndexRange points = points_by_curve[curve];
1083 if (points.size() == 1) {
1084 const float2 pos_proj = ED_view3d_project_float_v2_m4(
1085 vc.region, positions[points.first()], projection);
1086 /* Check the lasso bounding box first as an optimization. */
1087 if (BLI_rcti_isect_pt_v(&bbox, int2(pos_proj)) &&
1088 BLI_lasso_is_point_inside(
1089 lasso_coords, int(pos_proj.x), int(pos_proj.y), IS_CLIPPED))
1090 {
1091 for (bke::GSpanAttributeWriter &selection : selection_writers) {
1092 apply_selection_operation_at_index(selection.span, curve, sel_op);
1093 }
1094 changed = true;
1095 }
1096 return;
1097 }
1098 auto process_segment = [&](const int segment_i, const int next_i) {
1099 const float3 &pos1 = positions[segment_i];
1100 const float3 &pos2 = positions[next_i];
1101 const float2 pos1_proj = ED_view3d_project_float_v2_m4(
1102 vc.region, pos1, projection);
1103 const float2 pos2_proj = ED_view3d_project_float_v2_m4(
1104 vc.region, pos2, projection);
1105
1106 /* Check the lasso bounding box first as an optimization. */
1107 if (BLI_rcti_isect_segment(&bbox, int2(pos1_proj), int2(pos2_proj)) &&
1108 BLI_lasso_is_edge_inside(lasso_coords,
1109 int(pos1_proj.x),
1110 int(pos1_proj.y),
1111 int(pos2_proj.x),
1112 int(pos2_proj.y),
1113 IS_CLIPPED))
1114 {
1115 for (bke::GSpanAttributeWriter &selection : selection_writers) {
1116 apply_selection_operation_at_index(selection.span, curve, sel_op);
1117 }
1118 changed = true;
1119 return true;
1120 }
1121 return false;
1122 };
1123 bool segment_selected = false;
1124 for (const int segment_i : points.drop_back(cyclic[curve] ? 0 : 1)) {
1125 if (process_segment(segment_i, segment_i + 1)) {
1126 segment_selected = true;
1127 break;
1128 }
1129 }
1130 if (!segment_selected && cyclic[curve]) {
1131 process_segment(points.last(), points.first());
1132 }
1133 },
1135 });
1136 }
1137 finish_attribute_writers(selection_writers);
1138 return changed;
1139}
1140
1143 const bke::crazyspace::GeometryDeformation &deformation,
1144 const float4x4 &projection,
1145 const IndexMask &selection_mask,
1146 const IndexMask &bezier_mask,
1147 const bke::AttrDomain selection_domain,
1148 const int2 coord,
1149 const float radius,
1150 const eSelectOp sel_op)
1151{
1152 const float radius_sq = pow2f(radius);
1154 selection_domain);
1155 bool changed = false;
1156 if (sel_op == SEL_OP_SET) {
1157 for (bke::GSpanAttributeWriter &selection : selection_writers) {
1158 fill_selection_false(selection.span, selection_mask);
1159 };
1160 changed = true;
1161 }
1162
1163 if (selection_domain == bke::AttrDomain::Point) {
1165 curves,
1166 deformation,
1168 [&](IndexRange range, Span<float3> positions, StringRef selection_attribute_name) {
1169 const IndexMask &mask = (selection_attribute_name == ".selection") ? selection_mask :
1170 bezier_mask;
1171 mask.slice_content(range).foreach_index(
1172 [&](const int point) {
1173 const float2 pos_proj = ED_view3d_project_float_v2_m4(
1174 vc.region, positions[point], projection);
1175 if (math::distance_squared(pos_proj, float2(coord)) <= radius_sq) {
1176 apply_selection_operation_at_index(
1177 selection_attribute_writer_by_name(selection_writers,
1178 selection_attribute_name)
1179 .span,
1180 point,
1181 sel_op);
1182 changed = true;
1183 }
1184 },
1185 exec_mode::grain_size(1024));
1186 });
1187 }
1188 else if (selection_domain == bke::AttrDomain::Curve) {
1189 const OffsetIndices points_by_curve = curves.points_by_curve();
1190 const VArray<bool> cyclic = curves.cyclic();
1191 foreach_selectable_curve_range(
1192 curves,
1193 deformation,
1194 eHandleDisplay(vc.v3d->overlay.handle_display),
1195 [&](const IndexRange range,
1196 const Span<float3> positions,
1197 StringRef /* selection_attribute_name */) {
1198 const IndexMask &mask = selection_mask;
1199 mask.slice_content(range).foreach_index(
1200 [&](const int curve) {
1201 const IndexRange points = points_by_curve[curve];
1202 if (points.size() == 1) {
1203 const float2 pos_proj = ED_view3d_project_float_v2_m4(
1204 vc.region, positions[points.first()], projection);
1205 if (math::distance_squared(pos_proj, float2(coord)) <= radius_sq) {
1206 for (bke::GSpanAttributeWriter &selection : selection_writers) {
1207 apply_selection_operation_at_index(selection.span, curve, sel_op);
1208 }
1209 changed = true;
1210 }
1211 return;
1212 }
1213 auto process_segments = [&](const int segment_i, const int next_i) {
1214 const float3 &pos1 = positions[segment_i];
1215 const float3 &pos2 = positions[next_i];
1216 const float2 pos1_proj = ED_view3d_project_float_v2_m4(
1217 vc.region, pos1, projection);
1218 const float2 pos2_proj = ED_view3d_project_float_v2_m4(
1219 vc.region, pos2, projection);
1220
1221 const float distance_proj_sq = dist_squared_to_line_segment_v2(
1222 float2(coord), pos1_proj, pos2_proj);
1223 if (distance_proj_sq <= radius_sq) {
1224 for (bke::GSpanAttributeWriter &selection : selection_writers) {
1225 apply_selection_operation_at_index(selection.span, curve, sel_op);
1226 }
1227 changed = true;
1228 return true;
1229 }
1230 return false;
1231 };
1232 bool segment_selected = false;
1233 for (const int segment_i : points.drop_back(1)) {
1234 if (process_segments(segment_i, segment_i + 1)) {
1235 segment_selected = true;
1236 break;
1237 }
1238 }
1239 if (!segment_selected && cyclic[curve]) {
1240 process_segments(points.last(), points.first());
1241 }
1242 },
1244 });
1245 }
1246 finish_attribute_writers(selection_writers);
1247 return changed;
1248}
1249
1250template<typename PointSelectFn, typename LineSelectFn>
1252 const IndexMask &mask,
1253 const bke::AttrDomain selection_domain,
1254 IndexMaskMemory &memory,
1255 PointSelectFn &&point_predicate,
1256 LineSelectFn &&line_predicate)
1257{
1258 const OffsetIndices points_by_curve = curves.points_by_curve();
1259 const VArraySpan<bool> cyclic = curves.cyclic();
1260
1261 if (selection_domain == bke::AttrDomain::Point) {
1263 mask.slice_content(curves.points_range()), memory, point_predicate);
1264 }
1265 if (selection_domain == bke::AttrDomain::Curve) {
1267 mask.slice_content(curves.curves_range()), memory, [&](const int curve) -> bool {
1268 const IndexRange points = points_by_curve[curve];
1269 const bool is_cyclic = cyclic[curve];
1270
1271 /* Single-point curve can still be selected in curve mode.
1272 */
1273 if (points.size() == 1) {
1274 return point_predicate(points.first());
1275 }
1276
1277 for (const int point : points.drop_back(1)) {
1278 if (line_predicate(curve, point, point + 1)) {
1279 return true;
1280 }
1281 }
1282 if (is_cyclic) {
1283 if (line_predicate(curve, points.last(), points.first())) {
1284 return true;
1285 }
1286 }
1287 return false;
1288 });
1289 }
1290 return {};
1291}
1292
1294 const IndexMask &curves_mask,
1295 const StringRef attribute_name,
1296 const bool deselect,
1297 IndexMaskMemory &memory)
1298{
1299 const OffsetIndices points_by_curve = curves.points_by_curve();
1300 const VArray<bool> cyclic = curves.cyclic();
1301
1302 VArraySpan<bool> selection = *curves.attributes().lookup_or_default<bool>(
1303 attribute_name, bke::AttrDomain::Point, true);
1304
1305 /* Mask of points that are not selected yet but adjacent. */
1306 Array<bool> changed_points(curves.points_num());
1307
1308 auto is_point_changed1 = [&](const int point, const int neighbor) {
1309 return deselect ? (selection[point] && !selection[neighbor]) :
1310 (!selection[point] && selection[neighbor]);
1311 };
1312 auto is_point_changed2 = [&](const int point, const int neighbor1, const int neighbor2) {
1313 return deselect ? (selection[point] && (!selection[neighbor1] || !selection[neighbor2])) :
1314 (!selection[point] && (selection[neighbor1] || selection[neighbor2]));
1315 };
1316
1317 curves_mask.foreach_index([&](const int64_t curve) {
1318 const IndexRange points = points_by_curve[curve];
1319 if (points.size() == 1) {
1320 /* Single point curve does not add anything to the mask. */
1321 return;
1322 }
1323
1324 if (cyclic[curve]) {
1325 changed_points[points.first()] = is_point_changed2(
1326 points.first(), points.last(), points.first() + 1);
1327 for (const int point : points.drop_front(1).drop_back(1)) {
1328 changed_points[point] = is_point_changed2(point, point - 1, point + 1);
1329 }
1330 changed_points[points.last()] = is_point_changed2(
1331 points.last(), points.last() - 1, points.first());
1332 }
1333 else {
1334 changed_points[points.first()] = is_point_changed1(points.first(), points.first() + 1);
1335 for (const int point : points.drop_front(1).drop_back(1)) {
1336 changed_points[point] = is_point_changed2(point, point - 1, point + 1);
1337 }
1338 changed_points[points.last()] = is_point_changed1(points.last(), points.last() - 1);
1339 }
1340 });
1341
1342 return IndexMask::from_bools(changed_points, memory);
1343}
1344
1346 const StringRef attribute_name,
1347 const bool deselect,
1348 IndexMaskMemory &memory)
1349{
1350 return select_adjacent_mask(curves, curves.curves_range(), attribute_name, deselect, memory);
1351}
1352
1355 const bke::crazyspace::GeometryDeformation &deformation,
1356 const float4x4 &projection,
1357 const IndexMask &selection_mask,
1358 const IndexMask &bezier_mask,
1359 const bke::AttrDomain selection_domain,
1360 const StringRef attribute_name,
1361 const rcti &rect,
1362 IndexMaskMemory &memory)
1363{
1364 const std::optional<Span<float3>> positions_opt = get_selection_attribute_positions(
1365 curves, deformation, attribute_name);
1366 if (!positions_opt) {
1367 return {};
1368 }
1369 const Span<float3> positions = *positions_opt;
1370
1371 auto point_predicate = [&](const int point) {
1372 const float2 pos_proj = ED_view3d_project_float_v2_m4(vc.region, positions[point], projection);
1373 /* Check the lasso bounding box first as an optimization. */
1374 return BLI_rcti_isect_pt_v(&rect, int2(pos_proj));
1375 };
1376 auto line_predicate = [&](const int /*curve*/, const int point, const int next_point_i) {
1377 const float2 pos_proj = ED_view3d_project_float_v2_m4(vc.region, positions[point], projection);
1378 const float2 next_pos_proj = ED_view3d_project_float_v2_m4(
1379 vc.region, positions[next_point_i], projection);
1380 return BLI_rcti_isect_segment(&rect, int2(pos_proj), int2(next_pos_proj));
1381 };
1382
1383 const IndexMask &mask = (attribute_name == ".selection") ? selection_mask : bezier_mask;
1385 curves, mask, selection_domain, memory, point_predicate, line_predicate);
1386}
1387
1390 const bke::crazyspace::GeometryDeformation &deformation,
1391 const float4x4 &projection,
1392 const IndexMask &selection_mask,
1393 const IndexMask &bezier_mask,
1394 const bke::AttrDomain selection_domain,
1395 const StringRef attribute_name,
1396 const Span<int2> lasso_coords,
1397 IndexMaskMemory &memory)
1398{
1399 rcti bbox;
1400 BLI_lasso_boundbox(&bbox, lasso_coords);
1401 const std::optional<Span<float3>> positions_opt = get_selection_attribute_positions(
1402 curves, deformation, attribute_name);
1403 if (!positions_opt) {
1404 return {};
1405 }
1406 const Span<float3> positions = *positions_opt;
1407
1408 auto point_predicate = [&](const int point) {
1409 const float2 pos_proj = ED_view3d_project_float_v2_m4(vc.region, positions[point], projection);
1410 /* Check the lasso bounding box first as an optimization. */
1411 return BLI_rcti_isect_pt_v(&bbox, int2(pos_proj)) &&
1412 BLI_lasso_is_point_inside(lasso_coords, int(pos_proj.x), int(pos_proj.y), IS_CLIPPED);
1413 };
1414 auto line_predicate = [&](const int /*curve*/, const int point, const int next_point_i) {
1415 const float2 pos_proj = ED_view3d_project_float_v2_m4(vc.region, positions[point], projection);
1416 const float2 next_pos_proj = ED_view3d_project_float_v2_m4(
1417 vc.region, positions[next_point_i], projection);
1418 return BLI_rcti_isect_segment(&bbox, int2(pos_proj), int2(next_pos_proj)) &&
1419 BLI_lasso_is_edge_inside(lasso_coords,
1420 int(pos_proj.x),
1421 int(pos_proj.y),
1422 int(next_pos_proj.x),
1423 int(next_pos_proj.y),
1424 IS_CLIPPED);
1425 };
1426
1427 const IndexMask &mask = (attribute_name == ".selection") ? selection_mask : bezier_mask;
1429 curves, mask, selection_domain, memory, point_predicate, line_predicate);
1430}
1431
1434 const bke::crazyspace::GeometryDeformation &deformation,
1435 const float4x4 &projection,
1436 const IndexMask &selection_mask,
1437 const IndexMask &bezier_mask,
1438 const bke::AttrDomain selection_domain,
1439 const StringRef attribute_name,
1440 const int2 coord,
1441 const float radius,
1442 IndexMaskMemory &memory)
1443{
1444 const float radius_sq = pow2f(radius);
1445 const std::optional<Span<float3>> positions_opt = get_selection_attribute_positions(
1446 curves, deformation, attribute_name);
1447 if (!positions_opt) {
1448 return {};
1449 }
1450 const Span<float3> positions = *positions_opt;
1451
1452 auto point_predicate = [&](const int point) {
1453 const float2 pos_proj = ED_view3d_project_float_v2_m4(vc.region, positions[point], projection);
1454 const float distance_proj_sq = math::distance_squared(pos_proj, float2(coord));
1455 return distance_proj_sq <= radius_sq;
1456 };
1457 auto line_predicate = [&](const int /*curve*/, const int point, const int next_point_i) {
1458 const float2 pos_proj = ED_view3d_project_float_v2_m4(vc.region, positions[point], projection);
1459 const float2 next_pos_proj = ED_view3d_project_float_v2_m4(
1460 vc.region, positions[next_point_i], projection);
1461 const float distance_proj_sq = dist_squared_to_line_segment_v2(
1462 float2(coord), pos_proj, next_pos_proj);
1463 return distance_proj_sq <= radius_sq;
1464 };
1465
1466 const IndexMask &mask = (attribute_name == ".selection") ? selection_mask : bezier_mask;
1468 curves, mask, selection_domain, memory, point_predicate, line_predicate);
1469}
1470
1471} // namespace blender::ed::curves
Low-level operations for curves.
Low-level operations for curves.
#define IS_CLIPPED
Definition ED_view3d.hh:269
#define PRF_scope(category)
#define BLI_assert_unreachable()
Span< T > as_span() const
Definition BLI_array.hh:254
bool is() const
GMutableSpan slice(const int64_t start, int64_t size) const
const CPPType & type() const
MutableSpan< T > typed() const
Span< T > typed() const
const CPPType & type() const
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
static IndexMask from_bools(Span< bool > bools, LinearAllocator<> &memory)
static IndexMask from_union(const IndexMask &mask_a, const IndexMask &mask_b, LinearAllocator<> &memory)
constexpr int64_t first() 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
constexpr bool is_empty() const
constexpr IndexRange()=default
constexpr IndexRange drop_front(int64_t n) const
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr Span()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool contains(const T &value) const
Definition BLI_span.hh:281
IndexRange index_range() const
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
void append(const T &value)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
bool contains(StringRef name) const
std::optional< AttributeMetaData > lookup_meta_data(StringRef name) const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_for_write_span(StringRef name)
constexpr int64_t size() const
void foreach_range(ForeachRangeFn auto &&fn) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
void invert_booleans(MutableSpan< bool > span)
bool contains(const VArray< bool > &varray, const IndexMask &indices_to_check, bool value)
IndexMask curve_type_point_selection(const bke::CurvesGeometry &curves, CurveType curve_type, LinearAllocator<> &memory)
bool has_anything_selected(const VArray< bool > &varray, const IndexRange range_to_check)
void apply_selection_operation_at_index(GMutableSpan selection, const int index, const eSelectOp sel_op)
void foreach_selectable_point_range(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, SelectionRangeFn range_consumer)
IndexMask select_circle_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const int2 coord, const float radius, IndexMaskMemory &memory)
void remove_selection_attributes(bke::MutableAttributeAccessor &attributes, Span< StringRef > selection_attribute_names)
static std::optional< FindClosestData > find_closest_point_to_screen_co(const ARegion *region, const Span< float3 > positions, const float4x4 &projection, const IndexMask &points_mask, const float2 mouse_pos, const float radius, const FindClosestData &initial_closest)
void select_linked(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool unselect)
static Vector< bke::GSpanAttributeWriter > init_selection_writers(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain)
void select_all(bke::CurvesGeometry &curves, const IndexMask &mask, const bke::AttrDomain selection_domain, int action)
IndexMask select_mask_from_predicates(const bke::CurvesGeometry &curves, const IndexMask &mask, const bke::AttrDomain selection_domain, IndexMaskMemory &memory, PointSelectFn &&point_predicate, LineSelectFn &&line_predicate)
IndexMask retrieve_selected_points(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
void select_alternate(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool deselect_ends)
void foreach_selectable_curve_range(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, SelectionRangeFn range_consumer)
static bool is_everything_selected(GMutableSpan &selection_curve)
void foreach_selection_attribute_writer(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, FunctionRef< void(bke::GSpanAttributeWriter &selection)> fn)
void select_adjacent(bke::CurvesGeometry &curves, const IndexMask &curves_mask, const bool deselect)
static bke::GSpanAttributeWriter & selection_attribute_writer_by_name(MutableSpan< bke::GSpanAttributeWriter > selections, StringRef attribute_name)
static void invert_selection(MutableSpan< float > selection, const IndexMask &mask)
Span< StringRef > get_curves_bezier_selection_attribute_names(const bke::CurvesGeometry &curves)
void fill_selection_false(GMutableSpan selection)
IndexMask select_lasso_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const Span< int2 > lasso_coords, IndexMaskMemory &memory)
bool select_circle(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const int2 coord, const float radius, const eSelectOp sel_op)
static void finish_attribute_writers(MutableSpan< bke::GSpanAttributeWriter > attribute_writers)
IndexMask select_adjacent_mask(const bke::CurvesGeometry &curves, const IndexMask &curves_mask, const StringRef attribute_name, const bool deselect, IndexMaskMemory &memory)
IndexMask retrieve_selected_curves(const bke::CurvesGeometry &curves, LinearAllocator<> &memory)
void fill_selection_true(GMutableSpan selection)
Span< StringRef > get_curves_selection_attribute_names(const bke::CurvesGeometry &curves)
void fill_selection(GMutableSpan selection, bool value)
std::optional< FindClosestData > closest_elem_find_screen_space(const ViewContext &vc, const OffsetIndices< int > points_by_curve, const Span< float3 > positions, const VArray< bool > &cyclic, const float4x4 &projection, const IndexMask &mask, const bke::AttrDomain domain, const int2 coord, const FindClosestData &initial_closest)
Span< StringRef > get_curves_all_selection_attribute_names()
static void init_selectable_foreach(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, eHandleDisplay handle_display, Span< StringRef > &r_bezier_attribute_names, Span< float3 > &r_positions, std::optional< std::array< Span< float3 >, 2 > > &r_bezier_handle_positions, IndexMaskMemory &r_memory, IndexMask &r_bezier_curves)
static std::optional< FindClosestData > find_closest_curve_to_screen_co(const ARegion *region, const OffsetIndices< int > points_by_curve, const Span< float3 > positions, const VArray< bool > &cyclic, const float4x4 &projection, const IndexMask &curves_mask, const float2 mouse_pos, float radius, const FindClosestData &initial_closest)
IndexMask select_box_mask(const ViewContext &vc, const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const StringRef attribute_name, const rcti &rect, IndexMaskMemory &memory)
bool select_lasso(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const Span< int2 > lasso_coords, const eSelectOp sel_op)
IndexMask retrieve_all_selected_points(const bke::CurvesGeometry &curves, const int handle_display, LinearAllocator<> &memory)
std::optional< Span< float3 > > get_selection_attribute_positions(const bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const StringRef attribute_name)
bke::GSpanAttributeWriter ensure_selection_attribute(bke::CurvesGeometry &curves, bke::AttrDomain selection_domain, bke::AttrType create_type, StringRef attribute_name)
static FindClosestData closer_elem(const FindClosestData &a, const FindClosestData &b)
FunctionRef< void( IndexRange range, Span< float3 > positions, StringRef selection_attribute_name)> SelectionRangeFn
Definition ED_curves.hh:196
bool select_box(const ViewContext &vc, bke::CurvesGeometry &curves, const bke::crazyspace::GeometryDeformation &deformation, const float4x4 &projection, const IndexMask &selection_mask, const IndexMask &bezier_mask, const bke::AttrDomain selection_domain, const rcti &rect, const eSelectOp sel_op)
constexpr ParallelGrainSize grain_size(int grain_size)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
T distance_squared(const VecBase< T, Size > &a, const VecBase< T, Size > &b)
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
Definition BLI_task.hh:127
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
float2 ED_view3d_project_float_v2_m4(const ARegion *region, const float co[3], const float4x4 &mat)
MatBase< float, 4, 4 > float4x4
bool BLI_lasso_is_point_inside(Span< int2 > mcoords, int sx, int sy, int error_value)
Definition lasso_2d.cc:42
MINLINE float pow2f(float x)
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
Definition math_geom.cc:307
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2])
bool BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2])
float ED_view3d_select_dist_px()
bool BLI_lasso_is_edge_inside(Span< int2 > mcoords, int x0, int y0, int x1, int y1, int error_value)
Definition lasso_2d.cc:56
void BLI_lasso_boundbox(rcti *rect, Span< int2 > mcoords)
Definition lasso_2d.cc:21
eHandleDisplay handle_display
View3DOverlay overlay