annotate layer/Colour3DPlotLayer.h @ 1431:af824022bffd single-point

Begin fixing the various snap operations. Also remove SnapNearest, which is never used and seems to consume more lines of code than the rest!
author Chris Cannam
date Wed, 20 Mar 2019 14:59:34 +0000
parents a18e78b9c78b
children 39f1154c0e97
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@1406 49 const ZoomConstraint *getZoomConstraint() const override {
Chris@156 50 return m_model ? m_model->getZoomConstraint() : 0;
Chris@156 51 }
Chris@1406 52 const Model *getModel() const override { return m_model; }
Chris@1406 53 void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override;
Chris@1406 54 void setSynchronousPainting(bool synchronous) override;
Chris@0 55
Chris@1406 56 int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override;
Chris@1406 57 void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override;
Chris@25 58
Chris@1406 59 QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override;
Chris@25 60
Chris@1406 61 bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1266 62 int &resolution,
Chris@1406 63 SnapType snap) const override;
Chris@24 64
Chris@1406 65 void setLayerDormant(const LayerGeometryProvider *v, bool dormant) override;
Chris@475 66
Chris@1406 67 bool isLayerScrollable(const LayerGeometryProvider *v) const override;
Chris@25 68
Chris@1406 69 ColourSignificance getLayerColourSignificance() const override {
Chris@287 70 return ColourHasMeaningfulValue;
Chris@287 71 }
Chris@183 72
Chris@0 73 void setModel(const DenseThreeDimensionalModel *model);
Chris@0 74
Chris@1406 75 int getCompletion(LayerGeometryProvider *) const override { return m_model->getCompletion(); }
Chris@24 76
Chris@1406 77 PropertyList getProperties() const override;
Chris@1406 78 PropertyType getPropertyType(const PropertyName &) const override;
Chris@1406 79 QString getPropertyLabel(const PropertyName &) const override;
Chris@1406 80 QString getPropertyIconName(const PropertyName &) const override;
Chris@1406 81 QString getPropertyGroupName(const PropertyName &) const override;
Chris@1406 82 int getPropertyRangeAndValue(const PropertyName &,
Chris@1406 83 int *min, int *max, int *deflt) const override;
Chris@1406 84 QString getPropertyValueLabel(const PropertyName &,
Chris@1406 85 int value) const override;
Chris@1406 86 QString getPropertyValueIconName(const PropertyName &,
Chris@1406 87 int value) const override;
Chris@1406 88 RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
Chris@1406 89 void setProperty(const PropertyName &, int value) override;
Chris@1406 90 void setProperties(const QXmlAttributes &) override;
Chris@11 91
Chris@1105 92 void setColourScale(ColourScaleType);
Chris@1105 93 ColourScaleType 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@1103 108 void setBinScale(BinScale);
Chris@1103 109 BinScale getBinScale() const;
Chris@531 110
Chris@719 111 /**
Chris@1104 112 * Specify the normalization mode for individual columns.
Chris@719 113 */
Chris@1104 114 void setNormalization(ColumnNormalization);
Chris@1104 115 ColumnNormalization getNormalization() const;
Chris@1104 116
Chris@1104 117 /**
Chris@1104 118 * Specify whether to normalize the visible area.
Chris@1104 119 */
Chris@1104 120 void setNormalizeVisibleArea(bool);
Chris@1104 121 bool getNormalizeVisibleArea() const;
Chris@719 122
Chris@357 123 void setInvertVertical(bool i);
Chris@357 124 bool getInvertVertical() const;
Chris@357 125
Chris@465 126 void setOpaque(bool i);
Chris@465 127 bool getOpaque() const;
Chris@465 128
Chris@535 129 void setSmooth(bool i);
Chris@535 130 bool getSmooth() const;
Chris@535 131
Chris@1406 132 bool getValueExtents(double &min, double &max,
Chris@1406 133 bool &logarithmic, QString &unit) const override;
Chris@444 134
Chris@1406 135 bool getDisplayExtents(double &min, double &max) const override;
Chris@1406 136 bool setDisplayExtents(double min, double max) override;
Chris@444 137
Chris@1406 138 bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
Chris@1406 139 double &/* value */, QString &/* unit */) const override;
Chris@725 140
Chris@1406 141 int getVerticalZoomSteps(int &defaultStep) const override;
Chris@1406 142 int getCurrentVerticalZoomStep() const override;
Chris@1406 143 void setVerticalZoomStep(int) override;
Chris@1406 144 RangeMapper *getNewVerticalZoomRangeMapper() const override;
Chris@444 145
Chris@1406 146 const Model *getSliceableModel() const override { return m_model; }
Chris@193 147
Chris@1406 148 void toXml(QTextStream &stream, QString indent = "",
Chris@1406 149 QString extraAttributes = "") const override;
Chris@197 150
Chris@0 151 protected slots:
Chris@0 152 void cacheInvalid();
Chris@908 153 void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
Chris@461 154 void modelChanged();
Chris@908 155 void modelChangedWithin(sv_frame_t, sv_frame_t);
Chris@0 156
Chris@0 157 protected:
Chris@0 158 const DenseThreeDimensionalModel *m_model; // I do not own this
Chris@0 159
Chris@1105 160 ColourScaleType m_colourScale;
Chris@1104 161 bool m_colourScaleSet;
Chris@1104 162 int m_colourMap;
Chris@1362 163 bool m_colourInverted;
Chris@1104 164 float m_gain;
Chris@1103 165 BinScale m_binScale;
Chris@1104 166 ColumnNormalization m_normalization; // of individual columns
Chris@1104 167 bool m_normalizeVisibleArea;
Chris@1104 168 bool m_invertVertical;
Chris@1104 169 bool m_opaque;
Chris@1104 170 bool m_smooth;
Chris@1104 171 int m_peakResolution;
Chris@197 172
Chris@725 173 // Minimum and maximum bin numbers visible within the view. We
Chris@725 174 // always snap to whole bins at view edges.
Chris@1104 175 int m_miny;
Chris@1104 176 int m_maxy;
Chris@1100 177
Chris@1104 178 bool m_synchronous;
Chris@1104 179
Chris@1105 180 static ColourScaleType convertToColourScale(int value);
Chris@1105 181 static int convertFromColourScale(ColourScaleType);
Chris@1104 182 static std::pair<ColumnNormalization, bool> convertToColumnNorm(int value);
Chris@1104 183 static int convertFromColumnNorm(ColumnNormalization norm, bool visible);
Chris@1101 184
Chris@1100 185 mutable Dense3DModelPeakCache *m_peakCache;
Chris@1100 186 const int m_peakCacheDivisor;
Chris@1100 187 Dense3DModelPeakCache *getPeakCache() const;
Chris@1100 188
Chris@1121 189 typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
Chris@1121 190 mutable ViewMagMap m_viewMags;
Chris@1235 191 mutable ViewMagMap m_lastRenderedMags; // when in normalizeVisibleArea mode
Chris@1235 192 void invalidateMagnitudes();
Chris@1121 193
Chris@1100 194 typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
Chris@1100 195 mutable ViewRendererMap m_renderers;
Chris@1121 196
Chris@1113 197 Colour3DPlotRenderer *getRenderer(const LayerGeometryProvider *) const;
Chris@1107 198 void invalidateRenderers();
Chris@1100 199
Chris@725 200 /**
Chris@725 201 * Return the y coordinate at which the given bin "starts"
Chris@725 202 * (i.e. at the bottom of the bin, if the given bin is an integer
Chris@725 203 * and the vertical scale is the usual way up). Bin number may be
Chris@725 204 * fractional, to obtain a position part-way through a bin.
Chris@725 205 */
Chris@1406 206 double getYForBin(const LayerGeometryProvider *, double bin) const override;
Chris@903 207
Chris@903 208 /**
Chris@725 209 * Return the bin number, possibly fractional, at the given y
Chris@725 210 * coordinate. Note that the whole numbers occur at the positions
Chris@725 211 * at which the bins "start" (i.e. the bottom of the visible bin,
Chris@725 212 * if the vertical scale is the usual way up).
Chris@725 213 */
Chris@1406 214 double getBinForY(const LayerGeometryProvider *, double y) const override;
Chris@159 215
Chris@469 216 int getColourScaleWidth(QPainter &) const;
Chris@1101 217
Chris@1107 218 void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
Chris@0 219 };
Chris@0 220
Chris@0 221 #endif