Added methods to Histogram and Distribution to get back the number of inserted samples and their total sum

This commit is contained in:
Paolo Cignoni 2014-05-13 10:54:42 +00:00
parent 5c7949d261
commit db0a706384
1 changed files with 244 additions and 304 deletions

View File

@ -20,70 +20,6 @@
* for more details. *
* *
****************************************************************************/
/****************************************************************************
History
$Log: not supported by cvs2svn $
Revision 1.18 2008/03/05 11:21:49 cignoni
Heavily refactored the whole structure.
Some interfaces have been changed. Be careful.
Revision 1.17 2008/02/29 12:15:06 cignoni
added maxcount
Revision 1.16 2006/11/28 21:29:21 cignoni
Re added typedef Histogramf and Histogramd
Revision 1.15 2006/11/28 09:47:42 corsini
add documentation
fix typo
Revision 1.14 2006/05/04 00:09:53 cignoni
minor change: removed unused vars
Revision 1.13 2006/03/29 09:25:47 zifnab1974
extra includes necessary for compilation of meshlab on AMD 64 with gcc 3.4.5
Revision 1.12 2006/01/12 13:12:54 callieri
in FileWrite, added file closing after finishing
Revision 1.11 2005/09/16 11:51:23 cignoni
removed signed/unsigned warning
Revision 1.10 2005/06/17 00:54:55 cignoni
Corrected small bug in SetRange (H was resized to n instead of n+1)
Revision 1.9 2005/06/14 14:27:00 ganovelli
added include of algorithm
Revision 1.8 2005/06/10 14:59:39 cignoni
Added include assert.h and cast to ScalarType for a pow in SetRange() function.
Revision 1.7 2005/06/09 14:19:55 cignoni
Added typedef Histogramf and Histogramd
Revision 1.6 2005/06/07 09:37:33 ponchio
Added fabs() to variance, which can sometime be negative in case
of rounding errors (and sqrt chokes on it).
Revision 1.5 2005/06/07 07:44:08 cignoni
Added Percentile and removed small bug in Add
Revision 1.4 2005/04/04 10:48:35 cignoni
Added missing functions Avg, rms etc, now fully (almost) functional
Revision 1.3 2005/03/14 09:23:40 cignoni
Added missing include<vector>
Revision 1.2 2004/08/25 15:15:26 ganovelli
minor changes to comply gcc compiler (typename's and stuff)
Revision 1.1 2004/06/24 09:12:28 cignoni
Initial Release
****************************************************************************/
#ifndef __VCG_HISTOGRAM
#define __VCG_HISTOGRAM
@ -132,19 +68,22 @@ public:
if(v>max_v) max_v=v;
}
ScalarType Min() { return min_v; }
ScalarType Max() { return max_v; }
ScalarType Min() const { return min_v; }
ScalarType Max() const { return max_v; }
ScalarType Cnt() const { return ScalarType(vec.size()); }
ScalarType Sum(){ DirtyCheck(); return valSum; }
ScalarType Avg(){ DirtyCheck(); return avg;}
//! Returns the Root Mean Square of the data.
ScalarType RMS(){ DirtyCheck(); return rms;}
//! Returns the variance of the data.
// the average of the squares less the square of the average.
//! \brief Returns the variance of the data.
/// the average of the squares less the square of the average.
ScalarType Variance(){ DirtyCheck(); return sqrdAvg - avg*avg ;}
//! Returns the standard deviation of the data.
ScalarType StandardDeviation(){ DirtyCheck(); return sqrt( Variance() );}
void DirtyCheck()
{
if(!dirty) return;
@ -201,7 +140,7 @@ protected:
/// incrementally updated values
ScalarType cnt; //! Number of accumulated samples.
ScalarType avg; //! Average.
ScalarType sum; //! Average.
ScalarType rms; //! Root mean square.
/**
@ -224,12 +163,13 @@ public:
*/
void SetRange(ScalarType _minv, ScalarType _maxv, int _n,ScalarType gamma=1.0 );
ScalarType MinV() {return minv;}; //! Minimum value.
ScalarType MaxV() {return maxv;}; //! Maximum value.
ScalarType MinV() {return minv;} //! Minimum value.
ScalarType MaxV() {return maxv;} //! Maximum value.
ScalarType Sum() {return sum;} //! Total sum of inserted values.
ScalarType Cnt() {return cnt;}
ScalarType MinElem() {return minElem;}; //! Minimum element added to the histogram. It could be < or > than MinV;.
ScalarType MaxElem() {return maxElem;}; //! Maximum element added to the histogram. It could be < or > than MinV;..
ScalarType MinElem() {return minElem;} //! Minimum element added to the histogram. It could be < or > than MinV;.
ScalarType MaxElem() {return maxElem;} //! Maximum element added to the histogram. It could be < or > than MinV;..
/**
* Add a new value to the histogram.
@ -240,12 +180,12 @@ public:
void Add(ScalarType v, ScalarType increment=ScalarType(1.0));
ScalarType MaxCount() const;
int BinNum() const {return n;};
int BinNum() const {return n;}
ScalarType BinCount(ScalarType v);
ScalarType BinCountInd(int index) {return H[index];}
ScalarType BinCount(ScalarType v, ScalarType width);
ScalarType BinLowerBound(int index) {return R[index];}
ScalarType BinUpperBound(int index) {return R[index+1];};
ScalarType BinUpperBound(int index) {return R[index+1];}
ScalarType RangeCount(ScalarType rangeMin, ScalarType rangeMax);
ScalarType BinWidth(ScalarType v);
@ -257,7 +197,7 @@ public:
ScalarType Percentile(ScalarType frac) const;
//! Returns the average of the data.
ScalarType Avg(){ return avg/cnt;}
ScalarType Avg(){ return sum/cnt;}
//! Returns the Root Mean Square of the data.
ScalarType RMS(){ return sqrt(rms/double(cnt));}
@ -281,7 +221,7 @@ void Histogram<ScalarType>::Clear()
H.clear();
R.clear();
cnt=0;
avg=0;
sum=0;
rms=0;
n=0;
minv=0;
@ -373,7 +313,7 @@ void Histogram<ScalarType>::Add(ScalarType v, ScalarType increment)
assert((pos>=0)&&(pos<=n+1));
H[pos]+=increment;
cnt+=increment;
avg+=v*increment;
sum+=v*increment;
rms += (v*v)*increment;
}