comparison layer/Colour3DPlotLayer.cpp @ 805:1d526ba11a24 warnfix_no_size_t

Remove size_t's and fix warnings in layer/
author Chris Cannam
date Tue, 17 Jun 2014 15:18:06 +0100
parents d7e8cefedbbc
children 6c52314b31b0
comparison
equal deleted inserted replaced
782:ddae586bc47b 805:1d526ba11a24
39 39
40 Colour3DPlotLayer::Colour3DPlotLayer() : 40 Colour3DPlotLayer::Colour3DPlotLayer() :
41 m_model(0), 41 m_model(0),
42 m_cache(0), 42 m_cache(0),
43 m_peaksCache(0), 43 m_peaksCache(0),
44 m_peakResolution(256),
45 m_cacheValidStart(0), 44 m_cacheValidStart(0),
46 m_cacheValidEnd(0), 45 m_cacheValidEnd(0),
47 m_colourScale(LinearScale), 46 m_colourScale(LinearScale),
48 m_colourScaleSet(false), 47 m_colourScaleSet(false),
49 m_colourMap(0), 48 m_colourMap(0),
53 m_normalizeVisibleArea(false), 52 m_normalizeVisibleArea(false),
54 m_normalizeHybrid(false), 53 m_normalizeHybrid(false),
55 m_invertVertical(false), 54 m_invertVertical(false),
56 m_opaque(false), 55 m_opaque(false),
57 m_smooth(false), 56 m_smooth(false),
57 m_peakResolution(256),
58 m_miny(0), 58 m_miny(0),
59 m_maxy(0) 59 m_maxy(0)
60 { 60 {
61 61
62 } 62 }
76 if (!m_model || !m_model->isOK()) return; 76 if (!m_model || !m_model->isOK()) return;
77 77
78 connectSignals(m_model); 78 connectSignals(m_model);
79 79
80 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged())); 80 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
81 connect(m_model, SIGNAL(modelChanged(size_t, size_t)), 81 connect(m_model, SIGNAL(modelChanged(int, int)),
82 this, SLOT(modelChanged(size_t, size_t))); 82 this, SLOT(modelChanged(int, int)));
83 83
84 m_peakResolution = 256; 84 m_peakResolution = 256;
85 if (model->getResolution() > 512) { 85 if (model->getResolution() > 512) {
86 m_peakResolution = 16; 86 m_peakResolution = 16;
87 } else if (model->getResolution() > 128) { 87 } else if (model->getResolution() > 128) {
105 m_cacheValidStart = 0; 105 m_cacheValidStart = 0;
106 m_cacheValidEnd = 0; 106 m_cacheValidEnd = 0;
107 } 107 }
108 108
109 void 109 void
110 Colour3DPlotLayer::cacheInvalid(size_t startFrame, size_t endFrame) 110 Colour3DPlotLayer::cacheInvalid(int startFrame, int endFrame)
111 { 111 {
112 if (!m_cache) return; 112 if (!m_cache) return;
113 113
114 size_t modelResolution = m_model->getResolution(); 114 int modelResolution = m_model->getResolution();
115 size_t start = startFrame / modelResolution; 115 int start = startFrame / modelResolution;
116 size_t end = endFrame / modelResolution + 1; 116 int end = endFrame / modelResolution + 1;
117 if (m_cacheValidStart < end) m_cacheValidStart = end; 117 if (m_cacheValidStart < end) m_cacheValidStart = end;
118 if (m_cacheValidEnd > start) m_cacheValidEnd = start; 118 if (m_cacheValidEnd > start) m_cacheValidEnd = start;
119 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart; 119 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart;
120 } 120 }
121 121
133 } 133 }
134 cacheInvalid(); 134 cacheInvalid();
135 } 135 }
136 136
137 void 137 void
138 Colour3DPlotLayer::modelChanged(size_t startFrame, size_t endFrame) 138 Colour3DPlotLayer::modelChanged(int startFrame, int endFrame)
139 { 139 {
140 if (!m_colourScaleSet && m_colourScale == LinearScale) { 140 if (!m_colourScaleSet && m_colourScale == LinearScale) {
141 if (m_model && m_model->getWidth() > 50) { 141 if (m_model && m_model->getWidth() > 50) {
142 if (m_model->shouldUseLogValueScale()) { 142 if (m_model->shouldUseLogValueScale()) {
143 setColourScale(LogScale); 143 setColourScale(LogScale);
578 emit layerParametersChanged(); 578 emit layerParametersChanged();
579 return true; 579 return true;
580 } 580 }
581 581
582 bool 582 bool
583 Colour3DPlotLayer::getYScaleValue(const View *v, int y, 583 Colour3DPlotLayer::getYScaleValue(const View *, int,
584 float &value, QString &unit) const 584 float &, QString &) const
585 { 585 {
586 return false;//!!! 586 return false;//!!!
587 } 587 }
588 588
589 int 589 int
677 if (!m_model) return ""; 677 if (!m_model) return "";
678 678
679 int x = pos.x(); 679 int x = pos.x();
680 int y = pos.y(); 680 int y = pos.y();
681 681
682 size_t modelStart = m_model->getStartFrame(); 682 int modelStart = m_model->getStartFrame();
683 size_t modelResolution = m_model->getResolution(); 683 int modelResolution = m_model->getResolution();
684 684
685 float srRatio = 685 float srRatio =
686 float(v->getViewManager()->getMainModelSampleRate()) / 686 float(v->getViewManager()->getMainModelSampleRate()) /
687 float(m_model->getSampleRate()); 687 float(m_model->getSampleRate());
688 688
743 743
744 QString sampleText = QString("[%1]").arg(m_model->getHeight()); 744 QString sampleText = QString("[%1]").arg(m_model->getHeight());
745 int tw = paint.fontMetrics().width(sampleText); 745 int tw = paint.fontMetrics().width(sampleText);
746 bool another = false; 746 bool another = false;
747 747
748 for (size_t i = 0; i < m_model->getHeight(); ++i) { 748 for (int i = 0; i < m_model->getHeight(); ++i) {
749 if (m_model->getBinName(i).length() > sampleText.length()) { 749 if (m_model->getBinName(i).length() > sampleText.length()) {
750 sampleText = m_model->getBinName(i); 750 sampleText = m_model->getBinName(i);
751 another = true; 751 another = true;
752 } 752 }
753 } 753 }
855 855
856 paint.save(); 856 paint.save();
857 857
858 int py = h; 858 int py = h;
859 859
860 for (size_t i = symin; i <= symax; ++i) { 860 for (int i = symin; i <= symax; ++i) {
861 861
862 int y0; 862 int y0;
863 863
864 y0 = lrintf(getYForBin(v, i)); 864 y0 = lrintf(getYForBin(v, i));
865 int h = py - y0; 865 int h = py - y0;
882 paint.drawLine(cw, y0, w, y0); 882 paint.drawLine(cw, y0, w, y0);
883 } 883 }
884 884
885 if (i > symin) { 885 if (i > symin) {
886 886
887 size_t idx = i - 1; 887 int idx = i - 1;
888 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; 888 if (m_invertVertical) idx = m_model->getHeight() - idx - 1;
889 889
890 QString text = m_model->getBinName(idx); 890 QString text = m_model->getBinName(idx);
891 if (text == "") text = QString("[%1]").arg(idx + 1); 891 if (text == "") text = QString("[%1]").arg(idx + 1);
892 892
899 899
900 paint.restore(); 900 paint.restore();
901 } 901 }
902 902
903 DenseThreeDimensionalModel::Column 903 DenseThreeDimensionalModel::Column
904 Colour3DPlotLayer::getColumn(size_t col) const 904 Colour3DPlotLayer::getColumn(int col) const
905 { 905 {
906 DenseThreeDimensionalModel::Column values = m_model->getColumn(col); 906 DenseThreeDimensionalModel::Column values = m_model->getColumn(col);
907 while (values.size() < m_model->getHeight()) values.push_back(0.f); 907 while (values.size() < m_model->getHeight()) values.push_back(0.f);
908 if (!m_normalizeColumns && !m_normalizeHybrid) return values; 908 if (!m_normalizeColumns && !m_normalizeHybrid) return values;
909 909
911 float min = 0.f, max = 0.f; 911 float min = 0.f, max = 0.f;
912 912
913 min = m_model->getMinimumLevel(); 913 min = m_model->getMinimumLevel();
914 max = m_model->getMaximumLevel(); 914 max = m_model->getMaximumLevel();
915 915
916 for (size_t y = 0; y < values.size(); ++y) { 916 for (int y = 0; y < values.size(); ++y) {
917 if (y == 0 || values.at(y) > colMax) colMax = values.at(y); 917 if (y == 0 || values.at(y) > colMax) colMax = values.at(y);
918 if (y == 0 || values.at(y) < colMin) colMin = values.at(y); 918 if (y == 0 || values.at(y) < colMin) colMin = values.at(y);
919 } 919 }
920 if (colMin == colMax) colMax = colMin + 1; 920 if (colMin == colMax) colMax = colMin + 1;
921 921
922 for (size_t y = 0; y < values.size(); ++y) { 922 for (int y = 0; y < values.size(); ++y) {
923 923
924 float value = values.at(y); 924 float value = values.at(y);
925 float norm = (value - colMin) / (colMax - colMin); 925 float norm = (value - colMin) / (colMax - colMin);
926 float newvalue = min + (max - min) * norm; 926 float newvalue = min + (max - min) * norm;
927 927
928 if (value != newvalue) values[y] = newvalue; 928 if (value != newvalue) values[y] = newvalue;
929 } 929 }
930 930
931 if (m_normalizeHybrid && (colMax > 0.0)) { 931 if (m_normalizeHybrid && (colMax > 0.0)) {
932 float logmax = log10(colMax); 932 float logmax = log10(colMax);
933 for (size_t y = 0; y < values.size(); ++y) { 933 for (int y = 0; y < values.size(); ++y) {
934 values[y] *= logmax; 934 values[y] *= logmax;
935 } 935 }
936 } 936 }
937 937
938 return values; 938 return values;
939 } 939 }
940 940
941 void 941 void
942 Colour3DPlotLayer::fillCache(size_t firstBin, size_t lastBin) const 942 Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const
943 { 943 {
944 Profiler profiler("Colour3DPlotLayer::fillCache"); 944 Profiler profiler("Colour3DPlotLayer::fillCache");
945 945
946 size_t modelStart = m_model->getStartFrame(); 946 int modelStart = m_model->getStartFrame();
947 size_t modelEnd = m_model->getEndFrame(); 947 int modelEnd = m_model->getEndFrame();
948 size_t modelResolution = m_model->getResolution(); 948 int modelResolution = m_model->getResolution();
949 949
950 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 950 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
951 SVDEBUG << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << endl; 951 SVDEBUG << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << endl;
952 #endif 952 #endif
953 953
954 size_t modelStartBin = modelStart / modelResolution; 954 int modelStartBin = modelStart / modelResolution;
955 size_t modelEndBin = modelEnd / modelResolution; 955 int modelEndBin = modelEnd / modelResolution;
956 956
957 size_t cacheWidth = modelEndBin - modelStartBin + 1; 957 int cacheWidth = modelEndBin - modelStartBin + 1;
958 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1; 958 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1;
959 size_t cacheHeight = m_model->getHeight(); 959 int cacheHeight = m_model->getHeight();
960 960
961 if (m_cache && (m_cache->height() != int(cacheHeight))) { 961 if (m_cache && (m_cache->height() != int(cacheHeight))) {
962 // height has changed: delete everything rather than resizing 962 // height has changed: delete everything rather than resizing
963 delete m_cache; 963 delete m_cache;
964 delete m_peaksCache; 964 delete m_peaksCache;
1008 cerr << "Cache is valid in this region already" << endl; 1008 cerr << "Cache is valid in this region already" << endl;
1009 #endif 1009 #endif
1010 return; 1010 return;
1011 } 1011 }
1012 1012
1013 size_t fillStart = firstBin; 1013 int fillStart = firstBin;
1014 size_t fillEnd = lastBin; 1014 int fillEnd = lastBin;
1015 1015
1016 if (fillStart < modelStartBin) fillStart = modelStartBin; 1016 if (fillStart < modelStartBin) fillStart = modelStartBin;
1017 if (fillStart > modelEndBin) fillStart = modelEndBin; 1017 if (fillStart > modelEndBin) fillStart = modelEndBin;
1018 if (fillEnd < modelStartBin) fillEnd = modelStartBin; 1018 if (fillEnd < modelStartBin) fillEnd = modelStartBin;
1019 if (fillEnd > modelEndBin) fillEnd = modelEndBin; 1019 if (fillEnd > modelEndBin) fillEnd = modelEndBin;
1081 1081
1082 float visibleMax = 0.f, visibleMin = 0.f; 1082 float visibleMax = 0.f, visibleMin = 0.f;
1083 1083
1084 if (normalizeVisible) { 1084 if (normalizeVisible) {
1085 1085
1086 for (size_t c = fillStart; c <= fillEnd; ++c) { 1086 for (int c = fillStart; c <= fillEnd; ++c) {
1087 1087
1088 values = getColumn(c); 1088 values = getColumn(c);
1089 1089
1090 float colMax = 0.f, colMin = 0.f; 1090 float colMax = 0.f, colMin = 0.f;
1091 1091
1092 for (size_t y = 0; y < cacheHeight; ++y) { 1092 for (int y = 0; y < cacheHeight; ++y) {
1093 if (y >= values.size()) break; 1093 if (y >= values.size()) break;
1094 if (y == 0 || values[y] > colMax) colMax = values[y]; 1094 if (y == 0 || values[y] > colMax) colMax = values[y];
1095 if (y == 0 || values[y] < colMin) colMin = values[y]; 1095 if (y == 0 || values[y] < colMin) colMin = values[y];
1096 } 1096 }
1097 1097
1123 for (int y = 0; y < cacheHeight; ++y) { 1123 for (int y = 0; y < cacheHeight; ++y) {
1124 peaks[y] = 0; 1124 peaks[y] = 0;
1125 } 1125 }
1126 } 1126 }
1127 1127
1128 for (size_t c = fillStart; c <= fillEnd; ++c) { 1128 for (int c = fillStart; c <= fillEnd; ++c) {
1129 1129
1130 values = getColumn(c); 1130 values = getColumn(c);
1131 1131
1132 if (c >= m_cache->width()) { 1132 if (c >= m_cache->width()) {
1133 cerr << "ERROR: column " << c << " >= cache width " 1133 cerr << "ERROR: column " << c << " >= cache width "
1134 << m_cache->width() << endl; 1134 << m_cache->width() << endl;
1135 continue; 1135 continue;
1136 } 1136 }
1137 1137
1138 for (size_t y = 0; y < cacheHeight; ++y) { 1138 for (int y = 0; y < cacheHeight; ++y) {
1139 1139
1140 float value = min; 1140 float value = min;
1141 if (y < values.size()) { 1141 if (y < values.size()) {
1142 value = values.at(y); 1142 value = values.at(y);
1143 } 1143 }
1170 } 1170 }
1171 } 1171 }
1172 } 1172 }
1173 1173
1174 if (peaks) { 1174 if (peaks) {
1175 size_t notch = (c % m_peakResolution); 1175 int notch = (c % m_peakResolution);
1176 if (notch == m_peakResolution-1 || c == fillEnd) { 1176 if (notch == m_peakResolution-1 || c == fillEnd) {
1177 size_t pc = c / m_peakResolution; 1177 int pc = c / m_peakResolution;
1178 if (pc >= m_peaksCache->width()) { 1178 if (pc >= m_peaksCache->width()) {
1179 cerr << "ERROR: peak column " << pc 1179 cerr << "ERROR: peak column " << pc
1180 << " (from col " << c << ") >= peaks cache width " 1180 << " (from col " << c << ") >= peaks cache width "
1181 << m_peaksCache->width() << endl; 1181 << m_peaksCache->width() << endl;
1182 continue; 1182 continue;
1183 } 1183 }
1184 for (size_t y = 0; y < cacheHeight; ++y) { 1184 for (int y = 0; y < cacheHeight; ++y) {
1185 if (m_invertVertical) { 1185 if (m_invertVertical) {
1186 m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]); 1186 m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]);
1187 } else { 1187 } else {
1188 if (y >= m_peaksCache->height()) { 1188 if (y >= m_peaksCache->height()) {
1189 cerr << "ERROR: row " << y 1189 cerr << "ERROR: row " << y
1226 return; 1226 return;
1227 } 1227 }
1228 1228
1229 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect(); 1229 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect();
1230 1230
1231 size_t modelStart = m_model->getStartFrame(); 1231 int modelStart = m_model->getStartFrame();
1232 size_t modelEnd = m_model->getEndFrame(); 1232 int modelEnd = m_model->getEndFrame();
1233 size_t modelResolution = m_model->getResolution(); 1233 int modelResolution = m_model->getResolution();
1234 1234
1235 // The cache is from the model's start frame to the model's end 1235 // The cache is from the model's start frame to the model's end
1236 // frame at the model's window increment frames per pixel. We 1236 // frame at the model's window increment frames per pixel. We
1237 // want to draw from our start frame + x0 * zoomLevel to our start 1237 // want to draw from our start frame + x0 * zoomLevel to our start
1238 // frame + x1 * zoomLevel at zoomLevel frames per pixel. 1238 // frame + x1 * zoomLevel at zoomLevel frames per pixel.
1583 paint.drawImage(x0, 0, img); 1583 paint.drawImage(x0, 0, img);
1584 } 1584 }
1585 1585
1586 bool 1586 bool
1587 Colour3DPlotLayer::snapToFeatureFrame(View *v, int &frame, 1587 Colour3DPlotLayer::snapToFeatureFrame(View *v, int &frame,
1588 size_t &resolution, 1588 int &resolution,
1589 SnapType snap) const 1589 SnapType snap) const
1590 { 1590 {
1591 if (!m_model) { 1591 if (!m_model) {
1592 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 1592 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
1593 } 1593 }