35#ifndef AAX_CPIECEWISELINEARTAPERDELEGATE_H
36#define AAX_CPIECEWISELINEARTAPERDELEGATE_H
67template <
typename T,
int32_t RealPrecision=100>
93 T
Round(
double iValue)
const;
96 double* mNormalizedValues;
103template <
typename T,
int32_t RealPrecision>
106 if (RealPrecision > 0)
107 return static_cast<T
>(floor(iValue * RealPrecision + 0.5) / RealPrecision);
109 return static_cast<T
>(iValue);
112template <
typename T,
int32_t RealPrecision>
114 mNormalizedValues(0),
120 mNormalizedValues =
new double[numValues];
121 mRealValues =
new T[numValues];
122 mNumValues = numValues;
126 mMaxValue = realValues[0];
127 mMinValue = realValues[0];
129 for (int32_t i=0; i< numValues; i++)
131 mNormalizedValues[i] = normalizedValues[i];
132 mRealValues[i] = realValues[i];
133 if (mRealValues[i] > mMaxValue)
134 mMaxValue = mRealValues[i];
135 if (mRealValues[i] < mMinValue)
136 mMinValue = mRealValues[i];
140template <
typename T,
int32_t RealPrecision>
142 mNormalizedValues(0),
148 mNormalizedValues =
new double[other.mNumValues];
149 mRealValues =
new T[other.mNumValues];
150 mNumValues = other.mNumValues;
151 mMaxValue = other.mMaxValue;
152 mMinValue = other.mMinValue;
153 for (int32_t i=0; i< mNumValues; i++)
155 mNormalizedValues[i] = other.mNormalizedValues[i];
156 mRealValues[i] = other.mRealValues[i];
160template <
typename T,
int32_t RealPrecision>
164 delete [] mNormalizedValues;
165 delete [] mRealValues;
169template <
typename T,
int32_t RealPrecision>
175template <
typename T,
int32_t RealPrecision>
178 if (mMinValue == mMaxValue)
182 value = Round(value);
184 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
185 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
187 if (value > highValue)
189 if (value < lowValue)
195template <
typename T,
int32_t RealPrecision>
200 if (normalizedValue > 1.0)
201 normalizedValue = 1.0;
202 if (normalizedValue < 0.0)
203 normalizedValue = 0.0;
206 int32_t mLowerIndex = 0;
207 int32_t mUpperIndex = 0;
208 for (int32_t i=1;i<mNumValues;i++)
211 if (mNormalizedValues[i] >= normalizedValue)
217 double delta = normalizedValue - mNormalizedValues[mLowerIndex];
218 double slope = double(mRealValues[mUpperIndex] - mRealValues[mLowerIndex]) / (mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]);
219 double interpolatedValue = mRealValues[mLowerIndex] + (delta * slope);
220 return ConstrainRealValue(
static_cast<T
>(interpolatedValue));
223template <
typename T,
int32_t RealPrecision>
226 realValue = ConstrainRealValue(realValue);
229 int32_t mLowerIndex = 0;
230 int32_t mUpperIndex = 0;
231 if (mRealValues[0] < mRealValues[mNumValues-1])
234 for (int32_t i=1;i<mNumValues;i++)
237 if (mRealValues[i] >= realValue)
245 for (int32_t i=1;i<mNumValues;i++)
248 if (mRealValues[i] <= realValue)
255 double delta = realValue - mRealValues[mLowerIndex];
256 double slope = (mRealValues[mUpperIndex] == mRealValues[mLowerIndex]) ? 0.5 :
double(mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]) / (mRealValues[mUpperIndex] - mRealValues[mLowerIndex]);
257 double interpolatedValue = mNormalizedValues[mLowerIndex] + (delta * slope);
258 return static_cast<T
>(interpolatedValue);
Defines the taper conversion behavior for a parameter.
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
A piece-wise linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:69
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:87
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:113
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:86
~AAX_CPieceWiseLinearTaperDelegate()
Definition: AAX_CPieceWiseLinearTaperDelegate.h:161
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:224
T Round(double iValue) const
Definition: AAX_CPieceWiseLinearTaperDelegate.h:104
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:196
AAX_CPieceWiseLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:170
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:176
Definition: AAX_ITaperDelegate.h:99