annotate layer/Colour3DPlotLayer.h @ 1105:ea5ae9dd10ba spectrogram-minor-refactor

Convert ColourScaleType into an enum class
author Chris Cannam
date Thu, 14 Jul 2016 16:52:16 +0100
parents 46cc4644206d
children 6d720fe1c8cc
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@1101 55 virtual void setSynchronousPainting(bool synchronous);
Chris@0 56
Chris@916 57 virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const;
Chris@916 58 virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const;
Chris@25 59
Chris@916 60 virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const;
Chris@25 61
Chris@916 62 virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@805 63 int &resolution,
Chris@28 64 SnapType snap) const;
Chris@24 65
Chris@916 66 virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant);
Chris@475 67
Chris@916 68 virtual bool isLayerScrollable(const LayerGeometryProvider *v) const;
Chris@25 69
Chris@287 70 virtual ColourSignificance getLayerColourSignificance() const {
Chris@287 71 return ColourHasMeaningfulValue;
Chris@287 72 }
Chris@183 73
Chris@0 74 void setModel(const DenseThreeDimensionalModel *model);
Chris@0 75
Chris@916 76 virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); }
Chris@24 77
Chris@0 78 virtual PropertyList getProperties() const;
Chris@0 79 virtual PropertyType getPropertyType(const PropertyName &) const;
Chris@159 80 virtual QString getPropertyLabel(const PropertyName &) const;
Chris@346 81 virtual QString getPropertyIconName(const PropertyName &) const;
Chris@159 82 virtual QString getPropertyGroupName(const PropertyName &) const;
Chris@0 83 virtual int getPropertyRangeAndValue(const PropertyName &,
Chris@216 84 int *min, int *max, int *deflt) const;
Chris@0 85 virtual QString getPropertyValueLabel(const PropertyName &,
Chris@0 86 int value) const;
Chris@1099 87 virtual QString getPropertyValueIconName(const PropertyName &,
Chris@1099 88 int value) const;
Chris@534 89 virtual RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const;
Chris@0 90 virtual void setProperty(const PropertyName &, int value);
Chris@197 91 virtual void setProperties(const QXmlAttributes &);
Chris@11 92
Chris@1105 93 void setColourScale(ColourScaleType);
Chris@1105 94 ColourScaleType getColourScale() const { return m_colourScale; }
Chris@159 95
Chris@197 96 void setColourMap(int map);
Chris@197 97 int getColourMap() const;
Chris@197 98
Chris@534 99 /**
Chris@534 100 * Set the gain multiplier for sample values in this view.
Chris@534 101 * The default is 1.0.
Chris@534 102 */
Chris@534 103 void setGain(float gain);
Chris@534 104 float getGain() const;
Chris@531 105
Chris@531 106 /**
Chris@531 107 * Specify the scale for the y axis.
Chris@531 108 */
Chris@1103 109 void setBinScale(BinScale);
Chris@1103 110 BinScale getBinScale() const;
Chris@531 111
Chris@719 112 /**
Chris@1104 113 * Specify the normalization mode for individual columns.
Chris@719 114 */
Chris@1104 115 void setNormalization(ColumnNormalization);
Chris@1104 116 ColumnNormalization getNormalization() const;
Chris@1104 117
Chris@1104 118 /**
Chris@1104 119 * Specify whether to normalize the visible area.
Chris@1104 120 */
Chris@1104 121 void setNormalizeVisibleArea(bool);
Chris@1104 122 bool getNormalizeVisibleArea() const;
Chris@719 123
Chris@357 124 void setInvertVertical(bool i);
Chris@357 125 bool getInvertVertical() const;
Chris@357 126
Chris@465 127 void setOpaque(bool i);
Chris@465 128 bool getOpaque() const;
Chris@465 129
Chris@535 130 void setSmooth(bool i);
Chris@535 131 bool getSmooth() const;
Chris@535 132
Chris@904 133 virtual bool getValueExtents(double &min, double &max,
Chris@444 134 bool &logarithmic, QString &unit) const;
Chris@444 135
Chris@904 136 virtual bool getDisplayExtents(double &min, double &max) const;
Chris@904 137 virtual bool setDisplayExtents(double min, double max);
Chris@444 138
Chris@916 139 virtual bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
Chris@904 140 double &/* value */, QString &/* unit */) const;
Chris@725 141
Chris@444 142 virtual int getVerticalZoomSteps(int &defaultStep) const;
Chris@444 143 virtual int getCurrentVerticalZoomStep() const;
Chris@444 144 virtual void setVerticalZoomStep(int);
Chris@444 145 virtual RangeMapper *getNewVerticalZoomRangeMapper() const;
Chris@444 146
Chris@193 147 virtual const Model *getSliceableModel() const { return m_model; }
Chris@193 148
Chris@316 149 virtual void toXml(QTextStream &stream, QString indent = "",
Chris@316 150 QString extraAttributes = "") const;
Chris@197 151
Chris@0 152 protected slots:
Chris@0 153 void cacheInvalid();
Chris@908 154 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
Chris@461 155 void modelChanged();
Chris@908 156 void modelChangedWithin(sv_frame_t, sv_frame_t);
Chris@0 157
Chris@0 158 protected:
Chris@0 159 const DenseThreeDimensionalModel *m_model; // I do not own this
Chris@0 160
Chris@0 161 mutable QImage *m_cache;
Chris@469 162 mutable QImage *m_peaksCache;
Chris@805 163 mutable int m_cacheValidStart;
Chris@805 164 mutable int m_cacheValidEnd;
Chris@98 165
Chris@1105 166 ColourScaleType m_colourScale;
Chris@1104 167 bool m_colourScaleSet;
Chris@1104 168 int m_colourMap;
Chris@1104 169 float m_gain;
Chris@1103 170 BinScale m_binScale;
Chris@1104 171 ColumnNormalization m_normalization; // of individual columns
Chris@1104 172 bool m_normalizeVisibleArea;
Chris@1104 173 bool m_invertVertical;
Chris@1104 174 bool m_opaque;
Chris@1104 175 bool m_smooth;
Chris@1104 176 int m_peakResolution;
Chris@197 177
Chris@725 178 // Minimum and maximum bin numbers visible within the view. We
Chris@725 179 // always snap to whole bins at view edges.
Chris@1104 180 int m_miny;
Chris@1104 181 int m_maxy;
Chris@1100 182
Chris@1104 183 bool m_synchronous;
Chris@1104 184
Chris@1105 185 static ColourScaleType convertToColourScale(int value);
Chris@1105 186 static int convertFromColourScale(ColourScaleType);
Chris@1104 187 static std::pair<ColumnNormalization, bool> convertToColumnNorm(int value);
Chris@1104 188 static int convertFromColumnNorm(ColumnNormalization norm, bool visible);
Chris@1101 189
Chris@1100 190 mutable Dense3DModelPeakCache *m_peakCache;
Chris@1100 191 const int m_peakCacheDivisor;
Chris@1100 192 Dense3DModelPeakCache *getPeakCache() const;
Chris@1100 193
Chris@1100 194 typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
Chris@1100 195 mutable ViewRendererMap m_renderers;
Chris@1100 196 Colour3DPlotRenderer *getRenderer(LayerGeometryProvider *) const;
Chris@1100 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@903 205
Chris@903 206 /**
Chris@725 207 * Return the bin number, possibly fractional, at the given y
Chris@725 208 * coordinate. Note that the whole numbers occur at the positions
Chris@725 209 * at which the bins "start" (i.e. the bottom of the visible bin,
Chris@725 210 * if the vertical scale is the usual way up).
Chris@725 211 */
Chris@916 212 double getBinForY(LayerGeometryProvider *, double y) const;
Chris@444 213
Chris@805 214 DenseThreeDimensionalModel::Column getColumn(int col) const;
Chris@159 215
Chris@812 216 /**
Chris@812 217 * True if we have the opaque or smooth flag set, or if the cells
Chris@812 218 * are so small you can't see their borders. False for big,
Chris@812 219 * translucent cells.
Chris@812 220 */
Chris@916 221 bool shouldPaintDenseIn(const LayerGeometryProvider *) const;
Chris@812 222
Chris@469 223 int getColourScaleWidth(QPainter &) const;
Chris@805 224 void fillCache(int firstBin, int lastBin) const;
Chris@916 225 void paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@1101 226
Chris@1101 227 void paintAlternative(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@1101 228
Chris@0 229 };
Chris@0 230
Chris@0 231 #endif