annotate trunk/src/Modules/Output/Graphics/GraphicsViewTime.cc @ 402:69466da9745e

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