annotate src/Modules/Output/Graphics/GraphAxisSpec.cc @ 126:a9cb396529c2

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