Mercurial > hg > aimc
comparison trunk/src/Modules/Output/Graphics/GraphicsView.cc @ 411:a908972d234e
- Added support for movies!
author | tomwalters |
---|---|
date | Thu, 21 Oct 2010 01:46:39 +0000 |
parents | 7af493eb1563 |
children | b6d5c0cc1849 |
comparison
equal
deleted
inserted
replaced
410:7af493eb1563 | 411:a908972d234e |
---|---|
19 | 19 |
20 #include "Support/Common.h" | 20 #include "Support/Common.h" |
21 | 21 |
22 #include "Modules/Output/Graphics/GraphicsView.h" | 22 #include "Modules/Output/Graphics/GraphicsView.h" |
23 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h" | 23 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h" |
24 #include "Modules/Output/Graphics/Devices/GraphicsOutputDeviceMovie.h" | |
24 | 25 |
25 namespace aimc { | 26 namespace aimc { |
26 | 27 |
27 GraphicsView::GraphicsView(Parameters *parameters) : Module(parameters) { | 28 GraphicsView::GraphicsView(Parameters *parameters) : Module(parameters) { |
28 module_description_ = "Graphics output."; | 29 module_description_ = "Graphics output."; |
29 module_identifier_ = "graphics"; | 30 module_identifier_ = "graphics"; |
30 module_type_ = "output"; | 31 module_type_ = "output"; |
31 module_version_ = "$Id: $"; | 32 module_version_ = "$Id: $"; |
32 | 33 |
33 m_pDev = new GraphicsOutputDeviceCairo(); | 34 m_pDev = new GraphicsOutputDeviceMovie(parameters); |
34 m_bPlotLabels = false; | 35 m_bPlotLabels = false; |
35 m_pAxisX = new GraphAxisSpec(); | 36 m_pAxisX = new GraphAxisSpec(); |
36 AIM_ASSERT(m_pAxisX); | 37 AIM_ASSERT(m_pAxisX); |
37 m_pAxisY = new GraphAxisSpec(); | 38 m_pAxisY = new GraphAxisSpec(); |
38 AIM_ASSERT(m_pAxisY); | 39 AIM_ASSERT(m_pAxisY); |
46 1, | 47 1, |
47 Scale::SCALE_LINEAR)) { | 48 Scale::SCALE_LINEAR)) { |
48 LOG_ERROR("Axis initialization failed"); | 49 LOG_ERROR("Axis initialization failed"); |
49 initialized_ = false; | 50 initialized_ = false; |
50 } | 51 } |
51 m_fMarginLeft = parameters_->GetFloat(_S("graph.margin.left")); | 52 m_fMarginLeft = parameters_->DefaultFloat(_S("graph.margin.left"), 0.05); |
52 m_fMarginRight = parameters_->GetFloat(_S("graph.margin.right")); | 53 m_fMarginRight = parameters_->DefaultFloat(_S("graph.margin.right"), 0.005); |
53 m_fMarginTop = parameters_->GetFloat(_S("graph.margin.top")); | 54 m_fMarginTop = parameters_->DefaultFloat(_S("graph.margin.top"), 0.005); |
54 m_fMarginBottom = parameters_->GetFloat(_S("graph.margin.bottom")); | 55 m_fMarginBottom = parameters_->DefaultFloat(_S("graph.margin.bottom"), 0.05); |
55 m_bPlotLabels = parameters_->GetBool(_S("graph.plotlabels")); | 56 m_bPlotLabels = parameters_->DefaultBool(_S("graph.plotlabels"), true); |
56 | 57 |
57 const char *sGraphType = parameters_->GetString(_S("graph.type")); | 58 const char *sGraphType = parameters_->DefaultString(_S("graph.type"), "line"); |
58 if (strcmp(sGraphType, _S("line"))==0) | 59 if (strcmp(sGraphType, _S("line"))==0) |
59 m_iGraphType = GraphTypeLine; | 60 m_iGraphType = GraphTypeLine; |
60 else if (strcmp(sGraphType, _S("colormap"))==0) | 61 else if (strcmp(sGraphType, _S("colormap"))==0) |
61 m_iGraphType = GraphTypeColormap; | 62 m_iGraphType = GraphTypeColormap; |
62 else if (strcmp(sGraphType, _S("none"))==0) | 63 else if (strcmp(sGraphType, _S("none"))==0) |
64 else { | 65 else { |
65 LOG_ERROR(_T("Unrecognized graph type: '%s'"), sGraphType); | 66 LOG_ERROR(_T("Unrecognized graph type: '%s'"), sGraphType); |
66 initialized_ = false; | 67 initialized_ = false; |
67 } | 68 } |
68 | 69 |
69 if (strcmp(parameters_->GetString(_S("graph.mindistance")),"auto") == 0) | 70 if (strcmp(parameters_->DefaultString(_S("graph.mindistance"), "auto"),"auto") == 0) |
70 // -1 means detect later, based on type and Fire() argument | 71 // -1 means detect later, based on type and Fire() argument |
71 m_fMinPlotDistance = -1; | 72 m_fMinPlotDistance = -1; |
72 else | 73 else |
73 m_fMinPlotDistance = parameters_->GetFloat(_S("graph.mindistance")); | 74 m_fMinPlotDistance = parameters_->GetFloat(_S("graph.mindistance")); |
74 } | 75 } |
78 DELETE_IF_NONNULL(m_pAxisY); | 79 DELETE_IF_NONNULL(m_pAxisY); |
79 DELETE_IF_NONNULL(m_pAxisFreq); | 80 DELETE_IF_NONNULL(m_pAxisFreq); |
80 } | 81 } |
81 | 82 |
82 void GraphicsView::ResetInternal() { | 83 void GraphicsView::ResetInternal() { |
84 if (m_pDev != NULL) { | |
85 m_pDev->Stop(); | |
86 } | |
83 } | 87 } |
84 | 88 |
85 bool GraphicsView::InitializeInternal(const SignalBank &bank) { | 89 bool GraphicsView::InitializeInternal(const SignalBank &bank) { |
86 if (!m_pDev) { | 90 if (!m_pDev) { |
87 LOG_ERROR("Output device not connected"); | 91 LOG_ERROR("Output device not connected"); |
93 if (!m_pAxisFreq->Initialize(parameters_, | 97 if (!m_pAxisFreq->Initialize(parameters_, |
94 "graph.freq", | 98 "graph.freq", |
95 y_min, | 99 y_min, |
96 y_max, | 100 y_max, |
97 Scale::SCALE_ERB)) { | 101 Scale::SCALE_ERB)) { |
98 LOG_ERROR(""); | 102 LOG_ERROR("Frequency axis init failed."); |
99 return false; | 103 return false; |
100 } | 104 } |
101 | 105 |
102 float x_min = 0.0; | 106 float x_min = 0.0; |
103 float x_max = 1000.0 * bank.buffer_length() / bank.sample_rate(); | 107 float x_max = 1000.0 * bank.buffer_length() / bank.sample_rate(); |
104 if (!m_pAxisX->Initialize(parameters_, | 108 if (!m_pAxisX->Initialize(parameters_, |
105 "graph.x", | 109 "graph.x", |
106 x_min, | 110 x_min, |
107 x_max, | 111 x_max, |
108 Scale::SCALE_LINEAR)) { | 112 Scale::SCALE_LINEAR)) { |
109 LOG_ERROR(""); | 113 LOG_ERROR("Time axis init failed."); |
110 return false; | 114 return false; |
111 } | 115 } |
112 | 116 |
113 /* Inform graphics output of maximum number of vertices between | 117 /* Inform graphics output of maximum number of vertices between |
114 * gBegin*() and gEnd(), for any type of plot. Colormap needs most. | 118 * gBegin*() and gEnd(), for any type of plot. Colormap needs most. |
115 */ | 119 */ |
116 if (!m_pDev->Initialize(std::max<int>(10, bank.buffer_length() * 2 + 2))) { | 120 LOG_INFO("Initializing graphics output device."); |
117 LOG_ERROR(""); | 121 |
122 if (!m_pDev->Initialize(global_parameters_)) { | |
123 LOG_ERROR("Graphics output device init failed."); | |
118 return false; | 124 return false; |
119 } | 125 } |
126 m_pDev->Start(); | |
127 previous_start_time_ = 0; | |
120 return true; | 128 return true; |
121 } | 129 } |
122 | 130 |
123 void GraphicsView::Process(const SignalBank &bank) { | 131 void GraphicsView::Process(const SignalBank &bank) { |
124 float height = 1.0 / bank.channel_count(); | 132 float height = 1.0 / bank.channel_count(); |
143 yOffs = yOffs * (1.0f - height) + height / 2.0; | 151 yOffs = yOffs * (1.0f - height) + height / 2.0; |
144 yOffs = yOffs * (1.0f - m_fMarginTop - m_fMarginBottom) + m_fMarginBottom; | 152 yOffs = yOffs * (1.0f - m_fMarginTop - m_fMarginBottom) + m_fMarginBottom; |
145 PlotData(bank[i], bank.sample_rate(), yOffs, heightMinMargin, xScaling); | 153 PlotData(bank[i], bank.sample_rate(), yOffs, heightMinMargin, xScaling); |
146 } | 154 } |
147 m_pDev->gRelease(); | 155 m_pDev->gRelease(); |
156 | |
157 frame_rate_ = bank.sample_rate() | |
158 / (bank.start_time() - previous_start_time_); | |
159 previous_start_time_ = bank.start_time(); | |
160 global_parameters_->SetFloat("frame_rate", frame_rate_); | |
148 } | 161 } |
149 | 162 |
150 void GraphicsView::SetAxisScale(Scale::ScaleType iHori, | 163 void GraphicsView::SetAxisScale(Scale::ScaleType iHori, |
151 Scale::ScaleType iVert, | 164 Scale::ScaleType iVert, |
152 Scale::ScaleType iFreq) { | 165 Scale::ScaleType iFreq) { |