comparison layer/Colour3DPlotLayer.cpp @ 1469:11a150e65ee1 by-id

Some work on updating layers for ModelId bits
author Chris Cannam
date Thu, 27 Jun 2019 13:16:25 +0100
parents 39f1154c0e97
children f2525e6cbdf1
comparison
equal deleted inserted replaced
1468:de41a11cabc2 1469:11a150e65ee1
41 41
42 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1 42 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1
43 43
44 44
45 Colour3DPlotLayer::Colour3DPlotLayer() : 45 Colour3DPlotLayer::Colour3DPlotLayer() :
46 m_model(nullptr),
47 m_colourScale(ColourScaleType::Linear), 46 m_colourScale(ColourScaleType::Linear),
48 m_colourScaleSet(false), 47 m_colourScaleSet(false),
49 m_colourMap(0), 48 m_colourMap(0),
50 m_colourInverted(false), 49 m_colourInverted(false),
51 m_gain(1.0), 50 m_gain(1.0),
57 m_smooth(false), 56 m_smooth(false),
58 m_peakResolution(256), 57 m_peakResolution(256),
59 m_miny(0), 58 m_miny(0),
60 m_maxy(0), 59 m_maxy(0),
61 m_synchronous(false), 60 m_synchronous(false),
62 m_peakCache(nullptr),
63 m_peakCacheDivisor(8) 61 m_peakCacheDivisor(8)
64 { 62 {
65 QSettings settings; 63 QSettings settings;
66 settings.beginGroup("Preferences"); 64 settings.beginGroup("Preferences");
67 setColourMap(settings.value("colour-3d-plot-colour", ColourMapper::Green).toInt()); 65 setColourMap(settings.value("colour-3d-plot-colour",
66 ColourMapper::Green).toInt());
68 settings.endGroup(); 67 settings.endGroup();
69 } 68 }
70 69
71 Colour3DPlotLayer::~Colour3DPlotLayer() 70 Colour3DPlotLayer::~Colour3DPlotLayer()
72 { 71 {
73 invalidateRenderers(); 72 invalidateRenderers();
74 if (m_peakCache) m_peakCache->aboutToDelete(); 73 }
75 delete m_peakCache; 74
75 const ZoomConstraint *
76 Colour3DPlotLayer::getZoomConstraint() const
77 {
78 auto model = ModelById::get(m_model);
79 if (model) return model->getZoomConstraint();
80 else return nullptr;
76 } 81 }
77 82
78 ColourScaleType 83 ColourScaleType
79 Colour3DPlotLayer::convertToColourScale(int value) 84 Colour3DPlotLayer::convertToColourScale(int value)
80 { 85 {
134 { 139 {
135 m_synchronous = synchronous; 140 m_synchronous = synchronous;
136 } 141 }
137 142
138 void 143 void
139 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model) 144 Colour3DPlotLayer::setModel(ModelId modelId)
140 { 145 {
141 SVDEBUG << "Colour3DPlotLayer::setModel(" << model << ")" << endl; 146 SVDEBUG << "Colour3DPlotLayer::setModel(" << modelId << ")" << endl;
142 147
143 if (m_model == model) return; 148 if (m_model == modelId) return;
144 const DenseThreeDimensionalModel *oldModel = m_model; 149
145 m_model = model; 150 auto model = ModelById::getAs<DenseThreeDimensionalModel>(modelId);
146 if (!m_model || !m_model->isOK()) return; 151 if (!model) throw std::logic_error("Not a DenseThreeDimensionalModel");
152
153 //!!! const DenseThreeDimensionalModel *oldModel = m_model;
154 m_model = modelId;
147 155
148 connectSignals(m_model); 156 connectSignals(m_model);
149 157
150 connect(m_model, SIGNAL(modelChanged()), 158 connect(model.get(), SIGNAL(modelChanged()),
151 this, SLOT(handleModelChanged())); 159 this, SLOT(handleModelChanged()));
152 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), 160 connect(model.get(), SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
153 this, SLOT(handleModelChangedWithin(sv_frame_t, sv_frame_t))); 161 this, SLOT(handleModelChangedWithin(sv_frame_t, sv_frame_t)));
154 162
155 m_peakResolution = 256; 163 m_peakResolution = 256;
156 if (model->getResolution() > 512) { 164 if (model->getResolution() > 512) {
157 m_peakResolution = 16; 165 m_peakResolution = 16;
162 } 170 }
163 171
164 invalidatePeakCache(); 172 invalidatePeakCache();
165 173
166 emit modelReplaced(); 174 emit modelReplaced();
167 emit sliceableModelReplaced(oldModel, model); 175 //!!! emit sliceableModelReplaced(oldModel, model);
168 } 176 }
169 177
170 void 178 void
171 Colour3DPlotLayer::invalidatePeakCache() 179 Colour3DPlotLayer::invalidatePeakCache()
172 { 180 {
173 // renderers use the peak cache, so we must invalidate those too 181 // renderers use the peak cache, so we must invalidate those too
174 invalidateRenderers(); 182 invalidateRenderers();
175 invalidateMagnitudes(); 183 invalidateMagnitudes();
176 184
177 if (m_peakCache) m_peakCache->aboutToDelete();
178 delete m_peakCache; 185 delete m_peakCache;
179 m_peakCache = nullptr; 186 m_peakCache = nullptr;
180 } 187 }
181 188
182 void 189 void
209 216
210 void 217 void
211 Colour3DPlotLayer::handleModelChanged() 218 Colour3DPlotLayer::handleModelChanged()
212 { 219 {
213 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) { 220 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
214 if (m_model) { 221 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
215 if (m_model->shouldUseLogValueScale()) { 222 if (model) {
223 if (model->shouldUseLogValueScale()) {
216 setColourScale(ColourScaleType::Log); 224 setColourScale(ColourScaleType::Log);
217 } else { 225 } else {
218 m_colourScaleSet = true; 226 m_colourScaleSet = true;
219 } 227 }
220 } 228 }
225 233
226 void 234 void
227 Colour3DPlotLayer::handleModelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) 235 Colour3DPlotLayer::handleModelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
228 { 236 {
229 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) { 237 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
230 if (m_model && m_model->getWidth() > 50) { 238 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
231 if (m_model->shouldUseLogValueScale()) { 239 if (model && model->getWidth() > 50) {
240 if (model->shouldUseLogValueScale()) {
232 setColourScale(ColourScaleType::Log); 241 setColourScale(ColourScaleType::Log);
233 } else { 242 } else {
234 m_colourScaleSet = true; 243 m_colourScaleSet = true;
235 } 244 }
236 } 245 }
647 // guaranteeing to get an invisible seam if someone else scrolls 656 // guaranteeing to get an invisible seam if someone else scrolls
648 // us and we just fill in 657 // us and we just fill in
649 return false; 658 return false;
650 } 659 }
651 660
661 int
662 Colour3DPlotLayer::getCompletion(LayerGeometryProvider *) const
663 {
664 auto model = ModelById::get(m_model);
665 if (model) return model->getCompletion();
666 else return 0;
667 }
668
652 bool 669 bool
653 Colour3DPlotLayer::getValueExtents(double &min, double &max, 670 Colour3DPlotLayer::getValueExtents(double &min, double &max,
654 bool &logarithmic, QString &unit) const 671 bool &logarithmic, QString &unit) const
655 { 672 {
656 if (!m_model) return false; 673 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
674 if (!model) return false;
657 675
658 min = 0; 676 min = 0;
659 max = double(m_model->getHeight()); 677 max = double(model->getHeight());
660 678
661 logarithmic = (m_binScale == BinScale::Log); 679 logarithmic = (m_binScale == BinScale::Log);
662 unit = ""; 680 unit = "";
663 681
664 return true; 682 return true;
665 } 683 }
666 684
667 bool 685 bool
668 Colour3DPlotLayer::getDisplayExtents(double &min, double &max) const 686 Colour3DPlotLayer::getDisplayExtents(double &min, double &max) const
669 { 687 {
670 if (!m_model) return false; 688 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
671 689 if (!model) return false;
672 double hmax = double(m_model->getHeight()); 690
691 double hmax = double(model->getHeight());
673 692
674 min = m_miny; 693 min = m_miny;
675 max = m_maxy; 694 max = m_maxy;
676 if (max <= min) { 695 if (max <= min) {
677 min = 0; 696 min = 0;
684 } 703 }
685 704
686 bool 705 bool
687 Colour3DPlotLayer::setDisplayExtents(double min, double max) 706 Colour3DPlotLayer::setDisplayExtents(double min, double max)
688 { 707 {
689 if (!m_model) return false;
690
691 m_miny = int(lrint(min)); 708 m_miny = int(lrint(min));
692 m_maxy = int(lrint(max)); 709 m_maxy = int(lrint(max));
693 710
694 invalidateRenderers(); 711 invalidateRenderers();
695 712
705 } 722 }
706 723
707 int 724 int
708 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const 725 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
709 { 726 {
710 if (!m_model) return 0; 727 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
728 if (!model) return 0;
711 729
712 defaultStep = 0; 730 defaultStep = 0;
713 int h = m_model->getHeight(); 731 int h = model->getHeight();
714 return h; 732 return h;
715 } 733 }
716 734
717 int 735 int
718 Colour3DPlotLayer::getCurrentVerticalZoomStep() const 736 Colour3DPlotLayer::getCurrentVerticalZoomStep() const
719 { 737 {
720 if (!m_model) return 0; 738 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
739 if (!model) return 0;
721 740
722 double min, max; 741 double min, max;
723 getDisplayExtents(min, max); 742 getDisplayExtents(min, max);
724 return m_model->getHeight() - int(lrint(max - min)); 743 return model->getHeight() - int(lrint(max - min));
725 } 744 }
726 745
727 void 746 void
728 Colour3DPlotLayer::setVerticalZoomStep(int step) 747 Colour3DPlotLayer::setVerticalZoomStep(int step)
729 { 748 {
730 if (!m_model) return; 749 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
750 if (!model) return;
731 751
732 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << endl; 752 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << endl;
733 753
734 int dist = m_model->getHeight() - step; 754 int dist = model->getHeight() - step;
735 if (dist < 1) dist = 1; 755 if (dist < 1) dist = 1;
736 double centre = m_miny + (m_maxy - m_miny) / 2.0; 756 double centre = m_miny + (m_maxy - m_miny) / 2.0;
737 m_miny = int(lrint(centre - dist/2.0)); 757 m_miny = int(lrint(centre - dist/2.0));
738 if (m_miny < 0) m_miny = 0; 758 if (m_miny < 0) m_miny = 0;
739 m_maxy = m_miny + dist; 759 m_maxy = m_miny + dist;
740 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight(); 760 if (m_maxy > model->getHeight()) m_maxy = model->getHeight();
741 761
742 invalidateRenderers(); 762 invalidateRenderers();
743 763
744 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << endl; 764 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << endl;
745 765
747 } 767 }
748 768
749 RangeMapper * 769 RangeMapper *
750 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const 770 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const
751 { 771 {
752 if (!m_model) return nullptr; 772 //!!! most of our uses of model in these functions is just to
753 773 //!!! retrieve the model's height - perhaps we should cache it
754 return new LinearRangeMapper(0, m_model->getHeight(), 774
755 0, m_model->getHeight(), ""); 775 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
776 if (!model) return nullptr;
777
778 return new LinearRangeMapper(0, model->getHeight(),
779 0, model->getHeight(), "");
756 } 780 }
757 781
758 double 782 double
759 Colour3DPlotLayer::getYForBin(const LayerGeometryProvider *v, double bin) const 783 Colour3DPlotLayer::getYForBin(const LayerGeometryProvider *v, double bin) const
760 { 784 {
761 double y = bin; 785 double y = bin;
762 if (!m_model) return y; 786 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
763 double mn = 0, mx = m_model->getHeight(); 787 if (!model) return y;
788 double mn = 0, mx = model->getHeight();
764 getDisplayExtents(mn, mx); 789 getDisplayExtents(mn, mx);
765 double h = v->getPaintHeight(); 790 double h = v->getPaintHeight();
766 if (m_binScale == BinScale::Linear) { 791 if (m_binScale == BinScale::Linear) {
767 y = h - (((bin - mn) * h) / (mx - mn)); 792 y = h - (((bin - mn) * h) / (mx - mn));
768 } else { 793 } else {
775 800
776 double 801 double
777 Colour3DPlotLayer::getBinForY(const LayerGeometryProvider *v, double y) const 802 Colour3DPlotLayer::getBinForY(const LayerGeometryProvider *v, double y) const
778 { 803 {
779 double bin = y; 804 double bin = y;
780 if (!m_model) return bin; 805 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
781 double mn = 0, mx = m_model->getHeight(); 806 if (!model) return bin;
807 double mn = 0, mx = model->getHeight();
782 getDisplayExtents(mn, mx); 808 getDisplayExtents(mn, mx);
783 double h = v->getPaintHeight(); 809 double h = v->getPaintHeight();
784 if (m_binScale == BinScale::Linear) { 810 if (m_binScale == BinScale::Linear) {
785 // Arrange that the first bin (mn) appears as the exact result 811 // Arrange that the first bin (mn) appears as the exact result
786 // for the first pixel (which is pixel h-1) and the first 812 // for the first pixel (which is pixel h-1) and the first
796 } 822 }
797 823
798 QString 824 QString
799 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const 825 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
800 { 826 {
801 if (!m_model) return ""; 827 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
828 if (!model) return "";
802 829
803 int x = pos.x(); 830 int x = pos.x();
804 int y = pos.y(); 831 int y = pos.y();
805 832
806 sv_frame_t modelStart = m_model->getStartFrame(); 833 sv_frame_t modelStart = model->getStartFrame();
807 int modelResolution = m_model->getResolution(); 834 int modelResolution = model->getResolution();
808 835
809 double srRatio = 836 double srRatio =
810 v->getViewManager()->getMainModelSampleRate() / 837 v->getViewManager()->getMainModelSampleRate() /
811 m_model->getSampleRate(); 838 model->getSampleRate();
812 839
813 int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) / 840 int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) /
814 modelResolution); 841 modelResolution);
815 842
816 int f0 = sx0 * modelResolution; 843 int f0 = sx0 * modelResolution;
817 int f1 = f0 + modelResolution; 844 int f1 = f0 + modelResolution;
818 845
819 int sh = m_model->getHeight(); 846 int sh = model->getHeight();
820 847
821 int symin = m_miny; 848 int symin = m_miny;
822 int symax = m_maxy; 849 int symax = m_maxy;
823 if (symax <= symin) { 850 if (symax <= symin) {
824 symin = 0; 851 symin = 0;
830 // double binHeight = double(v->getPaintHeight()) / (symax - symin); 857 // double binHeight = double(v->getPaintHeight()) / (symax - symin);
831 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin; 858 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin;
832 859
833 int sy = getIBinForY(v, y); 860 int sy = getIBinForY(v, y);
834 861
835 if (sy < 0 || sy >= m_model->getHeight()) { 862 if (sy < 0 || sy >= model->getHeight()) {
836 return ""; 863 return "";
837 } 864 }
838 865
839 if (m_invertVertical) { 866 if (m_invertVertical) {
840 sy = m_model->getHeight() - sy - 1; 867 sy = model->getHeight() - sy - 1;
841 } 868 }
842 869
843 float value = m_model->getValueAt(sx0, sy); 870 float value = model->getValueAt(sx0, sy);
844 871
845 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl; 872 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl;
846 873
847 QString binName = m_model->getBinName(sy); 874 QString binName = model->getBinName(sy);
848 if (binName == "") binName = QString("[%1]").arg(sy + 1); 875 if (binName == "") binName = QString("[%1]").arg(sy + 1);
849 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1); 876 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
850 877
851 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4") 878 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
852 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate()) 879 .arg(RealTime::frame2RealTime(f0, model->getSampleRate())
853 .toText(true).c_str()) 880 .toText(true).c_str())
854 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate()) 881 .arg(RealTime::frame2RealTime(f1, model->getSampleRate())
855 .toText(true).c_str()) 882 .toText(true).c_str())
856 .arg(binName) 883 .arg(binName)
857 .arg(value); 884 .arg(value);
858 885
859 return text; 886 return text;
868 } 895 }
869 896
870 int 897 int
871 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const 898 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
872 { 899 {
873 if (!m_model) return 0; 900 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
874 901 if (!model) return 0;
875 QString sampleText = QString("[%1]").arg(m_model->getHeight()); 902
903 QString sampleText = QString("[%1]").arg(model->getHeight());
876 int tw = paint.fontMetrics().width(sampleText); 904 int tw = paint.fontMetrics().width(sampleText);
877 bool another = false; 905 bool another = false;
878 906
879 for (int i = 0; i < m_model->getHeight(); ++i) { 907 for (int i = 0; i < model->getHeight(); ++i) {
880 if (m_model->getBinName(i).length() > sampleText.length()) { 908 if (model->getBinName(i).length() > sampleText.length()) {
881 sampleText = m_model->getBinName(i); 909 sampleText = model->getBinName(i);
882 another = true; 910 another = true;
883 } 911 }
884 } 912 }
885 if (another) { 913 if (another) {
886 tw = std::max(tw, paint.fontMetrics().width(sampleText)); 914 tw = std::max(tw, paint.fontMetrics().width(sampleText));
890 } 918 }
891 919
892 void 920 void
893 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const 921 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
894 { 922 {
895 if (!m_model) return; 923 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
924 if (!model) return;
896 925
897 int h = rect.height(), w = rect.width(); 926 int h = rect.height(), w = rect.width();
898 927
899 int cw = getColourScaleWidth(paint); 928 int cw = getColourScaleWidth(paint);
900 929
946 paint.restore(); 975 paint.restore();
947 } 976 }
948 977
949 paint.setPen(v->getForeground()); 978 paint.setPen(v->getForeground());
950 979
951 int sh = m_model->getHeight(); 980 int sh = model->getHeight();
952 981
953 int symin = m_miny; 982 int symin = m_miny;
954 int symax = m_maxy; 983 int symax = m_maxy;
955 if (symax <= symin) { 984 if (symax <= symin) {
956 symin = 0; 985 symin = 0;
992 1021
993 if (i > symin) { 1022 if (i > symin) {
994 1023
995 int idx = i - 1; 1024 int idx = i - 1;
996 if (m_invertVertical) { 1025 if (m_invertVertical) {
997 idx = m_model->getHeight() - idx - 1; 1026 idx = model->getHeight() - idx - 1;
998 } 1027 }
999 1028
1000 QString text = m_model->getBinName(idx); 1029 QString text = model->getBinName(idx);
1001 if (text == "") text = QString("[%1]").arg(idx + 1); 1030 if (text == "") text = QString("[%1]").arg(idx + 1);
1002 1031
1003 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) + 1032 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) +
1004 paint.fontMetrics().ascent() + 1; 1033 paint.fontMetrics().ascent() + 1;
1005 1034
1011 } 1040 }
1012 1041
1013 Colour3DPlotRenderer * 1042 Colour3DPlotRenderer *
1014 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const 1043 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const
1015 { 1044 {
1045 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
1046 if (!model) return nullptr;
1047
1016 int viewId = v->getId(); 1048 int viewId = v->getId();
1017 1049
1018 if (m_renderers.find(viewId) == m_renderers.end()) { 1050 if (m_renderers.find(viewId) == m_renderers.end()) {
1019 1051
1020 Colour3DPlotRenderer::Sources sources; 1052 Colour3DPlotRenderer::Sources sources;
1021 sources.verticalBinLayer = this; 1053 sources.verticalBinLayer = this;
1022 sources.fft = nullptr;
1023 sources.source = m_model; 1054 sources.source = m_model;
1024 sources.peakCaches.push_back(getPeakCache()); 1055 sources.peakCaches.push_back(getPeakCache());
1025 1056
1026 ColourScale::Parameters cparams; 1057 ColourScale::Parameters cparams;
1027 cparams.colourMap = m_colourMap; 1058 cparams.colourMap = m_colourMap;
1035 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) { 1066 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) {
1036 minValue = m_viewMags[viewId].getMin(); 1067 minValue = m_viewMags[viewId].getMin();
1037 maxValue = m_viewMags[viewId].getMax(); 1068 maxValue = m_viewMags[viewId].getMax();
1038 } else if (m_normalization == ColumnNormalization::Hybrid) { 1069 } else if (m_normalization == ColumnNormalization::Hybrid) {
1039 minValue = 0; 1070 minValue = 0;
1040 maxValue = log10(m_model->getMaximumLevel() + 1.0); 1071 maxValue = log10(model->getMaximumLevel() + 1.0);
1041 } else if (m_normalization == ColumnNormalization::None) { 1072 } else if (m_normalization == ColumnNormalization::None) {
1042 minValue = m_model->getMinimumLevel(); 1073 minValue = model->getMinimumLevel();
1043 maxValue = m_model->getMaximumLevel(); 1074 maxValue = model->getMaximumLevel();
1044 } 1075 }
1045 1076
1046 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is " 1077 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is "
1047 << minValue << " -> " << maxValue 1078 << minValue << " -> " << maxValue
1048 << " (model min = " << m_model->getMinimumLevel() 1079 << " (model min = " << model->getMinimumLevel()
1049 << ", max = " << m_model->getMaximumLevel() << ")" 1080 << ", max = " << model->getMaximumLevel() << ")"
1050 << endl; 1081 << endl;
1051 1082
1052 if (maxValue <= minValue) { 1083 if (maxValue <= minValue) {
1053 maxValue = minValue + 0.1f; 1084 maxValue = minValue + 0.1f;
1054 1085
1137 } 1168 }
1138 1169
1139 void 1170 void
1140 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const 1171 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
1141 { 1172 {
1173 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
1142 /* 1174 /*
1143 if (m_model) { 1175 if (model) {
1144 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << endl; 1176 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << model->shouldUseLogValueScale() << endl;
1145 } 1177 }
1146 */ 1178 */
1147 Profiler profiler("Colour3DPlotLayer::paint"); 1179 Profiler profiler("Colour3DPlotLayer::paint");
1148 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1180 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1149 SVDEBUG << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl; 1181 SVDEBUG << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl;
1150 #endif 1182 #endif
1151 1183
1152 int completion = 0; 1184 int completion = 0;
1153 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) { 1185 if (!model || !model->isOK() || !model->isReady(&completion)) {
1154 if (completion > 0) { 1186 if (completion > 0) {
1155 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100, 1187 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100,
1156 10, QColor(120, 120, 120)); 1188 10, QColor(120, 120, 120));
1157 } 1189 }
1158 return; 1190 return;
1159 } 1191 }
1160 1192
1161 if (m_model->getWidth() == 0) { 1193 if (model->getWidth() == 0) {
1162 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1194 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1163 SVDEBUG << "Colour3DPlotLayer::paint(): model width == 0, " 1195 SVDEBUG << "Colour3DPlotLayer::paint(): model width == 0, "
1164 << "nothing to paint (yet)" << endl; 1196 << "nothing to paint (yet)" << endl;
1165 #endif 1197 #endif
1166 return; 1198 return;
1172 bool 1204 bool
1173 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, 1205 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
1174 int &resolution, 1206 int &resolution,
1175 SnapType snap) const 1207 SnapType snap) const
1176 { 1208 {
1177 if (!m_model) { 1209 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
1210 if (!model) {
1178 return Layer::snapToFeatureFrame(v, frame, resolution, snap); 1211 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
1179 } 1212 }
1180 1213
1181 resolution = m_model->getResolution(); 1214 resolution = model->getResolution();
1182 sv_frame_t left = (frame / resolution) * resolution; 1215 sv_frame_t left = (frame / resolution) * resolution;
1183 sv_frame_t right = left + resolution; 1216 sv_frame_t right = left + resolution;
1184 1217
1185 switch (snap) { 1218 switch (snap) {
1186 case SnapLeft: frame = left; break; 1219 case SnapLeft: frame = left; break;