Colour3DPlotLayer.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef COLOUR_3D_PLOT_LAYER_H
17 #define COLOUR_3D_PLOT_LAYER_H
18 
19 #include "SliceableLayer.h"
20 #include "VerticalBinLayer.h"
21 
22 #include "ColourScale.h"
23 #include "Colour3DPlotRenderer.h"
24 
25 #include "data/model/DenseThreeDimensionalModel.h"
26 
27 class View;
28 class QPainter;
29 class QImage;
30 
42 {
43  Q_OBJECT
44 
45 public:
48 
49  ModelId getModel() const override { return m_model; }
50 
51  ModelId getExportModel(LayerGeometryProvider *) const override;
52 
53  const ZoomConstraint *getZoomConstraint() const override;
54 
56  QPainter &paint, QRect rect) const override;
57  void setSynchronousPainting(bool synchronous) override;
58 
60  bool, QPainter &) const override;
62  bool, QPainter &paint, QRect rect) const override;
63 
65  QPoint &) const override;
66 
67  bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
68  int &resolution,
69  SnapType snap, int ycoord) const override;
70 
72  bool dormant) override;
73 
74  bool isLayerScrollable(const LayerGeometryProvider *v) const override;
75 
78  }
79 
80  void setModel(ModelId model); // a DenseThreeDimensionalModel
81 
82  int getCompletion(LayerGeometryProvider *) const override;
83 
84  PropertyList getProperties() const override;
85  PropertyType getPropertyType(const PropertyName &) const override;
86  QString getPropertyLabel(const PropertyName &) const override;
87  QString getPropertyIconName(const PropertyName &) const override;
88  QString getPropertyGroupName(const PropertyName &) const override;
89  int getPropertyRangeAndValue(const PropertyName &,
90  int *min, int *max, int *deflt) const override;
91  QString getPropertyValueLabel(const PropertyName &,
92  int value) const override;
93  QString getPropertyValueIconName(const PropertyName &,
94  int value) const override;
95  RangeMapper *getNewPropertyRangeMapper(const PropertyName &) const override;
96  void setProperty(const PropertyName &, int value) override;
97  void setProperties(const QXmlAttributes &) override;
98 
101 
102  void setColourMap(int map);
103  int getColourMap() const;
104 
109  void setGain(float gain);
110  float getGain() const;
111 
115  void setBinScale(BinScale);
116  BinScale getBinScale() const;
117 
121  void setNormalization(ColumnNormalization);
122  ColumnNormalization getNormalization() const;
123 
127  void setNormalizeVisibleArea(bool);
128  bool getNormalizeVisibleArea() const;
129 
130  void setInvertVertical(bool i);
131  bool getInvertVertical() const;
132 
133  void setOpaque(bool i);
134  bool getOpaque() const;
135 
136  void setSmooth(bool i);
137  bool getSmooth() const;
138 
139  bool hasLightBackground() const override;
140 
141  bool getValueExtents(double &min, double &max,
142  bool &logarithmic, QString &unit) const override;
143 
144  bool getDisplayExtents(double &min, double &max) const override;
145  bool setDisplayExtents(double min, double max) override;
146 
147  bool getYScaleValue(const LayerGeometryProvider *, int /* y */,
148  double &/* value */, QString &/* unit */) const override;
149 
150  int getVerticalZoomSteps(int &defaultStep) const override;
151  int getCurrentVerticalZoomStep() const override;
152  void setVerticalZoomStep(int) override;
153  RangeMapper *getNewVerticalZoomRangeMapper() const override;
154 
155  ModelId getSliceableModel() const override { return m_model; }
156 
157  void toXml(QTextStream &stream, QString indent = "",
158  QString extraAttributes = "") const override;
159 
160 protected slots:
161  void handleModelChanged(ModelId);
162  void handleModelChangedWithin(ModelId, sv_frame_t, sv_frame_t);
163 
164 protected:
165  ModelId m_model; // A DenseThreeDimensionalModel
166 
171  float m_gain;
173  ColumnNormalization m_normalization; // of individual columns
176  bool m_opaque;
177  bool m_smooth;
179 
180  // Minimum and maximum bin numbers visible within the view. We
181  // always snap to whole bins at view edges.
182  int m_miny;
183  int m_maxy;
184 
186 
187  static ColourScaleType convertToColourScale(int value);
189  static std::pair<ColumnNormalization, bool> convertToColumnNorm(int value);
190  static int convertFromColumnNorm(ColumnNormalization norm, bool visible);
191 
192  mutable ModelId m_peakCache;
194  void invalidatePeakCache();
195  ModelId getPeakCache() const;
196 
197  mutable std::vector<ModelId> m_exporters; // used, waiting to be released
198 
199  typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
200  mutable ViewMagMap m_viewMags;
201  mutable ViewMagMap m_lastRenderedMags; // when in normalizeVisibleArea mode
202  void invalidateMagnitudes();
203 
204  typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
205  mutable ViewRendererMap m_renderers;
206 
208  void invalidateRenderers();
209 
216  double getYForBin(const LayerGeometryProvider *, double bin) const override;
217 
224  double getBinForY(const LayerGeometryProvider *, double y) const override;
225 
226  int getColourScaleWidth(QPainter &) const;
227 
228  void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const;
229 };
230 
231 #endif
QString getPropertyValueIconName(const PropertyName &, int value) const override
bool getDisplayExtents(double &min, double &max) const override
Return the minimum and maximum values within the visible area for the y axis of this layer...
int getCurrentVerticalZoomStep() const override
Get the current vertical zoom step.
static std::pair< ColumnNormalization, bool > convertToColumnNorm(int value)
static int convertFromColourScale(ColourScaleType)
ModelId getModel() const override
Return the ID of the model represented in this layer.
ModelId getExportModel(LayerGeometryProvider *) const override
Return the ID of a model representing the contents of this layer in a form suitable for export to a t...
PropertyType getPropertyType(const PropertyName &) const override
QString getPropertyLabel(const PropertyName &) const override
void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const override
Paint the given rectangle of this layer onto the given view using the given painter, superimposing it on top of any existing material in that view.
ModelId getPeakCache() const
std::map< int, Colour3DPlotRenderer * > ViewRendererMap
ModelId getSliceableModel() const override
void setVerticalZoomStep(int) override
Set the vertical zoom step.
void setProperty(const PropertyName &, int value) override
int getCompletion(LayerGeometryProvider *) const override
Return the proportion of background work complete in drawing this view, as a percentage – in most ca...
This is a view that displays dense 3-D data (time, some sort of binned y-axis range, value) as a colour plot with value mapped to colour range.
int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const override
bool isLayerScrollable(const LayerGeometryProvider *v) const override
This should return true if the layer can safely be scrolled automatically by a given view (simply cop...
ColourSignificance
Definition: Layer.h:348
void setColourMap(int map)
double getYForBin(const LayerGeometryProvider *, double bin) const override
Return the y coordinate at which the given bin "starts" (i.e.
void handleModelChanged(ModelId)
void setInvertVertical(bool i)
ViewRendererMap m_renderers
bool getInvertVertical() const
std::map< int, MagnitudeRange > ViewMagMap
bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap, int ycoord) const override
Adjust the given frame to snap to the nearest feature, if possible.
Interface for classes that provide geometry information (such as size, start frame, and a large number of other properties) about the disposition of a layer.
void setGain(float gain)
Set the gain multiplier for sample values in this view.
Interface for layers in which the Y axis corresponds to bin number rather than scale value...
std::vector< ModelId > m_exporters
ColourSignificance getLayerColourSignificance() const override
This should return the degree of meaning associated with colour in this layer.
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
int getPropertyRangeAndValue(const PropertyName &, int *min, int *max, int *deflt) const override
ViewMagMap m_lastRenderedMags
static ColourScaleType convertToColourScale(int value)
void setModel(ModelId model)
float getGain() const
bool hasLightBackground() const override
SnapType
Definition: Layer.h:195
void setSynchronousPainting(bool synchronous) override
Enable or disable synchronous painting.
int getVerticalZoomSteps(int &defaultStep) const override
Get the number of vertical zoom steps available for this layer.
QString getPropertyIconName(const PropertyName &) const override
void setColourScale(ColourScaleType)
int getColourScaleWidth(QPainter &) const
ColourScaleType getColourScale() const
bool getNormalizeVisibleArea() const
PropertyList getProperties() const override
ColourScaleType
Definition: ColourScale.h:21
QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const override
void paintWithRenderer(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
void setBinScale(BinScale)
Specify the scale for the y axis.
const ZoomConstraint * getZoomConstraint() const override
Return a zoom constraint object defining the supported zoom levels for this layer.
void setNormalizeVisibleArea(bool)
Specify whether to normalize the visible area.
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
int getColourMap() const
void setProperties(const QXmlAttributes &) override
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
const int m_peakCacheDivisor
ColourScaleType m_colourScale
QString getPropertyValueLabel(const PropertyName &, int value) const override
static int convertFromColumnNorm(ColumnNormalization norm, bool visible)
bool setDisplayExtents(double min, double max) override
Set the displayed minimum and maximum values for the y axis to the given range, if supported...
void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const override
BinScale getBinScale() const
ColumnNormalization getNormalization() const
RangeMapper * getNewVerticalZoomRangeMapper() const override
Create and return a range mapper for vertical zoom step values.
Colour3DPlotRenderer * getRenderer(const LayerGeometryProvider *) const
void setLayerDormant(const LayerGeometryProvider *v, bool dormant) override
Indicate that a layer is not currently visible in the given view and is not expected to become visibl...
bool getYScaleValue(const LayerGeometryProvider *, int, double &, QString &) const override
Return the value and unit at the given y coordinate in the given view.
void handleModelChangedWithin(ModelId, sv_frame_t, sv_frame_t)
void setNormalization(ColumnNormalization)
Specify the normalization mode for individual columns.
bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const override
Return the minimum and maximum values for the y axis of the model in this layer, as well as whether t...
double getBinForY(const LayerGeometryProvider *, double y) const override
Return the bin number, possibly fractional, at the given y coordinate.
RangeMapper * getNewPropertyRangeMapper(const PropertyName &) const override
ColumnNormalization m_normalization
QString getPropertyGroupName(const PropertyName &) const override