annotate layer/Colour3DPlotLayer.h @ 1082:5b4fe7bb9430 spectrogram-minor-refactor

VerticalBinLayer for vertical mapping abstraction. Not totally sure about this
author Chris Cannam
date Fri, 01 Jul 2016 09:55:48 +0100
parents 521f7e8b0559
children 179ea8a2f650
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@1068 16 #ifndef COLOUR_3D_PLOT_LAYER_H
Chris@1068 17 #define COLOUR_3D_PLOT_LAYER_H
Chris@0 18
Chris@193 19 #include "SliceableLayer.h"
Chris@1082 20 #include "VerticalBinLayer.h"
Chris@0 21
Chris@128 22 #include "data/model/DenseThreeDimensionalModel.h"
Chris@0 23
Chris@0 24 class View;
Chris@0 25 class QPainter;
Chris@0 26 class QImage;
Chris@0 27
Chris@0 28 /**
Chris@0 29 * This is a view that displays dense 3-D data (time, some sort of
Chris@0 30 * binned y-axis range, value) as a colour plot with value mapped to
Chris@0 31 * colour range. Its source is a DenseThreeDimensionalModel.
Chris@0 32 *
Chris@0 33 * This was the original implementation for the spectrogram view, but
Chris@1068 34 * it was replaced for that purpose with a more efficient
Chris@1068 35 * implementation that derived the spectrogram itself from a
Chris@1068 36 * DenseTimeValueModel instead of using a three-dimensional model.
Chris@0 37 */
Chris@1082 38 class Colour3DPlotLayer : public SliceableLayer,
Chris@1082 39 public VerticalBinLayer
Chris@0 40 {
Chris@0 41 Q_OBJECT
Chris@0 42
Chris@0 43 public:
Chris@44 44 Colour3DPlotLayer();
Chris@0 45 ~Colour3DPlotLayer();
Chris@0 46
Chris@156 47 virtual const ZoomConstraint *getZoomConstraint() const {
Chris@156 48 return m_model ? m_model->getZoomConstraint() : 0;
Chris@156 49 }
Chris@0 50 virtual const Model *getModel() const { return m_model; }
Chris@916 51 virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@0 52
Chris@916 53 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const;
Chris@916 54 virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const;
Chris@25 55
Chris@916 56 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
Chris@25 57
Chris@916 58 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@805 59 int &resolution,
Chris@28 60 SnapType snap) const;
Chris@24 61
Chris@916 62 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
Chris@475 63
Chris@916 64 virtual bool isLayerScrollable(const LayerGeometryProvider *v) const;
Chris@25 65
Chris@287 66 virtual ColourSignificance getLayerColourSignificance() const {
Chris@287 67 return ColourHasMeaningfulValue;
Chris@287 68 }
Chris@183 69
Chris@0 70 void setModel(const DenseThreeDimensionalModel *model);
Chris@0 71
Chris@916 72 virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); }
Chris@24 73
Chris@0 74 virtual PropertyList getProperties() const;
Chris@0 75 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@159 76 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@346 77 virtual QString getPropertyIconName(const PropertyName &) const;
Chris@159 78 virtual QString getPropertyGroupName(const PropertyName &) const;
Chris@0 79 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@216 80 int *min, int *max, int *deflt) const;
Chris@0 81 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@0 82 int value) const;
Chris@534 83 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
Chris@0 84 virtual void setProperty(const PropertyName &, int value);
Chris@197 85 virtual void setProperties(const QXmlAttributes &);
Chris@11 86
Chris@509 87 enum ColourScale {
Chris@509 88 LinearScale,
Chris@509 89 LogScale,
Chris@509 90 PlusMinusOneScale,
Chris@509 91 AbsoluteScale
Chris@509 92 };
Chris@159 93
Chris@159 94 void setColourScale(ColourScale);
Chris@159 95 ColourScale getColourScale() const { return m_colourScale; }
Chris@159 96
Chris@197 97 void setColourMap(int map);
Chris@197 98 int getColourMap() const;
Chris@197 99
Chris@534 100 /**
Chris@534 101 * Set the gain multiplier for sample values in this view.
Chris@534 102 * The default is 1.0.
Chris@534 103 */
Chris@534 104 void setGain(float gain);
Chris@534 105 float getGain() const;
Chris@534 106
Chris@531 107 enum BinScale {
Chris@531 108 LinearBinScale,
Chris@531 109 LogBinScale
Chris@531 110 };
Chris@531 111
Chris@531 112 /**
Chris@531 113 * Specify the scale for the y axis.
Chris@531 114 */
Chris@531 115 void setBinScale(BinScale);
Chris@531 116 BinScale getBinScale() const;
Chris@531 117
Chris@719 118 /**
Chris@719 119 * Normalize each column to its maximum value, independent of its
Chris@719 120 * neighbours.
Chris@719 121 */
Chris@197 122 void setNormalizeColumns(bool n);
Chris@197 123 bool getNormalizeColumns() const;
Chris@197 124
Chris@719 125 /**
Chris@719 126 * Normalize each value against the maximum in the visible region.
Chris@719 127 */
Chris@197 128 void setNormalizeVisibleArea(bool n);
Chris@197 129 bool getNormalizeVisibleArea() const;
Chris@197 130
Chris@719 131 /**
Chris@719 132 * Normalize each column to its maximum value, and then scale by
Chris@719 133 * the log of the (absolute) maximum value.
Chris@719 134 */
Chris@719 135 void setNormalizeHybrid(bool n);
Chris@719 136 bool getNormalizeHybrid() const;
Chris@719 137
Chris@357 138 void setInvertVertical(bool i);
Chris@357 139 bool getInvertVertical() const;
Chris@357 140
Chris@465 141 void setOpaque(bool i);
Chris@465 142 bool getOpaque() const;
Chris@465 143
Chris@535 144 void setSmooth(bool i);
Chris@535 145 bool getSmooth() const;
Chris@535 146
Chris@904 147 virtual bool getValueExtents(double &min, double &max,
Chris@444 148 bool &logarithmic, QString &unit) const;
Chris@444 149
Chris@904 150 virtual bool getDisplayExtents(double &min, double &max) const;
Chris@904 151 virtual bool setDisplayExtents(double min, double max);
Chris@444 152
Chris@916 153 virtual bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
Chris@904 154 double &/* value */, QString &/* unit */) const;
Chris@725 155
Chris@444 156 virtual int getVerticalZoomSteps(int &defaultStep) const;
Chris@444 157 virtual int getCurrentVerticalZoomStep() const;
Chris@444 158 virtual void setVerticalZoomStep(int);
Chris@444 159 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
Chris@444 160
Chris@193 161 virtual const Model *getSliceableModel() const { return m_model; }
Chris@193 162
Chris@316 163 virtual void toXml(QTextStream &stream, QString indent = "",
Chris@316 164 QString extraAttributes = "") const;
Chris@197 165
Chris@0 166 protected slots:
Chris@0 167 void cacheInvalid();
Chris@908 168 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
Chris@461 169 void modelChanged();
Chris@908 170 void modelChangedWithin(sv_frame_t, sv_frame_t);
Chris@0 171
Chris@0 172 protected:
Chris@0 173 const DenseThreeDimensionalModel *m_model; // I do not own this
Chris@0 174
Chris@0 175 mutable QImage *m_cache;
Chris@469 176 mutable QImage *m_peaksCache;
Chris@805 177 mutable int m_cacheValidStart;
Chris@805 178 mutable int m_cacheValidEnd;
Chris@98 179
Chris@159 180 ColourScale m_colourScale;
Chris@461 181 bool m_colourScaleSet;
Chris@197 182 int m_colourMap;
Chris@534 183 float m_gain;
Chris@531 184 BinScale m_binScale;
Chris@197 185 bool m_normalizeColumns;
Chris@197 186 bool m_normalizeVisibleArea;
Chris@719 187 bool m_normalizeHybrid;
Chris@357 188 bool m_invertVertical;
Chris@465 189 bool m_opaque;
Chris@535 190 bool m_smooth;
Chris@805 191 int m_peakResolution;
Chris@197 192
Chris@725 193 // Minimum and maximum bin numbers visible within the view. We
Chris@725 194 // always snap to whole bins at view edges.
Chris@444 195 int m_miny;
Chris@444 196 int m_maxy;
Chris@725 197
Chris@725 198 /**
Chris@725 199 * Return the y coordinate at which the given bin "starts"
Chris@725 200 * (i.e. at the bottom of the bin, if the given bin is an integer
Chris@725 201 * and the vertical scale is the usual way up). Bin number may be
Chris@725 202 * fractional, to obtain a position part-way through a bin.
Chris@725 203 */
Chris@916 204 double getYForBin(LayerGeometryProvider *, double bin) const;
Chris@725 205
Chris@725 206 /**
Chris@903 207 * As getYForBin, but rounding to integer values.
Chris@903 208 */
Chris@916 209 int getIYForBin(LayerGeometryProvider *, int bin) const;
Chris@903 210
Chris@903 211 /**
Chris@725 212 * Return the bin number, possibly fractional, at the given y
Chris@725 213 * coordinate. Note that the whole numbers occur at the positions
Chris@725 214 * at which the bins "start" (i.e. the bottom of the visible bin,
Chris@725 215 * if the vertical scale is the usual way up).
Chris@725 216 */
Chris@916 217 double getBinForY(LayerGeometryProvider *, double y) const;
Chris@903 218
Chris@903 219 /**
Chris@903 220 * As getBinForY, but rounding to integer values.
Chris@903 221 */
Chris@916 222 int getIBinForY(LayerGeometryProvider *, int y) const;
Chris@444 223
Chris@805 224 DenseThreeDimensionalModel::Column getColumn(int col) const;
Chris@159 225
Chris@812 226 /**
Chris@812 227 * True if we have the opaque or smooth flag set, or if the cells
Chris@812 228 * are so small you can't see their borders. False for big,
Chris@812 229 * translucent cells.
Chris@812 230 */
Chris@916 231 bool shouldPaintDenseIn(const LayerGeometryProvider *) const;
Chris@812 232
Chris@469 233 int getColourScaleWidth(QPainter &) const;
Chris@805 234 void fillCache(int firstBin, int lastBin) const;
Chris@916 235 void paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@0 236 };
Chris@0 237
Chris@0 238 #endif