Blender  V2.93
attribute_math.cc
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #include "BKE_attribute_math.hh"
18 
19 namespace blender::attribute_math {
20 
22  : buffer_(output_buffer),
23  default_color_(default_color),
24  total_weights_(output_buffer.size(), 0.0f)
25 {
26  buffer_.fill(Color4f(0, 0, 0, 0));
27 }
28 
29 void Color4fMixer::mix_in(const int64_t index, const Color4f &color, const float weight)
30 {
31  BLI_assert(weight >= 0.0f);
32  Color4f &output_color = buffer_[index];
33  output_color.r += color.r * weight;
34  output_color.g += color.g * weight;
35  output_color.b += color.b * weight;
36  output_color.a += color.a * weight;
37  total_weights_[index] += weight;
38 }
39 
41 {
42  for (const int64_t i : buffer_.index_range()) {
43  const float weight = total_weights_[i];
44  Color4f &output_color = buffer_[i];
45  if (weight > 0.0f) {
46  const float weight_inv = 1.0f / weight;
47  output_color.r *= weight_inv;
48  output_color.g *= weight_inv;
49  output_color.b *= weight_inv;
50  output_color.a *= weight_inv;
51  }
52  else {
53  output_color = default_color_;
54  }
55  }
56 }
57 
58 } // namespace blender::attribute_math
#define BLI_assert(a)
Definition: BLI_assert.h:58
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void mix_in(const int64_t index, const Color4f &color, const float weight=1.0f)
Color4fMixer(MutableSpan< Color4f > buffer, Color4f default_color={0, 0, 0, 1})
__int64 int64_t
Definition: stdint.h:92