annotate trunk/src/Modules/Output/Graphics/GraphicsView.h @ 546:e5ae2ed4249c

(none)
author Ulf.Hammarqvist@gmail.com
date Sat, 31 Mar 2012 17:36:22 +0000
parents a908972d234e
children 16a590fbc0ba
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 General graphics view definition
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: $
tomwalters@397 25 */
tomwalters@397 26
tomwalters@397 27 #ifndef __GRAPHICS_VIEW_H__
tomwalters@397 28 #define __GRAPHICS_VIEW_H__
tomwalters@397 29
tom@399 30 #include "Support/Module.h"
tomwalters@397 31 #include "Support/Parameters.h"
tomwalters@397 32 #include "Support/SignalBank.h"
tomwalters@397 33 #include "Modules/Output/Graphics/Scale/Scale.h"
tomwalters@397 34 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h"
tomwalters@397 35 #include "Modules/Output/Graphics/GraphAxisSpec.h"
tomwalters@397 36
tom@399 37 namespace aimc {
tom@399 38
tomwalters@397 39 /*!
tomwalters@397 40 * \class GraphicsView "Modules/Output/Graphics/GraphicsView.h"
tomwalters@397 41 * \brief General graphics view module
tomwalters@397 42 *
tomwalters@397 43 * This class is a general graph drawing class for one or more Signals.
tomwalters@397 44 * \sa Signal, SignalBank
tomwalters@397 45 */
tomwalters@397 46 class GraphicsView : public Module {
tomwalters@397 47 public:
tomwalters@398 48 /*! \brief Create a new view
tomwalters@398 49 * \param params A parameter store
tomwalters@398 50 *
tomwalters@398 51 */
tomwalters@398 52 GraphicsView(Parameters *params);
tomwalters@398 53 virtual ~GraphicsView();
tomwalters@397 54
tomwalters@398 55 /*! \brief Create a copy of this GraphicsView
tomwalters@398 56 * \param pDev Output device to bind to
tomwalters@398 57 * \return Newly created GraphicsView, to be freed by the caller.
tomwalters@398 58 * \deprecated Possibly, use Initialize()
tomwalters@398 59 */
tomwalters@398 60 virtual GraphicsView *Clone(GraphicsOutputDevice *pDev) = 0;
tomwalters@397 61
tomwalters@398 62 /*! \brief (Re-)initialize this graphics view and it's device
tomwalters@398 63 * \param pParam Main parameter store to bind to
tomwalters@398 64 * \param pDev Graphics output device to draw to
tomwalters@398 65 * \return true on success, false on error
tomwalters@398 66 *
tomwalters@398 67 * It is possible to call Initialize() multiple times for binding
tomwalters@398 68 * to another graphics device or updating the parameters. This method
tomwalters@398 69 * does read all parameters than can be changed at run-time.
tomwalters@398 70 *
tomwalters@398 71 * One of the Initialize() functions _must_ be called before actually
tomwalters@398 72 * using it for plotting.
tomwalters@398 73 */
tomwalters@398 74 virtual bool InitializeInternal(const SignalBank &bank);
tom@399 75 virtual void ResetInternal();
tomwalters@398 76 /*! \brief Set the axes' scale
tomwalters@398 77 * \param iXScale Scale type of the horizontal axis
tomwalters@398 78 * \param iYScale Scale type of the vertical axis for signal data
tomwalters@398 79 * \param iFreqScale Scale type of the vertical axis
tomwalters@398 80 * \deprecated Possibly, use AimParameters and Initialize
tomwalters@398 81 * \todo const arguments
tomwalters@398 82 */
tomwalters@398 83 virtual void SetAxisScale(Scale::ScaleType iXScale,
tomwalters@397 84 Scale::ScaleType iYScale,
tomwalters@397 85 Scale::ScaleType iFreqScale);
tomwalters@397 86
tomwalters@397 87
tomwalters@398 88 virtual void Process(const SignalBank &bank);
tomwalters@397 89
tomwalters@397 90 protected:
tomwalters@398 91 /*! \brief Plot the data of a signal
tomwalters@398 92 * \param pSig Signal to plot
tomwalters@398 93 * \param yOffset Vertical offset (between 0 and 1), where to plot 0 signal value.
tomwalters@398 94 * \param height Height of the signal to plot (between 0 and 1)
tomwalters@398 95 * \param xScale Scaling in x-direction. 1.0 makes it cover the whole length. 0.5 only the left half.
tomwalters@398 96 */
tomwalters@398 97 virtual void PlotData(const vector<float> &signal,
tom@399 98 float sample_rate,
tomwalters@397 99 float yOffset,
tomwalters@397 100 float height,
tomwalters@397 101 float xScale) = 0;
tomwalters@397 102
tomwalters@398 103 /*! \brief Plot the axes for a signal bank
tomwalters@398 104 * \param pSig Signal to plot the axes for
tomwalters@398 105 */
tomwalters@398 106 virtual void PlotAxes(const SignalBank &bank) = 0;
tomwalters@397 107
tomwalters@398 108 //! \brief Calls the correct m_pDev->gBegin*() for the current PlotType
tomwalters@398 109 virtual void BeginDataStrip();
tomwalters@398 110 /*! \brief Plot a data point (with smart reduction)
tomwalters@398 111 * \param x X-coordinate of point (in OpenGL space)
tomwalters@398 112 * \param y y-coordinate of point (in OpenGL space)
tomwalters@398 113 * \param val Value to plot (from -0.5..0.5)
tomwalters@398 114 * \param height Height to use for plotting (in OpenGL space)
tomwalters@398 115 * \param isLast True if this is the last point of this batch to draw
tomwalters@398 116 *
tomwalters@398 117 * This method tries to reduce the number of actual graphics output
tomwalters@398 118 * operations using it's interpolation methods (e.g., a line).
tomwalters@398 119 */
tomwalters@398 120 virtual void PlotDataPoint(float x,
tomwalters@397 121 float y,
tomwalters@397 122 float val,
tomwalters@397 123 float height,
tomwalters@397 124 bool isLast);
tomwalters@397 125
tomwalters@398 126 /*! \brief Plot a data point (directly)
tomwalters@398 127 * \param x X-coordinate of point (in OpenGL space)
tomwalters@398 128 * \param y y-coordinate of point (in OpenGL space)
tomwalters@398 129 * \param val Value to plot (from -0.5..0.5)
tomwalters@398 130 * \param height Height to use for plotting (in OpenGL space)
tomwalters@398 131 */
tomwalters@398 132 virtual void PlotDataPointDirect(float x, float y, float val, float height);
tomwalters@397 133
tomwalters@398 134 //! \brief Where to plot to
tomwalters@398 135 GraphicsOutputDevice *m_pDev;
tomwalters@397 136
tomwalters@398 137 //! \brief Axes specifications
tomwalters@398 138 GraphAxisSpec *m_pAxisX, *m_pAxisY, *m_pAxisFreq;
tomwalters@397 139
tomwalters@398 140 //! \brief Graph margins
tomwalters@398 141 float m_fMarginLeft, m_fMarginRight, m_fMarginTop, m_fMarginBottom;
tomwalters@397 142
tomwalters@398 143 //! \brief Whether labels are plotted or not
tomwalters@398 144 bool m_bPlotLabels;
tomwalters@397 145
tomwalters@398 146 //! \brief Graphics device type
tomwalters@398 147 enum GraphType {
tomwalters@398 148 GraphTypeNone,
tomwalters@397 149 GraphTypeLine,
tomwalters@397 150 GraphTypeColormap
tomwalters@398 151 };
tomwalters@398 152 GraphType m_iGraphType;
tomwalters@397 153
tomwalters@398 154 /*! \brief Minimum distance between subsequent values for plotting a point
tomwalters@398 155 *
tomwalters@398 156 * This value is set in Initialize() from parameter graph.mindistance.
tomwalters@398 157 */
tomwalters@398 158 float m_fMinPlotDistance;
tomwalters@397 159
tomwalters@398 160 //! \brief true if this next point is the first of the strip
tomwalters@398 161 bool m_bFirstPoint;
tomwalters@398 162 //! \brief Value of previously plotted point
tomwalters@398 163 float m_fPrevVal, m_fPrevX, m_fPrevY, m_fPrevHeight;
tomwalters@398 164 //! \brief Number of times m_fValPrev was within range m_fMinPlotDistance
tomwalters@398 165 int m_iPrevValEqual;
tomwalters@411 166 float frame_rate_;
tomwalters@411 167 int previous_start_time_;
tom@399 168
tom@399 169 bool initialized_;
tomwalters@397 170 };
tom@399 171 } // namespace aimc
tomwalters@397 172 #endif /* __GRAPHICS_VIEW_H__ */