25 #ifndef AAX_CPIECEWISELINEARTAPERDELEGATE_H
26 #define AAX_CPIECEWISELINEARTAPERDELEGATE_H
57 template <
typename T,
int32_t RealPrecision=100>
83 T
Round(
double iValue)
const;
86 double* mNormalizedValues;
93 template <
typename T,
int32_t RealPrecision>
96 if (RealPrecision > 0)
97 return static_cast<T
>(floor(iValue * RealPrecision + 0.5) / RealPrecision);
99 return static_cast<T
>(iValue);
102 template <
typename T,
int32_t RealPrecision>
104 mNormalizedValues(0),
110 mNormalizedValues =
new double[numValues];
111 mRealValues =
new T[numValues];
112 mNumValues = numValues;
116 mMaxValue = realValues[0];
117 mMinValue = realValues[0];
119 for (int32_t i=0; i< numValues; i++)
121 mNormalizedValues[i] = normalizedValues[i];
122 mRealValues[i] = realValues[i];
123 if (mRealValues[i] > mMaxValue)
124 mMaxValue = mRealValues[i];
125 if (mRealValues[i] < mMinValue)
126 mMinValue = mRealValues[i];
130 template <
typename T,
int32_t RealPrecision>
132 mNormalizedValues(0),
138 mNormalizedValues =
new double[other.mNumValues];
139 mRealValues =
new T[other.mNumValues];
140 mNumValues = other.mNumValues;
141 mMaxValue = other.mMaxValue;
142 mMinValue = other.mMinValue;
143 for (int32_t i=0; i< mNumValues; i++)
145 mNormalizedValues[i] = other.mNormalizedValues[i];
146 mRealValues[i] = other.mRealValues[i];
150 template <
typename T,
int32_t RealPrecision>
154 delete [] mNormalizedValues;
155 delete [] mRealValues;
159 template <
typename T,
int32_t RealPrecision>
165 template <
typename T,
int32_t RealPrecision>
169 value = Round(value);
171 if (value > mMaxValue)
173 if (value < mMinValue)
178 template <
typename T,
int32_t RealPrecision>
183 if (normalizedValue > 1.0)
184 normalizedValue = 1.0;
185 if (normalizedValue < 0.0)
186 normalizedValue = 0.0;
189 int32_t mLowerIndex = 0;
190 int32_t mUpperIndex = 0;
191 for (int32_t i=1;i<mNumValues;i++)
194 if (mNormalizedValues[i] >= normalizedValue)
200 double delta = normalizedValue - mNormalizedValues[mLowerIndex];
201 double slope = double(mRealValues[mUpperIndex] - mRealValues[mLowerIndex]) / (mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]);
202 double interpolatedValue = mRealValues[mLowerIndex] + (delta * slope);
203 return ConstrainRealValue(static_cast<T>(interpolatedValue));
206 template <
typename T,
int32_t RealPrecision>
209 realValue = ConstrainRealValue(realValue);
212 int32_t mLowerIndex = 0;
213 int32_t mUpperIndex = 0;
214 if (mRealValues[0] < mRealValues[mNumValues-1])
217 for (int32_t i=1;i<mNumValues;i++)
220 if (mRealValues[i] >= realValue)
228 for (int32_t i=1;i<mNumValues;i++)
231 if (mRealValues[i] <= realValue)
238 double delta = realValue - mRealValues[mLowerIndex];
239 double slope = double(mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]) / (mRealValues[mUpperIndex] - mRealValues[mLowerIndex]);
240 double interpolatedValue = mNormalizedValues[mLowerIndex] + (delta * slope);
241 return static_cast<T
>(interpolatedValue);
247 #endif //AAX_CPIECEWISELINEARTAPERDELEGATE_H
Various utility definitions for AAX.
T Round(double iValue) const
Definition: AAX_CPieceWiseLinearTaperDelegate.h:94
T GetMaximumValue() const
Returns the taper's maximum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:77
Defines the taper conversion behavior for a parameter.
AAX_CPieceWiseLinearTaperDelegate(const double *normalizedValues, const T *realValues, int32_t numValues)
Constructs a Piece-wise Linear Taper with paired normalized and real values.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:103
Classes for conversion to and from normalized parameter values.
Definition: AAX_ITaperDelegate.h:88
AAX_CPieceWiseLinearTaperDelegate< T, RealPrecision > * Clone() const
Constructs and returns a copy of the taper delegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:160
T GetMinimumValue() const
Returns the taper's minimum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:76
~AAX_CPieceWiseLinearTaperDelegate()
Definition: AAX_CPieceWiseLinearTaperDelegate.h:151
double RealToNormalized(T realValue) const
Normalizes a real parameter value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:207
A piece-wise linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:58
T ConstrainRealValue(T value) const
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:166
T NormalizedToReal(double normalizedValue) const
Converts a normalized value to a real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:179