annotate src/Modules/Output/Graphics/GraphicsView.h @ 611:0fbaf443ec82

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