view src/Modules/Output/Graphics/Scale/Scale.cc @ 118:18237d55e346

- A few changes to get graphics working. In progress.
author tom@acousticscale.org
date Sat, 16 Oct 2010 22:27:03 +0000
parents c5ac2f0c7fc5
children 9d880fb93c39
line wrap: on
line source
/*!
 * \file
 * \brief Frequency scale for generating filter banks and their frequencies
 *
 * \author Willem van Engen <cnbh@willem.engen.nl>
 * \date created 2006/09/28
 * \version \$Id: Scale.cpp 459 2007-11-08 11:50:04Z tom $
 */
/* (c) 2006, University of Cambridge, Medical Research Council
 * http://www.pdn.cam.ac.uk/groups/cnbh/aimmanual
 */
#include "Support/Common.h"
#include "Modules/Output/Graphics/Scale/Scale.h"
#include "Modules/Output/Graphics/Scale/ScaleLinear.h"
#include "Modules/Output/Graphics/Scale/ScaleERB.h"
#include "Modules/Output/Graphics/Scale/ScaleLog.h"
#include "Modules/Output/Graphics/Scale/ScaleLogScaled.h"

Scale *Scale::Create(ScaleType iType,
		     unsigned int min,
		     unsigned int max,
		     float density) {
  switch(iType) {
  case SCALE_LINEAR:
    return static_cast<Scale*>(new ScaleLinear(min, max, density));
  case SCALE_ERB:
    return static_cast<Scale*>(new ScaleERB(min, max, density));
  case SCALE_LOG:
    return static_cast<Scale*>(new ScaleLog(min, max, density));
  case SCALE_LOGSCALED:
    return static_cast<Scale*>(new ScaleLogScaled(min, max, density));
  default:
    aimASSERT(0);
    break;
  }
  // Unreachable code
  aimASSERT(0);
  return NULL;
}

Scale *Scale::Create(ScaleType iType) {
  return Create(iType, 0, 0, 0);
}

Scale *Scale::Clone() {
  Scale *pScale = Create(m_iType, m_iMin, m_iMax, m_fDensity);
  AIM_ASSERT(pScale);
  pScale->m_fScaledCurHalfSum = m_fScaledCurHalfSum;
  pScale->m_fScaledCurDiff = m_fScaledCurDiff;
  return pScale;
}

float Scale::FromLinearScaled(float fVal) {
  /*! This function returns
   *    ( FromLinear(fVal) - (fMinScaled+fMaxScaled)/2 ) / (fMaxScaled-fMinScaled)
   */
  float fValScaled = FromLinear(fVal);
  return (fValScaled - m_fScaledCurHalfSum) / m_fScaledCurDiff;
}

void Scale::FromLinearScaledExtrema(float fMin, float fMax) {
  float fMinScaled = FromLinear(fMin);
  float fMaxScaled = FromLinear(fMax);
  m_fScaledCurHalfSum = (fMinScaled+fMaxScaled)/2;
  m_fScaledCurDiff = fMaxScaled-fMinScaled;
  m_fMin = fMin;
  m_fMax = fMax;
}

void Scale::FromLinearScaledExtrema(Scale *pScale) {
  aimASSERT(pScale);
  FromLinearScaledExtrema(pScale->m_fMin, pScale->m_fMax);
}