annotate src/Modules/Output/Graphics/GraphicsViewTime.cc @ 646:e76951e4da20

Style fixes. - Fix most lint errors found by http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py - Clean up commenting style. - Alphabetize #includes and using statements.
author ronw@google.com
date Tue, 11 Jun 2013 20:41:15 +0000
parents d609725e568a
children
rev   line source
tomwalters@116 1 // Copyright 2006-2010, Willem van Engen, Thomas Walters
tomwalters@116 2 //
tomwalters@116 3 // AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@116 4 // http://www.acousticscale.org/AIMC
tomwalters@116 5 //
tomwalters@116 6 // Licensed under the Apache License, Version 2.0 (the "License");
tomwalters@116 7 // you may not use this file except in compliance with the License.
tomwalters@116 8 // You may obtain a copy of the License at
tomwalters@116 9 //
tomwalters@116 10 // http://www.apache.org/licenses/LICENSE-2.0
tomwalters@116 11 //
tomwalters@116 12 // Unless required by applicable law or agreed to in writing, software
tomwalters@116 13 // distributed under the License is distributed on an "AS IS" BASIS,
tomwalters@116 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
tomwalters@116 15 // See the License for the specific language governing permissions and
tomwalters@116 16 // limitations under the License.
tomwalters@116 17
tomwalters@116 18 /*!
tomwalters@116 19 * \file
tomwalters@116 20 * \brief Time-representation graphics view
tomwalters@116 21 *
tomwalters@116 22 * \author Willem van Engen <cnbh@willem.engen.nl>
tomwalters@116 23 * \date created 2006/09/26
tomwalters@116 24 * \version \$Id: GraphicsViewTime.cpp 607 2008-06-25 00:14:14Z tom $
tomwalters@116 25 */
tomwalters@116 26
tomwalters@116 27 #include "Support/Common.h"
tomwalters@116 28
tomwalters@116 29 #include <stdio.h>
tomwalters@116 30
tomwalters@116 31 #include "Support/SignalBank.h"
tomwalters@116 32 #include "Modules/Output/Graphics/GraphicsView.h"
tomwalters@116 33 #include "Modules/Output/Graphics/GraphicsViewTime.h"
tomwalters@116 34
tom@229 35 namespace aimc {
tom@229 36
tomwalters@116 37 GraphicsViewTime::GraphicsViewTime(Parameters *pParam)
tomwalters@228 38 : GraphicsView(pParam) {
tomwalters@232 39 module_description_ = "Graphics output.";
tomwalters@232 40 module_identifier_ = "graphics_time";
tomwalters@232 41 module_type_ = "output";
tomwalters@232 42 module_version_ = "$Id: $";
tomwalters@116 43 }
tomwalters@116 44
tomwalters@116 45 GraphicsViewTime *GraphicsViewTime::Clone(GraphicsOutputDevice *pDev) {
tomwalters@237 46 GraphicsViewTime *pView = new GraphicsViewTime(parameters_);
tomwalters@228 47 // Copy everything
tomwalters@228 48 pView->m_pAxisX->SetDisplayRange(m_pAxisX->m_fMax, m_pAxisX->m_fMin);
tomwalters@228 49 pView->m_pAxisX->SetDisplayScale(m_pAxisX->m_pScale->getType());
tomwalters@228 50 pView->m_pAxisY->SetDisplayRange(m_pAxisY->m_fMax, m_pAxisY->m_fMin);
tomwalters@228 51 pView->m_pAxisY->SetDisplayScale(m_pAxisY->m_pScale->getType());
tomwalters@228 52 pView->m_pAxisFreq->SetDisplayRange(m_pAxisFreq->m_fMax, m_pAxisFreq->m_fMin);
tomwalters@228 53 pView->m_pAxisFreq->SetDisplayScale(m_pAxisFreq->m_pScale->getType());
tomwalters@228 54 return pView;
tomwalters@116 55 }
tomwalters@116 56
tomwalters@116 57 void GraphicsViewTime::PlotAxes(const SignalBank &bank) {
tomwalters@228 58 m_pDev->gColor3f(0.0f, 0.7f, 0.7f);
tomwalters@228 59 // Vertical axis
tomwalters@228 60 m_pDev->gBeginLineStrip();
tomwalters@228 61 m_pDev->gVertex2f(m_fMarginLeft, m_fMarginBottom);
tomwalters@228 62 m_pDev->gVertex2f(m_fMarginLeft, 1.0f - m_fMarginTop);
tomwalters@228 63 m_pDev->gEnd();
tomwalters@228 64 // Horizontal axis
tomwalters@228 65 m_pDev->gBeginLineStrip();
tomwalters@228 66 m_pDev->gVertex2f(m_fMarginLeft, m_fMarginBottom);
tomwalters@228 67 m_pDev->gVertex2f(1.0f-m_fMarginRight, m_fMarginBottom);
tomwalters@228 68 m_pDev->gEnd();
tomwalters@116 69
tomwalters@237 70 //if (!m_bPlotLabels)
tomwalters@237 71 // return;
tomwalters@116 72
tomwalters@228 73 // Labels
tomwalters@228 74 char sTxt[80];
tomwalters@228 75 snprintf(sTxt, sizeof(sTxt) / sizeof(sTxt[0]),
tomwalters@116 76 _S("%s [%.0f..%.0f Hz, %s scale]"),
tomwalters@228 77 m_pAxisFreq->m_sLabel ? m_pAxisFreq->m_sLabel : "",
tomwalters@228 78 m_pAxisFreq->m_fMin, m_pAxisFreq->m_fMax,
tomwalters@228 79 m_pAxisFreq->m_pScale->getName());
tomwalters@228 80 m_pDev->gText2f(0.0025f, 0.35f, sTxt, true);
tom@229 81 snprintf(sTxt, sizeof(sTxt) / sizeof(sTxt[0]),
tomwalters@232 82 _S("%s [%.2f..%.2f ms, %s scale]"),
tomwalters@232 83 m_pAxisX->m_sLabel ? m_pAxisX->m_sLabel : "",
tomwalters@232 84 m_pAxisX->m_fMin,
tomwalters@232 85 m_pAxisX->m_fMax,
tomwalters@232 86 m_pAxisX->m_pScale->getName());
tomwalters@256 87
tomwalters@228 88 m_pDev->gText2f(m_fMarginLeft, 0.0025f, sTxt, false);
tomwalters@145 89
tomwalters@228 90 // Frame time
tomwalters@237 91 snprintf(sTxt, sizeof(sTxt)/sizeof(sTxt[0]), _S("t=%.0f ms"),
tomwalters@237 92 1000.0 * bank.start_time() / bank.sample_rate());
tomwalters@237 93 m_pDev->gText2f(0.8f, 0.0025f, sTxt, false);
tomwalters@116 94 }
tomwalters@116 95
tomwalters@508 96 void GraphicsViewTime::PlotStrobes(const vector<float>& signal,
tomwalters@508 97 const vector<int>& strobes,
tomwalters@508 98 float sample_rate,
tomwalters@508 99 float y_offset,
tomwalters@508 100 float height,
tomwalters@508 101 float x_scale,
tomwalters@508 102 float diameter) {
tomwalters@508 103 x_scale *= 1000.0 / sample_rate;
tomwalters@508 104 m_pDev->gColor3f(1.0f, 0.0f, 0.0f);
tomwalters@508 105 for (vector<int>::const_iterator i = strobes.begin();
tomwalters@508 106 i != strobes.end(); ++i) {
tomwalters@508 107 float x = *i * x_scale;
tomwalters@508 108 float y = signal[*i];
tomwalters@508 109 x = m_pAxisX->m_pScale->FromLinearScaled(x) + 0.5f;
tomwalters@508 110 y = m_pAxisY->m_pScale->FromLinearScaled(y);
tomwalters@508 111
tomwalters@508 112 if (x < 0.0)
tomwalters@508 113 continue;
tomwalters@508 114
tomwalters@508 115 // Now fit it into the drawing area.
tomwalters@508 116 x = x * (1.0f - m_fMarginLeft - m_fMarginRight) + m_fMarginLeft; // fit inside x-axis area
tomwalters@508 117 PlotStrobe(x, y_offset, y, height, diameter);
tomwalters@508 118 }
tomwalters@508 119 }
tomwalters@508 120
tomwalters@116 121 void GraphicsViewTime::PlotData(const vector<float> &signal,
tomwalters@116 122 float sample_rate,
tomwalters@116 123 float yOffset,
tomwalters@116 124 float height,
tomwalters@116 125 float xScale) {
tomwalters@228 126 AIM_ASSERT(xScale >= 0 && xScale <= 1);
tomwalters@228 127 AIM_ASSERT(height > 0 && height <= 1);
tomwalters@228 128 AIM_ASSERT(yOffset >= 0 && yOffset <= 1);
tomwalters@228 129 AIM_ASSERT(m_pAxisX && m_pAxisX->m_pScale);
tomwalters@228 130 AIM_ASSERT(m_pAxisY && m_pAxisY->m_pScale);
tomwalters@116 131
tomwalters@228 132 // Make sure we get time is ms as x value
tomwalters@228 133 xScale *= 1000.0 / sample_rate;
tomwalters@228 134 m_pDev->gColor3f(1.0f, 1.0f, 0.8f);
tomwalters@228 135 BeginDataStrip();
tomwalters@116 136
tomwalters@228 137 // Draw the signal.
tomwalters@228 138 float x = 0;
tomwalters@228 139 float y = 0;
tom@229 140 for (unsigned int i = 0; i < signal.size(); i++) {
tomwalters@228 141 // Find out where to draw and do so
tomwalters@228 142 x = xScale * i;
tomwalters@228 143 y = signal[i];
tomwalters@228 144 x = m_pAxisX->m_pScale->FromLinearScaled(x) + 0.5f;
tomwalters@228 145 y = m_pAxisY->m_pScale->FromLinearScaled(y);
tomwalters@116 146
tomwalters@228 147 if (x < 0.0)
tomwalters@116 148 continue;
tomwalters@116 149
tomwalters@228 150 // Now fit it into the drawing area
tomwalters@228 151 x = x * (1.0f - m_fMarginLeft - m_fMarginRight) + m_fMarginLeft; // fit inside x-axis area
tomwalters@228 152 PlotDataPoint(x, yOffset, y, height, false);
tomwalters@228 153 /* There's no point in drawing anything when x>1.0, outside of view.
tomwalters@228 154 * x is continuously increasing, so we can just stop completely. We need to
tomwalters@228 155 * plot this point however, to finish the final line. */
tomwalters@228 156 if (x > 1.0)
tomwalters@228 157 break;
tomwalters@228 158 }
tomwalters@228 159 // Redraw the last point in case it's needed
tomwalters@228 160 PlotDataPoint(x, yOffset, y, height, true);
tomwalters@116 161
tomwalters@228 162 m_pDev->gEnd();
tomwalters@116 163 }
tom@229 164 } // namespace aimc