22#ifndef AAX_CPIECEWISELINEARTAPERDELEGATE_H
23#define AAX_CPIECEWISELINEARTAPERDELEGATE_H
54template <
typename T,
int32_t RealPrecision=100>
80 T
Round(
double iValue)
const;
83 double* mNormalizedValues;
90template <
typename T,
int32_t RealPrecision>
93 if (RealPrecision > 0)
94 return static_cast<T
>(floor(iValue * RealPrecision + 0.5) / RealPrecision);
96 return static_cast<T
>(iValue);
99template <
typename T,
int32_t RealPrecision>
101 mNormalizedValues(0),
107 mNormalizedValues =
new double[numValues];
108 mRealValues =
new T[numValues];
109 mNumValues = numValues;
113 mMaxValue = realValues[0];
114 mMinValue = realValues[0];
116 for (int32_t i=0; i< numValues; i++)
118 mNormalizedValues[i] = normalizedValues[i];
119 mRealValues[i] = realValues[i];
120 if (mRealValues[i] > mMaxValue)
121 mMaxValue = mRealValues[i];
122 if (mRealValues[i] < mMinValue)
123 mMinValue = mRealValues[i];
127template <
typename T,
int32_t RealPrecision>
129 mNormalizedValues(0),
135 mNormalizedValues =
new double[other.mNumValues];
136 mRealValues =
new T[other.mNumValues];
137 mNumValues = other.mNumValues;
138 mMaxValue = other.mMaxValue;
139 mMinValue = other.mMinValue;
140 for (int32_t i=0; i< mNumValues; i++)
142 mNormalizedValues[i] = other.mNormalizedValues[i];
143 mRealValues[i] = other.mRealValues[i];
147template <
typename T,
int32_t RealPrecision>
151 delete [] mNormalizedValues;
152 delete [] mRealValues;
156template <
typename T,
int32_t RealPrecision>
162template <
typename T,
int32_t RealPrecision>
165 if (mMinValue == mMaxValue)
169 value = Round(value);
171 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
172 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
174 if (value > highValue)
176 if (value < lowValue)
182template <
typename T,
int32_t RealPrecision>
187 if (normalizedValue > 1.0)
188 normalizedValue = 1.0;
189 if (normalizedValue < 0.0)
190 normalizedValue = 0.0;
193 int32_t mLowerIndex = 0;
194 int32_t mUpperIndex = 0;
195 for (int32_t i=1;i<mNumValues;i++)
198 if (mNormalizedValues[i] >= normalizedValue)
204 double delta = normalizedValue - mNormalizedValues[mLowerIndex];
205 double slope = double(mRealValues[mUpperIndex] - mRealValues[mLowerIndex]) / (mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]);
206 double interpolatedValue = mRealValues[mLowerIndex] + (delta * slope);
207 return ConstrainRealValue(
static_cast<T
>(interpolatedValue));
210template <
typename T,
int32_t RealPrecision>
213 realValue = ConstrainRealValue(realValue);
216 int32_t mLowerIndex = 0;
217 int32_t mUpperIndex = 0;
218 if (mRealValues[0] < mRealValues[mNumValues-1])
221 for (int32_t i=1;i<mNumValues;i++)
224 if (mRealValues[i] >= realValue)
232 for (int32_t i=1;i<mNumValues;i++)
235 if (mRealValues[i] <= realValue)
242 double delta = realValue - mRealValues[mLowerIndex];
243 double slope = (mRealValues[mUpperIndex] == mRealValues[mLowerIndex]) ? 0.5 :
double(mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]) / (mRealValues[mUpperIndex] - mRealValues[mLowerIndex]);
244 double interpolatedValue = mNormalizedValues[mLowerIndex] + (delta * slope);
245 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:151
A piece-wise linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:56
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:74
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:100
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:73
~AAX_CPieceWiseLinearTaperDelegate()
Definition: AAX_CPieceWiseLinearTaperDelegate.h:148
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:211
T Round(double iValue) const
Definition: AAX_CPieceWiseLinearTaperDelegate.h:91
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:183
AAX_CPieceWiseLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:157
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:163
Definition: AAX_ITaperDelegate.h:86