Mercurial > hg > aimc
comparison trunk/src/Modules/Output/Graphics/GraphicsView.cc @ 399:7bfed53caacf
- A few changes to get graphics working. In progress.
author | tom@acousticscale.org |
---|---|
date | Sat, 16 Oct 2010 22:27:03 +0000 |
parents | 3ee03a6b95a0 |
children | 69466da9745e |
comparison
equal
deleted
inserted
replaced
398:3ee03a6b95a0 | 399:7bfed53caacf |
---|---|
13 // distributed under the License is distributed on an "AS IS" BASIS, | 13 // distributed under the License is distributed on an "AS IS" BASIS, |
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15 // See the License for the specific language governing permissions and | 15 // See the License for the specific language governing permissions and |
16 // limitations under the License. | 16 // limitations under the License. |
17 | 17 |
18 #include <algorithm> | |
19 | |
18 #include "Support/Common.h" | 20 #include "Support/Common.h" |
19 | 21 |
20 #include "Output/GraphicsView.h" | 22 #include "Modules/Output/Graphics/GraphicsView.h" |
21 #include "Output/GraphicsOutputDevice.h" | 23 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h" |
24 | |
25 namespace aimc { | |
22 | 26 |
23 GraphicsView::GraphicsView(Parameters *parameters) : Module(parameters) { | 27 GraphicsView::GraphicsView(Parameters *parameters) : Module(parameters) { |
24 module_description_ = ""; | 28 module_description_ = ""; |
25 module_identifier_ = "graphics"; | 29 module_identifier_ = "graphics"; |
26 module_type_ = "output"; | 30 module_type_ = "output"; |
32 AIM_ASSERT(m_pAxisX); | 36 AIM_ASSERT(m_pAxisX); |
33 m_pAxisY = new GraphAxisSpec(); | 37 m_pAxisY = new GraphAxisSpec(); |
34 AIM_ASSERT(m_pAxisY); | 38 AIM_ASSERT(m_pAxisY); |
35 m_pAxisFreq = new GraphAxisSpec(); | 39 m_pAxisFreq = new GraphAxisSpec(); |
36 AIM_ASSERT(m_pAxisFreq); | 40 AIM_ASSERT(m_pAxisFreq); |
37 | 41 initialized_ = true; |
38 m_pAxisY->Initialize(m_pParam, | 42 |
39 _S("graph.y"), | 43 if (!m_pAxisY->Initialize(m_pParam, |
40 -1, | 44 _S("graph.y"), |
41 1, | 45 -1, |
42 Scale::SCALE_LINEAR); | 46 1, |
47 Scale::SCALE_LINEAR)) { | |
48 LOG_ERROR("Axis initialization failed"); | |
49 initialized_ = false; | |
50 } | |
43 m_fMarginLeft = m_pParam->GetFloat(_S("graph.margin.left")); | 51 m_fMarginLeft = m_pParam->GetFloat(_S("graph.margin.left")); |
44 m_fMarginRight = m_pParam->GetFloat(_S("graph.margin.right")); | 52 m_fMarginRight = m_pParam->GetFloat(_S("graph.margin.right")); |
45 m_fMarginTop = m_pParam->GetFloat(_S("graph.margin.top")); | 53 m_fMarginTop = m_pParam->GetFloat(_S("graph.margin.top")); |
46 m_fMarginBottom = m_pParam->GetFloat(_S("graph.margin.bottom")); | 54 m_fMarginBottom = m_pParam->GetFloat(_S("graph.margin.bottom")); |
47 m_bPlotLabels = m_pParam->GetBool(_S("graph.plotlabels")); | 55 m_bPlotLabels = m_pParam->GetBool(_S("graph.plotlabels")); |
52 else if (strcmp(sGraphType, _S("colormap"))==0) | 60 else if (strcmp(sGraphType, _S("colormap"))==0) |
53 m_iGraphType = GraphTypeColormap; | 61 m_iGraphType = GraphTypeColormap; |
54 else if (strcmp(sGraphType, _S("none"))==0) | 62 else if (strcmp(sGraphType, _S("none"))==0) |
55 m_iGraphType = GraphTypeNone; | 63 m_iGraphType = GraphTypeNone; |
56 else { | 64 else { |
57 ret = false; | 65 LOG_ERROR(_T("Unrecognized graph type: '%s'"), sGraphType); |
58 AIM_ERROR(_T("Unrecognized graph type: '%s'"), sGraphType); | 66 initialized_ = false; |
59 } | 67 } |
60 | 68 |
61 if (strcmp(m_pParam->GetString(_S("graph.mindistance")),"auto") == 0) | 69 if (strcmp(m_pParam->GetString(_S("graph.mindistance")),"auto") == 0) |
62 // -1 means detect later, based on type and Fire() argument | 70 // -1 means detect later, based on type and Fire() argument |
63 m_fMinPlotDistance = -1; | 71 m_fMinPlotDistance = -1; |
64 else | 72 else |
65 m_fMinPlotDistance = m_pParam->GetFloat(_S("graph.mindistance")); | 73 m_fMinPlotDistance = m_pParam->GetFloat(_S("graph.mindistance")); |
66 | |
67 } | 74 } |
68 | 75 |
69 GraphicsView::~GraphicsView() { | 76 GraphicsView::~GraphicsView() { |
70 DELETE_IF_NONNULL(m_pAxisX); | 77 DELETE_IF_NONNULL(m_pAxisX); |
71 DELETE_IF_NONNULL(m_pAxisY); | 78 DELETE_IF_NONNULL(m_pAxisY); |
72 DELETE_IF_NONNULL(m_pAxisFreq); | 79 DELETE_IF_NONNULL(m_pAxisFreq); |
73 } | 80 } |
74 | 81 |
75 bool | 82 void GraphicsView::ResetInternal() { |
83 } | |
76 | 84 |
77 bool GraphicsView::InitializeInternal(const SignalBank &bank) { | 85 bool GraphicsView::InitializeInternal(const SignalBank &bank) { |
78 if (!m_pDev) { | 86 if (!m_pDev) { |
79 LOG_ERROR("Output device not connected"); | 87 LOG_ERROR("Output device not connected"); |
80 return false; | 88 return false; |
103 } | 111 } |
104 | 112 |
105 /* Inform graphics output of maximum number of vertices between | 113 /* Inform graphics output of maximum number of vertices between |
106 * gBegin*() and gEnd(), for any type of plot. Colormap needs most. | 114 * gBegin*() and gEnd(), for any type of plot. Colormap needs most. |
107 */ | 115 */ |
108 if (!m_pDev->Initialize(MAX(10, bank.buffer_length() * 2 + 2))) { | 116 if (!m_pDev->Initialize(std::max<int>(10, bank.buffer_length() * 2 + 2))) { |
109 LOG_ERROR(""); | 117 LOG_ERROR(""); |
110 return false; | 118 return false; |
111 } | 119 } |
120 return true; | |
112 } | 121 } |
113 | 122 |
114 void GraphicsView::Process(const SignalBank &bank) { | 123 void GraphicsView::Process(const SignalBank &bank) { |
115 float height = 1.0 / bank.channel_count(); | 124 float height = 1.0 / bank.channel_count(); |
116 float heightMinMargin = height * (1.0f - m_fMarginBottom - m_fMarginTop); | 125 float heightMinMargin = height * (1.0f - m_fMarginBottom - m_fMarginTop); |
131 break; | 140 break; |
132 | 141 |
133 // Scale to single channel graphing. | 142 // Scale to single channel graphing. |
134 yOffs = yOffs * (1.0f - height) + height / 2.0; | 143 yOffs = yOffs * (1.0f - height) + height / 2.0; |
135 yOffs = yOffs * (1.0f - m_fMarginTop - m_fMarginBottom) + m_fMarginBottom; | 144 yOffs = yOffs * (1.0f - m_fMarginTop - m_fMarginBottom) + m_fMarginBottom; |
136 PlotData(bank[i], yOffs, heightMinMargin, xScaling); | 145 PlotData(bank[i], bank.sample_rate(), yOffs, heightMinMargin, xScaling); |
137 } | 146 } |
138 m_pDev->gRelease(); | 147 m_pDev->gRelease(); |
139 } | 148 } |
140 | 149 |
141 void GraphicsView::SetAxisScale(Scale::ScaleType iHori, | 150 void GraphicsView::SetAxisScale(Scale::ScaleType iHori, |
188 * But if the value changes (or it's the last point), we must draw the | 197 * But if the value changes (or it's the last point), we must draw the |
189 * previous point too. | 198 * previous point too. |
190 */ | 199 */ |
191 if (!m_bFirstPoint | 200 if (!m_bFirstPoint |
192 && !isLast | 201 && !isLast |
193 && fabs(m_fPrevVal-val) < m_fMinPlotDistance) { | 202 && abs(m_fPrevVal-val) < m_fMinPlotDistance) { |
194 m_iPrevValEqual++; | 203 m_iPrevValEqual++; |
195 // Don't set m_fPrevVal to avoid not catching slow changes | 204 // Don't set m_fPrevVal to avoid not catching slow changes |
196 m_fPrevX = x; | 205 m_fPrevX = x; |
197 m_fPrevY = y; | 206 m_fPrevY = y; |
198 m_fPrevHeight = height; | 207 m_fPrevHeight = height; |
230 default: | 239 default: |
231 // Shouldn't happen | 240 // Shouldn't happen |
232 AIM_ASSERT(0); | 241 AIM_ASSERT(0); |
233 } | 242 } |
234 } | 243 } |
244 } // namespace aimc |