comparison layer/Colour3DPlotLayer.h @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents d930ff725f64
children dd3901fe8623
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
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();
47 48
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(View *v, QPainter &paint, QRect rect) const; 53 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
53 54 virtual void setSynchronousPainting(bool synchronous);
54 virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; 55
55 virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; 56 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const;
56 57 virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const;
57 virtual QString getFeatureDescription(View *v, QPoint &) const; 58
58 59 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
59 virtual bool snapToFeatureFrame(View *v, sv_frame_t &frame, 60
61 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
60 int &resolution, 62 int &resolution,
61 SnapType snap) const; 63 SnapType snap) const;
62 64
63 virtual void setLayerDormant(const View *v, bool dormant); 65 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
64 66
65 virtual bool isLayerScrollable(const View *v) const; 67 virtual bool isLayerScrollable(const LayerGeometryProvider *v) const;
66 68
67 virtual ColourSignificance getLayerColourSignificance() const { 69 virtual ColourSignificance getLayerColourSignificance() const {
68 return ColourHasMeaningfulValue; 70 return ColourHasMeaningfulValue;
69 } 71 }
70 72
71 void setModel(const DenseThreeDimensionalModel *model); 73 void setModel(const DenseThreeDimensionalModel *model);
72 74
73 virtual int getCompletion(View *) const { return m_model->getCompletion(); } 75 virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); }
74 76
75 virtual PropertyList getProperties() const; 77 virtual PropertyList getProperties() const;
76 virtual PropertyType getPropertyType(const PropertyName &) const; 78 virtual PropertyType getPropertyType(const PropertyName &) const;
77 virtual QString getPropertyLabel(const PropertyName &) const; 79 virtual QString getPropertyLabel(const PropertyName &) const;
78 virtual QString getPropertyIconName(const PropertyName &) const; 80 virtual QString getPropertyIconName(const PropertyName &) 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 125
142 void setOpaque(bool i); 126 void setOpaque(bool i);
149 bool &logarithmic, QString &unit) const; 133 bool &logarithmic, QString &unit) const;
150 134
151 virtual bool getDisplayExtents(double &min, double &max) const; 135 virtual bool getDisplayExtents(double &min, double &max) const;
152 virtual bool setDisplayExtents(double min, double max); 136 virtual bool setDisplayExtents(double min, double max);
153 137
154 virtual bool getYScaleValue(const View *, int /* y */, 138 virtual bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
155 double &/* value */, QString &/* unit */) const; 139 double &/* value */, QString &/* unit */) const;
156 140
157 virtual int getVerticalZoomSteps(int &defaultStep) const; 141 virtual int getVerticalZoomSteps(int &defaultStep) const;
158 virtual int getCurrentVerticalZoomStep() const; 142 virtual int getCurrentVerticalZoomStep() const;
159 virtual void setVerticalZoomStep(int); 143 virtual void setVerticalZoomStep(int);
171 void modelChangedWithin(sv_frame_t, sv_frame_t); 155 void modelChangedWithin(sv_frame_t, sv_frame_t);
172 156
173 protected: 157 protected:
174 const DenseThreeDimensionalModel *m_model; // I do not own this 158 const DenseThreeDimensionalModel *m_model; // I do not own this
175 159
176 mutable QImage *m_cache; 160 ColourScaleType m_colourScale;
177 mutable QImage *m_peaksCache; 161 bool m_colourScaleSet;
178 mutable int m_cacheValidStart; 162 int m_colourMap;
179 mutable int m_cacheValidEnd; 163 float m_gain;
180 164 BinScale m_binScale;
181 ColourScale m_colourScale; 165 ColumnNormalization m_normalization; // of individual columns
182 bool m_colourScaleSet; 166 bool m_normalizeVisibleArea;
183 int m_colourMap; 167 bool m_invertVertical;
184 float m_gain; 168 bool m_opaque;
185 BinScale m_binScale; 169 bool m_smooth;
186 bool m_normalizeColumns; 170 int m_peakResolution;
187 bool m_normalizeVisibleArea;
188 bool m_normalizeHybrid;
189 bool m_invertVertical;
190 bool m_opaque;
191 bool m_smooth;
192 int m_peakResolution;
193 171
194 // Minimum and maximum bin numbers visible within the view. We 172 // Minimum and maximum bin numbers visible within the view. We
195 // always snap to whole bins at view edges. 173 // always snap to whole bins at view edges.
196 int m_miny; 174 int m_miny;
197 int m_maxy; 175 int m_maxy;
198 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
199 /** 197 /**
200 * Return the y coordinate at which the given bin "starts" 198 * Return the y coordinate at which the given bin "starts"
201 * (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
202 * 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
203 * fractional, to obtain a position part-way through a bin. 201 * fractional, to obtain a position part-way through a bin.
204 */ 202 */
205 double getYForBin(View *, double bin) const; 203 double getYForBin(const LayerGeometryProvider *, double bin) const;
206
207 /**
208 * As getYForBin, but rounding to integer values.
209 */
210 int getIYForBin(View *, int bin) const;
211 204
212 /** 205 /**
213 * Return the bin number, possibly fractional, at the given y 206 * Return the bin number, possibly fractional, at the given y
214 * coordinate. Note that the whole numbers occur at the positions 207 * coordinate. Note that the whole numbers occur at the positions
215 * 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,
216 * if the vertical scale is the usual way up). 209 * if the vertical scale is the usual way up).
217 */ 210 */
218 double getBinForY(View *, double y) const; 211 double getBinForY(const LayerGeometryProvider *, double y) const;
219
220 /**
221 * As getBinForY, but rounding to integer values.
222 */
223 int getIBinForY(View *, int y) const;
224 212
225 DenseThreeDimensionalModel::Column getColumn(int col) const; 213 DenseThreeDimensionalModel::Column getColumn(int col) const;
226 214
227 /**
228 * True if we have the opaque or smooth flag set, or if the cells
229 * are so small you can't see their borders. False for big,
230 * translucent cells.
231 */
232 bool shouldPaintDenseIn(const View *) const;
233
234 int getColourScaleWidth(QPainter &) const; 215 int getColourScaleWidth(QPainter &) const;
235 void fillCache(int firstBin, int lastBin) const; 216
236 void paintDense(View *v, QPainter &paint, QRect rect) const; 217 void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
237 }; 218 };
238 219
239 #endif 220 #endif