From 17fb55c9e09a9f12b2f3e4097aaa5255d42f7425 Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 7 Jun 2005 07:44:08 +0000 Subject: [PATCH] Added Percentile and removed small bug in Add --- vcg/math/histogram.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/vcg/math/histogram.h b/vcg/math/histogram.h index 825399ec..8a6d9b65 100644 --- a/vcg/math/histogram.h +++ b/vcg/math/histogram.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +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 @@ -121,12 +124,13 @@ int Histogram::Interize(ScalarType val) template void Histogram::Add(ScalarType v){ int pos= lower_bound(R.begin(),R.end(),v)-R.begin()-1; - if(pos<=n){ + if(pos>=0 && pos<=n){ ++H[pos]; ++cnt; avg+=v; rms += v*v; } + } @@ -137,5 +141,26 @@ fp=fopen(filename.c_str(),"w"); for(int i=0;i +ScalarType Histogram::Percentile(ScalarType frac) const +{ + if(H.size()==0 && R.size()==0) return 0; + assert(frac>=0 && frac<=1); + ScalarType sum=0,partsum=0; + int isum=0,ipartsum=0; + for(int i=0;i=sum) break; + } + return R[i+1]; +} + + }// end namespace #endif