Blender V2.61 - r43446

subd_stencil.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "subd_stencil.h"
00020 
00021 #include "util_debug.h"
00022 #include "util_math.h"
00023 
00024 CCL_NAMESPACE_BEGIN
00025 
00026 StencilMask::StencilMask()
00027 {
00028 }
00029 
00030 StencilMask::StencilMask(int size)
00031 {
00032     /* initialize weights to zero. */
00033     weights.resize(size, 0.0f);
00034 }
00035 
00036 void StencilMask::resize(int size)
00037 {
00038     weights.resize(size, 0.0f);
00039 }
00040 
00041 StencilMask& StencilMask::operator=(float value)
00042 {
00043     const int size = weights.size();
00044     for(int i = 0; i < size; i++)
00045         weights[i] = value;
00046 
00047     return *this;
00048 }
00049 
00050 void StencilMask::operator+=(const StencilMask& mask)
00051 {
00052     assert(mask.size() == size());
00053     
00054     const int size = weights.size();
00055     for(int i = 0; i < size; i++)
00056         weights[i] += mask.weights[i];
00057 }
00058 
00059 void StencilMask::operator-=(const StencilMask& mask)
00060 {
00061     assert(mask.size() == size());
00062     
00063     const int size = weights.size();
00064     for(int i = 0; i < size; i++)
00065         weights[i] -= mask.weights[i];
00066 }
00067 
00068 void StencilMask::operator*=(float scale)
00069 {
00070     const int size = weights.size();
00071 
00072     for(int i = 0; i < size; i++)
00073         weights[i] *= scale;
00074 }
00075 
00076 void StencilMask::operator/=(float scale)
00077 {
00078     *this *= 1.0f/scale;
00079 }
00080 
00081 float StencilMask::sum() const
00082 {
00083     float total = 0.0f;
00084     const int size = weights.size();
00085 
00086     for(int i = 0; i < size; i++)
00087         total += weights[i];
00088     
00089     return total;
00090 }
00091 
00092 bool StencilMask::is_normalized() const
00093 {
00094     return fabsf(sum() - 1.0f) < 0.0001f;
00095 }
00096 
00097 void StencilMask::normalize()
00098 {
00099     *this /= sum();
00100 }
00101 
00102 CCL_NAMESPACE_END
00103