Mercurial > hg > svcore
comparison data/model/Dense3DModelPeakCache.cpp @ 545:c603d9439b37
* Add peak cache type for 3d models
author | Chris Cannam |
---|---|
date | Wed, 04 Feb 2009 13:33:50 +0000 |
parents | |
children | 95391b480e17 |
comparison
equal
deleted
inserted
replaced
544:65d955c4d671 | 545:c603d9439b37 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2009 QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "Dense3DModelPeakCache.h" | |
17 | |
18 Dense3DModelPeakCache::Dense3DModelPeakCache(DenseThreeDimensionalModel *source, | |
19 size_t columnsPerPeak) : | |
20 m_source(source), | |
21 m_resolution(columnsPerPeak) | |
22 { | |
23 m_cache = new EditableDenseThreeDimensionalModel | |
24 (source->getSampleRate(), | |
25 getResolution(), | |
26 source->getHeight(), | |
27 EditableDenseThreeDimensionalModel::NoCompression, | |
28 false); | |
29 | |
30 connect(source, SIGNAL(modelChanged()), | |
31 this, SLOT(sourceModelChanged())); | |
32 connect(source, SIGNAL(modelAboutToBeDeleted()), | |
33 this, SLOT(sourceModelAboutToBeDeleted())); | |
34 | |
35 } | |
36 | |
37 Dense3DModelPeakCache::~Dense3DModelPeakCache() | |
38 { | |
39 delete m_cache; | |
40 } | |
41 | |
42 bool | |
43 Dense3DModelPeakCache::isColumnAvailable(size_t column) const | |
44 { | |
45 if (!m_source) return false; | |
46 if (haveColumn(column)) return true; | |
47 for (int i = 0; i < m_resolution; ++i) { | |
48 if (!m_source->isColumnAvailable(column * m_resolution + i)) { | |
49 return false; | |
50 } | |
51 } | |
52 return true; | |
53 } | |
54 | |
55 Dense3DModelPeakCache::Column | |
56 Dense3DModelPeakCache::getColumn(size_t column) const | |
57 { | |
58 if (!m_source) return Column(); | |
59 if (!haveColumn(column)) fillColumn(column); | |
60 return m_cache->getColumn(column); | |
61 } | |
62 | |
63 float | |
64 Dense3DModelPeakCache::getValueAt(size_t column, size_t n) const | |
65 { | |
66 if (!m_source) return 0.f; | |
67 if (!haveColumn(column)) fillColumn(column); | |
68 return m_cache->getValueAt(column, n); | |
69 } | |
70 | |
71 void | |
72 Dense3DModelPeakCache::sourceModelChanged() | |
73 { | |
74 if (!m_source) return; | |
75 m_coverage.resize(getWidth()); | |
76 } | |
77 | |
78 void | |
79 Dense3DModelPeakCache::sourceModelAboutToBeDeleted() | |
80 { | |
81 m_source = 0; | |
82 } | |
83 | |
84 bool | |
85 Dense3DModelPeakCache::haveColumn(size_t column) const | |
86 { | |
87 return m_coverage.get(column); | |
88 } | |
89 | |
90 void | |
91 Dense3DModelPeakCache::fillColumn(size_t column) const | |
92 { | |
93 Column peak; | |
94 for (int i = 0; i < m_resolution; ++i) { | |
95 Column here = m_source->getColumn(column * m_resolution + i); | |
96 if (i == 0) { | |
97 peak = here; | |
98 } else { | |
99 for (int j = 0; j < peak.size() && j < here.size(); ++j) { | |
100 if (here[j] > peak[j]) peak[j] = here[j]; | |
101 } | |
102 } | |
103 } | |
104 m_cache->setColumn(column, peak); | |
105 m_coverage.set(column); | |
106 } | |
107 | |
108 |