Mercurial > hg > aimc
comparison src/Modules/Output/Graphics/GraphicsViewTime.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-2010, Willem van Engen, Thomas Walters | |
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 /*! | |
19 * \file | |
20 * \brief Time-representation graphics view | |
21 * | |
22 * \author Willem van Engen <cnbh@willem.engen.nl> | |
23 * \date created 2006/09/26 | |
24 * \version \$Id: GraphicsViewTime.cpp 607 2008-06-25 00:14:14Z tom $ | |
25 */ | |
26 | |
27 #include "Support/Common.h" | |
28 | |
29 #include <stdio.h> | |
30 | |
31 #include "Support/SignalBank.h" | |
32 #include "Modules/Output/Graphics/GraphicsView.h" | |
33 #include "Modules/Output/Graphics/GraphicsViewTime.h" | |
34 | |
35 GraphicsViewTime::GraphicsViewTime(Parameters *pParam) | |
36 : GraphicsView(pParam) { | |
37 } | |
38 | |
39 GraphicsViewTime *GraphicsViewTime::Clone(GraphicsOutputDevice *pDev) { | |
40 GraphicsViewTime *pView = new GraphicsViewTime(m_pParam); | |
41 // Copy everything | |
42 pView->m_pAxisX->SetDisplayRange(m_pAxisX->m_fMax, m_pAxisX->m_fMin); | |
43 pView->m_pAxisX->SetDisplayScale(m_pAxisX->m_pScale->getType()); | |
44 pView->m_pAxisY->SetDisplayRange(m_pAxisY->m_fMax, m_pAxisY->m_fMin); | |
45 pView->m_pAxisY->SetDisplayScale(m_pAxisY->m_pScale->getType()); | |
46 pView->m_pAxisFreq->SetDisplayRange(m_pAxisFreq->m_fMax, m_pAxisFreq->m_fMin); | |
47 pView->m_pAxisFreq->SetDisplayScale(m_pAxisFreq->m_pScale->getType()); | |
48 return pView; | |
49 } | |
50 | |
51 void GraphicsViewTime::PlotAxes(const SignalBank &bank) { | |
52 m_pDev->gColor3f(0.0f, 0.7f, 0.7f); | |
53 // Vertical axis | |
54 m_pDev->gBeginLineStrip(); | |
55 m_pDev->gVertex2f(m_fMarginLeft, m_fMarginBottom); | |
56 m_pDev->gVertex2f(m_fMarginLeft, 1.0f - m_fMarginTop); | |
57 m_pDev->gEnd(); | |
58 // Horizontal axis | |
59 m_pDev->gBeginLineStrip(); | |
60 m_pDev->gVertex2f(m_fMarginLeft, m_fMarginBottom); | |
61 m_pDev->gVertex2f(1.0f-m_fMarginRight, m_fMarginBottom); | |
62 m_pDev->gEnd(); | |
63 | |
64 if (!m_bPlotLabels) | |
65 return; | |
66 | |
67 // Labels | |
68 char sTxt[80]; | |
69 snprintf(sTxt, sizeof(sTxt) / sizeof(sTxt[0]), | |
70 _S("%s [%.0f..%.0f Hz, %s scale]"), | |
71 m_pAxisFreq->m_sLabel ? m_pAxisFreq->m_sLabel : "", | |
72 m_pAxisFreq->m_fMin, m_pAxisFreq->m_fMax, | |
73 m_pAxisFreq->m_pScale->getName()); | |
74 m_pDev->gText2f(0.0025f, 0.35f, sTxt, true); | |
75 if (m_bPlotScaled) { | |
76 snprintf(sTxt, sizeof(sTxt) / sizeof(sTxt[0]), | |
77 _S("%s [cycles, %s scale]"), | |
78 m_pAxisX->m_sLabel ? m_pAxisX->m_sLabel : "", | |
79 m_pAxisX->m_pScale->getName()); | |
80 } else { | |
81 snprintf(sTxt, sizeof(sTxt) / sizeof(sTxt[0]), | |
82 _S("%s [%.2f..%.2f ms, %s scale]"), | |
83 m_pAxisX->m_sLabel ? m_pAxisX->m_sLabel : "", | |
84 m_pAxisX->m_fMin, | |
85 m_pAxisX->m_fMax, | |
86 m_pAxisX->m_pScale->getName()); | |
87 } | |
88 m_pDev->gText2f(m_fMarginLeft, 0.0025f, sTxt, false); | |
89 | |
90 // Frame time | |
91 snprintf(sTxt, sizeof(sTxt)/sizeof(sTxt[0]), _S("t=%.0f ms"), | |
92 pBank->getSampleTime(0)); | |
93 m_pDev->gText2f(0.8f, 0.0025f, sTxt, false); | |
94 } | |
95 | |
96 void GraphicsViewTime::PlotData(const vector<float> &signal, | |
97 float sample_rate, | |
98 float yOffset, | |
99 float height, | |
100 float xScale) { | |
101 AIM_ASSERT(pSig); | |
102 AIM_ASSERT(xScale >= 0 && xScale <= 1); | |
103 AIM_ASSERT(height > 0 && height <= 1); | |
104 AIM_ASSERT(yOffset >= 0 && yOffset <= 1); | |
105 AIM_ASSERT(m_pAxisX && m_pAxisX->m_pScale); | |
106 AIM_ASSERT(m_pAxisY && m_pAxisY->m_pScale); | |
107 | |
108 // Make sure we get time is ms as x value | |
109 xScale *= 1000.0 / sample_rate; | |
110 m_pDev->gColor3f(1.0f, 1.0f, 0.8f); | |
111 BeginDataStrip(); | |
112 | |
113 // Draw the signal. | |
114 float x = 0; | |
115 float y = 0; | |
116 for (int i = 0; i < signal.size(); i++) { | |
117 // Find out where to draw and do so | |
118 x = xScale * i; | |
119 y = signal[i]; | |
120 x = m_pAxisX->m_pScale->FromLinearScaled(x) + 0.5f; | |
121 y = m_pAxisY->m_pScale->FromLinearScaled(y); | |
122 | |
123 if (x < 0.0) | |
124 continue; | |
125 | |
126 // Now fit it into the drawing area | |
127 x = x * (1.0f - m_fMarginLeft - m_fMarginRight) + m_fMarginLeft; // fit inside x-axis area | |
128 PlotDataPoint(x, yOffset, y, height, false); | |
129 /* There's no point in drawing anything when x>1.0, outside of view. | |
130 * x is continuously increasing, so we can just stop completely. We need to | |
131 * plot this point however, to finish the final line. */ | |
132 if (x > 1.0) | |
133 break; | |
134 } | |
135 // Redraw the last point in case it's needed | |
136 PlotDataPoint(x, yOffset, y, height, true); | |
137 | |
138 m_pDev->gEnd(); | |
139 } |