annotate layer/Colour3DPlotLayer.h @ 972:1011ffb1b6d5 osx-retina

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