annotate trunk/src/Modules/Output/Graphics/GraphAxisSpec.cc @ 397:7a573750b186

- First add of a lot of graphics code from the old version. Not working yet, not even compiling yet.
author tomwalters
date Fri, 15 Oct 2010 05:40:53 +0000
parents
children 3ee03a6b95a0
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@397 25 m_pScale = NULL;
tomwalters@397 26 m_sLabel = NULL;
tomwalters@397 27 SetDisplayRange(fMin, fMax);
tomwalters@397 28 SetDisplayScale(iScale);
tomwalters@397 29 }
tomwalters@397 30
tomwalters@397 31 GraphAxisSpec::GraphAxisSpec() {
tomwalters@397 32 m_pScale = NULL;
tomwalters@397 33 m_sLabel = NULL;
tomwalters@397 34 m_fMin = 0;
tomwalters@397 35 m_fMax = 0;
tomwalters@397 36 }
tomwalters@397 37
tomwalters@397 38 GraphAxisSpec::~GraphAxisSpec() {
tomwalters@397 39 DELETE_IF_NONNULL(m_pScale);
tomwalters@397 40 }
tomwalters@397 41
tomwalters@397 42 void GraphAxisSpec::SetDisplayRange(float fMin, float fMax) {
tomwalters@397 43 AIM_ASSERT(fMin <= fMax);
tomwalters@397 44 m_fMin = fMin;
tomwalters@397 45 m_fMax = fMax;
tomwalters@397 46 if (m_pScale)
tomwalters@397 47 m_pScale->FromLinearScaledExtrema(m_fMin, m_fMax);
tomwalters@397 48 }
tomwalters@397 49
tomwalters@397 50 void GraphAxisSpec::SetDisplayScale(Scale::ScaleType iScale) {
tomwalters@397 51 DELETE_IF_NONNULL(m_pScale);
tomwalters@397 52 m_pScale = Scale::Create(iScale);
tomwalters@397 53 aimASSERT(m_pScale);
tomwalters@397 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@397 62 AIM_ASSERT(pParam);
tomwalters@397 63 AIM_ASSERT(sPrefix && sPrefix[0]!='\0');
tomwalters@397 64 char sParamName[Parameters::MaxParamNameLength];
tomwalters@397 65
tomwalters@397 66 //! The following parameters are recognized for each axis:
tomwalters@397 67 //! - \c "<prefix>.min", the minimum value; a float or \c 'auto'
tomwalters@397 68 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 69 "%s.min",
tomwalters@397 70 sPrefix);
tomwalters@397 71 if (pParam->IsSet(sParamName)) {
tomwalters@397 72 if (strcmp(parameters->GetString(sParamName), "auto") == 0)
tomwalters@397 73 m_fMin = fMin;
tomwalters@397 74 else
tomwalters@397 75 m_fMin = parameters->GetFloat(sParamName);
tomwalters@397 76 }
tomwalters@397 77
tomwalters@397 78 //! - \c "<prefix>.max", the maximum value; a float or \c 'auto'
tomwalters@397 79 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 80 "%s.max",
tomwalters@397 81 sPrefix);
tomwalters@397 82 if (pParam->IsSet(sParamName)) {
tomwalters@397 83 if (strcmp(parameters->GetString(sParamName), "auto")==0)
tomwalters@397 84 m_fMax = fMax;
tomwalters@397 85 else
tomwalters@397 86 m_fMax = parameters->GetFloat(sParamName);
tomwalters@397 87 }
tomwalters@397 88
tomwalters@397 89 // Make sure ranges are updated properly
tomwalters@397 90 SetDisplayRange(m_fMin, m_fMax);
tomwalters@397 91
tomwalters@397 92 //! - \c "<prefix>.scale", the scale; one of \c 'auto',
tomwalters@397 93 //! \c 'linear', \c 'erb' or \c 'log'
tomwalters@397 94 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 95 "%s.scale",
tomwalters@397 96 sPrefix);
tomwalters@397 97 if (pParam->IsSet(sParamName)) {
tomwalters@397 98 // Scale change, we updated min/max values already so no need to
tomwalters@397 99 Scale::ScaleType iThisScale;
tomwalters@397 100 const char *sVal = parameters->GetString(sParamName);
tomwalters@397 101 if (strcmp(sVal, "auto")==0)
tomwalters@397 102 iThisScale = iScale;
tomwalters@397 103 else if (strcmp(sVal, "linear")==0)
tomwalters@397 104 iThisScale = Scale::SCALE_LINEAR;
tomwalters@397 105 else if (strcmp(sVal, "erb")==0)
tomwalters@397 106 iThisScale = Scale::SCALE_ERB;
tomwalters@397 107 else if (strcmp(sVal, "log")==0)
tomwalters@397 108 iThisScale = Scale::SCALE_LOG;
tomwalters@397 109 else {
tomwalters@397 110 AIM_ERROR(_T("Unrecognized scale type in parameter '%s': '%s'"),
tomwalters@397 111 sParamName,
tomwalters@397 112 sVal);
tomwalters@397 113 return false;
tomwalters@397 114 }
tomwalters@397 115 SetDisplayScale(iThisScale);
tomwalters@397 116 }
tomwalters@397 117
tomwalters@397 118 //! - \c "<prefix>.label", the label; a string
tomwalters@397 119 snprintf(sParamName, sizeof(sParamName)/sizeof(sParamName[0]),
tomwalters@397 120 "%s.label",
tomwalters@397 121 sPrefix);
tomwalters@397 122 if (parameters->IsSet(sParamName))
tomwalters@397 123 m_sLabel = parameters->GetString(sParamName); // Assumes strings remains valid
tomwalters@397 124
tomwalters@397 125 return true;
tomwalters@397 126 }