Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1100:102f986ec032 spectrogram-minor-refactor
Create, but don't yet use, a renderer in the colour 3d plot layer
author | Chris Cannam |
---|---|
date | Wed, 13 Jul 2016 13:06:28 +0100 |
parents | 5c6271734790 |
children | 1364cbf4453d |
comparison
equal
deleted
inserted
replaced
1099:5c6271734790 | 1100:102f986ec032 |
---|---|
20 #include "base/RangeMapper.h" | 20 #include "base/RangeMapper.h" |
21 | 21 |
22 #include "ColourMapper.h" | 22 #include "ColourMapper.h" |
23 #include "LayerGeometryProvider.h" | 23 #include "LayerGeometryProvider.h" |
24 #include "PaintAssistant.h" | 24 #include "PaintAssistant.h" |
25 | |
26 #include "data/model/Dense3DModelPeakCache.h" | |
25 | 27 |
26 #include "view/ViewManager.h" | 28 #include "view/ViewManager.h" |
27 | 29 |
28 #include <QPainter> | 30 #include <QPainter> |
29 #include <QImage> | 31 #include <QImage> |
59 m_invertVertical(false), | 61 m_invertVertical(false), |
60 m_opaque(false), | 62 m_opaque(false), |
61 m_smooth(false), | 63 m_smooth(false), |
62 m_peakResolution(256), | 64 m_peakResolution(256), |
63 m_miny(0), | 65 m_miny(0), |
64 m_maxy(0) | 66 m_maxy(0), |
67 m_peakCache(0), | |
68 m_peakCacheDivisor(8) | |
65 { | 69 { |
66 QSettings settings; | 70 QSettings settings; |
67 settings.beginGroup("Preferences"); | 71 settings.beginGroup("Preferences"); |
68 setColourMap(settings.value("colour-3d-plot-colour", ColourMapper::Green).toInt()); | 72 setColourMap(settings.value("colour-3d-plot-colour", ColourMapper::Green).toInt()); |
69 settings.endGroup(); | 73 settings.endGroup(); |
70 } | 74 } |
71 | 75 |
72 Colour3DPlotLayer::~Colour3DPlotLayer() | 76 Colour3DPlotLayer::~Colour3DPlotLayer() |
73 { | 77 { |
74 delete m_cache; | 78 delete m_cache; |
75 delete m_peaksCache; | 79 delete m_peaksCache; //!!! this one is to go... |
80 delete m_peakCache; | |
76 } | 81 } |
77 | 82 |
78 void | 83 void |
79 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model) | 84 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model) |
80 { | 85 { |
95 } else if (model->getResolution() > 128) { | 100 } else if (model->getResolution() > 128) { |
96 m_peakResolution = 64; | 101 m_peakResolution = 64; |
97 } else if (model->getResolution() > 2) { | 102 } else if (model->getResolution() > 2) { |
98 m_peakResolution = 128; | 103 m_peakResolution = 128; |
99 } | 104 } |
105 | |
106 delete m_peakCache; | |
107 m_peakCache = 0; | |
108 | |
100 cacheInvalid(); | 109 cacheInvalid(); |
101 | 110 |
102 emit modelReplaced(); | 111 emit modelReplaced(); |
103 emit sliceableModelReplaced(oldModel, model); | 112 emit sliceableModelReplaced(oldModel, model); |
104 } | 113 } |
105 | 114 |
106 void | 115 void |
107 Colour3DPlotLayer::cacheInvalid() | 116 Colour3DPlotLayer::cacheInvalid() |
108 { | 117 { |
118 //!!! to go | |
119 | |
109 delete m_cache; | 120 delete m_cache; |
110 delete m_peaksCache; | 121 delete m_peaksCache; |
111 m_cache = 0; | 122 m_cache = 0; |
112 m_peaksCache = 0; | 123 m_peaksCache = 0; |
113 m_cacheValidStart = 0; | 124 m_cacheValidStart = 0; |
115 } | 126 } |
116 | 127 |
117 void | 128 void |
118 Colour3DPlotLayer::cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame) | 129 Colour3DPlotLayer::cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame) |
119 { | 130 { |
131 //!!! to go | |
132 | |
120 if (!m_cache || !m_model) return; | 133 if (!m_cache || !m_model) return; |
121 | 134 |
122 int modelResolution = m_model->getResolution(); | 135 int modelResolution = m_model->getResolution(); |
123 int start = int(startFrame / modelResolution); | 136 int start = int(startFrame / modelResolution); |
124 int end = int(endFrame / modelResolution + 1); | 137 int end = int(endFrame / modelResolution + 1); |
125 if (m_cacheValidStart < end) m_cacheValidStart = end; | 138 if (m_cacheValidStart < end) m_cacheValidStart = end; |
126 if (m_cacheValidEnd > start) m_cacheValidEnd = start; | 139 if (m_cacheValidEnd > start) m_cacheValidEnd = start; |
127 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart; | 140 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart; |
141 } | |
142 | |
143 Dense3DModelPeakCache * | |
144 Colour3DPlotLayer::getPeakCache() const | |
145 { | |
146 if (!m_peakCache) { | |
147 m_peakCache = new Dense3DModelPeakCache(m_model, m_peakCacheDivisor); | |
148 } | |
149 return m_peakCache; | |
128 } | 150 } |
129 | 151 |
130 void | 152 void |
131 Colour3DPlotLayer::modelChanged() | 153 Colour3DPlotLayer::modelChanged() |
132 { | 154 { |
1261 m_model->getHeight() >= v->getPaintHeight() || | 1283 m_model->getHeight() >= v->getPaintHeight() || |
1262 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { | 1284 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { |
1263 return true; | 1285 return true; |
1264 } | 1286 } |
1265 return false; | 1287 return false; |
1288 } | |
1289 | |
1290 Colour3DPlotRenderer * | |
1291 Colour3DPlotLayer::getRenderer(LayerGeometryProvider *v) const | |
1292 { | |
1293 if (m_renderers.find(v->getId()) == m_renderers.end()) { | |
1294 | |
1295 Colour3DPlotRenderer::Sources sources; | |
1296 sources.verticalBinLayer = this; | |
1297 sources.fft = 0; | |
1298 sources.source = m_model; | |
1299 sources.peaks = getPeakCache(); | |
1300 | |
1301 ColourScale::Parameters cparams; | |
1302 cparams.colourMap = m_colourMap; | |
1303 cparams.scale = m_colourScale; | |
1304 cparams.gain = m_gain; | |
1305 | |
1306 Colour3DPlotRenderer::Parameters params; | |
1307 params.colourScale = ColourScale(cparams); | |
1308 params.normalization = m_normalization; | |
1309 params.binScale = m_binScale; | |
1310 params.alwaysOpaque = m_opaque; | |
1311 params.invertVertical = m_invertVertical; | |
1312 params.interpolate = m_smooth; | |
1313 | |
1314 m_renderers[v->getId()] = new Colour3DPlotRenderer(sources, params); | |
1315 } | |
1316 | |
1317 return m_renderers[v->getId()]; | |
1266 } | 1318 } |
1267 | 1319 |
1268 void | 1320 void |
1269 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const | 1321 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const |
1270 { | 1322 { |