BitmapToolkit Scol plugin
Smoothers.cpp
Go to the documentation of this file.
1#include "Smoothers.h"
2
3template <typename T>
5{
6 if (std::is_same<T, float>::value)
8 else if (std::is_same<T, Vector2>::value)
10 else if (std::is_same<T, Vector3>::value)
11 return SMOOTHER_TYPE_VEC3;
13}
14
16// Linear Smoothing
17// Constructor
18template <typename T>
20{
21 mFactor = factor;
22 initialized = false;
23 value = T();
24}
25
26template <typename T>
28{
29 mFactor = factor;
30}
31
32// Extrapolate
33template <typename T>
35{
36 return value;
37}
38
39// Smooth
40template <typename T>
42{
43 return value;
44}
45
46// Internal compute
47template <typename T>
49{
50 if (!initialized)
51 {
52 value = val;
53 initialized = true;
54 return;
55 }
56
57 T lastValue = value;
58 value = mFactor * val + (1.0f - mFactor) * lastValue;
59}
60
61// Smoother method SMOOTHER_METHOD_LINEAR
62template <typename T>
67
68template <typename T>
70{
71 initialized = false;
72}
74
76// Double Exponential Smoothing
77// Constructor
78template <typename T>
80{
81 mAlpha = alpha;
82 mBeta = beta;
83 value = T();
84 slope = T();
85 init = false;
86}
87
88template <typename T>
90{
91 mAlpha = alpha;
92 mBeta = beta;
93}
94
95// Extrapolate
96template <typename T>
98{
99 return value + slope;
100}
101
102// Smooth
103template <typename T>
108
109// Internal compute
110template <typename T>
112{
113 if (!init)
114 {
115 slope = T();
116 value = val;
117 init = true;
118 return;
119 }
120
121 T lastValue = value;
122 value = (mAlpha * val) + ((1.0f - mAlpha) * (value + slope));
123 slope = (mBeta * (value - lastValue)) + ((1.0f - mBeta) * slope);
124}
125
126// Smoother method SMOOTHER_METHOD_DOUBLEEXP
127template <typename T>
132
133template <typename T>
135{
136 init = false;
137}
139
141// Force compile for float, Vector2, Vector3
142template class DoubleExponentialSmoother < float > ;
143template class DoubleExponentialSmoother < Vector2 >;
144template class DoubleExponentialSmoother < Vector3 >;
145
146template class LinearSmoother < float >;
147template class LinearSmoother < Vector2 >;
148template class LinearSmoother < Vector3 >;
149
#define SMOOTHER_TYPE_VEC2
Definition Smoothers.h:9
#define SMOOTHER_TYPE_VEC3
Definition Smoothers.h:10
#define SMOOTHER_TYPE_FLOAT
Definition Smoothers.h:8
#define SMOOTHER_TYPE_UNDEFINED
Definition Smoothers.h:7
#define SMOOTHER_METHOD_LINEAR
Definition Smoothers.h:13
#define SMOOTHER_METHOD_DOUBLEEXP
Definition Smoothers.h:14
virtual void clearValues()
DoubleExponentialSmoother(float alpha=0.5f, float beta=0.5f)
Definition Smoothers.cpp:79
virtual void pushValue(T val)
virtual int getSmootherMethod()
void setSmoothingFactor(float alpha, float beta)
Definition Smoothers.cpp:89
virtual T getExtrapolatedValue()
Definition Smoothers.cpp:97
virtual void clearValues()
Definition Smoothers.cpp:69
virtual T getSmoothedValue()
Definition Smoothers.cpp:41
virtual void pushValue(T val)
Definition Smoothers.cpp:48
virtual int getSmootherMethod()
Definition Smoothers.cpp:63
void setSmoothingFactor(float factor)
Definition Smoothers.cpp:27
LinearSmoother(float factor=0.5f)
Definition Smoothers.cpp:19
virtual T getExtrapolatedValue()
Definition Smoothers.cpp:34
int getSmootherType()
Definition Smoothers.cpp:4