Blender V5.3
BKE_attribute_math.hh
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#pragma once
10
11#include "BLI_array.hh"
12#include "BLI_color_types.hh"
13#include "BLI_cpp_type.hh"
14#include "BLI_generic_span.hh"
16#include "BLI_math_color.hh"
18#include "BLI_math_vector.hh"
19#include "BLI_math_vector_c.hh"
20#include "BLI_offset_indices.hh"
21
22#include "PRF_profile.hh"
23
24#include "BKE_attribute.hh"
25
26namespace blender {
27
28class GVArray;
29
31
35template<typename Fn> inline void to_static_type(const CPPType &cpp_type, Fn &&fn)
36{
37 cpp_type.to_static_type<float,
38 float2,
39 float3,
40 float4,
41 int,
42 int2,
43 bool,
44 int8_t,
45 short2,
49 float4x4>([&]<typename T>() { fn.template operator()<T>(); });
50}
51
52template<typename Fn> inline void to_static_type(const bke::AttrType data_type, Fn &&fn)
53{
54 const CPPType &cpp_type = bke::attribute_type_to_cpp_type(data_type);
55 to_static_type(cpp_type, std::forward<Fn>(fn));
56}
57
58/* -------------------------------------------------------------------- */
63
64template<typename T> T mix2(float factor, const T &a, const T &b);
65
66template<> inline bool mix2(const float factor, const bool &a, const bool &b)
67{
68 return ((1.0f - factor) * a + factor * b) >= 0.5f;
69}
70
71template<> inline int8_t mix2(const float factor, const int8_t &a, const int8_t &b)
72{
73 return int8_t(std::round((1.0f - factor) * a + factor * b));
74}
75
76template<> inline int mix2(const float factor, const int &a, const int &b)
77{
78 return int(std::round((1.0f - factor) * a + factor * b));
79}
80
81template<> inline short2 mix2(const float factor, const short2 &a, const short2 &b)
82{
83 return math::interpolate(a, b, factor);
84}
85
86template<> inline int2 mix2(const float factor, const int2 &a, const int2 &b)
87{
88 return math::interpolate(a, b, factor);
89}
90
91template<> inline float mix2(const float factor, const float &a, const float &b)
92{
93 return (1.0f - factor) * a + factor * b;
94}
95
96template<> inline float2 mix2(const float factor, const float2 &a, const float2 &b)
97{
98 return math::interpolate(a, b, factor);
99}
100
101template<> inline float3 mix2(const float factor, const float3 &a, const float3 &b)
102{
103 return math::interpolate(a, b, factor);
104}
105
106template<> inline float4 mix2(const float factor, const float4 &a, const float4 &b)
107{
108 return math::interpolate(a, b, factor);
109}
110
111template<>
112inline ColorGeometry4f mix2(const float factor, const ColorGeometry4f &a, const ColorGeometry4f &b)
113{
114 return math::interpolate(a, b, factor);
115}
116
117template<>
118inline ColorGeometry4b mix2(const float factor, const ColorGeometry4b &a, const ColorGeometry4b &b)
119{
120 return math::interpolate(a, b, factor);
121}
122
124
125/* -------------------------------------------------------------------- */
130
131template<typename T> T mix3(const float3 &weights, const T &v0, const T &v1, const T &v2);
132
133template<>
134inline int8_t mix3(const float3 &weights, const int8_t &v0, const int8_t &v1, const int8_t &v2)
135{
136 return int8_t(std::round(weights.x * v0 + weights.y * v1 + weights.z * v2));
137}
138
139template<> inline bool mix3(const float3 &weights, const bool &v0, const bool &v1, const bool &v2)
140{
141 return (weights.x * v0 + weights.y * v1 + weights.z * v2) >= 0.5f;
142}
143
144template<> inline int mix3(const float3 &weights, const int &v0, const int &v1, const int &v2)
145{
146 return int(std::round(weights.x * v0 + weights.y * v1 + weights.z * v2));
147}
148
149template<>
150inline short2 mix3(const float3 &weights, const short2 &v0, const short2 &v1, const short2 &v2)
151{
152 return short2(weights.x * float2(v0) + weights.y * float2(v1) + weights.z * float2(v2));
153}
154
155template<> inline int2 mix3(const float3 &weights, const int2 &v0, const int2 &v1, const int2 &v2)
156{
157 return int2(weights.x * float2(v0) + weights.y * float2(v1) + weights.z * float2(v2));
158}
159
160template<>
161inline float mix3(const float3 &weights, const float &v0, const float &v1, const float &v2)
162{
163 return weights.x * v0 + weights.y * v1 + weights.z * v2;
164}
165
166template<>
167inline float2 mix3(const float3 &weights, const float2 &v0, const float2 &v1, const float2 &v2)
168{
169 return weights.x * v0 + weights.y * v1 + weights.z * v2;
170}
171
172template<>
173inline float3 mix3(const float3 &weights, const float3 &v0, const float3 &v1, const float3 &v2)
174{
175 return weights.x * v0 + weights.y * v1 + weights.z * v2;
176}
177
178template<>
179inline float4 mix3(const float3 &weights, const float4 &v0, const float4 &v1, const float4 &v2)
180{
181 return weights.x * v0 + weights.y * v1 + weights.z * v2;
182}
183
184template<>
185inline ColorGeometry4f mix3(const float3 &weights,
186 const ColorGeometry4f &v0,
187 const ColorGeometry4f &v1,
188 const ColorGeometry4f &v2)
189{
191 interp_v4_v4v4v4(result, v0, v1, v2, weights);
192 return result;
193}
194
195template<>
196inline ColorGeometry4b mix3(const float3 &weights,
197 const ColorGeometry4b &v0,
198 const ColorGeometry4b &v1,
199 const ColorGeometry4b &v2)
200{
201 const float4 v0_f{&v0.r};
202 const float4 v1_f{&v1.r};
203 const float4 v2_f{&v2.r};
204 const float4 mixed = v0_f * weights[0] + v1_f * weights[1] + v2_f * weights[2];
205 return ColorGeometry4b{
206 uint8_t(mixed[0]), uint8_t(mixed[1]), uint8_t(mixed[2]), uint8_t(mixed[3])};
207}
208
210
211/* -------------------------------------------------------------------- */
215
216template<typename T>
217T mix4(const float4 &weights, const T &v0, const T &v1, const T &v2, const T &v3);
218
219template<>
221 const float4 &weights, const int8_t &v0, const int8_t &v1, const int8_t &v2, const int8_t &v3)
222{
223 return int8_t(std::round(weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3));
224}
225
226template<>
227inline bool mix4(
228 const float4 &weights, const bool &v0, const bool &v1, const bool &v2, const bool &v3)
229{
230 return (weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3) >= 0.5f;
231}
232
233template<>
234inline int mix4(const float4 &weights, const int &v0, const int &v1, const int &v2, const int &v3)
235{
236 return int(std::round(weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3));
237}
238
239template<>
241 const float4 &weights, const short2 &v0, const short2 &v1, const short2 &v2, const short2 &v3)
242{
243 return short2(weights.x * float2(v0) + weights.y * float2(v1) + weights.z * float2(v2) +
244 weights.w * float2(v3));
245}
246
247template<>
248inline int2 mix4(
249 const float4 &weights, const int2 &v0, const int2 &v1, const int2 &v2, const int2 &v3)
250{
251 return int2(weights.x * float2(v0) + weights.y * float2(v1) + weights.z * float2(v2) +
252 weights.w * float2(v3));
253}
254
255template<>
256inline float mix4(
257 const float4 &weights, const float &v0, const float &v1, const float &v2, const float &v3)
258{
259 return weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3;
260}
261
262template<>
264 const float4 &weights, const float2 &v0, const float2 &v1, const float2 &v2, const float2 &v3)
265{
266 return weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3;
267}
268
269template<>
271 const float4 &weights, const float3 &v0, const float3 &v1, const float3 &v2, const float3 &v3)
272{
273 return weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3;
274}
275
276template<>
278 const float4 &weights, const float4 &v0, const float4 &v1, const float4 &v2, const float4 &v3)
279{
280 return weights.x * v0 + weights.y * v1 + weights.z * v2 + weights.w * v3;
281}
282
283template<>
284inline ColorGeometry4f mix4(const float4 &weights,
285 const ColorGeometry4f &v0,
286 const ColorGeometry4f &v1,
287 const ColorGeometry4f &v2,
288 const ColorGeometry4f &v3)
289{
291 interp_v4_v4v4v4v4(result, v0, v1, v2, v3, weights);
292 return result;
293}
294
295template<>
296inline ColorGeometry4b mix4(const float4 &weights,
297 const ColorGeometry4b &v0,
298 const ColorGeometry4b &v1,
299 const ColorGeometry4b &v2,
300 const ColorGeometry4b &v3)
301{
302 const float4 v0_f{&v0.r};
303 const float4 v1_f{&v1.r};
304 const float4 v2_f{&v2.r};
305 const float4 v3_f{&v3.r};
306 float4 mixed;
307 interp_v4_v4v4v4v4(mixed, v0_f, v1_f, v2_f, v3_f, weights);
308 return ColorGeometry4b{
309 uint8_t(mixed[0]), uint8_t(mixed[1]), uint8_t(mixed[2]), uint8_t(mixed[3])};
310}
311
313
314/* -------------------------------------------------------------------- */
321
322namespace detail {
323
324static double int_to_double(const int &value)
325{
326 return double(value);
327}
328static int double_to_int(const double &value)
329{
330 return int(std::round(value));
331}
332
333static double2 int2_to_double2(const int2 &value)
334{
335 return double2(value);
336}
337static int2 double2_to_int2(const double2 &value)
338{
339 return int2(math::round(value));
340}
341
342static float int8_t_to_float(const int8_t &value)
343{
344 return float(value);
345}
346static int8_t float_to_int8_t(const float &value)
347{
348 return int8_t(std::round(value));
349}
350
351static float2 short2_to_float2(const short2 &value)
352{
353 return float2(value);
354}
355static short2 float2_to_short2(const float2 &value)
356{
357 return short2(math::round(value));
358}
359
361{
362 return value.expmap();
363}
365{
366 return math::Quaternion::expmap(value);
367}
368
370{
371 return float4(value.r, value.g, value.b, value.a);
372}
374{
375 return ColorGeometry4b(value.x, value.y, value.z, value.w);
376}
377
378} // namespace detail
379
380template<typename T> inline T mix_indices(const Span<T> src, const Span<int> indices)
381{
382 T accum(0);
383 const float weight = math::rcp(float(indices.size()));
384 for (const int i : indices) {
385 accum += src[i] * weight;
386 }
387 return accum;
388}
389
390template<typename T, typename ToAccumFn, typename ToFinalFn>
391inline T mix_indices(const Span<T> src,
392 const Span<int> indices,
393 const ToAccumFn &to_accum_fn,
394 const ToFinalFn &to_final_fn)
395{
396 using AccumT = std::invoke_result_t<ToAccumFn, T>;
397 static_assert(std::is_same_v<std::invoke_result_t<ToFinalFn, AccumT>, T>);
398 const float weight = math::rcp(float(indices.size()));
399 AccumT accum(0);
400 for (const int i : indices) {
401 accum += to_accum_fn(src[i]) * weight;
402 }
403 return to_final_fn(accum);
404}
405
406inline bool mix_indices(const Span<bool> src, const Span<int> indices)
407{
408 return std::ranges::any_of(indices, [&](const int i) { return src[i]; });
409}
410
411inline int mix_indices(const Span<int> src, const Span<int> indices)
412{
414}
415
416inline int2 mix_indices(const Span<int2> src, const Span<int> indices)
417{
419}
420
421inline int8_t mix_indices(const Span<int8_t> src, const Span<int> indices)
422{
424}
425
426inline short2 mix_indices(const Span<short2> src, const Span<int> indices)
427{
429}
430
432{
434}
435
440
442{
443 return ColorGeometry4f(mix_indices(src.cast<float4>(), indices));
444}
445
447
448template<typename T>
449inline T mix_indices(const Span<T> src, const Span<int> indices, const Span<float> weights)
450{
451 T accum(0);
452 float weight_accum = 0.0f;
453 for (const int i : indices.index_range()) {
454 accum += src[indices[i]] * weights[i];
455 weight_accum += weights[i];
456 }
457 return accum * math::safe_rcp(weight_accum);
458}
459
460template<typename T, typename ToAccumFn, typename ToFinalFn>
461inline T mix_indices(const Span<T> src,
462 const Span<int> indices,
463 const Span<float> weights,
464 const ToAccumFn &to_accum_fn,
465 const ToFinalFn &to_final_fn)
466{
467 using AccumT = std::invoke_result_t<ToAccumFn, T>;
468 static_assert(std::is_same_v<std::invoke_result_t<ToFinalFn, AccumT>, T>);
469 AccumT accum(0);
470 float weight_accum = 0.0f;
471 for (const int i : indices.index_range()) {
472 accum += to_accum_fn(src[indices[i]]) * weights[i];
473 weight_accum += weights[i];
474 }
475 return to_final_fn(accum * math::safe_rcp(weight_accum));
476}
477
478inline bool mix_indices(const Span<bool> src, const Span<int> indices, const Span<float> weights)
479{
480 for (const int i : indices.index_range()) {
481 if (src[indices[i]] && weights[i] > 0.0f) {
482 return true;
483 }
484 }
485 return false;
486}
487
488inline int mix_indices(const Span<int> src, const Span<int> indices, const Span<float> weights)
489{
490 return mix_indices(src, indices, weights, detail::int_to_double, detail::double_to_int);
491}
492
493inline int2 mix_indices(const Span<int2> src, const Span<int> indices, const Span<float> weights)
494{
495 return mix_indices(src, indices, weights, detail::int2_to_double2, detail::double2_to_int2);
496}
497
499 const Span<int> indices,
500 const Span<float> weights)
501{
502 return mix_indices(src, indices, weights, detail::int8_t_to_float, detail::float_to_int8_t);
503}
504
506 const Span<int> indices,
507 const Span<float> weights)
508{
509 return mix_indices(src, indices, weights, detail::short2_to_float2, detail::float2_to_short2);
510}
511
513 const Span<int> indices,
514 const Span<float> weights)
515{
516 return mix_indices(src, indices, weights, detail::quat_to_expmap, detail::expmap_to_quat);
517}
518
520 const Span<int> indices,
521 const Span<float> weights)
522{
523 return mix_indices(
525}
526
528 const Span<int> indices,
529 const Span<float> weights)
530{
531 return ColorGeometry4f(mix_indices(src.cast<float4>(), indices, weights));
532}
533
535
536template<typename T> class SimpleMixer {
537 private:
538 MutableSpan<T> buffer_;
539 T default_value_;
540 Array<float> total_weights_;
541
542 public:
547 SimpleMixer(MutableSpan<T> buffer, T default_value = {})
548 : SimpleMixer(buffer, buffer.index_range(), default_value)
549 {
550 }
551
555 SimpleMixer(MutableSpan<T> buffer, const IndexMask &mask, T default_value = {})
556 : buffer_(buffer), default_value_(default_value), total_weights_(buffer.size(), 0.0f)
557 {
558 BLI_STATIC_ASSERT(std::is_trivial_v<T>, "");
559 index_mask::masked_fill(buffer_, default_value_, mask);
560 }
561
565 void set(const int64_t index, const T &value, const float weight = 1.0f)
566 {
567 buffer_[index] = value * weight;
568 total_weights_[index] = weight;
569 }
570
574 void mix_in(const int64_t index, const T &value, const float weight = 1.0f)
575 {
576 buffer_[index] += value * weight;
577 total_weights_[index] += weight;
578 }
579
583 void finalize()
584 {
585 this->finalize(IndexMask(buffer_.size()));
586 }
587
589 {
590 PRF_scope_with_name("SimpleMixer::finalize", ProfileCategory::Default);
591 mask.foreach_index([&](const int64_t i) {
592 const float weight = total_weights_[i];
593 if (weight > 0.0f) {
594 buffer_[i] *= 1.0f / weight;
595 }
596 else {
597 buffer_[i] = default_value_;
598 }
599 });
600 }
601};
602
612 private:
613 MutableSpan<bool> buffer_;
614
615 public:
620 : BooleanPropagationMixer(buffer, buffer.index_range())
621 {
622 }
623
627 BooleanPropagationMixer(MutableSpan<bool> buffer, const IndexMask &mask) : buffer_(buffer)
628 {
629 index_mask::masked_fill(buffer_, false, mask);
630 }
631
635 void set(const int64_t index, const bool value, [[maybe_unused]] const float weight = 1.0f)
636 {
637 buffer_[index] = value;
638 }
639
643 void mix_in(const int64_t index, const bool value, [[maybe_unused]] const float weight = 1.0f)
644 {
645 buffer_[index] |= value;
646 }
647
651 void finalize() {}
652
653 void finalize(const IndexMask & /*mask*/) {}
654};
655
660template<typename T,
661 typename AccumulationT,
662 AccumulationT (*ValueToAccumulate)(const T &value),
663 T (*AccumulateToValue)(const AccumulationT &value)>
665 private:
666 struct Item {
667 /* Store both values together, because they are accessed together. */
668 AccumulationT value = AccumulationT(0);
669 float weight = 0.0f;
670 };
671
672 MutableSpan<T> buffer_;
673 T default_value_;
674 Array<Item> accumulation_buffer_;
675
676 public:
678 : SimpleMixerWithAccumulationType(buffer, buffer.index_range(), default_value)
679 {
680 }
681
686 const IndexMask &mask,
687 T default_value = {})
688 : buffer_(buffer), default_value_(default_value), accumulation_buffer_(buffer.size())
689 {
690 index_mask::masked_fill(buffer_, default_value_, mask);
691 }
692
693 void set(const int64_t index, const T &value, const float weight = 1.0f)
694 {
695 const AccumulationT converted_value = ValueToAccumulate(value);
696 Item &item = accumulation_buffer_[index];
697 item.value = converted_value * weight;
698 item.weight = weight;
699 }
700
701 void mix_in(const int64_t index, const T &value, const float weight = 1.0f)
702 {
703 const AccumulationT converted_value = ValueToAccumulate(value);
704 Item &item = accumulation_buffer_[index];
705 item.value += converted_value * weight;
706 item.weight += weight;
707 }
708
709 void finalize()
710 {
711 this->finalize(buffer_.index_range());
712 }
713
715 {
716 PRF_scope_with_name("SimpleMixerWithAccumulationType::finalize", ProfileCategory::Default);
717 mask.foreach_index([&](const int64_t i) {
718 const Item &item = accumulation_buffer_[i];
719 if (item.weight > 0.0f) {
720 const float weight_inv = 1.0f / item.weight;
721 const T converted_value = AccumulateToValue(item.value * weight_inv);
722 buffer_[i] = converted_value;
723 }
724 else {
725 buffer_[i] = default_value_;
726 }
727 });
728 }
729};
730
732 private:
734 ColorGeometry4f default_color_;
735 Array<float> total_weights_;
736
737 public:
739 ColorGeometry4f default_color = ColorGeometry4f(0.0f, 0.0f, 0.0f, 1.0f));
744 const IndexMask &mask,
745 ColorGeometry4f default_color = ColorGeometry4f(0.0f, 0.0f, 0.0f, 1.0f));
746 void set(int64_t index, const ColorGeometry4f &color, float weight = 1.0f);
747 void mix_in(int64_t index, const ColorGeometry4f &color, float weight = 1.0f);
748 void finalize();
749 void finalize(const IndexMask &mask);
750};
751
753 private:
755 ColorGeometry4b default_color_;
756 Array<float> total_weights_;
757 Array<float4> accumulation_buffer_;
758
759 public:
761 ColorGeometry4b default_color = ColorGeometry4b(0, 0, 0, 255));
766 const IndexMask &mask,
767 ColorGeometry4b default_color = ColorGeometry4b(0, 0, 0, 255));
768 void set(int64_t index, const ColorGeometry4b &color, float weight = 1.0f);
769 void mix_in(int64_t index, const ColorGeometry4b &color, float weight = 1.0f);
770 void finalize();
771 void finalize(const IndexMask &mask);
772};
773
775 private:
776 MutableSpan<float4x4> buffer_;
777 Array<float> total_weights_;
778 Array<float3> location_buffer_;
779 Array<float3> expmap_buffer_;
780 Array<float3> scale_buffer_;
781
782 public:
788 void set(int64_t index, const float4x4 &value, float weight = 1.0f);
789 void mix_in(int64_t index, const float4x4 &value, float weight = 1.0f);
790 void finalize();
791 void finalize(const IndexMask &mask);
792};
793
794template<typename T> struct DefaultMixerStruct {
795 /* Use void by default. This can be checked for in `if constexpr` statements. */
796 using type = void;
797};
798template<> struct DefaultMixerStruct<float> {
800};
801template<> struct DefaultMixerStruct<float2> {
803};
804template<> struct DefaultMixerStruct<float3> {
806};
807template<> struct DefaultMixerStruct<float4> {
809};
811 /* Use a special mixer for colors. ColorGeometry4f can't be added/multiplied, because this is not
812 * something one should usually do with colors. */
814};
820};
821template<> struct DefaultMixerStruct<int> {
822 /* Store interpolated ints in a double temporarily, so that weights are handled correctly. It
823 * uses double instead of float so that it is accurate for all 32 bit integers. */
824 using type =
826};
833template<> struct DefaultMixerStruct<int2> {
834 /* Store interpolated ints in a double temporarily, so that weights are handled correctly. It
835 * uses double instead of float so that it is accurate for all 32 bit integers. */
837 double2,
840};
841template<> struct DefaultMixerStruct<bool> {
842 static float bool_to_float(const bool &value)
843 {
844 return value ? 1.0f : 0.0f;
845 }
846 static bool float_to_bool(const float &value)
847 {
848 return value >= 0.5f;
849 }
850 /* Store interpolated booleans in a float temporary.
851 * Otherwise information provided by weights is easily rounded away. */
853};
854
855template<> struct DefaultMixerStruct<int8_t> {
856 /* Store interpolated 8 bit integers in a float temporarily to increase accuracy. */
858 float,
861};
868
869template<typename T> struct DefaultPropagationMixerStruct {
870 /* Use void by default. This can be checked for in `if constexpr` statements. */
872};
873
874template<> struct DefaultPropagationMixerStruct<bool> {
876};
877
883template<typename T>
885
886/* Utility to get a good default mixer for a given type. This is `void` when there is no default
887 * mixer for the given type. */
888template<typename T> using DefaultMixer = typename DefaultMixerStruct<T>::type;
889
890void mix_groups(GSpan src,
891 OffsetIndices<int> groups,
892 Span<int> all_indices,
893 std::optional<Span<float>> all_weights,
894 GMutableSpan dst);
899void mix_groups(GSpan src,
900 OffsetIndices<int> groups,
901 Span<int> all_indices,
902 std::optional<Span<float>> all_weights,
903 const IndexMask &dst_mask,
904 GMutableSpan dst);
905inline void mix_groups(GSpan src,
906 OffsetIndices<int> groups,
907 Span<int> all_indices,
908 GMutableSpan dst)
909{
910 mix_groups(src, groups, all_indices, std::nullopt, dst);
911}
912inline void mix_groups(GSpan src, GroupedSpan<int> indices, GMutableSpan dst)
913{
914 mix_groups(src, indices.offsets, indices.data, dst);
915}
916
918
919/* -------------------------------------------------------------------- */
925
930void shift_left(GMutableSpan data, int src_begin, int src_end, int dst_begin);
931
936void shift_right(GMutableSpan data, int src_begin, int src_end, int dst_begin);
937
938void gather(GSpan src, Span<int> map, GMutableSpan dst);
939void gather(const GVArray &src, Span<int> map, GMutableSpan dst);
940void gather(GSpan src, Span<int> map, const IndexMask &dst_mask, GMutableSpan dst);
941void gather(const GVArray &src, Span<int> map, const IndexMask &dst_mask, GMutableSpan dst);
943 OffsetIndices<int> dst_offsets,
944 const IndexMask &selection,
945 GSpan src,
946 GMutableSpan dst);
947void gather_to_groups(OffsetIndices<int> dst_offsets,
948 const IndexMask &src_selection,
949 GSpan src,
950 GMutableSpan dst);
951
953 OffsetIndices<int> dst_offsets,
954 GSpan src,
955 GMutableSpan dst);
956
958
959} // namespace bke::attribute_math
960
961} // namespace blender
#define PRF_scope_with_name(ui_name, category)
void to_static_type(Fn &&fn) const
ChannelStorageType r
ChannelStorageType g
ChannelStorageType b
ChannelStorageType a
Span< NewT > constexpr cast() const
Definition BLI_span.hh:422
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
BooleanPropagationMixer(MutableSpan< bool > buffer, const IndexMask &mask)
void set(const int64_t index, const bool value, const float weight=1.0f)
void mix_in(const int64_t index, const bool value, const float weight=1.0f)
ColorGeometry4bMixer(MutableSpan< ColorGeometry4b > buffer, ColorGeometry4b default_color=ColorGeometry4b(0, 0, 0, 255))
void mix_in(int64_t index, const ColorGeometry4b &color, float weight=1.0f)
void set(int64_t index, const ColorGeometry4b &color, float weight=1.0f)
void mix_in(int64_t index, const ColorGeometry4f &color, float weight=1.0f)
ColorGeometry4fMixer(MutableSpan< ColorGeometry4f > buffer, ColorGeometry4f default_color=ColorGeometry4f(0.0f, 0.0f, 0.0f, 1.0f))
void set(int64_t index, const ColorGeometry4f &color, float weight=1.0f)
SimpleMixerWithAccumulationType(MutableSpan< T > buffer, const IndexMask &mask, T default_value={})
void mix_in(const int64_t index, const T &value, const float weight=1.0f)
SimpleMixerWithAccumulationType(MutableSpan< T > buffer, T default_value={})
void set(const int64_t index, const T &value, const float weight=1.0f)
SimpleMixer(MutableSpan< T > buffer, const IndexMask &mask, T default_value={})
void mix_in(const int64_t index, const T &value, const float weight=1.0f)
void set(const int64_t index, const T &value, const float weight=1.0f)
SimpleMixer(MutableSpan< T > buffer, T default_value={})
void mix_in(int64_t index, const float4x4 &value, float weight=1.0f)
void set(int64_t index, const float4x4 &value, float weight=1.0f)
float4x4Mixer(MutableSpan< float4x4 > buffer)
#define T
static short2 float2_to_short2(const float2 &value)
static int8_t float_to_int8_t(const float &value)
static int double_to_int(const double &value)
static float int8_t_to_float(const int8_t &value)
static float3 quat_to_expmap(const math::Quaternion &value)
static int2 double2_to_int2(const double2 &value)
static double int_to_double(const int &value)
static float4 byte_color_to_float4(const ColorGeometry4b &value)
static math::Quaternion expmap_to_quat(const float3 &value)
static float2 short2_to_float2(const short2 &value)
static ColorGeometry4b float4_to_byte_color(const float4 &value)
static double2 int2_to_double2(const int2 &value)
T mix_indices(const Span< T > src, const Span< int > indices)
void gather(GSpan src, Span< int > map, GMutableSpan dst)
void gather_to_groups(OffsetIndices< int > dst_offsets, const IndexMask &src_selection, GSpan src, GMutableSpan dst)
T mix3(const float3 &weights, const T &v0, const T &v1, const T &v2)
void gather_ranges_to_groups(Span< IndexRange > src_ranges, OffsetIndices< int > dst_offsets, GSpan src, GMutableSpan dst)
void shift_right(GMutableSpan data, int src_begin, int src_end, int dst_begin)
typename DefaultMixerStruct< T >::type DefaultMixer
T mix4(const float4 &weights, const T &v0, const T &v1, const T &v2, const T &v3)
void gather_group_to_group(OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, GSpan src, GMutableSpan dst)
void shift_left(GMutableSpan data, int src_begin, int src_end, int dst_begin)
void mix_groups(GSpan src, OffsetIndices< int > groups, Span< int > all_indices, std::optional< Span< float > > all_weights, GMutableSpan dst)
typename DefaultPropagationMixerStruct< T >::type DefaultPropagationMixer
void to_static_type(const CPPType &cpp_type, Fn &&fn)
T mix2(float factor, const T &a, const T &b)
const CPPType & attribute_type_to_cpp_type(AttrType type)
void masked_fill(MutableSpan< T > data, const T &value, const IndexMask &mask)
QuaternionBase< float > Quaternion
T safe_rcp(const T &a)
T interpolate(const T &a, const T &b, const FactorT &t)
T rcp(const T &a)
T round(const T &a)
BMesh Iterators.
__int64 int64_t
Definition BKE_text.h:90
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3])
VecBase< double, 2 > double2
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
BMesh const char void * data
unsigned char uint8_t
Definition BKE_text.h:79
ATTR_WARN_UNUSED_RESULT const BMVert * v2
VecBase< int16_t, 2 > short2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
void interp_v4_v4v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float v4[4], const float w[4])
signed char int8_t
Definition BKE_text.h:76
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
SimpleMixerWithAccumulationType< bool, float, bool_to_float, float_to_bool > type
SimpleMixerWithAccumulationType< int2, double2, detail::int2_to_double2, detail::double2_to_int2 > type
SimpleMixerWithAccumulationType< int8_t, float, detail::int8_t_to_float, detail::float_to_int8_t > type
SimpleMixerWithAccumulationType< int, double, detail::int_to_double, detail::double_to_int > type
SimpleMixerWithAccumulationType< math::Quaternion, float3, detail::quat_to_expmap, detail::expmap_to_quat > type
SimpleMixerWithAccumulationType< short2, float2, detail::short2_to_float2, detail::float2_to_short2 > type
VecBase< float, 3 > expmap() const
static QuaternionBase expmap(const VecBase< T, 3 > &expmap)