comparison src/Modules/Output/Graphics/GraphicsViewTime.cc @ 117:c5ac2f0c7fc5

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