/home/neoflo/smb4k/SERVEUR/Millie/trunk/src/MillieStd.cpp

Aller à la documentation de ce fichier.
00001 /******************************************************************************
00002  *       __    _    _   _       _       _   _____                             *
00003  *       | \  / |  | | | |     | |     | |  | ___|                            *
00004  *       |  \/  |  | | | |     | |     | |  | |_                              *
00005  *       |      |  | | | |     | |     | |  |  _|                             *
00006  *       | |\/| |  | | | |__   | |__   | |  | |__                             *
00007  *       |_|  |_|  |_| |____|  |____|  |_|  |____|                            *
00008  * __________________________________________________________________________ *
00009  *                 Multifunctional Library For Image Processing               *
00010  *                                                                            *
00011  *                                                                            *
00012  *                                                                            *
00013  *      (c) Copyright 2007 by Humbert Florent                                 *
00014  *                                                                            *
00015  *      This program is free software; you can redistribute it and/or modify  *
00016  *      it under the terms of the GNU General Public License as published by  *
00017  *      the Free Software Foundation; only version 2 of the License.          *
00018  *                                                                            *
00019  *      This program is distributed in the hope that it will be useful,       *
00020  *      but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00021  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00022  *      GNU General Public License for more details.                          *
00023  *                                                                            *
00024  *      You should have received a copy of the GNU General Public License     *
00025  *      along with this program; if not, write to the Free Software           *
00026  *      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA             *
00027  *      02111-1307, USA.                                                      *
00028  ******************************************************************************/
00029 
00032 #include "MillieStd.hpp"
00033 
00034 
00035 using namespace Millie;
00036 
00037 /*éventuellement à intégrer directement à la classe DataBuffer*/
00038 float Millie::getMaximum(DataBuffer<float>& buffer)
00039 {
00040   if(buffer.getSize() == 0)
00041     throw IllegalArgument("getMaximum : data buffer empty");
00042 
00043   float maximum = buffer[0];
00044 
00045   for(int i = 1; i<buffer.getSize();i++)
00046   {
00047     if(buffer[i]> maximum)
00048       maximum = buffer[i];
00049   }
00050 
00051   return maximum;
00052 }
00053 
00054 float Millie::getMinimum(DataBuffer<float>& buffer)
00055 {
00056   if(buffer.getSize() == 0)
00057     throw IllegalArgument("getMinimum : data buffer empty");
00058 
00059   float minimum = buffer[0];
00060 
00061   for(int i = 1; i<buffer.getSize(); i++)
00062   {
00063     if(buffer[i]< minimum)
00064       minimum = buffer[i];
00065   }
00066 
00067   return minimum;
00068 }
00069 
00070 /*éventuellement à intégrer directement à la classe DataBuffer*/
00071 float Millie::getMaximum(std::vector<float>& buffer)
00072 {
00073   if(buffer.size() == 0)
00074     throw IllegalArgument("getMaximum : data buffer empty");
00075 
00076   float maximum = buffer[0];
00077 
00078   for(unsigned int i = 1; i<buffer.size();i++)
00079   {
00080     if(buffer[i]> maximum)
00081       maximum = buffer[i];
00082   }
00083 
00084   return maximum;
00085 }
00086 
00087 float Millie::getMinimum(std::vector<float>& buffer)
00088 {
00089   if(buffer.size() == 0)
00090     throw IllegalArgument("getMinimum : data buffer empty");
00091 
00092   float minimum = buffer[0];
00093 
00094   for(unsigned int i = 1; i<buffer.size(); i++)
00095   {
00096     if(buffer[i]< minimum)
00097       minimum = buffer[i];
00098   }
00099 
00100   return minimum;
00101 }
00102 
00103 
00104 
00105 float Millie::getAverage(std::vector<float> & vect)
00106 {
00107   if(vect.size() == 0)
00108     throw IllegalArgument("computeVariance : empty vector");
00109 
00110   float moyenne = 0;
00111   for(unsigned int i = 0; i<vect.size(); i++)
00112     moyenne += vect[i];
00113 
00114   moyenne /= vect.size();
00115   return moyenne;
00116 
00117 }
00118 
00119 float Millie::getVariance(std::vector<float>& vect)
00120 {
00121   float moyenne = getAverage(vect);
00122 
00123   float variance = 0.0f;
00124 
00125   for(unsigned int i = 0; i<vect.size(); i++)
00126     variance += Math::square(vect[i] - moyenne);
00127 
00128   return variance;
00129 }
00130 
00131 float Millie::getVariance(DataBuffer<float>& buffer)
00132 {
00133   float moyenne = getAverage(buffer);
00134 
00135   float variance = 0.0f;
00136 
00137   for(int i = 0; i<buffer.getSize(); i++)
00138     variance += Math::square(buffer[i] - moyenne);
00139 
00140   return variance;
00141 }
00142 
00143 float Millie::getAverage(DataBuffer<float>& buffer)
00144 {
00145   if(buffer.getSize() == 0)
00146     throw IllegalArgument("computeVariance : empty vector");
00147 
00148   float moyenne = 0;
00149   for(int i = 0; i<buffer.getSize(); i++)
00150     moyenne += buffer[i];
00151 
00152   moyenne /= buffer.getSize();
00153   return moyenne;
00154 
00155 }
00156 /*
00157 float Millie::carre(float a)
00158 {
00159  return(a*a);
00160 }
00161 */
00162 
00163 

Généré le Fri May 18 23:24:34 2007 pour Millie par  doxygen 1.5.1