45 #include "CAVolumeCurve.h"
46 #include "CADebugMacros.h"
53 CAVolumeCurve::CAVolumeCurve()
57 mIsApplyingTransferFunction(true),
58 mTransferFunction(kPow2Over1Curve),
59 mRawToScalarExponentNumerator(2.0),
60 mRawToScalarExponentDenominator(1.0)
64 CAVolumeCurve::~CAVolumeCurve()
68 SInt32 CAVolumeCurve::GetMinimumRaw()
const
72 if(!mCurveMap.empty())
74 CurveMap::const_iterator theIterator = mCurveMap.begin();
75 theAnswer = theIterator->first.mMinimum;
81 SInt32 CAVolumeCurve::GetMaximumRaw()
const
85 if(!mCurveMap.empty())
87 CurveMap::const_iterator theIterator = mCurveMap.begin();
88 std::advance(theIterator, mCurveMap.size() - 1);
89 theAnswer = theIterator->first.mMaximum;
95 Float64 CAVolumeCurve::GetMinimumDB()
const
97 Float64 theAnswer = 0;
99 if(!mCurveMap.empty())
101 CurveMap::const_iterator theIterator = mCurveMap.begin();
102 theAnswer = theIterator->second.mMinimum;
108 Float64 CAVolumeCurve::GetMaximumDB()
const
110 Float64 theAnswer = 0;
112 if(!mCurveMap.empty())
114 CurveMap::const_iterator theIterator = mCurveMap.begin();
115 std::advance(theIterator, mCurveMap.size() - 1);
116 theAnswer = theIterator->second.mMaximum;
122 void CAVolumeCurve::SetTransferFunction(
int inTransferFunction)
124 mTransferFunction = inTransferFunction;
127 switch(inTransferFunction)
130 mIsApplyingTransferFunction =
false;
131 mRawToScalarExponentNumerator = 1.0;
132 mRawToScalarExponentDenominator = 1.0;
135 case kPow1Over3Curve:
136 mIsApplyingTransferFunction =
true;
137 mRawToScalarExponentNumerator = 1.0;
138 mRawToScalarExponentDenominator = 3.0;
141 case kPow1Over2Curve:
142 mIsApplyingTransferFunction =
true;
143 mRawToScalarExponentNumerator = 1.0;
144 mRawToScalarExponentDenominator = 2.0;
147 case kPow3Over4Curve:
148 mIsApplyingTransferFunction =
true;
149 mRawToScalarExponentNumerator = 3.0;
150 mRawToScalarExponentDenominator = 4.0;
153 case kPow3Over2Curve:
154 mIsApplyingTransferFunction =
true;
155 mRawToScalarExponentNumerator = 3.0;
156 mRawToScalarExponentDenominator = 2.0;
159 case kPow2Over1Curve:
160 mIsApplyingTransferFunction =
true;
161 mRawToScalarExponentNumerator = 2.0;
162 mRawToScalarExponentDenominator = 1.0;
165 case kPow3Over1Curve:
166 mIsApplyingTransferFunction =
true;
167 mRawToScalarExponentNumerator = 3.0;
168 mRawToScalarExponentDenominator = 1.0;
171 case kPow4Over1Curve:
172 mIsApplyingTransferFunction =
true;
173 mRawToScalarExponentNumerator = 4.0;
174 mRawToScalarExponentDenominator = 1.0;
177 case kPow5Over1Curve:
178 mIsApplyingTransferFunction =
true;
179 mRawToScalarExponentNumerator = 5.0;
180 mRawToScalarExponentDenominator = 1.0;
183 case kPow6Over1Curve:
184 mIsApplyingTransferFunction =
true;
185 mRawToScalarExponentNumerator = 6.0;
186 mRawToScalarExponentDenominator = 1.0;
189 case kPow7Over1Curve:
190 mIsApplyingTransferFunction =
true;
191 mRawToScalarExponentNumerator = 7.0;
192 mRawToScalarExponentDenominator = 1.0;
195 case kPow8Over1Curve:
196 mIsApplyingTransferFunction =
true;
197 mRawToScalarExponentNumerator = 8.0;
198 mRawToScalarExponentDenominator = 1.0;
201 case kPow9Over1Curve:
202 mIsApplyingTransferFunction =
true;
203 mRawToScalarExponentNumerator = 9.0;
204 mRawToScalarExponentDenominator = 1.0;
207 case kPow10Over1Curve:
208 mIsApplyingTransferFunction =
true;
209 mRawToScalarExponentNumerator = 10.0;
210 mRawToScalarExponentDenominator = 1.0;
213 case kPow11Over1Curve:
214 mIsApplyingTransferFunction =
true;
215 mRawToScalarExponentNumerator = 11.0;
216 mRawToScalarExponentDenominator = 1.0;
219 case kPow12Over1Curve:
220 mIsApplyingTransferFunction =
true;
221 mRawToScalarExponentNumerator = 12.0;
222 mRawToScalarExponentDenominator = 1.0;
226 mIsApplyingTransferFunction =
true;
227 mRawToScalarExponentNumerator = 2.0;
228 mRawToScalarExponentDenominator = 1.0;
233 void CAVolumeCurve::AddRange(SInt32 inMinRaw, SInt32 inMaxRaw, Float64 inMinDB, Float64 inMaxDB)
235 CARawPoint theRaw(inMinRaw, inMaxRaw);
236 CADBPoint theDB(inMinDB, inMaxDB);
238 bool isOverlapped =
false;
240 CurveMap::iterator theIterator = mCurveMap.begin();
241 while((theIterator != mCurveMap.end()) && !isOverlapped && !isDone)
243 isOverlapped = CARawPoint::Overlap(theRaw, theIterator->first);
244 isDone = theRaw >= theIterator->first;
246 if(!isOverlapped && !isDone)
248 std::advance(theIterator, 1);
254 mCurveMap.insert(CurveMap::value_type(theRaw, theDB));
258 DebugMessage(
"CAVolumeCurve::AddRange: new point overlaps");
262 void CAVolumeCurve::ResetRange()
267 bool CAVolumeCurve::CheckForContinuity()
const
269 bool theAnswer =
true;
271 CurveMap::const_iterator theIterator = mCurveMap.begin();
272 if(theIterator != mCurveMap.end())
274 SInt32 theRaw = theIterator->first.mMinimum;
275 Float64 theDB = theIterator->second.mMinimum;
278 SInt32 theRawMin = theIterator->first.mMinimum;
279 SInt32 theRawMax = theIterator->first.mMaximum;
280 SInt32 theRawRange = theRawMax - theRawMin;
282 Float64 theDBMin = theIterator->second.mMinimum;
283 Float64 theDBMax = theIterator->second.mMaximum;
284 Float64 theDBRange = theDBMax - theDBMin;
286 theAnswer = theRaw == theRawMin;
287 theAnswer = theDB == theDBMin;
289 theRaw += theRawRange;
292 std::advance(theIterator, 1);
294 while((theIterator != mCurveMap.end()) && theAnswer);
300 SInt32 CAVolumeCurve::ConvertDBToRaw(Float64 inDB)
const
303 Float64 theOverallDBMin = GetMinimumDB();
304 Float64 theOverallDBMax = GetMaximumDB();
306 if(inDB < theOverallDBMin) inDB = theOverallDBMin;
307 if(inDB > theOverallDBMax) inDB = theOverallDBMax;
310 CurveMap::const_iterator theIterator = mCurveMap.begin();
313 SInt32 theAnswer = theIterator->first.mMinimum;
317 while(!isDone && (theIterator != mCurveMap.end()))
319 SInt32 theRawMin = theIterator->first.mMinimum;
320 SInt32 theRawMax = theIterator->first.mMaximum;
321 SInt32 theRawRange = theRawMax - theRawMin;
323 Float64 theDBMin = theIterator->second.mMinimum;
324 Float64 theDBMax = theIterator->second.mMaximum;
325 Float64 theDBRange = theDBMax - theDBMin;
327 Float64 theDBPerRaw = theDBRange /
static_cast<Float64
>(theRawRange);
333 theAnswer += theRawRange;
339 Float64 theNumberRawSteps = inDB - theDBMin;
340 theNumberRawSteps /= theDBPerRaw;
343 theNumberRawSteps = round(theNumberRawSteps);
346 theAnswer +=
static_cast<SInt32
>(theNumberRawSteps);
353 std::advance(theIterator, 1);
359 Float64 CAVolumeCurve::ConvertRawToDB(SInt32 inRaw)
const
361 Float64 theAnswer = 0;
364 SInt32 theOverallRawMin = GetMinimumRaw();
365 SInt32 theOverallRawMax = GetMaximumRaw();
367 if(inRaw < theOverallRawMin) inRaw = theOverallRawMin;
368 if(inRaw > theOverallRawMax) inRaw = theOverallRawMax;
371 SInt32 theNumberRawSteps = inRaw - theOverallRawMin;
374 CurveMap::const_iterator theIterator = mCurveMap.begin();
377 theAnswer = theIterator->second.mMinimum;
380 while((theNumberRawSteps > 0) && (theIterator != mCurveMap.end()))
383 SInt32 theRawMin = theIterator->first.mMinimum;
384 SInt32 theRawMax = theIterator->first.mMaximum;
385 SInt32 theRawRange = theRawMax - theRawMin;
387 Float64 theDBMin = theIterator->second.mMinimum;
388 Float64 theDBMax = theIterator->second.mMaximum;
389 Float64 theDBRange = theDBMax - theDBMin;
391 Float64 theDBPerRaw = theDBRange /
static_cast<Float64
>(theRawRange);
394 SInt32 theRawStepsToAdd = std::min(theRawRange, theNumberRawSteps);
397 theAnswer += theRawStepsToAdd * theDBPerRaw;
400 theNumberRawSteps -= theRawStepsToAdd;
403 std::advance(theIterator, 1);
409 Float64 CAVolumeCurve::ConvertRawToScalar(SInt32 inRaw)
const
412 Float64 theDBMin = GetMinimumDB();
413 Float64 theDBMax = GetMaximumDB();
414 Float64 theDBRange = theDBMax - theDBMin;
415 SInt32 theRawMin = GetMinimumRaw();
416 SInt32 theRawMax = GetMaximumRaw();
417 SInt32 theRawRange = theRawMax - theRawMin;
420 if(inRaw < theRawMin) inRaw = theRawMin;
421 if(inRaw > theRawMax) inRaw = theRawMax;
424 Float64 theAnswer =
static_cast<Float64
>(inRaw - theRawMin) / static_cast<Float64>(theRawRange);
427 if(mIsApplyingTransferFunction && (theDBRange > 30.0))
429 theAnswer = pow(theAnswer, mRawToScalarExponentNumerator / mRawToScalarExponentDenominator);
435 Float64 CAVolumeCurve::ConvertDBToScalar(Float64 inDB)
const
437 SInt32 theRawValue = ConvertDBToRaw(inDB);
438 Float64 theAnswer = ConvertRawToScalar(theRawValue);
442 SInt32 CAVolumeCurve::ConvertScalarToRaw(Float64 inScalar)
const
445 inScalar = std::min(1.0, std::max(0.0, inScalar));
448 Float64 theDBMin = GetMinimumDB();
449 Float64 theDBMax = GetMaximumDB();
450 Float64 theDBRange = theDBMax - theDBMin;
451 SInt32 theRawMin = GetMinimumRaw();
452 SInt32 theRawMax = GetMaximumRaw();
453 SInt32 theRawRange = theRawMax - theRawMin;
456 if(mIsApplyingTransferFunction && (theDBRange > 30.0))
458 inScalar = pow(inScalar, mRawToScalarExponentDenominator / mRawToScalarExponentNumerator);
462 Float64 theNumberRawSteps = inScalar *
static_cast<Float64
>(theRawRange);
463 theNumberRawSteps = round(theNumberRawSteps);
466 SInt32 theAnswer = theRawMin +
static_cast<SInt32
>(theNumberRawSteps);
471 Float64 CAVolumeCurve::ConvertScalarToDB(Float64 inScalar)
const
473 SInt32 theRawValue = ConvertScalarToRaw(inScalar);
474 Float64 theAnswer = ConvertRawToDB(theRawValue);