#include <value_smoother.h>
Inheritance diagram for NLMISC::CValueSmoother:
Public Member Functions | |
void | addValue (floatdt) |
add a new value to be smoothed. | |
CValueSmoother (uint n=16) | |
Constructor. | |
const std::vector< float > & | getLastFrames () const |
uint | getNumFrame () const |
float | 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 |
|
Constructor.
Definition at line 201 of file value_smoother.h. References uint.
00201 : CValueSmootherTemplate<float>(n) 00202 { 00203 } |
|
add a new value to be smoothed.
Definition at line 80 of file value_smoother.h. Referenced by NL3D::CCloudScape::anim(), NL3D::CLoadBalancingGroup::computeRatioAndSmooth(), and NL3D::CCloudScape::init().
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. References uint.
00113 {
00114 return _NumFrame;
00115 }
|
|
get the smoothed value.
Definition at line 104 of file value_smoother.h. Referenced by NL3D::CLoadBalancingGroup::computeRatioAndSmooth().
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. References uint. Referenced by NL3D::CLoadBalancingGroup::CLoadBalancingGroup(), NL3D::CLoadBalancingGroup::computeRatioAndSmooth(), and NL3D::CCloudScape::init().
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. Referenced by NL3D::CLoadBalancingGroup::computeRatioAndSmooth().
00071 { 00072 std::fill(_LastFrames.begin(), _LastFrames.end(), T(0)); 00073 00074 _CurFrame = 0; 00075 _NumFrame = 0; 00076 _FrameSum = 0; 00077 } |