annotate src/Modules/Output/Graphics/Scale/Scale.cc @ 185:550d0d6bffe5

- AWS
author tomwalters
date Wed, 11 Aug 2010 13:06:30 +0000
parents 9d880fb93c39
children 73c6d61440ad
rev   line source
tomwalters@116 1 /*!
tomwalters@116 2 * \file
tomwalters@116 3 * \brief Frequency scale for generating filter banks and their frequencies
tomwalters@116 4 *
tomwalters@116 5 * \author Willem van Engen <cnbh@willem.engen.nl>
tomwalters@116 6 * \date created 2006/09/28
tomwalters@116 7 * \version \$Id: Scale.cpp 459 2007-11-08 11:50:04Z tom $
tomwalters@116 8 */
tomwalters@116 9 /* (c) 2006, University of Cambridge, Medical Research Council
tomwalters@116 10 * http://www.pdn.cam.ac.uk/groups/cnbh/aimmanual
tomwalters@116 11 */
tom@118 12 #include "Support/Common.h"
tom@118 13 #include "Modules/Output/Graphics/Scale/Scale.h"
tom@118 14 #include "Modules/Output/Graphics/Scale/ScaleLinear.h"
tom@118 15 #include "Modules/Output/Graphics/Scale/ScaleERB.h"
tom@118 16 #include "Modules/Output/Graphics/Scale/ScaleLog.h"
tom@118 17 #include "Modules/Output/Graphics/Scale/ScaleLogScaled.h"
tomwalters@116 18
tom@119 19 namespace aimc {
tom@119 20
tom@118 21 Scale *Scale::Create(ScaleType iType,
tom@118 22 unsigned int min,
tom@118 23 unsigned int max,
tom@118 24 float density) {
tomwalters@117 25 switch(iType) {
tomwalters@117 26 case SCALE_LINEAR:
tomwalters@117 27 return static_cast<Scale*>(new ScaleLinear(min, max, density));
tomwalters@117 28 case SCALE_ERB:
tomwalters@117 29 return static_cast<Scale*>(new ScaleERB(min, max, density));
tomwalters@117 30 case SCALE_LOG:
tomwalters@117 31 return static_cast<Scale*>(new ScaleLog(min, max, density));
tomwalters@117 32 case SCALE_LOGSCALED:
tomwalters@117 33 return static_cast<Scale*>(new ScaleLogScaled(min, max, density));
tomwalters@117 34 default:
tom@119 35 AIM_ASSERT(0);
tomwalters@117 36 break;
tomwalters@117 37 }
tomwalters@117 38 // Unreachable code
tom@119 39 AIM_ASSERT(0);
tomwalters@117 40 return NULL;
tomwalters@116 41 }
tomwalters@116 42
tom@118 43 Scale *Scale::Create(ScaleType iType) {
tomwalters@117 44 return Create(iType, 0, 0, 0);
tomwalters@116 45 }
tomwalters@116 46
tom@118 47 Scale *Scale::Clone() {
tomwalters@117 48 Scale *pScale = Create(m_iType, m_iMin, m_iMax, m_fDensity);
tom@118 49 AIM_ASSERT(pScale);
tomwalters@117 50 pScale->m_fScaledCurHalfSum = m_fScaledCurHalfSum;
tomwalters@117 51 pScale->m_fScaledCurDiff = m_fScaledCurDiff;
tomwalters@117 52 return pScale;
tomwalters@116 53 }
tomwalters@116 54
tom@118 55 float Scale::FromLinearScaled(float fVal) {
tomwalters@117 56 /*! This function returns
tomwalters@117 57 * ( FromLinear(fVal) - (fMinScaled+fMaxScaled)/2 ) / (fMaxScaled-fMinScaled)
tomwalters@117 58 */
tomwalters@117 59 float fValScaled = FromLinear(fVal);
tomwalters@117 60 return (fValScaled - m_fScaledCurHalfSum) / m_fScaledCurDiff;
tomwalters@116 61 }
tom@118 62
tom@118 63 void Scale::FromLinearScaledExtrema(float fMin, float fMax) {
tomwalters@117 64 float fMinScaled = FromLinear(fMin);
tomwalters@117 65 float fMaxScaled = FromLinear(fMax);
tomwalters@117 66 m_fScaledCurHalfSum = (fMinScaled+fMaxScaled)/2;
tomwalters@117 67 m_fScaledCurDiff = fMaxScaled-fMinScaled;
tomwalters@117 68 m_fMin = fMin;
tomwalters@117 69 m_fMax = fMax;
tomwalters@116 70 }
tom@118 71
tom@118 72 void Scale::FromLinearScaledExtrema(Scale *pScale) {
tom@119 73 AIM_ASSERT(pScale);
tomwalters@117 74 FromLinearScaledExtrema(pScale->m_fMin, pScale->m_fMax);
tomwalters@116 75 }
tom@119 76 } // namespace aimc