tomwalters@116: /*! tomwalters@116: * \file tomwalters@116: * \brief Frequency scale for generating filter banks and their frequencies tomwalters@116: * tomwalters@116: * \author Willem van Engen tomwalters@116: * \date created 2006/09/28 tomwalters@116: * \version \$Id: Scale.cpp 459 2007-11-08 11:50:04Z tom $ tomwalters@116: */ tomwalters@116: /* (c) 2006, University of Cambridge, Medical Research Council tomwalters@116: * http://www.pdn.cam.ac.uk/groups/cnbh/aimmanual tomwalters@116: */ tom@229: #include "Support/Common.h" tom@229: #include "Modules/Output/Graphics/Scale/Scale.h" tom@229: #include "Modules/Output/Graphics/Scale/ScaleLinear.h" tom@229: #include "Modules/Output/Graphics/Scale/ScaleERB.h" tom@229: #include "Modules/Output/Graphics/Scale/ScaleLog.h" tom@229: #include "Modules/Output/Graphics/Scale/ScaleLogScaled.h" tomwalters@116: tom@229: Scale *Scale::Create(ScaleType iType, tom@229: unsigned int min, tom@229: unsigned int max, tom@229: float density) { tomwalters@228: switch(iType) { tomwalters@228: case SCALE_LINEAR: tomwalters@228: return static_cast(new ScaleLinear(min, max, density)); tomwalters@228: case SCALE_ERB: tomwalters@228: return static_cast(new ScaleERB(min, max, density)); tomwalters@228: case SCALE_LOG: tomwalters@228: return static_cast(new ScaleLog(min, max, density)); tomwalters@228: case SCALE_LOGSCALED: tomwalters@228: return static_cast(new ScaleLogScaled(min, max, density)); tomwalters@228: default: tomwalters@228: aimASSERT(0); tomwalters@228: break; tomwalters@228: } tomwalters@228: // Unreachable code tomwalters@228: aimASSERT(0); tomwalters@228: return NULL; tomwalters@116: } tomwalters@116: tom@229: Scale *Scale::Create(ScaleType iType) { tomwalters@228: return Create(iType, 0, 0, 0); tomwalters@116: } tomwalters@116: tom@229: Scale *Scale::Clone() { tomwalters@228: Scale *pScale = Create(m_iType, m_iMin, m_iMax, m_fDensity); tom@229: AIM_ASSERT(pScale); tomwalters@228: pScale->m_fScaledCurHalfSum = m_fScaledCurHalfSum; tomwalters@228: pScale->m_fScaledCurDiff = m_fScaledCurDiff; tomwalters@228: return pScale; tomwalters@116: } tomwalters@116: tom@229: float Scale::FromLinearScaled(float fVal) { tomwalters@228: /*! This function returns tomwalters@228: * ( FromLinear(fVal) - (fMinScaled+fMaxScaled)/2 ) / (fMaxScaled-fMinScaled) tomwalters@228: */ tomwalters@228: float fValScaled = FromLinear(fVal); tomwalters@228: return (fValScaled - m_fScaledCurHalfSum) / m_fScaledCurDiff; tomwalters@227: } tom@229: tom@229: void Scale::FromLinearScaledExtrema(float fMin, float fMax) { tomwalters@228: float fMinScaled = FromLinear(fMin); tomwalters@228: float fMaxScaled = FromLinear(fMax); tomwalters@228: m_fScaledCurHalfSum = (fMinScaled+fMaxScaled)/2; tomwalters@228: m_fScaledCurDiff = fMaxScaled-fMinScaled; tomwalters@228: m_fMin = fMin; tomwalters@228: m_fMax = fMax; tomwalters@227: } tom@229: tom@229: void Scale::FromLinearScaledExtrema(Scale *pScale) { tomwalters@228: aimASSERT(pScale); tomwalters@228: FromLinearScaledExtrema(pScale->m_fMin, pScale->m_fMax); tomwalters@116: }