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