Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1114:a42e5a3c63ef spectrogram-minor-refactor
Tidy
author | Chris Cannam |
---|---|
date | Tue, 19 Jul 2016 14:50:39 +0100 |
parents | 261a00010918 |
children | d930ff725f64 |
comparison
equal
deleted
inserted
replaced
1113:261a00010918 | 1114:a42e5a3c63ef |
---|---|
1043 } | 1043 } |
1044 } | 1044 } |
1045 | 1045 |
1046 return values; | 1046 return values; |
1047 } | 1047 } |
1048 /*!!! replace this | 1048 |
1049 bool | |
1050 Colour3DPlotLayer::shouldPaintDenseIn(const LayerGeometryProvider *v) const | |
1051 { | |
1052 if (!m_model || !v || !(v->getViewManager())) { | |
1053 return false; | |
1054 } | |
1055 double srRatio = | |
1056 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); | |
1057 if (m_opaque || | |
1058 m_smooth || | |
1059 m_model->getHeight() >= v->getPaintHeight() || | |
1060 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { | |
1061 return true; | |
1062 } | |
1063 return false; | |
1064 } | |
1065 */ | |
1066 Colour3DPlotRenderer * | 1049 Colour3DPlotRenderer * |
1067 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const | 1050 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const |
1068 { | 1051 { |
1069 if (m_renderers.find(v->getId()) == m_renderers.end()) { | 1052 if (m_renderers.find(v->getId()) == m_renderers.end()) { |
1070 | 1053 |
1164 //!!! SpectrogramLayer not present in Colour3DPlotLayer? | 1147 //!!! SpectrogramLayer not present in Colour3DPlotLayer? |
1165 //!!! unnecessary? vestigial? forgotten? | 1148 //!!! unnecessary? vestigial? forgotten? |
1166 | 1149 |
1167 paintWithRenderer(v, paint, rect); | 1150 paintWithRenderer(v, paint, rect); |
1168 } | 1151 } |
1169 | |
1170 /*!!! This will be needed in some form still. | |
1171 | |
1172 sv_frame_t modelStart = m_model->getStartFrame(); | |
1173 sv_frame_t modelEnd = m_model->getEndFrame(); | |
1174 int modelResolution = m_model->getResolution(); | |
1175 | |
1176 // The cache is from the model's start frame to the model's end | |
1177 // frame at the model's window increment frames per pixel. We | |
1178 // want to draw from our start frame + x0 * zoomLevel to our start | |
1179 // frame + x1 * zoomLevel at zoomLevel frames per pixel. | |
1180 | |
1181 // We have quite different paint mechanisms for rendering "large" | |
1182 // bins (more than one bin per pixel in both directions) and | |
1183 // "small". This is "large"; see paintDense below for "small". | |
1184 | |
1185 int x0 = rect.left(); | |
1186 int x1 = rect.right() + 1; | |
1187 | |
1188 int h = v->getPaintHeight(); | |
1189 | |
1190 double srRatio = | |
1191 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); | |
1192 | |
1193 // the s-prefix values are source, i.e. model, column and bin numbers | |
1194 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) | |
1195 / modelResolution); | |
1196 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart)) | |
1197 / modelResolution); | |
1198 int sh = m_model->getHeight(); | |
1199 | |
1200 int symin = m_miny; | |
1201 int symax = m_maxy; | |
1202 if (symax <= symin) { | |
1203 symin = 0; | |
1204 symax = sh; | |
1205 } | |
1206 if (symin < 0) symin = 0; | |
1207 if (symax > sh) symax = sh; | |
1208 | |
1209 if (sx0 > 0) --sx0; | |
1210 fillCache(sx0 < 0 ? 0 : sx0, | |
1211 sx1 < 0 ? 0 : sx1); | |
1212 | |
1213 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | |
1214 cerr << "Colour3DPlotLayer::paint: height = "<< m_model->getHeight() << ", modelStart = " << modelStart << ", resolution = " << modelResolution << ", model rate = " << m_model->getSampleRate() << " (zoom level = " << v->getZoomLevel() << ", srRatio = " << srRatio << ")" << endl; | |
1215 #endif | |
1216 | |
1217 if (shouldPaintDenseIn(v)) { | |
1218 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | |
1219 cerr << "calling paintDense" << endl; | |
1220 #endif | |
1221 paintDense(v, paint, rect); | |
1222 return; | |
1223 } | |
1224 | |
1225 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | |
1226 cerr << "Colour3DPlotLayer::paint: w " << x1-x0 << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sx1-sx0 << ", sh " << sh << endl; | |
1227 cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << endl; | |
1228 #endif | |
1229 | |
1230 QPoint illuminatePos; | |
1231 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); | |
1232 | |
1233 const int buflen = 40; | |
1234 char labelbuf[buflen]; | |
1235 | |
1236 for (int sx = sx0; sx <= sx1; ++sx) { | |
1237 | |
1238 sv_frame_t fx = sx * modelResolution + modelStart; | |
1239 | |
1240 if (fx + modelResolution <= modelStart || fx > modelEnd) continue; | |
1241 | |
1242 int rx0 = v->getXForFrame(int(double(fx) * srRatio)); | |
1243 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * srRatio)); | |
1244 | |
1245 int rw = rx1 - rx0; | |
1246 if (rw < 1) rw = 1; | |
1247 | |
1248 bool showLabel = (rw > 10 && | |
1249 paint.fontMetrics().width("0.000000") < rw - 3 && | |
1250 paint.fontMetrics().height() < (h / sh)); | |
1251 | |
1252 for (int sy = symin; sy < symax; ++sy) { | |
1253 | |
1254 int ry0 = getIYForBin(v, sy); | |
1255 int ry1 = getIYForBin(v, sy + 1); | |
1256 QRect r(rx0, ry1, rw, ry0 - ry1); | |
1257 | |
1258 QRgb pixel = qRgb(255, 255, 255); | |
1259 if (sx >= 0 && sx < m_cache->width() && | |
1260 sy >= 0 && sy < m_cache->height()) { | |
1261 pixel = m_cache->pixel(sx, sy); | |
1262 } | |
1263 | |
1264 if (rw == 1) { | |
1265 paint.setPen(pixel); | |
1266 paint.setBrush(Qt::NoBrush); | |
1267 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1); | |
1268 continue; | |
1269 } | |
1270 | |
1271 QColor pen(255, 255, 255, 80); | |
1272 QColor brush(pixel); | |
1273 | |
1274 if (rw > 3 && r.height() > 3) { | |
1275 brush.setAlpha(160); | |
1276 } | |
1277 | |
1278 paint.setPen(Qt::NoPen); | |
1279 paint.setBrush(brush); | |
1280 | |
1281 if (illuminate) { | |
1282 if (r.contains(illuminatePos)) { | |
1283 paint.setPen(v->getForeground()); | |
1284 } | |
1285 } | |
1286 | |
1287 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | |
1288 // cerr << "rect " << r.x() << "," << r.y() << " " | |
1289 // << r.width() << "x" << r.height() << endl; | |
1290 #endif | |
1291 | |
1292 paint.drawRect(r); | |
1293 | |
1294 if (showLabel) { | |
1295 if (sx >= 0 && sx < m_cache->width() && | |
1296 sy >= 0 && sy < m_cache->height()) { | |
1297 double value = m_model->getValueAt(sx, sy); | |
1298 snprintf(labelbuf, buflen, "%06f", value); | |
1299 QString text(labelbuf); | |
1300 PaintAssistant::drawVisibleText | |
1301 (v, | |
1302 paint, | |
1303 rx0 + 2, | |
1304 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), | |
1305 text, | |
1306 PaintAssistant::OutlinedText); | |
1307 } | |
1308 } | |
1309 } | |
1310 } | |
1311 } | |
1312 */ | |
1313 | |
1314 | 1152 |
1315 bool | 1153 bool |
1316 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, | 1154 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, |
1317 int &resolution, | 1155 int &resolution, |
1318 SnapType snap) const | 1156 SnapType snap) const |