#include <value_smoother.h>
Nevrax France
Definition at line 45 of file value_smoother.h.
Public Member Functions | |
void | addValue (T dt) |
add a new value to be smoothed. | |
CValueSmootherTemplate (uint n=16) | |
Constructor. | |
const std::vector< T > & | getLastFrames () const |
uint | getNumFrame () const |
T | getSmoothValue () const |
get the smoothed value. | |
void | init (uint n) |
reset the ValueSmoother, and set the number of frame to smooth. | |
void | reset () |
reset only the ValueSmoother | |
Private Attributes | |
uint | _CurFrame |
T | _FrameSum |
std::vector< T > | _LastFrames |
uint | _NumFrame |
|
Constructor.
Definition at line 50 of file value_smoother.h.
00051 { 00052 init(n); 00053 } |
|
add a new value to be smoothed.
Definition at line 80 of file value_smoother.h.
00081 { 00082 if (_LastFrames.empty()) 00083 return; 00084 00085 // update the frame sum. NB: see init(), at start, array is full of 0. so it works even for un-inited values. 00086 _FrameSum-= _LastFrames[_CurFrame]; 00087 _FrameSum+= dt; 00088 00089 // backup this value in the array. 00090 _LastFrames[_CurFrame]= dt; 00091 00092 // next frame. 00093 _CurFrame++; 00094 // _CurFrame%=_LastFrames.size(); 00095 if (_CurFrame >= _LastFrames.size()) 00096 _CurFrame -= _LastFrames.size(); 00097 00098 // update the number of frames added. 00099 _NumFrame++; 00100 _NumFrame= std::min(_NumFrame, (uint)_LastFrames.size()); 00101 } |
|
Definition at line 117 of file value_smoother.h.
00118 { 00119 return _LastFrames; 00120 } |
|
Definition at line 112 of file value_smoother.h.
00113 { 00114 return _NumFrame; 00115 } |
|
get the smoothed value.
Definition at line 104 of file value_smoother.h.
00105 { 00106 if(_NumFrame>0) 00107 return T(_FrameSum / _NumFrame); 00108 else 00109 return T(0); 00110 } |
|
reset the ValueSmoother, and set the number of frame to smooth.
Definition at line 56 of file value_smoother.h. Referenced by NLMISC::CValueSmootherTemplate< bool >::CValueSmootherTemplate(), and NLMISC::CValueSmootherTemplate< float >::CValueSmootherTemplate().
00057 { 00058 // reset all the array to 0. 00059 _LastFrames.clear(); 00060 00061 if (n > 0) 00062 _LastFrames.resize(n, 0); 00063 00064 _CurFrame = 0; 00065 _NumFrame = 0; 00066 _FrameSum = 0; 00067 } |
|
reset only the ValueSmoother
Definition at line 70 of file value_smoother.h.
00071 { 00072 std::fill(_LastFrames.begin(), _LastFrames.end(), T(0)); 00073 00074 _CurFrame = 0; 00075 _NumFrame = 0; 00076 _FrameSum = 0; 00077 } |
|
Definition at line 124 of file value_smoother.h. |
|
Definition at line 126 of file value_smoother.h. |
|
Definition at line 123 of file value_smoother.h. |
|
Definition at line 125 of file value_smoother.h. |