2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "subd_stencil.h"
21
#include "util_debug.h"
22
#include "util_math.h"
26
StencilMask::StencilMask()
30
StencilMask::StencilMask(int size)
32
/* initialize weights to zero. */
33
weights.resize(size, 0.0f);
36
void StencilMask::resize(int size)
38
weights.resize(size, 0.0f);
41
StencilMask& StencilMask::operator=(float value)
43
const int size = weights.size();
44
for(int i = 0; i < size; i++)
50
void StencilMask::operator+=(const StencilMask& mask)
52
assert(mask.size() == size());
54
const int size = weights.size();
55
for(int i = 0; i < size; i++)
56
weights[i] += mask.weights[i];
59
void StencilMask::operator-=(const StencilMask& mask)
61
assert(mask.size() == size());
63
const int size = weights.size();
64
for(int i = 0; i < size; i++)
65
weights[i] -= mask.weights[i];
68
void StencilMask::operator*=(float scale)
70
const int size = weights.size();
72
for(int i = 0; i < size; i++)
76
void StencilMask::operator/=(float scale)
81
float StencilMask::sum() const
84
const int size = weights.size();
86
for(int i = 0; i < size; i++)
92
bool StencilMask::is_normalized() const
94
return fabsf(sum() - 1.0f) < 0.0001f;
97
void StencilMask::normalize()