annotate layer/Colour3DPlotLayer.h @ 1605:ae2d5f8ff005

When asked to render the whole view width, we need to wait for the layers to be ready before we can determine what the width is
author Chris Cannam
date Thu, 30 Apr 2020 14:47:13 +0100
parents 563bab925c9b
children
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@1110 41 class Colour3DPlotLayer : public VerticalBinLayer
Chris@0 42 {
Chris@0 43 Q_OBJECT
Chris@0 44
Chris@0 45 public:
Chris@44 46 Colour3DPlotLayer();
Chris@0 47 ~Colour3DPlotLayer();
Chris@0 48
Chris@1469 49 ModelId getModel() const override { return m_model; }
Chris@1469 50
Chris@1563 51 ModelId getExportModel(LayerGeometryProvider *) const override;
Chris@1563 52
Chris@1469 53 const ZoomConstraint *getZoomConstraint() const override;
Chris@1469 54
Chris@1469 55 void paint(LayerGeometryProvider *v,
Chris@1469 56 QPainter &paint, QRect rect) const override;
Chris@1406 57 void setSynchronousPainting(bool synchronous) override;
Chris@0 58
Chris@1469 59 int getVerticalScaleWidth(LayerGeometryProvider *v,
Chris@1469 60 bool, QPainter &) const override;
Chris@1469 61 void paintVerticalScale(LayerGeometryProvider *v,
Chris@1469 62 bool, QPainter &paint, QRect rect) const override;
Chris@25 63
Chris@1469 64 QString getFeatureDescription(LayerGeometryProvider *v,
Chris@1469 65 QPoint &) const override;
Chris@25 66
Chris@1406 67 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1469 68 int &resolution,
Chris@1547 69 SnapType snap, int ycoord) const override;
Chris@24 70
Chris@1469 71 void setLayerDormant(const LayerGeometryProvider *v,
Chris@1469 72 bool dormant) override;
Chris@475 73
Chris@1406 74 bool isLayerScrollable(const LayerGeometryProvider *v) const override;
Chris@25 75
Chris@1406 76 ColourSignificance getLayerColourSignificance() const override {
Chris@287 77 return ColourHasMeaningfulValue;
Chris@287 78 }
Chris@183 79
Chris@1469 80 void setModel(ModelId model); // a DenseThreeDimensionalModel
Chris@0 81
Chris@1469 82 int getCompletion(LayerGeometryProvider *) const override;
Chris@24 83
Chris@1406 84 PropertyList getProperties() const override;
Chris@1406 85 PropertyType getPropertyType(const PropertyName &) const override;
Chris@1406 86 QString getPropertyLabel(const PropertyName &) const override;
Chris@1406 87 QString getPropertyIconName(const PropertyName &) const override;
Chris@1406 88 QString getPropertyGroupName(const PropertyName &) const override;
Chris@1406 89 int getPropertyRangeAndValue(const PropertyName &,
Chris@1469 90 int *min, int *max, int *deflt) const override;
Chris@1406 91 QString getPropertyValueLabel(const PropertyName &,
Chris@1469 92 int value) const override;
Chris@1406 93 QString getPropertyValueIconName(const PropertyName &,
Chris@1469 94 int value) const override;
Chris@1406 95 RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
Chris@1406 96 void setProperty(const PropertyName &, int value) override;
Chris@1406 97 void setProperties(const QXmlAttributes &) override;
Chris@11 98
Chris@1105 99 void setColourScale(ColourScaleType);
Chris@1105 100 ColourScaleType getColourScale() const { return m_colourScale; }
Chris@159 101
Chris@197 102 void setColourMap(int map);
Chris@197 103 int getColourMap() const;
Chris@197 104
Chris@534 105 /**
Chris@534 106 * Set the gain multiplier for sample values in this view.
Chris@534 107 * The default is 1.0.
Chris@534 108 */
Chris@534 109 void setGain(float gain);
Chris@534 110 float getGain() const;
Chris@531 111
Chris@531 112 /**
Chris@531 113 * Specify the scale for the y axis.
Chris@531 114 */
Chris@1103 115 void setBinScale(BinScale);
Chris@1103 116 BinScale getBinScale() const;
Chris@531 117
Chris@719 118 /**
Chris@1104 119 * Specify the normalization mode for individual columns.
Chris@719 120 */
Chris@1104 121 void setNormalization(ColumnNormalization);
Chris@1104 122 ColumnNormalization getNormalization() const;
Chris@1104 123
Chris@1104 124 /**
Chris@1104 125 * Specify whether to normalize the visible area.
Chris@1104 126 */
Chris@1104 127 void setNormalizeVisibleArea(bool);
Chris@1104 128 bool getNormalizeVisibleArea() const;
Chris@719 129
Chris@357 130 void setInvertVertical(bool i);
Chris@357 131 bool getInvertVertical() const;
Chris@357 132
Chris@465 133 void setOpaque(bool i);
Chris@465 134 bool getOpaque() const;
Chris@465 135
Chris@535 136 void setSmooth(bool i);
Chris@535 137 bool getSmooth() const;
Chris@535 138
Chris@1453 139 bool hasLightBackground() const override;
Chris@1453 140
Chris@1406 141 bool getValueExtents(double &min, double &max,
Chris@1469 142 bool &logarithmic, QString &unit) const override;
Chris@444 143
Chris@1406 144 bool getDisplayExtents(double &min, double &max) const override;
Chris@1406 145 bool setDisplayExtents(double min, double max) override;
Chris@444 146
Chris@1406 147 bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
Chris@1469 148 double &/* value */, QString &/* unit */) const override;
Chris@725 149
Chris@1406 150 int getVerticalZoomSteps(int &defaultStep) const override;
Chris@1406 151 int getCurrentVerticalZoomStep() const override;
Chris@1406 152 void setVerticalZoomStep(int) override;
Chris@1406 153 RangeMapper *getNewVerticalZoomRangeMapper() const override;
Chris@444 154
Chris@1469 155 ModelId getSliceableModel() const override { return m_model; }
Chris@193 156
Chris@1406 157 void toXml(QTextStream &stream, QString indent = "",
Chris@1469 158 QString extraAttributes = "") const override;
Chris@197 159
Chris@0 160 protected slots:
Chris@1481 161 void handleModelChanged(ModelId);
Chris@1481 162 void handleModelChangedWithin(ModelId, sv_frame_t, sv_frame_t);
Chris@0 163
Chris@0 164 protected:
Chris@1469 165 ModelId m_model; // A DenseThreeDimensionalModel
Chris@0 166
Chris@1105 167 ColourScaleType m_colourScale;
Chris@1104 168 bool m_colourScaleSet;
Chris@1104 169 int m_colourMap;
Chris@1362 170 bool m_colourInverted;
Chris@1104 171 float m_gain;
Chris@1103 172 BinScale m_binScale;
Chris@1104 173 ColumnNormalization m_normalization; // of individual columns
Chris@1104 174 bool m_normalizeVisibleArea;
Chris@1104 175 bool m_invertVertical;
Chris@1104 176 bool m_opaque;
Chris@1104 177 bool m_smooth;
Chris@1104 178 int m_peakResolution;
Chris@197 179
Chris@725 180 // Minimum and maximum bin numbers visible within the view. We
Chris@725 181 // always snap to whole bins at view edges.
Chris@1104 182 int m_miny;
Chris@1104 183 int m_maxy;
Chris@1100 184
Chris@1104 185 bool m_synchronous;
Chris@1104 186
Chris@1105 187 static ColourScaleType convertToColourScale(int value);
Chris@1105 188 static int convertFromColourScale(ColourScaleType);
Chris@1104 189 static std::pair<ColumnNormalization, bool> convertToColumnNorm(int value);
Chris@1104 190 static int convertFromColumnNorm(ColumnNormalization norm, bool visible);
Chris@1101 191
Chris@1473 192 mutable ModelId m_peakCache;
Chris@1100 193 const int m_peakCacheDivisor;
Chris@1469 194 void invalidatePeakCache();
Chris@1473 195 ModelId getPeakCache() const;
Chris@1100 196
Chris@1563 197 mutable std::vector<ModelId> m_exporters; // used, waiting to be released
Chris@1563 198
Chris@1121 199 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
Chris@1121 200 mutable ViewMagMap m_viewMags;
Chris@1235 201 mutable ViewMagMap m_lastRenderedMags; // when in normalizeVisibleArea mode
Chris@1235 202 void invalidateMagnitudes();
Chris@1121 203
Chris@1100 204 typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
Chris@1100 205 mutable ViewRendererMap m_renderers;
Chris@1121 206
Chris@1113 207 Colour3DPlotRenderer *getRenderer(const LayerGeometryProvider *) const;
Chris@1107 208 void invalidateRenderers();
Chris@1100 209
Chris@725 210 /**
Chris@725 211 * Return the y coordinate at which the given bin "starts"
Chris@725 212 * (i.e. at the bottom of the bin, if the given bin is an integer
Chris@725 213 * and the vertical scale is the usual way up). Bin number may be
Chris@725 214 * fractional, to obtain a position part-way through a bin.
Chris@725 215 */
Chris@1406 216 double getYForBin(const LayerGeometryProvider *, double bin) const override;
Chris@903 217
Chris@903 218 /**
Chris@725 219 * Return the bin number, possibly fractional, at the given y
Chris@725 220 * coordinate. Note that the whole numbers occur at the positions
Chris@725 221 * at which the bins "start" (i.e. the bottom of the visible bin,
Chris@725 222 * if the vertical scale is the usual way up).
Chris@725 223 */
Chris@1406 224 double getBinForY(const LayerGeometryProvider *, double y) const override;
Chris@159 225
Chris@469 226 int getColourScaleWidth(QPainter &) const;
Chris@1101 227
Chris@1107 228 void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@0 229 };
Chris@0 230
Chris@0 231 #endif