annotate trunk/src/Modules/Output/Graphics/GraphAxisSpec.cc @ 398:3ee03a6b95a0

- All \t to two spaces (style guide compliance)
author tomwalters
date Fri, 15 Oct 2010 05:46:53 +0000
parents 7a573750b186
children 7bfed53caacf
rev   line source
tomwalters@397 1 // Copyright 2006, Willem van Engen
tomwalters@397 2 //
tomwalters@397 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@397 4 // http://www.acousticscale.org/AIMC
tomwalters@397 5 //
tomwalters@397 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@397 7 // you may not use this file except in compliance with the License.
tomwalters@397 8 // You may obtain a copy of the License at
tomwalters@397 9 //
tomwalters@397 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@397 11 //
tomwalters@397 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@397 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@397 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@397 15 // See the License for the specific language governing permissions and
tomwalters@397 16 // limitations under the License.
tomwalters@397 17
tomwalters@397 18 #include "Support/Common.h"
tomwalters@397 19 #include <string.h>
tomwalters@397 20 #include <stdio.h>
tomwalters@397 21
tomwalters@397 22 #include "Modules/Output/Graphics/GraphAxisSpec.h"
tomwalters@397 23
tomwalters@397 24 GraphAxisSpec::GraphAxisSpec(float fMin, float fMax, Scale::ScaleType iScale) {
tomwalters@398 25 m_pScale = NULL;
tomwalters@398 26 m_sLabel = NULL;
tomwalters@398 27 SetDisplayRange(fMin, fMax);
tomwalters@398 28 SetDisplayScale(iScale);
tomwalters@397 29 }
tomwalters@397 30
tomwalters@397 31 GraphAxisSpec::GraphAxisSpec() {
tomwalters@398 32 m_pScale = NULL;
tomwalters@398 33 m_sLabel = NULL;
tomwalters@398 34 m_fMin = 0;
tomwalters@398 35 m_fMax = 0;
tomwalters@397 36 }
tomwalters@397 37
tomwalters@397 38 GraphAxisSpec::~GraphAxisSpec() {
tomwalters@398 39 DELETE_IF_NONNULL(m_pScale);
tomwalters@397 40 }
tomwalters@397 41
tomwalters@397 42 void GraphAxisSpec::SetDisplayRange(float fMin, float fMax) {
tomwalters@398 43 AIM_ASSERT(fMin <= fMax);
tomwalters@398 44 m_fMin = fMin;
tomwalters@398 45 m_fMax = fMax;
tomwalters@398 46 if (m_pScale)
tomwalters@398 47 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax);
tomwalters@397 48 }
tomwalters@397 49
tomwalters@397 50 void GraphAxisSpec::SetDisplayScale(Scale::ScaleType iScale) {
tomwalters@398 51 DELETE_IF_NONNULL(m_pScale);
tomwalters@398 52 m_pScale = Scale::Create(iScale);
tomwalters@398 53 aimASSERT(m_pScale);
tomwalters@398 54 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax);
tomwalters@397 55 }
tomwalters@397 56
tomwalters@397 57 bool GraphAxisSpec::Initialize(Parameters *parameters,
tomwalters@397 58 const char *sPrefix,
tomwalters@397 59 float fMin,
tomwalters@397 60 float fMax,
tomwalters@397 61 Scale::ScaleType iScale) {
tomwalters@398 62 AIM_ASSERT(pParam);
tomwalters@398 63 AIM_ASSERT(sPrefix && sPrefix[0]!='\0');
tomwalters@398 64 char sParamName[Parameters::MaxParamNameLength];
tomwalters@397 65
tomwalters@398 66 //! The following parameters are recognized for each axis:
tomwalters@398 67 //! - \c "<prefix>.min", the minimum value; a float or \c 'auto'
tomwalters@398 68 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 69 "%s.min",
tomwalters@397 70 sPrefix);
tomwalters@398 71 if (pParam->IsSet(sParamName)) {
tomwalters@398 72 if (strcmp(parameters->GetString(sParamName), "auto") == 0)
tomwalters@398 73 m_fMin = fMin;
tomwalters@398 74 else
tomwalters@398 75 m_fMin = parameters->GetFloat(sParamName);
tomwalters@398 76 }
tomwalters@397 77
tomwalters@398 78 //! - \c "<prefix>.max", the maximum value; a float or \c 'auto'
tomwalters@398 79 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 80 "%s.max",
tomwalters@397 81 sPrefix);
tomwalters@398 82 if (pParam->IsSet(sParamName)) {
tomwalters@398 83 if (strcmp(parameters->GetString(sParamName), "auto")==0)
tomwalters@398 84 m_fMax = fMax;
tomwalters@398 85 else
tomwalters@398 86 m_fMax = parameters->GetFloat(sParamName);
tomwalters@398 87 }
tomwalters@397 88
tomwalters@398 89 // Make sure ranges are updated properly
tomwalters@398 90 SetDisplayRange(m_fMin, m_fMax);
tomwalters@397 91
tomwalters@398 92 //! - \c "<prefix>.scale", the scale; one of \c 'auto',
tomwalters@397 93 //! \c 'linear', \c 'erb' or \c 'log'
tomwalters@398 94 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 95 "%s.scale",
tomwalters@397 96 sPrefix);
tomwalters@398 97 if (pParam->IsSet(sParamName)) {
tomwalters@398 98 // Scale change, we updated min/max values already so no need to
tomwalters@398 99 Scale::ScaleType iThisScale;
tomwalters@398 100 const char *sVal = parameters->GetString(sParamName);
tomwalters@398 101 if (strcmp(sVal, "auto")==0)
tomwalters@398 102 iThisScale = iScale;
tomwalters@398 103 else if (strcmp(sVal, "linear")==0)
tomwalters@398 104 iThisScale = Scale::SCALE_LINEAR;
tomwalters@398 105 else if (strcmp(sVal, "erb")==0)
tomwalters@398 106 iThisScale = Scale::SCALE_ERB;
tomwalters@398 107 else if (strcmp(sVal, "log")==0)
tomwalters@398 108 iThisScale = Scale::SCALE_LOG;
tomwalters@398 109 else {
tomwalters@398 110 AIM_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"),
tomwalters@397 111 sParamName,
tomwalters@397 112 sVal);
tomwalters@398 113 return false;
tomwalters@398 114 }
tomwalters@398 115 SetDisplayScale(iThisScale);
tomwalters@398 116 }
tomwalters@397 117
tomwalters@398 118 //! - \c "<prefix>.label", the label; a string
tomwalters@398 119 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 120 "%s.label",
tomwalters@397 121 sPrefix);
tomwalters@398 122 if (parameters->IsSet(sParamName))
tomwalters@398 123 m_sLabel = parameters->GetString(sParamName); // Assumes strings remains valid
tomwalters@397 124
tomwalters@398 125 return true;
tomwalters@397 126 }