comparison src/Modules/Output/Graphics/GraphicsView.h @ 116:47b009f2c936

- First add of a lot of graphics code from the old version. Not working yet, not even compiling yet.
author tomwalters
date Fri, 15 Oct 2010 05:40:53 +0000
parents
children c5ac2f0c7fc5
comparison
equal deleted inserted replaced
115:3801517c4e8f 116:47b009f2c936
1 // Copyright 2006-2010, Willem van Engen, Thomas Walters
2 //
3 // AIM-C: A C++ implementation of the Auditory Image Model
4 // http://www.acousticscale.org/AIMC
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17
18 /*!
19 * \file
20 * \brief General graphics view definition
21 *
22 * \author Willem van Engen <cnbh@willem.engen.nl>
23 * \date created 2006/09/26
24 * \version \$Id: $
25 */
26
27 #ifndef __GRAPHICS_VIEW_H__
28 #define __GRAPHICS_VIEW_H__
29
30 #include "Support/Parameters.h"
31 #include "Support/SignalBank.h"
32 #include "Modules/Output/Graphics/Scale/Scale.h"
33 #include "Modules/Output/Graphics/Devices/GraphicsOutputDevice.h"
34 #include "Modules/Output/Graphics/GraphAxisSpec.h"
35
36 /*!
37 * \class GraphicsView "Modules/Output/Graphics/GraphicsView.h"
38 * \brief General graphics view module
39 *
40 * This class is a general graph drawing class for one or more Signals.
41 * \sa Signal, SignalBank
42 */
43 class GraphicsView : public Module {
44 public:
45 /*! \brief Create a new view
46 * \param params A parameter store
47 *
48 */
49 GraphicsView(Parameters *params);
50 virtual ~GraphicsView();
51
52 /*! \brief Create a copy of this GraphicsView
53 * \param pDev Output device to bind to
54 * \return Newly created GraphicsView, to be freed by the caller.
55 * \deprecated Possibly, use Initialize()
56 */
57 virtual GraphicsView *Clone(GraphicsOutputDevice *pDev) = 0;
58
59 /*! \brief (Re-)initialize this graphics view and it's device
60 * \param pParam Main parameter store to bind to
61 * \param pDev Graphics output device to draw to
62 * \return true on success, false on error
63 *
64 * It is possible to call Initialize() multiple times for binding
65 * to another graphics device or updating the parameters. This method
66 * does read all parameters than can be changed at run-time.
67 *
68 * One of the Initialize() functions _must_ be called before actually
69 * using it for plotting.
70 */
71 virtual bool InitializeInternal(const SignalBank &bank);
72
73 /*! \brief Set the axes' scale
74 * \param iXScale Scale type of the horizontal axis
75 * \param iYScale Scale type of the vertical axis for signal data
76 * \param iFreqScale Scale type of the vertical axis
77 * \deprecated Possibly, use AimParameters and Initialize
78 * \todo const arguments
79 */
80 virtual void SetAxisScale(Scale::ScaleType iXScale,
81 Scale::ScaleType iYScale,
82 Scale::ScaleType iFreqScale);
83
84
85 virtual void Process(const SignalBank &bank);
86
87 protected:
88 /*! \brief Plot the data of a signal
89 * \param pSig Signal to plot
90 * \param yOffset Vertical offset (between 0 and 1), where to plot 0 signal value.
91 * \param height Height of the signal to plot (between 0 and 1)
92 * \param xScale Scaling in x-direction. 1.0 makes it cover the whole length. 0.5 only the left half.
93 */
94 virtual void PlotData(const vector<float> &signal,
95 float yOffset,
96 float height,
97 float xScale) = 0;
98
99 /*! \brief Plot the axes for a signal bank
100 * \param pSig Signal to plot the axes for
101 */
102 virtual void PlotAxes(const SignalBank &bank) = 0;
103
104 //! \brief Calls the correct m_pDev->gBegin*() for the current PlotType
105 virtual void BeginDataStrip();
106 /*! \brief Plot a data point (with smart reduction)
107 * \param x X-coordinate of point (in OpenGL space)
108 * \param y y-coordinate of point (in OpenGL space)
109 * \param val Value to plot (from -0.5..0.5)
110 * \param height Height to use for plotting (in OpenGL space)
111 * \param isLast True if this is the last point of this batch to draw
112 *
113 * This method tries to reduce the number of actual graphics output
114 * operations using it's interpolation methods (e.g., a line).
115 */
116 virtual void PlotDataPoint(float x,
117 float y,
118 float val,
119 float height,
120 bool isLast);
121
122 /*! \brief Plot a data point (directly)
123 * \param x X-coordinate of point (in OpenGL space)
124 * \param y y-coordinate of point (in OpenGL space)
125 * \param val Value to plot (from -0.5..0.5)
126 * \param height Height to use for plotting (in OpenGL space)
127 */
128 virtual void PlotDataPointDirect(float x, float y, float val, float height);
129
130 /*! \brief Plot a strobe point
131 * \param x X-coordinate of centre (in OpenGL space)
132 * \param y Y-coordinate of centre (in OpenGL space)
133 * \param size Size of the block drawn
134 * \param colour_r Red colour intensity
135 * \param colour_g Green colour intensity
136 * \param colour_b Blue colour intensity
137 */
138 virtual void PlotStrobePoint(float x,
139 float y,
140 float size,
141 float color_r,
142 float color_g,
143 float color_b);
144
145 //! \brief Where to plot to
146 GraphicsOutputDevice *m_pDev;
147
148 //! \brief Main parameter store
149 Parameters *m_pParam;
150
151 //! \brief Axes specifications
152 GraphAxisSpec *m_pAxisX, *m_pAxisY, *m_pAxisFreq;
153
154 //! \brief Graph margins
155 float m_fMarginLeft, m_fMarginRight, m_fMarginTop, m_fMarginBottom;
156
157 //! \brief Whether labels are plotted or not
158 bool m_bPlotLabels;
159
160 //! \brief Graphics device type
161 enum GraphType {
162 GraphTypeNone,
163 GraphTypeLine,
164 GraphTypeColormap
165 };
166 GraphType m_iGraphType;
167
168 /*! \brief Minimum distance between subsequent values for plotting a point
169 *
170 * This value is set in Initialize() from parameter graph.mindistance.
171 */
172 float m_fMinPlotDistance;
173
174 //! \brief true if this next point is the first of the strip
175 bool m_bFirstPoint;
176 //! \brief Value of previously plotted point
177 float m_fPrevVal, m_fPrevX, m_fPrevY, m_fPrevHeight;
178 //! \brief Number of times m_fValPrev was within range m_fMinPlotDistance
179 int m_iPrevValEqual;
180 };
181
182 #endif /* __GRAPHICS_VIEW_H__ */