Blender V4.3
curves_masks.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
10#include "BLI_rand.hh"
11
12#include "BKE_attribute.hh"
13#include "BKE_curves.hh"
14
15#include "ED_curves.hh"
16
17namespace blender::ed::curves {
18
20 const IndexMask &point_mask,
21 const GrainSize grain_size,
22 IndexMaskMemory &memory)
23{
24 Array<bool> selected(curves.points_num());
25 point_mask.to_bools(selected);
26
27 const OffsetIndices points_by_curve = curves.points_by_curve();
29 curves.curves_range(), grain_size, memory, [&](const int curve_i) {
30 const IndexRange points = points_by_curve[curve_i];
31 for (const int point_i : points) {
32 if (selected[point_i]) {
33 return true;
34 }
35 }
36 return false;
37 });
38}
39
41 const IndexMask &curves_mask,
42 const int amount_start,
43 const int amount_end,
44 const bool inverted,
45 IndexMaskMemory &memory)
46{
47 const OffsetIndices points_by_curve = curves.points_by_curve();
48
49 Array<bool> end_points(curves.points_num(), inverted ? false : true);
50 curves_mask.foreach_index(GrainSize(512), [&](const int64_t curve_i) {
51 end_points.as_mutable_span()
52 .slice(points_by_curve[curve_i].drop_front(amount_start).drop_back(amount_end))
53 .fill(inverted ? true : false);
54 });
55
56 return IndexMask::from_bools(end_points, memory);
57}
58
60 const int amount_start,
61 const int amount_end,
62 const bool inverted,
63 IndexMaskMemory &memory)
64{
65 return end_points(curves, curves.curves_range(), amount_start, amount_end, inverted, memory);
66}
67
69 const IndexMask &mask,
70 const bke::AttrDomain selection_domain,
71 const uint32_t random_seed,
72 const float probability,
73 IndexMaskMemory &memory)
74{
75 RandomNumberGenerator rng{random_seed};
76 const auto next_bool_random_value = [&]() { return rng.get_float() <= probability; };
77
78 const int64_t domain_size = curves.attributes().domain_size(selection_domain);
79
80 Array<bool> random(domain_size, false);
81 mask.foreach_index_optimized<int64_t>(
82 [&](const int64_t i) { random[i] = next_bool_random_value(); });
83
84 return IndexMask::from_bools(IndexRange(domain_size), random, memory);
85}
86
88 const bke::AttrDomain selection_domain,
89 const uint32_t random_seed,
90 const float probability,
91 IndexMaskMemory &memory)
92{
93 const IndexRange selection(curves.attributes().domain_size(selection_domain));
94 return random_mask(curves, selection, selection_domain, random_seed, probability, memory);
95}
96
97} // namespace blender::ed::curves
Low-level operations for curves.
static IndexMask from_predicate(const IndexMask &universe, GrainSize grain_size, IndexMaskMemory &memory, Fn &&predicate)
IndexMask slice(IndexRange range) const
void to_bools(MutableSpan< bool > r_bools) const
void foreach_index(Fn &&fn) const
IMETHOD void random(Vector &a)
addDelta operator for displacement rotational velocity.
Definition frames.inl:1282
IndexMask curve_mask_from_points(const bke::CurvesGeometry &curves, const IndexMask &point_mask, const GrainSize grain_size, IndexMaskMemory &memory)
IndexMask end_points(const bke::CurvesGeometry &curves, const IndexMask &curves_mask, const int amount_start, const int amount_end, const bool inverted, IndexMaskMemory &memory)
IndexMask random_mask(const bke::CurvesGeometry &curves, const IndexMask &mask, const bke::AttrDomain selection_domain, const uint32_t random_seed, const float probability, IndexMaskMemory &memory)
GPU_SHADER_INTERFACE_INFO(overlay_edit_curve_handle_iface, "vert").flat(Type pos vertex_in(1, Type::UINT, "data") .vertex_out(overlay_edit_curve_handle_iface) .geometry_layout(PrimitiveIn Frequency::GEOMETRY storage_buf(1, Qualifier::READ, "uint", "data[]", Frequency::GEOMETRY) .push_constant(Type Frequency::GEOMETRY selection[]
unsigned int uint32_t
Definition stdint.h:80
__int64 int64_t
Definition stdint.h:89