annotate layer/Colour3DPlotLayer.h @ 1099:5c6271734790 spectrogram-minor-refactor

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