comparison layer/Colour3DPlotRenderer.cpp @ 1221:eaab8bab3522

Measure time taken to render per pixel, and use the time last time around to decide whether to be time constrained this time around
author Chris Cannam
date Thu, 26 Jan 2017 11:55:11 +0000
parents c06861dec245
children 3ef162c9df00
comparison
equal deleted inserted replaced
1220:2954e9952b78 1221:eaab8bab3522
93 Colour3DPlotRenderer::render(const LayerGeometryProvider *v, 93 Colour3DPlotRenderer::render(const LayerGeometryProvider *v,
94 QPainter &paint, QRect rect, bool timeConstrained) 94 QPainter &paint, QRect rect, bool timeConstrained)
95 { 95 {
96 RenderType renderType = decideRenderType(v); 96 RenderType renderType = decideRenderType(v);
97 97
98 if (renderType != DrawBufferPixelResolution) { 98 if (timeConstrained) {
99 // Rendering should be fast in bin-resolution and direct draw 99 if (renderType != DrawBufferPixelResolution) {
100 // cases because we are quite well zoomed-in, and the sums are 100 // Rendering should be fast in bin-resolution and direct
101 // easier this way. Calculating boundaries later will be 101 // draw cases because we are quite well zoomed-in, and the
102 // fiddly for partial paints otherwise. 102 // sums are easier this way. Calculating boundaries later
103 timeConstrained = false; 103 // will be fiddly for partial paints otherwise.
104 } 104 timeConstrained = false;
105 105
106 } else if (m_secondsPerXPixelValid) {
107 double predicted = m_secondsPerXPixel * rect.width();
108 #ifdef DEBUG_COLOUR_PLOT_REPAINT
109 SVDEBUG << "Predicted time for width " << rect.width() << " = "
110 << predicted << endl;
111 #endif
112 if (predicted < 0.1) {
113 #ifdef DEBUG_COLOUR_PLOT_REPAINT
114 SVDEBUG << "Predicted time looks fast enough: no partial renders"
115 << endl;
116 #endif
117 timeConstrained = false;
118 }
119 }
120 }
121
106 int x0 = v->getXForViewX(rect.x()); 122 int x0 = v->getXForViewX(rect.x());
107 int x1 = v->getXForViewX(rect.x() + rect.width()); 123 int x1 = v->getXForViewX(rect.x() + rect.width());
108 if (x0 < 0) x0 = 0; 124 if (x0 < 0) x0 = 0;
109 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth(); 125 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
110 126
880 start = w-1; 896 start = w-1;
881 finish = -1; 897 finish = -1;
882 step = -1; 898 step = -1;
883 } 899 }
884 900
885 int columnCount = 0; 901 int xPixelCount = 0;
886 902
887 vector<float> preparedColumn; 903 vector<float> preparedColumn;
888 904
889 int modelWidth = sourceModel->getWidth(); 905 int modelWidth = sourceModel->getWidth();
890 906
895 for (int x = start; x != finish; x += step) { 911 for (int x = start; x != finish; x += step) {
896 912
897 // x is the on-canvas pixel coord; sx (later) will be the 913 // x is the on-canvas pixel coord; sx (later) will be the
898 // source column index 914 // source column index
899 915
900 ++columnCount; 916 ++xPixelCount;
901 917
902 if (binforx[x] < 0) continue; 918 if (binforx[x] < 0) continue;
903 919
904 int sx0 = binforx[x] / divisor; 920 int sx0 = binforx[x] / divisor;
905 int sx1 = sx0; 921 int sx1 = sx0;
976 } 992 }
977 993
978 m_magRanges.push_back(magRange); 994 m_magRanges.push_back(magRange);
979 } 995 }
980 996
981 double fractionComplete = double(columnCount) / double(w); 997 double fractionComplete = double(xPixelCount) / double(w);
982 if (timer.outOfTime(fractionComplete)) { 998 if (timer.outOfTime(fractionComplete)) {
983 #ifdef DEBUG_COLOUR_PLOT_REPAINT 999 #ifdef DEBUG_COLOUR_PLOT_REPAINT
984 SVDEBUG << "out of time" << endl; 1000 SVDEBUG << "out of time" << endl;
985 #endif 1001 #endif
986 return columnCount; 1002 updateTimings(timer, xPixelCount);
987 } 1003 return xPixelCount;
988 } 1004 }
989 1005 }
990 return columnCount; 1006
1007 updateTimings(timer, xPixelCount);
1008 return xPixelCount;
991 } 1009 }
992 1010
993 int 1011 int
994 Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v, 1012 Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v,
995 int w, int h, 1013 int w, int h,
1001 // Callers must have checked that the appropriate subset of 1019 // Callers must have checked that the appropriate subset of
1002 // Sources data members are set for the supplied flags (e.g. that 1020 // Sources data members are set for the supplied flags (e.g. that
1003 // fft model exists) 1021 // fft model exists)
1004 1022
1005 RenderTimer timer(timeConstrained ? 1023 RenderTimer timer(timeConstrained ?
1006 RenderTimer::FastRender : 1024 RenderTimer::SlowRender :
1007 RenderTimer::NoTimeout); 1025 RenderTimer::NoTimeout);
1008 1026
1009 const FFTModel *fft = m_sources.fft; 1027 const FFTModel *fft = m_sources.fft;
1010 1028
1011 int sh = fft->getHeight(); 1029 int sh = fft->getHeight();
1029 start = w-1; 1047 start = w-1;
1030 finish = -1; 1048 finish = -1;
1031 step = -1; 1049 step = -1;
1032 } 1050 }
1033 1051
1034 int columnCount = 0; 1052 int xPixelCount = 0;
1035 1053
1036 vector<float> preparedColumn; 1054 vector<float> preparedColumn;
1037 1055
1038 int modelWidth = fft->getWidth(); 1056 int modelWidth = fft->getWidth();
1039 #ifdef DEBUG_COLOUR_PLOT_REPAINT 1057 #ifdef DEBUG_COLOUR_PLOT_REPAINT
1055 for (int x = start; x != finish; x += step) { 1073 for (int x = start; x != finish; x += step) {
1056 1074
1057 // x is the on-canvas pixel coord; sx (later) will be the 1075 // x is the on-canvas pixel coord; sx (later) will be the
1058 // source column index 1076 // source column index
1059 1077
1060 ++columnCount; 1078 ++xPixelCount;
1061 1079
1062 if (binforx[x] < 0) continue; 1080 if (binforx[x] < 0) continue;
1063 1081
1064 int sx0 = binforx[x]; 1082 int sx0 = binforx[x];
1065 int sx1 = sx0; 1083 int sx1 = sx0;
1096 } 1114 }
1097 1115
1098 if (!pixelPeakColumn.empty()) { 1116 if (!pixelPeakColumn.empty()) {
1099 1117
1100 #ifdef DEBUG_COLOUR_PLOT_REPAINT 1118 #ifdef DEBUG_COLOUR_PLOT_REPAINT
1101 SVDEBUG << "found " << peakfreqs.size() << " peak freqs at column " 1119 // SVDEBUG << "found " << peakfreqs.size() << " peak freqs at column "
1102 << sx0 << endl; 1120 // << sx0 << endl;
1103 #endif 1121 #endif
1104 1122
1105 for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin(); 1123 for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin();
1106 pi != peakfreqs.end(); ++pi) { 1124 pi != peakfreqs.end(); ++pi) {
1107 1125
1137 SVDEBUG << "pixel peak column for range " << sx0 << " to " << sx1 1155 SVDEBUG << "pixel peak column for range " << sx0 << " to " << sx1
1138 << " is empty" << endl; 1156 << " is empty" << endl;
1139 #endif 1157 #endif
1140 } 1158 }
1141 1159
1142 double fractionComplete = double(columnCount) / double(w); 1160 double fractionComplete = double(xPixelCount) / double(w);
1143 if (timer.outOfTime(fractionComplete)) { 1161 if (timer.outOfTime(fractionComplete)) {
1144 #ifdef DEBUG_COLOUR_PLOT_REPAINT 1162 #ifdef DEBUG_COLOUR_PLOT_REPAINT
1145 SVDEBUG << "out of time" << endl; 1163 SVDEBUG << "out of time" << endl;
1146 #endif 1164 #endif
1147 return columnCount; 1165 updateTimings(timer, xPixelCount);
1148 } 1166 return xPixelCount;
1149 } 1167 }
1150 1168 }
1151 return columnCount; 1169
1170 updateTimings(timer, xPixelCount);
1171 return xPixelCount;
1172 }
1173
1174 void
1175 Colour3DPlotRenderer::updateTimings(const RenderTimer &timer, int xPixelCount)
1176 {
1177 m_secondsPerXPixel = timer.secondsPerItem(xPixelCount);
1178 m_secondsPerXPixelValid = (xPixelCount > 10);
1179
1180 #ifdef DEBUG_COLOUR_PLOT_REPAINT
1181 SVDEBUG << "seconds per x pixel = " << m_secondsPerXPixel
1182 << " (enough data? " << (m_secondsPerXPixelValid ? "yes" : "no")
1183 << ")" << endl;
1184 #endif
1185
1152 } 1186 }
1153 1187
1154 void 1188 void
1155 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h) 1189 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h)
1156 { 1190 {