Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 474:efc2bd6d3611
* take a bit more care about peaks cache sizing
author | Chris Cannam |
---|---|
date | Thu, 29 Jan 2009 14:17:12 +0000 |
parents | 13e8edbffbd7 |
children | 3f4b10e76ccd |
comparison
equal
deleted
inserted
replaced
473:4f4f943bfdfc | 474:efc2bd6d3611 |
---|---|
35 | 35 |
36 Colour3DPlotLayer::Colour3DPlotLayer() : | 36 Colour3DPlotLayer::Colour3DPlotLayer() : |
37 m_model(0), | 37 m_model(0), |
38 m_cache(0), | 38 m_cache(0), |
39 m_peaksCache(0), | 39 m_peaksCache(0), |
40 m_peakResolution(128), | 40 m_peakResolution(256), |
41 m_cacheValidStart(0), | 41 m_cacheValidStart(0), |
42 m_cacheValidEnd(0), | 42 m_cacheValidEnd(0), |
43 m_colourScale(LinearScale), | 43 m_colourScale(LinearScale), |
44 m_colourScaleSet(false), | 44 m_colourScaleSet(false), |
45 m_colourMap(0), | 45 m_colourMap(0), |
70 connectSignals(m_model); | 70 connectSignals(m_model); |
71 | 71 |
72 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged())); | 72 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged())); |
73 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), | 73 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), |
74 this, SLOT(modelChanged(size_t, size_t))); | 74 this, SLOT(modelChanged(size_t, size_t))); |
75 | |
76 m_peakResolution = 256; | |
77 if (model->getResolution() > 512) { | |
78 m_peakResolution = 16; | |
79 } else if (model->getResolution() > 128) { | |
80 m_peakResolution = 64; | |
81 } else if (model->getResolution() > 2) { | |
82 m_peakResolution = 128; | |
83 } | |
84 cacheInvalid(); | |
75 | 85 |
76 emit modelReplaced(); | 86 emit modelReplaced(); |
77 emit sliceableModelReplaced(oldModel, model); | 87 emit sliceableModelReplaced(oldModel, model); |
78 } | 88 } |
79 | 89 |
748 | 758 |
749 if (!m_cache) { | 759 if (!m_cache) { |
750 m_cache = new QImage | 760 m_cache = new QImage |
751 (cacheWidth, cacheHeight, QImage::Format_Indexed8); | 761 (cacheWidth, cacheHeight, QImage::Format_Indexed8); |
752 m_cache->setNumColors(256); | 762 m_cache->setNumColors(256); |
753 if (modelResolution < m_peakResolution / 2 && !m_normalizeVisibleArea) { | 763 if (!m_normalizeVisibleArea) { |
754 m_peaksCache = new QImage | 764 m_peaksCache = new QImage |
755 (cacheWidth / m_peakResolution + 1, cacheHeight, | 765 (cacheWidth / m_peakResolution + 1, cacheHeight, |
756 QImage::Format_Indexed8); | 766 QImage::Format_Indexed8); |
757 m_peaksCache->setNumColors(256); | 767 m_peaksCache->setNumColors(256); |
758 } else if (m_peaksCache) { | 768 } else if (m_peaksCache) { |
1116 memset(peaks, 0, w); | 1126 memset(peaks, 0, w); |
1117 | 1127 |
1118 int zoomLevel = v->getZoomLevel(); | 1128 int zoomLevel = v->getZoomLevel(); |
1119 | 1129 |
1120 QImage *source = m_cache; | 1130 QImage *source = m_cache; |
1121 if (m_peaksCache && | 1131 |
1122 ((modelResolution * srRatio * m_peakResolution) / zoomLevel) < 1) { | 1132 std::cerr << "modelResolution " << modelResolution << ", srRatio " |
1123 // std::cerr << "using peaks cache" << std::endl; | 1133 << srRatio << ", m_peakResolution " << m_peakResolution |
1124 source = m_peaksCache; | 1134 << ", zoomLevel " << zoomLevel << ", result " |
1125 modelResolution *= m_peakResolution; | 1135 << ((modelResolution * srRatio * m_peakResolution) / zoomLevel) |
1136 << std::endl; | |
1137 | |
1138 if (m_peaksCache) { | |
1139 if (((modelResolution * srRatio * m_peakResolution) / zoomLevel) < 1) { | |
1140 std::cerr << "using peaks cache" << std::endl; | |
1141 source = m_peaksCache; | |
1142 modelResolution *= m_peakResolution; | |
1143 } else { | |
1144 std::cerr << "not using peaks cache" << std::endl; | |
1145 } | |
1126 } else { | 1146 } else { |
1127 // std::cerr << "not using peaks cache" << std::endl; | 1147 std::cerr << "have no peaks cache" << std::endl; |
1128 } | 1148 } |
1129 | 1149 |
1130 int psy1i = -1; | 1150 int psy1i = -1; |
1131 int sw = source->width(); | 1151 int sw = source->width(); |
1132 | 1152 |
1173 | 1193 |
1174 uchar *sourceLine = source->scanLine(sy); | 1194 uchar *sourceLine = source->scanLine(sy); |
1175 | 1195 |
1176 for (int x = 0; x < w; ++x) { | 1196 for (int x = 0; x < w; ++x) { |
1177 | 1197 |
1198 int sx1i = sxa[x*2 + 1]; | |
1199 if (sx1i < 0) continue; | |
1200 | |
1178 int sx0i = sxa[x*2]; | 1201 int sx0i = sxa[x*2]; |
1179 int sx1i = sxa[x*2 + 1]; | 1202 if (sx0i >= sw) break; |
1180 | 1203 |
1181 uchar peak = 0; | 1204 uchar peak = 0; |
1182 for (int sx = sx0i; sx <= sx1i; ++sx) { | 1205 for (int sx = sx0i; sx <= sx1i; ++sx) { |
1183 if (sx < 0 || sx >= sw) continue; | 1206 if (sx < 0 || sx >= sw) continue; |
1184 if (sourceLine[sx] > peak) peak = sourceLine[sx]; | 1207 if (sourceLine[sx] > peak) peak = sourceLine[sx]; |