tomwalters@397: // Copyright 2006-2010, Willem van Engen, Thomas Walters tomwalters@397: // tomwalters@397: // AIM-C: A C++ implementation of the Auditory Image Model tomwalters@397: // http://www.acousticscale.org/AIMC tomwalters@397: // tomwalters@397: // Licensed under the Apache License, Version 2.0 (the "License"); tomwalters@397: // you may not use this file except in compliance with the License. tomwalters@397: // You may obtain a copy of the License at tomwalters@397: // tomwalters@397: // http://www.apache.org/licenses/LICENSE-2.0 tomwalters@397: // tomwalters@397: // Unless required by applicable law or agreed to in writing, software tomwalters@397: // distributed under the License is distributed on an "AS IS" BASIS, tomwalters@397: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. tomwalters@397: // See the License for the specific language governing permissions and tomwalters@397: // limitations under the License. tomwalters@397: tomwalters@397: /*! tomwalters@397: * \file tomwalters@397: * \brief General graphics view definition tomwalters@397: * tomwalters@397: * \author Willem van Engen tomwalters@397: * \date created 2006/09/26 tomwalters@397: * \version \$Id: $ tomwalters@397: */ tomwalters@397: tomwalters@397: #ifndef __GRAPHICS_VIEW_H__ tomwalters@397: #define __GRAPHICS_VIEW_H__ tomwalters@397: tom@399: #include "Support/Module.h" tomwalters@397: #include "Support/Parameters.h" tomwalters@397: #include "Support/SignalBank.h" tomwalters@397: #include "Modules/Output/Graphics/Scale/Scale.h" tomwalters@397: #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h" tomwalters@397: #include "Modules/Output/Graphics/GraphAxisSpec.h" tomwalters@397: tom@399: namespace aimc { tom@399: tomwalters@397: /*! tomwalters@397: * \class GraphicsView "Modules/Output/Graphics/GraphicsView.h" tomwalters@397: * \brief General graphics view module tomwalters@397: * tomwalters@397: * This class is a general graph drawing class for one or more Signals. tomwalters@397: * \sa Signal, SignalBank tomwalters@397: */ tomwalters@397: class GraphicsView : public Module { tomwalters@397: public: tomwalters@398: /*! \brief Create a new view tomwalters@398: * \param params A parameter store tomwalters@398: * tomwalters@398: */ tomwalters@398: GraphicsView(Parameters *params); tomwalters@398: virtual ~GraphicsView(); tomwalters@397: tomwalters@398: /*! \brief Create a copy of this GraphicsView tomwalters@398: * \param pDev Output device to bind to tomwalters@398: * \return Newly created GraphicsView, to be freed by the caller. tomwalters@398: * \deprecated Possibly, use Initialize() tomwalters@398: */ tomwalters@398: virtual GraphicsView *Clone(GraphicsOutputDevice *pDev) = 0; tomwalters@397: tomwalters@398: /*! \brief (Re-)initialize this graphics view and it's device tomwalters@398: * \param pParam Main parameter store to bind to tomwalters@398: * \param pDev Graphics output device to draw to tomwalters@398: * \return true on success, false on error tomwalters@398: * tomwalters@398: * It is possible to call Initialize() multiple times for binding tomwalters@398: * to another graphics device or updating the parameters. This method tomwalters@398: * does read all parameters than can be changed at run-time. tomwalters@398: * tomwalters@398: * One of the Initialize() functions _must_ be called before actually tomwalters@398: * using it for plotting. tomwalters@398: */ tomwalters@398: virtual bool InitializeInternal(const SignalBank &bank); tom@399: virtual void ResetInternal(); tomwalters@398: /*! \brief Set the axes' scale tomwalters@398: * \param iXScale Scale type of the horizontal axis tomwalters@398: * \param iYScale Scale type of the vertical axis for signal data tomwalters@398: * \param iFreqScale Scale type of the vertical axis tomwalters@398: * \deprecated Possibly, use AimParameters and Initialize tomwalters@398: * \todo const arguments tomwalters@398: */ tomwalters@398: virtual void SetAxisScale(Scale::ScaleType iXScale, tomwalters@397: Scale::ScaleType iYScale, tomwalters@397: Scale::ScaleType iFreqScale); tomwalters@397: tomwalters@397: tomwalters@398: virtual void Process(const SignalBank &bank); tomwalters@397: tomwalters@397: protected: tomwalters@398: /*! \brief Plot the data of a signal tomwalters@398: * \param pSig Signal to plot tomwalters@398: * \param yOffset Vertical offset (between 0 and 1), where to plot 0 signal value. tomwalters@398: * \param height Height of the signal to plot (between 0 and 1) tomwalters@398: * \param xScale Scaling in x-direction. 1.0 makes it cover the whole length. 0.5 only the left half. tomwalters@398: */ tomwalters@398: virtual void PlotData(const vector &signal, tomwalters@569: float sample_rate, tomwalters@397: float yOffset, tomwalters@397: float height, tomwalters@397: float xScale) = 0; tomwalters@569: tomwalters@569: virtual void PlotStrobes(const vector& signal, tomwalters@569: const vector& strobes, tomwalters@569: float sample_rate, tomwalters@569: float y_offset, tomwalters@569: float height, tomwalters@569: float x_scale, tomwalters@569: float diameter) = 0; tomwalters@569: tomwalters@569: virtual void PlotStrobe(float x, tomwalters@569: float y, tomwalters@569: float val, tomwalters@569: float height, tomwalters@569: float diameter); tomwalters@397: tomwalters@398: /*! \brief Plot the axes for a signal bank tomwalters@398: * \param pSig Signal to plot the axes for tomwalters@398: */ tomwalters@398: virtual void PlotAxes(const SignalBank &bank) = 0; tomwalters@397: tomwalters@398: //! \brief Calls the correct m_pDev->gBegin*() for the current PlotType tomwalters@398: virtual void BeginDataStrip(); tomwalters@398: /*! \brief Plot a data point (with smart reduction) tomwalters@398: * \param x X-coordinate of point (in OpenGL space) tomwalters@398: * \param y y-coordinate of point (in OpenGL space) tomwalters@398: * \param val Value to plot (from -0.5..0.5) tomwalters@398: * \param height Height to use for plotting (in OpenGL space) tomwalters@398: * \param isLast True if this is the last point of this batch to draw tomwalters@398: * tomwalters@398: * This method tries to reduce the number of actual graphics output tomwalters@398: * operations using it's interpolation methods (e.g., a line). tomwalters@398: */ tomwalters@398: virtual void PlotDataPoint(float x, tomwalters@397: float y, tomwalters@397: float val, tomwalters@397: float height, tomwalters@397: bool isLast); tomwalters@397: tomwalters@398: /*! \brief Plot a data point (directly) tomwalters@398: * \param x X-coordinate of point (in OpenGL space) tomwalters@398: * \param y y-coordinate of point (in OpenGL space) tomwalters@398: * \param val Value to plot (from -0.5..0.5) tomwalters@398: * \param height Height to use for plotting (in OpenGL space) tomwalters@398: */ tomwalters@398: virtual void PlotDataPointDirect(float x, float y, float val, float height); tomwalters@397: tomwalters@398: //! \brief Where to plot to tomwalters@398: GraphicsOutputDevice *m_pDev; tomwalters@397: tomwalters@398: //! \brief Axes specifications tomwalters@398: GraphAxisSpec *m_pAxisX, *m_pAxisY, *m_pAxisFreq; tomwalters@397: tomwalters@398: //! \brief Graph margins tomwalters@398: float m_fMarginLeft, m_fMarginRight, m_fMarginTop, m_fMarginBottom; tomwalters@397: tomwalters@398: //! \brief Whether labels are plotted or not tomwalters@398: bool m_bPlotLabels; tomwalters@397: tomwalters@398: //! \brief Graphics device type tomwalters@398: enum GraphType { tomwalters@398: GraphTypeNone, tomwalters@397: GraphTypeLine, tomwalters@397: GraphTypeColormap tomwalters@398: }; tomwalters@398: GraphType m_iGraphType; tomwalters@397: tomwalters@398: /*! \brief Minimum distance between subsequent values for plotting a point tomwalters@398: * tomwalters@398: * This value is set in Initialize() from parameter graph.mindistance. tomwalters@398: */ tomwalters@398: float m_fMinPlotDistance; tomwalters@397: tomwalters@398: //! \brief true if this next point is the first of the strip tomwalters@398: bool m_bFirstPoint; tomwalters@398: //! \brief Value of previously plotted point tomwalters@398: float m_fPrevVal, m_fPrevX, m_fPrevY, m_fPrevHeight; tomwalters@398: //! \brief Number of times m_fValPrev was within range m_fMinPlotDistance tomwalters@398: int m_iPrevValEqual; tomwalters@411: float frame_rate_; tomwalters@411: int previous_start_time_; tom@399: tom@399: bool initialized_; tomwalters@569: bool plotting_strobes_; tomwalters@397: }; tom@399: } // namespace aimc tomwalters@397: #endif /* __GRAPHICS_VIEW_H__ */