Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/BKE_attribute_math.hh
| Show First 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | void mix_in(const int64_t index, const T &value, const float weight = 1.0f) | ||||
| total_weights_[index] += weight; | total_weights_[index] += weight; | ||||
| } | } | ||||
| /** | /** | ||||
| * Has to be called before the buffer provided in the constructor is used. | * Has to be called before the buffer provided in the constructor is used. | ||||
| */ | */ | ||||
| void finalize() | void finalize() | ||||
| { | { | ||||
| for (const int64_t i : buffer_.index_range()) { | for (const int64_t i : iter_indices(buffer_)) { | ||||
| const float weight = total_weights_[i]; | const float weight = total_weights_[i]; | ||||
| if (weight > 0.0f) { | if (weight > 0.0f) { | ||||
| buffer_[i] *= 1.0f / weight; | buffer_[i] *= 1.0f / weight; | ||||
| } | } | ||||
| else { | else { | ||||
| buffer_[i] = default_value_; | buffer_[i] = default_value_; | ||||
| } | } | ||||
| } | } | ||||
| Show All 26 Lines | void mix_in(const int64_t index, const T &value, const float weight = 1.0f) | ||||
| const AccumulationT converted_value = static_cast<AccumulationT>(value); | const AccumulationT converted_value = static_cast<AccumulationT>(value); | ||||
| Item &item = accumulation_buffer_[index]; | Item &item = accumulation_buffer_[index]; | ||||
| item.value += converted_value * weight; | item.value += converted_value * weight; | ||||
| item.weight += weight; | item.weight += weight; | ||||
| } | } | ||||
| void finalize() | void finalize() | ||||
| { | { | ||||
| for (const int64_t i : buffer_.index_range()) { | for (const int64_t i : iter_indices(buffer_)) { | ||||
| const Item &item = accumulation_buffer_[i]; | const Item &item = accumulation_buffer_[i]; | ||||
| if (item.weight > 0.0f) { | if (item.weight > 0.0f) { | ||||
| const float weight_inv = 1.0f / item.weight; | const float weight_inv = 1.0f / item.weight; | ||||
| const T converted_value = ConvertToT(item.value * weight_inv); | const T converted_value = ConvertToT(item.value * weight_inv); | ||||
| buffer_[i] = converted_value; | buffer_[i] = converted_value; | ||||
| } | } | ||||
| else { | else { | ||||
| buffer_[i] = default_value_; | buffer_[i] = default_value_; | ||||
| ▲ Show 20 Lines • Show All 61 Lines • Show Last 20 Lines | |||||