comparison layer/Colour3DPlotLayer.h @ 1148:c0d841cb8ab9 tony-2.0-integration

Merge latest SV 3.0 branch code
author Chris Cannam
date Fri, 19 Aug 2016 15:58:57 +0100
parents d930ff725f64
children dd3901fe8623
comparison
equal deleted inserted replaced
1009:96cf499fad62 1148:c0d841cb8ab9
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #ifndef _COLOUR_3D_PLOT_H_ 16 #ifndef COLOUR_3D_PLOT_LAYER_H
17 #define _COLOUR_3D_PLOT_H_ 17 #define COLOUR_3D_PLOT_LAYER_H
18 18
19 #include "SliceableLayer.h" 19 #include "SliceableLayer.h"
20 #include "VerticalBinLayer.h"
21
22 #include "ColourScale.h"
23 #include "Colour3DPlotRenderer.h"
20 24
21 #include "data/model/DenseThreeDimensionalModel.h" 25 #include "data/model/DenseThreeDimensionalModel.h"
22 26
23 class View; 27 class View;
24 class QPainter; 28 class QPainter;
28 * This is a view that displays dense 3-D data (time, some sort of 32 * This is a view that displays dense 3-D data (time, some sort of
29 * binned y-axis range, value) as a colour plot with value mapped to 33 * binned y-axis range, value) as a colour plot with value mapped to
30 * colour range. Its source is a DenseThreeDimensionalModel. 34 * colour range. Its source is a DenseThreeDimensionalModel.
31 * 35 *
32 * This was the original implementation for the spectrogram view, but 36 * This was the original implementation for the spectrogram view, but
33 * it was replaced with a more efficient implementation that derived 37 * it was replaced for that purpose with a more efficient
34 * the spectrogram itself from a DenseTimeValueModel instead of using 38 * implementation that derived the spectrogram itself from a
35 * a three-dimensional model. This class is retained in case it 39 * DenseTimeValueModel instead of using a three-dimensional model.
36 * becomes useful, but it will probably need some cleaning up if it's
37 * ever actually used.
38 */ 40 */
39 41 class Colour3DPlotLayer : public VerticalBinLayer
40 class Colour3DPlotLayer : public SliceableLayer
41 { 42 {
42 Q_OBJECT 43 Q_OBJECT
43 44
44 public: 45 public:
45 Colour3DPlotLayer(); 46 Colour3DPlotLayer();
48 virtual const ZoomConstraint *getZoomConstraint() const { 49 virtual const ZoomConstraint *getZoomConstraint() const {
49 return m_model ? m_model->getZoomConstraint() : 0; 50 return m_model ? m_model->getZoomConstraint() : 0;
50 } 51 }
51 virtual const Model *getModel() const { return m_model; } 52 virtual const Model *getModel() const { return m_model; }
52 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; 53 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
54 virtual void setSynchronousPainting(bool synchronous);
53 55
54 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const; 56 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const;
55 virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const; 57 virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const;
56 58
57 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; 59 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
79 virtual QString getPropertyGroupName(const PropertyName &) const; 81 virtual QString getPropertyGroupName(const PropertyName &) const;
80 virtual int getPropertyRangeAndValue(const PropertyName &, 82 virtual int getPropertyRangeAndValue(const PropertyName &,
81 int *min, int *max, int *deflt) const; 83 int *min, int *max, int *deflt) const;
82 virtual QString getPropertyValueLabel(const PropertyName &, 84 virtual QString getPropertyValueLabel(const PropertyName &,
83 int value) const; 85 int value) const;
86 virtual QString getPropertyValueIconName(const PropertyName &,
87 int value) const;
84 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const; 88 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
85 virtual void setProperty(const PropertyName &, int value); 89 virtual void setProperty(const PropertyName &, int value);
86 virtual void setProperties(const QXmlAttributes &); 90 virtual void setProperties(const QXmlAttributes &);
87 91
88 enum ColourScale { 92 void setColourScale(ColourScaleType);
89 LinearScale, 93 ColourScaleType getColourScale() const { return m_colourScale; }
90 LogScale,
91 PlusMinusOneScale,
92 AbsoluteScale
93 };
94
95 void setColourScale(ColourScale);
96 ColourScale getColourScale() const { return m_colourScale; }
97 94
98 void setColourMap(int map); 95 void setColourMap(int map);
99 int getColourMap() const; 96 int getColourMap() const;
100 97
101 /** 98 /**
102 * Set the gain multiplier for sample values in this view. 99 * Set the gain multiplier for sample values in this view.
103 * The default is 1.0. 100 * The default is 1.0.
104 */ 101 */
105 void setGain(float gain); 102 void setGain(float gain);
106 float getGain() const; 103 float getGain() const;
107
108 enum BinScale {
109 LinearBinScale,
110 LogBinScale
111 };
112 104
113 /** 105 /**
114 * Specify the scale for the y axis. 106 * Specify the scale for the y axis.
115 */ 107 */
116 void setBinScale(BinScale); 108 void setBinScale(BinScale);
117 BinScale getBinScale() const; 109 BinScale getBinScale() const;
118 110
119 /** 111 /**
120 * Normalize each column to its maximum value, independent of its 112 * Specify the normalization mode for individual columns.
121 * neighbours. 113 */
122 */ 114 void setNormalization(ColumnNormalization);
123 void setNormalizeColumns(bool n); 115 ColumnNormalization getNormalization() const;
124 bool getNormalizeColumns() const; 116
125 117 /**
126 /** 118 * Specify whether to normalize the visible area.
127 * Normalize each value against the maximum in the visible region. 119 */
128 */ 120 void setNormalizeVisibleArea(bool);
129 void setNormalizeVisibleArea(bool n);
130 bool getNormalizeVisibleArea() const; 121 bool getNormalizeVisibleArea() const;
131
132 /**
133 * Normalize each column to its maximum value, and then scale by
134 * the log of the (absolute) maximum value.
135 */
136 void setNormalizeHybrid(bool n);
137 bool getNormalizeHybrid() const;
138 122
139 void setInvertVertical(bool i); 123 void setInvertVertical(bool i);
140 bool getInvertVertical() const; 124 bool getInvertVertical() const;
141
142 void setShowRectified(bool);
143 bool getShowRectified() const { return m_rectified; }
144 125
145 void setOpaque(bool i); 126 void setOpaque(bool i);
146 bool getOpaque() const; 127 bool getOpaque() const;
147 128
148 void setSmooth(bool i); 129 void setSmooth(bool i);
174 void modelChangedWithin(sv_frame_t, sv_frame_t); 155 void modelChangedWithin(sv_frame_t, sv_frame_t);
175 156
176 protected: 157 protected:
177 const DenseThreeDimensionalModel *m_model; // I do not own this 158 const DenseThreeDimensionalModel *m_model; // I do not own this
178 159
179 mutable QImage *m_cache; 160 ColourScaleType m_colourScale;
180 mutable QImage *m_peaksCache; 161 bool m_colourScaleSet;
181 mutable int m_cacheValidStart; 162 int m_colourMap;
182 mutable int m_cacheValidEnd; 163 float m_gain;
183 164 BinScale m_binScale;
184 ColourScale m_colourScale; 165 ColumnNormalization m_normalization; // of individual columns
185 bool m_colourScaleSet; 166 bool m_normalizeVisibleArea;
186 int m_colourMap; 167 bool m_invertVertical;
187 float m_gain; 168 bool m_opaque;
188 BinScale m_binScale; 169 bool m_smooth;
189 bool m_normalizeColumns; 170 int m_peakResolution;
190 bool m_normalizeVisibleArea;
191 bool m_normalizeHybrid;
192 bool m_invertVertical;
193 bool m_rectified;
194 bool m_opaque;
195 bool m_smooth;
196 int m_peakResolution;
197 171
198 // Minimum and maximum bin numbers visible within the view. We 172 // Minimum and maximum bin numbers visible within the view. We
199 // always snap to whole bins at view edges. 173 // always snap to whole bins at view edges.
200 int m_miny; 174 int m_miny;
201 int m_maxy; 175 int m_maxy;
202 176
177 bool m_synchronous;
178
179 static ColourScaleType convertToColourScale(int value);
180 static int convertFromColourScale(ColourScaleType);
181 static std::pair<ColumnNormalization, bool> convertToColumnNorm(int value);
182 static int convertFromColumnNorm(ColumnNormalization norm, bool visible);
183
184 mutable Dense3DModelPeakCache *m_peakCache;
185 const int m_peakCacheDivisor;
186 Dense3DModelPeakCache *getPeakCache() const;
187
188 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
189 mutable ViewMagMap m_viewMags;
190
191 typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
192 mutable ViewRendererMap m_renderers;
193
194 Colour3DPlotRenderer *getRenderer(const LayerGeometryProvider *) const;
195 void invalidateRenderers();
196
203 /** 197 /**
204 * Return the y coordinate at which the given bin "starts" 198 * Return the y coordinate at which the given bin "starts"
205 * (i.e. at the bottom of the bin, if the given bin is an integer 199 * (i.e. at the bottom of the bin, if the given bin is an integer
206 * and the vertical scale is the usual way up). Bin number may be 200 * and the vertical scale is the usual way up). Bin number may be
207 * fractional, to obtain a position part-way through a bin. 201 * fractional, to obtain a position part-way through a bin.
208 */ 202 */
209 double getYForBin(LayerGeometryProvider *, double bin) const; 203 double getYForBin(const LayerGeometryProvider *, double bin) const;
210
211 /**
212 * As getYForBin, but rounding to integer values.
213 */
214 int getIYForBin(LayerGeometryProvider *, int bin) const;
215 204
216 /** 205 /**
217 * Return the bin number, possibly fractional, at the given y 206 * Return the bin number, possibly fractional, at the given y
218 * coordinate. Note that the whole numbers occur at the positions 207 * coordinate. Note that the whole numbers occur at the positions
219 * at which the bins "start" (i.e. the bottom of the visible bin, 208 * at which the bins "start" (i.e. the bottom of the visible bin,
220 * if the vertical scale is the usual way up). 209 * if the vertical scale is the usual way up).
221 */ 210 */
222 double getBinForY(LayerGeometryProvider *, double y) const; 211 double getBinForY(const LayerGeometryProvider *, double y) const;
223
224 /**
225 * As getBinForY, but rounding to integer values.
226 */
227 int getIBinForY(LayerGeometryProvider *, int y) const;
228 212
229 DenseThreeDimensionalModel::Column getColumn(int col) const; 213 DenseThreeDimensionalModel::Column getColumn(int col) const;
230 214
231 /**
232 * True if we have the opaque or smooth flag set, or if the cells
233 * are so small you can't see their borders. False for big,
234 * translucent cells.
235 */
236 bool shouldPaintDenseIn(const LayerGeometryProvider *) const;
237
238 int getColourScaleWidth(QPainter &) const; 215 int getColourScaleWidth(QPainter &) const;
239 void fillCache(int firstBin, int lastBin) const; 216
240 void paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; 217 void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
241 }; 218 };
242 219
243 #endif 220 #endif