comparison data/model/BasicCompressedDenseThreeDimensionalModel.h @ 1777:d484490cdf69

Split EditableDenseThreeDimensionalModel into explicitly compressed and uncompressed variants. Simplifies the uncompressed version, and we may want to consider whether we need the compressed one at all.
author Chris Cannam
date Tue, 10 Sep 2019 16:34:47 +0100
parents
children c546429d4c2f
comparison
equal deleted inserted replaced
1776:5750b9e60818 1777:d484490cdf69
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 SV_BASIC_COMPRESSED_DENSE_THREE_DIMENSIONAL_MODEL_H
17 #define SV_BASIC_COMPRESSED_DENSE_THREE_DIMENSIONAL_MODEL_H
18
19 #include "DenseThreeDimensionalModel.h"
20
21 #include <QReadWriteLock>
22
23 #include <vector>
24
25 class BasicCompressedDenseThreeDimensionalModel : public DenseThreeDimensionalModel
26 {
27 Q_OBJECT
28
29 public:
30
31 // BasicCompressedDenseThreeDimensionalModel supports a basic
32 // compression method that reduces the size of multirate data
33 // (e.g. wavelet transform outputs) that are stored as plain 3d
34 // grids by about 60% or thereabouts. However, it can only be
35 // used for models whose columns are set in order from 0 and never
36 // subsequently changed. For a model that is actually going to be
37 // edited, you need an EditableDenseThreeDimensionalModel.
38
39 BasicCompressedDenseThreeDimensionalModel(sv_samplerate_t sampleRate,
40 int resolution,
41 int height,
42 bool notifyOnAdd = true);
43
44 bool isOK() const override;
45 bool isReady(int *completion = 0) const override;
46 void setCompletion(int completion, bool update = true);
47 int getCompletion() const override;
48
49 sv_samplerate_t getSampleRate() const override;
50 sv_frame_t getStartFrame() const override;
51 sv_frame_t getTrueEndFrame() const override;
52
53 /**
54 * Set the frame offset of the first column.
55 */
56 virtual void setStartFrame(sv_frame_t);
57
58 /**
59 * Return the number of sample frames covered by each set of bins.
60 */
61 int getResolution() const override;
62
63 /**
64 * Set the number of sample frames covered by each set of bins.
65 */
66 virtual void setResolution(int sz);
67
68 /**
69 * Return the number of columns.
70 */
71 int getWidth() const override;
72
73 /**
74 * Return the number of bins in each column.
75 */
76 int getHeight() const override;
77
78 /**
79 * Set the number of bins in each column.
80 *
81 * You can set (via setColumn) a vector of any length as a column,
82 * but any column being retrieved will be resized to this height
83 * (or the height that was supplied to the constructor, if this is
84 * never called) on retrieval. That is, the model owner determines
85 * the height of the model at a single stroke; the columns
86 * themselves don't have any effect on the height of the model.
87 */
88 virtual void setHeight(int sz);
89
90 /**
91 * Return the minimum value of the value in each bin.
92 */
93 float getMinimumLevel() const override;
94
95 /**
96 * Set the minimum value of the value in a bin.
97 */
98 virtual void setMinimumLevel(float sz);
99
100 /**
101 * Return the maximum value of the value in each bin.
102 */
103 float getMaximumLevel() const override;
104
105 /**
106 * Set the maximum value of the value in a bin.
107 */
108 virtual void setMaximumLevel(float sz);
109
110 /**
111 * Get the set of bin values at the given column.
112 */
113 Column getColumn(int x) const override;
114
115 /**
116 * Get a single value, from the n'th bin of the given column.
117 */
118 float getValueAt(int x, int n) const override;
119
120 /**
121 * Set the entire set of bin values at the given column.
122 */
123 virtual void setColumn(int x, const Column &values);
124
125 /**
126 * Return the name of bin n. This is a single label per bin that
127 * does not vary from one column to the next.
128 */
129 QString getBinName(int n) const override;
130
131 /**
132 * Set the name of bin n.
133 */
134 virtual void setBinName(int n, QString);
135
136 /**
137 * Set the names of all bins.
138 */
139 virtual void setBinNames(std::vector<QString> names);
140
141 /**
142 * Return true if the bins have values as well as names. (The
143 * values may have been derived from the names, e.g. by parsing
144 * numbers from them.) If this returns true, getBinValue() may be
145 * used to retrieve the values.
146 */
147 bool hasBinValues() const override;
148
149 /**
150 * Return the value of bin n, if any. This is a "vertical scale"
151 * value which does not vary from one column to the next. This is
152 * only meaningful if hasBinValues() returns true.
153 */
154 float getBinValue(int n) const override;
155
156 /**
157 * Set the values of all bins (separate from their labels). These
158 * are "vertical scale" values which do not vary from one column
159 * to the next.
160 */
161 virtual void setBinValues(std::vector<float> values);
162
163 /**
164 * Obtain the name of the unit of the values returned from
165 * getBinValue(), if any.
166 */
167 QString getBinValueUnit() const override;
168
169 /**
170 * Set the name of the unit of the values return from
171 * getBinValue() if any.
172 */
173 virtual void setBinValueUnit(QString unit);
174
175 /**
176 * Return true if the distribution of values in the bins is such
177 * as to suggest a log scale (mapping to colour etc) may be better
178 * than a linear one.
179 */
180 bool shouldUseLogValueScale() const override;
181
182 QString getTypeName() const override { return tr("Editable Dense 3-D"); }
183
184 QString toDelimitedDataString(QString delimiter,
185 DataExportOptions options,
186 sv_frame_t startFrame,
187 sv_frame_t duration) const override;
188
189 void toXml(QTextStream &out,
190 QString indent = "",
191 QString extraAttributes = "") const override;
192
193 protected:
194 typedef std::vector<Column> ValueMatrix;
195 ValueMatrix m_data;
196
197 // m_trunc is used for simple compression. If at least the top N
198 // elements of column x (for N = some proportion of the column
199 // height) are equal to those of an earlier column x', then
200 // m_trunc[x] will contain x-x' and column x will be truncated so
201 // as to remove the duplicate elements. If the equal elements are
202 // at the bottom, then m_trunc[x] will contain x'-x (a negative
203 // value). If m_trunc[x] is 0 then the whole of column x is
204 // stored.
205 std::vector<signed char> m_trunc;
206 void truncateAndStore(int index, const Column & values);
207 Column expandAndRetrieve(int index) const;
208 Column rightHeight(const Column &c) const;
209
210 std::vector<QString> m_binNames;
211 std::vector<float> m_binValues;
212 QString m_binValueUnit;
213
214 sv_frame_t m_startFrame;
215 sv_samplerate_t m_sampleRate;
216 int m_resolution;
217 int m_yBinCount;
218 float m_minimum;
219 float m_maximum;
220 bool m_haveExtents;
221 bool m_notifyOnAdd;
222 sv_frame_t m_sinceLastNotifyMin;
223 sv_frame_t m_sinceLastNotifyMax;
224 int m_completion;
225
226 mutable QReadWriteLock m_lock;
227 };
228
229 #endif