Mercurial > hg > svgui
comparison layer/SpectrumLayer.cpp @ 373:0895517bb2d1 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
this branch for fixes later)
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 10:32:45 +0000 |
parents | 2f83b6e3b8ca |
children |
comparison
equal
deleted
inserted
replaced
337:813170c57b13 | 373:0895517bb2d1 |
---|---|
45 setBinScale(LogBins); | 45 setBinScale(LogBins); |
46 } | 46 } |
47 | 47 |
48 SpectrumLayer::~SpectrumLayer() | 48 SpectrumLayer::~SpectrumLayer() |
49 { | 49 { |
50 //!!! delete parent's model | 50 Model *m = const_cast<Model *> |
51 // for (size_t i = 0; i < m_fft.size(); ++i) delete m_fft[i]; | 51 (static_cast<const Model *>(m_sliceableModel)); |
52 m->aboutToDelete(); | |
53 m_sliceableModel = 0; | |
54 delete m; | |
52 } | 55 } |
53 | 56 |
54 void | 57 void |
55 SpectrumLayer::setModel(DenseTimeValueModel *model) | 58 SpectrumLayer::setModel(DenseTimeValueModel *model) |
56 { | 59 { |
60 std::cerr << "SpectrumLayer::setModel(" << model << ") from " << m_originModel << std::endl; | |
61 | |
57 if (m_originModel == model) return; | 62 if (m_originModel == model) return; |
63 | |
58 m_originModel = model; | 64 m_originModel = model; |
59 | 65 |
60 if (m_sliceableModel) { | 66 if (m_sliceableModel) { |
61 const Model *oldModel = m_sliceableModel; | 67 Model *m = const_cast<Model *> |
68 (static_cast<const Model *>(m_sliceableModel)); | |
69 m->aboutToDelete(); | |
62 setSliceableModel(0); | 70 setSliceableModel(0); |
63 // surprised I'm allowed to delete a const pointer -- may be a | 71 delete m; |
64 // source of future compiler rejection? | 72 } |
65 delete oldModel; | 73 |
66 } | 74 m_newFFTNeeded = true; |
67 //!!! setupFFT(); | 75 |
76 emit layerParametersChanged(); | |
77 } | |
78 | |
79 void | |
80 SpectrumLayer::setChannel(int channel) | |
81 { | |
82 std::cerr << "SpectrumLayer::setChannel(" << channel << ") from " << m_channel << std::endl; | |
83 | |
84 m_channelSet = true; | |
85 | |
86 if (m_channel == channel) return; | |
87 | |
88 m_channel = channel; | |
89 | |
90 m_newFFTNeeded = true; | |
91 | |
92 emit layerParametersChanged(); | |
68 } | 93 } |
69 | 94 |
70 void | 95 void |
71 SpectrumLayer::setupFFT() | 96 SpectrumLayer::setupFFT() |
72 { | 97 { |
73 FFTModel *oldFFT = dynamic_cast<FFTModel *> | 98 if (m_sliceableModel) { |
74 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); | 99 Model *m = const_cast<Model *> |
75 | 100 (static_cast<const Model *>(m_sliceableModel)); |
76 if (oldFFT) { | 101 m->aboutToDelete(); |
77 setSliceableModel(0); | 102 setSliceableModel(0); |
78 delete oldFFT; | 103 delete m; |
104 } | |
105 | |
106 if (!m_originModel) { | |
107 return; | |
79 } | 108 } |
80 | 109 |
81 FFTModel *newFFT = new FFTModel(m_originModel, | 110 FFTModel *newFFT = new FFTModel(m_originModel, |
82 m_channel, | 111 m_channel, |
83 m_windowType, | 112 m_windowType, |
95 for (size_t i = 0; i < m_windowSize; ++i) { | 124 for (size_t i = 0; i < m_windowSize; ++i) { |
96 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f)); | 125 m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f)); |
97 } | 126 } |
98 | 127 |
99 newFFT->resume(); | 128 newFFT->resume(); |
100 } | 129 |
101 | 130 m_newFFTNeeded = false; |
102 void | |
103 SpectrumLayer::setChannel(int channel) | |
104 { | |
105 m_channelSet = true; | |
106 | |
107 FFTModel *fft = dynamic_cast<FFTModel *> | |
108 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); | |
109 | |
110 if (m_channel == channel) { | |
111 if (fft) fft->resume(); | |
112 return; | |
113 } | |
114 | |
115 m_channel = channel; | |
116 | |
117 emit layerParametersChanged(); | |
118 } | 131 } |
119 | 132 |
120 Layer::PropertyList | 133 Layer::PropertyList |
121 SpectrumLayer::getProperties() const | 134 SpectrumLayer::getProperties() const |
122 { | 135 { |
638 | 651 |
639 void | 652 void |
640 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const | 653 SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const |
641 { | 654 { |
642 if (!m_originModel || !m_originModel->isOK() || | 655 if (!m_originModel || !m_originModel->isOK() || |
643 !m_originModel->isReady()) return; | 656 !m_originModel->isReady()) { |
657 std::cerr << "SpectrumLayer::paint: no origin model, or origin model not OK or not ready" << std::endl; | |
658 return; | |
659 } | |
644 | 660 |
645 if (m_newFFTNeeded) { | 661 if (m_newFFTNeeded) { |
662 std::cerr << "SpectrumLayer::paint: new FFT needed, calling setupFFT" << std::endl; | |
646 const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh | 663 const_cast<SpectrumLayer *>(this)->setupFFT(); //ugh |
647 m_newFFTNeeded = false; | |
648 } | 664 } |
649 | 665 |
650 FFTModel *fft = dynamic_cast<FFTModel *> | 666 FFTModel *fft = dynamic_cast<FFTModel *> |
651 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); | 667 (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); |
652 | 668 |
657 | 673 |
658 int pkh = 0; | 674 int pkh = 0; |
659 //!!! if (m_binScale == LogBins) { | 675 //!!! if (m_binScale == LogBins) { |
660 pkh = 10; | 676 pkh = 10; |
661 //!!! } | 677 //!!! } |
678 | |
679 paint.save(); | |
662 | 680 |
663 if (fft && m_showPeaks) { | 681 if (fft && m_showPeaks) { |
664 | 682 |
665 // draw peak lines | 683 // draw peak lines |
666 | 684 |
797 | 815 |
798 ppx = px; | 816 ppx = px; |
799 px = x; | 817 px = x; |
800 } | 818 } |
801 // } | 819 // } |
820 | |
821 paint.restore(); | |
802 } | 822 } |
803 | 823 |
804 void | 824 void |
805 SpectrumLayer::getBiasCurve(BiasCurve &curve) const | 825 SpectrumLayer::getBiasCurve(BiasCurve &curve) const |
806 { | 826 { |