annotate layer/Colour3DPlotLayer.h @ 1073:cb4c9fb37ddc spectrogram-minor-refactor

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