33template<
typename Func>
48 using T =
typename decltype(type_tag)::type;
49 if constexpr (std::is_same_v<T, void>) {
59template<
typename Func>
72template<
typename T>
T mix2(
float factor,
const T &a,
const T &
b);
74template<>
inline bool mix2(
const float factor,
const bool &a,
const bool &
b)
76 return ((1.0f - factor) * a + factor *
b) >= 0.5f;
79template<>
inline int8_t
mix2(
const float factor,
const int8_t &a,
const int8_t &
b)
81 return int8_t(std::round((1.0f - factor) * a + factor *
b));
84template<>
inline int mix2(
const float factor,
const int &a,
const int &
b)
86 return int(std::round((1.0f - factor) * a + factor *
b));
99template<>
inline float mix2(
const float factor,
const float &a,
const float &
b)
101 return (1.0f - factor) * a + factor *
b;
137inline int8_t
mix3(
const float3 &weights,
const int8_t &v0,
const int8_t &v1,
const int8_t &
v2)
139 return int8_t(std::round(weights.x * v0 + weights.y * v1 + weights.z *
v2));
142template<>
inline bool mix3(
const float3 &weights,
const bool &v0,
const bool &v1,
const bool &
v2)
144 return (weights.x * v0 + weights.y * v1 + weights.z *
v2) >= 0.5f;
147template<>
inline int mix3(
const float3 &weights,
const int &v0,
const int &v1,
const int &
v2)
149 return int(std::round(weights.x * v0 + weights.y * v1 + weights.z *
v2));
164inline float mix3(
const float3 &weights,
const float &v0,
const float &v1,
const float &
v2)
166 return weights.x * v0 + weights.y * v1 + weights.z *
v2;
172 return weights.x * v0 + weights.y * v1 + weights.z *
v2;
178 return weights.x * v0 + weights.y * v1 + weights.z *
v2;
201 const float4 mixed = v0_f * weights[0] + v1_f * weights[1] + v2_f * weights[2];
203 uint8_t(mixed[0]), uint8_t(mixed[1]), uint8_t(mixed[2]), uint8_t(mixed[3])};
218 const float4 &weights,
const int8_t &v0,
const int8_t &v1,
const int8_t &
v2,
const int8_t &v3)
220 return int8_t(std::round(weights.x * v0 + weights.y * v1 + weights.z *
v2 + weights.w * v3));
225 const float4 &weights,
const bool &v0,
const bool &v1,
const bool &
v2,
const bool &v3)
227 return (weights.x * v0 + weights.y * v1 + weights.z *
v2 + weights.w * v3) >= 0.5f;
231inline int mix4(
const float4 &weights,
const int &v0,
const int &v1,
const int &
v2,
const int &v3)
233 return int(std::round(weights.x * v0 + weights.y * v1 + weights.z *
v2 + weights.w * v3));
254 const float4 &weights,
const float &v0,
const float &v1,
const float &
v2,
const float &v3)
256 return weights.x * v0 + weights.y * v1 + weights.z *
v2 + weights.w * v3;
263 return weights.x * v0 + weights.y * v1 + weights.z *
v2 + weights.w * v3;
270 return weights.x * v0 + weights.y * v1 + weights.z *
v2 + weights.w * v3;
299 uint8_t(mixed[0]), uint8_t(mixed[1]), uint8_t(mixed[2]), uint8_t(mixed[3])};
324 :
SimpleMixer(buffer, buffer.index_range(), default_value)
332 : buffer_(buffer), default_value_(default_value), total_weights_(buffer.
size(), 0.0f)
335 mask.foreach_index([&](
const int64_t i) { buffer_[
i] = default_value_; });
341 void set(
const int64_t index,
const T &value,
const float weight = 1.0f)
343 buffer_[index] = value * weight;
344 total_weights_[index] = weight;
352 buffer_[index] += value * weight;
353 total_weights_[index] += weight;
367 const float weight = total_weights_[
i];
369 buffer_[
i] *= 1.0f / weight;
372 buffer_[
i] = default_value_;
404 mask.foreach_index([&](
const int64_t i) { buffer_[
i] =
false; });
410 void set(
const int64_t index,
const bool value, [[maybe_unused]]
const float weight = 1.0f)
412 buffer_[index] = value;
418 void mix_in(
const int64_t index,
const bool value, [[maybe_unused]]
const float weight = 1.0f)
420 buffer_[index] |= value;
436 typename AccumulationT,
437 AccumulationT (*ValueToAccumulate)(
const T &value),
438 T (*AccumulateToValue)(
const AccumulationT &value)>
443 AccumulationT value = AccumulationT(0);
462 T default_value = {})
463 : buffer_(buffer), default_value_(default_value), accumulation_buffer_(buffer.
size())
465 mask.foreach_index([&](
const int64_t index) { buffer_[index] = default_value_; });
468 void set(
const int64_t index,
const T &value,
const float weight = 1.0f)
470 const AccumulationT converted_value = ValueToAccumulate(value);
471 Item &item = accumulation_buffer_[index];
472 item.value = converted_value * weight;
473 item.weight = weight;
478 const AccumulationT converted_value = ValueToAccumulate(value);
479 Item &item = accumulation_buffer_[index];
480 item.value += converted_value * weight;
481 item.weight += weight;
486 this->
finalize(buffer_.index_range());
492 const Item &item = accumulation_buffer_[
i];
493 if (item.weight > 0.0f) {
494 const float weight_inv = 1.0f / item.weight;
495 const T converted_value = AccumulateToValue(item.value * weight_inv);
496 buffer_[
i] = converted_value;
499 buffer_[
i] = default_value_;
595 return double(value);
599 return int(std::round(value));
632 return value ? 1.0f : 0.0f;
636 return value >= 0.5f;
650 return int8_t(std::round(value));
#define BLI_assert_unreachable()
#define BLI_STATIC_ASSERT(a, msg)
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])
void interp_v4_v4v4v4(float p[4], const float v1[4], const float v2[4], const float v3[4], const float w[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void to_static_type_tag(const Fn &fn) const
BooleanPropagationMixer(MutableSpan< bool > buffer)
void finalize(const IndexMask &)
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)
void finalize(const IndexMask &mask)
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 finalize(const IndexMask &mask)
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)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
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)
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
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)
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)
typename DefaultPropagationMixerStruct< T >::type DefaultPropagationMixer
T mix2(float factor, const T &a, const T &b)
const CPPType & attribute_type_to_cpp_type(AttrType type)
QuaternionBase< float > Quaternion
T interpolate(const T &a, const T &b, const FactorT &t)
VecBase< double, 2 > double2
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
blender::VecBase< int16_t, 2 > short2
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
ColorGeometry4bMixer type
ColorGeometry4fMixer type
static float bool_to_float(const bool &value)
static bool float_to_bool(const float &value)
SimpleMixerWithAccumulationType< bool, float, bool_to_float, float_to_bool > type
SimpleMixer< float2 > type
SimpleMixer< float3 > type
SimpleMixer< float > type
static int2 double_to_int(const double2 &value)
static double2 int_to_double(const int2 &value)
SimpleMixerWithAccumulationType< int2, double2, int_to_double, double_to_int > type
SimpleMixerWithAccumulationType< int8_t, float, int8_t_to_float, float_to_int8_t > type
static int8_t float_to_int8_t(const float &value)
static float int8_t_to_float(const int8_t &value)
static double int_to_double(const int &value)
SimpleMixerWithAccumulationType< int, double, int_to_double, double_to_int > type
static int double_to_int(const double &value)
SimpleMixerWithAccumulationType< math::Quaternion, float3, quat_to_expmap, expmap_to_quat > type
static float3 quat_to_expmap(const math::Quaternion &value)
static math::Quaternion expmap_to_quat(const float3 &value)
static short2 float_to_int(const float2 &value)
static float2 int_to_float(const short2 &value)
SimpleMixerWithAccumulationType< short2, float2, int_to_float, float_to_int > type
BooleanPropagationMixer type
typename DefaultMixerStruct< T >::type type
VecBase< float, 3 > expmap() const
static QuaternionBase expmap(const VecBase< T, 3 > &expmap)