Go to the documentation of this file.00001
00002
00003
00004
00005
00009
00010 #ifndef qtFloatMath_H_
00011 #define qtFloatMath_H_
00012
00013 #include "lgrGui.h"
00014
00015 #include <QtCore/QPoint>
00016 #include <QtCore/QRect>
00017 #include <math.h>
00018
00019 #include <limits.h>
00020 #define DT_ROUND(x) (((x) < LONG_MIN-0.5 || (x) > LONG_MAX+0.5) ? 0 : ((x)>=0?(int)((x)+0.5):(int)((x)-0.5)))
00021
00022 namespace MAKLogger
00023 {
00027 class DT_DLL_LGRGUI DtValueSmoother
00028 {
00029 public:
00030
00031 DtValueSmoother(int valuesToBuffer,double init)
00032 {
00033 myValues = new double[valuesToBuffer];
00034 myBufferSize = valuesToBuffer;
00035 for(int i = 0;i < myBufferSize;++i)
00036 {
00037 myValues[i] = init;
00038 }
00039
00040 }
00041
00042 ~DtValueSmoother()
00043 {
00044 delete[] myValues;
00045 }
00046
00047 void addValue(double value)
00048 {
00049 for(int i = 1;i < myBufferSize;++i)
00050 {
00051 myValues[i-1] = myValues[i];
00052 }
00053 myValues[myBufferSize-1] = value;
00054 }
00055
00057 double getSmoothedValue()
00058 {
00060 double deltaD = 0.0;
00061 for(int i = 1;i < myBufferSize;++i)
00062 {
00063 deltaD += myValues[i] - myValues[i-1];
00064 }
00065 deltaD /= (myBufferSize-1);
00066
00068 double newValue = 0.0;
00069 for(int j = 0;j < myBufferSize;++j)
00070 {
00071 newValue += myValues[j] + ((myBufferSize - j) * deltaD);
00072 }
00073 newValue /= myBufferSize;
00074 return newValue;
00075 }
00076
00077 protected:
00078 double* myValues;
00079 int myBufferSize;
00080 };
00081
00082
00083
00084 }
00085
00086 #endif
00087