Mercurial > hg > svcore
changeset 1154:aa588c391d1a 3.0-integration
Convert 3d model column type from QVector to std::vector; replace another user of ResizeableBitset
author | Chris Cannam |
---|---|
date | Fri, 22 Jan 2016 13:39:45 +0000 |
parents | ece369c5bb68 |
children | 546d4e417346 |
files | data/fileio/MatrixFile.cpp data/fileio/MatrixFile.h data/model/DenseThreeDimensionalModel.h data/model/EditableDenseThreeDimensionalModel.cpp data/model/EditableDenseThreeDimensionalModel.h data/model/FFTModel.cpp transform/FeatureExtractionModelTransformer.cpp |
diffstat | 7 files changed, 41 insertions(+), 47 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/MatrixFile.cpp Fri Jan 22 12:46:42 2016 +0000 +++ b/data/fileio/MatrixFile.cpp Fri Jan 22 13:39:45 2016 +0000 @@ -176,8 +176,6 @@ QMutexLocker locker(&m_createMutex); - delete m_setColumns; - if (m_fileName != "") { if (--m_refcount[m_fileName] == 0) { @@ -208,7 +206,7 @@ assert(m_mode == WriteOnly); - m_setColumns = new ResizeableBitset(m_width); + m_setColumns.resize(m_width, false); off_t off = m_headerSize + (m_width * m_height * m_cellSize) + m_width; @@ -316,7 +314,7 @@ MatrixFile::haveSetColumnAt(int x) const { if (m_mode == WriteOnly) { - return m_setColumns->get(x); + return m_setColumns[x]; } if (m_readyToReadColumn >= 0 && @@ -398,9 +396,10 @@ throw FileOperationFailed(m_fileName, "write"); } - m_setColumns->set(x); + m_setColumns[x] = true; if (m_autoClose) { - if (m_setColumns->isAllOn()) { + if (std::all_of(m_setColumns.begin(), m_setColumns.end(), + [](bool c) { return c; })) { #ifdef DEBUG_MATRIX_FILE cerr << "MatrixFile[" << m_fd << "]::setColumnAt(" << x << "): All columns set: auto-closing" << endl; #endif
--- a/data/fileio/MatrixFile.h Fri Jan 22 12:46:42 2016 +0000 +++ b/data/fileio/MatrixFile.h Fri Jan 22 13:39:45 2016 +0000 @@ -13,10 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _MATRIX_FILE_CACHE_H_ -#define _MATRIX_FILE_CACHE_H_ - -#include "base/ResizeableBitset.h" +#ifndef MATRIX_FILE_H +#define MATRIX_FILE_H #include "FileReadThread.h" @@ -91,7 +89,7 @@ int m_headerSize; QString m_fileName; - ResizeableBitset *m_setColumns; // only in writer + std::vector<bool> m_setColumns; // only populated in writer bool m_autoClose; // In reader: if this is >= 0, we can read that column directly
--- a/data/model/DenseThreeDimensionalModel.h Fri Jan 22 12:46:42 2016 +0000 +++ b/data/model/DenseThreeDimensionalModel.h Fri Jan 22 13:39:45 2016 +0000 @@ -64,7 +64,7 @@ */ virtual bool isColumnAvailable(int column) const = 0; - typedef QVector<float> Column; + typedef std::vector<float> Column; /** * Get data from the given column of bin values.
--- a/data/model/EditableDenseThreeDimensionalModel.cpp Fri Jan 22 12:46:42 2016 +0000 +++ b/data/model/EditableDenseThreeDimensionalModel.cpp Fri Jan 22 13:39:45 2016 +0000 @@ -96,7 +96,7 @@ int EditableDenseThreeDimensionalModel::getWidth() const { - return m_data.size(); + return int(m_data.size()); } int @@ -139,15 +139,15 @@ EditableDenseThreeDimensionalModel::getColumn(int index) const { QReadLocker locker(&m_lock); - if (index < 0 || index >= m_data.size()) return Column(); - return expandAndRetrieve(index); + if (in_range_for(m_data, index)) return expandAndRetrieve(index); + else return Column(); } float EditableDenseThreeDimensionalModel::getValueAt(int index, int n) const { Column c = getColumn(index); - if (int(n) < c.size()) return c.at(n); + if (in_range_for(c, n)) return c.at(n); return m_minimum; } @@ -157,7 +157,7 @@ EditableDenseThreeDimensionalModel::truncateAndStore(int index, const Column &values) { - assert(int(index) < m_data.size()); + assert(in_range_for(m_data, index)); //cout << "truncateAndStore(" << index << ", " << values.size() << ")" << endl; @@ -169,7 +169,7 @@ m_trunc[index] = 0; if (index == 0 || m_compression == NoCompression || - values.size() != int(m_yBinCount)) { + int(values.size()) != m_yBinCount) { // given += values.size(); // stored += values.size(); m_data[index] = values; @@ -206,7 +206,7 @@ Column p = expandAndRetrieve(index - tdist); int h = m_yBinCount; - if (p.size() == h && tdist <= maxdist) { + if (int(p.size()) == h && tdist <= maxdist) { int bcount = 0, tcount = 0; if (!known || !top) { @@ -282,7 +282,7 @@ int tdist = trunc; if (trunc < 0) { top = false; tdist = -trunc; } Column p = expandAndRetrieve(index - tdist); - int psize = p.size(), csize = c.size(); + int psize = int(p.size()), csize = int(c.size()); if (psize != m_yBinCount) { cerr << "WARNING: EditableDenseThreeDimensionalModel::expandAndRetrieve: Trying to expand from incorrectly sized column" << endl; } @@ -291,10 +291,6 @@ c.push_back(p.at(i)); } } else { - // push_front is very slow on QVector -- but not enough to - // make it desirable to choose a different container, since - // QVector has all the other advantages for us. easier to - // write the whole array out to a new vector Column cc(psize); for (int i = 0; i < psize - csize; ++i) { cc[i] = p.at(i); @@ -313,7 +309,7 @@ { QWriteLocker locker(&m_lock); - while (int(index) >= m_data.size()) { + while (index >= int(m_data.size())) { m_data.push_back(Column()); m_trunc.push_back(0); } @@ -322,7 +318,7 @@ // if (values.size() > m_yBinCount) m_yBinCount = values.size(); - for (int i = 0; i < values.size(); ++i) { + for (int i = 0; in_range_for(values, i); ++i) { float value = values[i]; if (ISNAN(value) || ISINF(value)) { continue; @@ -432,13 +428,13 @@ for (int i = 0; i < 10; ++i) { int index = i * 10; - if (index < m_data.size()) { + if (in_range_for(m_data, index)) { const Column &c = m_data.at(index); - while (c.size() > int(sample.size())) { + while (c.size() > sample.size()) { sample.push_back(0.0); n.push_back(0); } - for (int j = 0; j < c.size(); ++j) { + for (int j = 0; in_range_for(c, j); ++j) { sample[j] += c.at(j); ++n[j]; } @@ -486,9 +482,9 @@ { QReadLocker locker(&m_lock); QString s; - for (int i = 0; i < m_data.size(); ++i) { + for (int i = 0; in_range_for(m_data, i); ++i) { QStringList list; - for (int j = 0; j < m_data.at(i).size(); ++j) { + for (int j = 0; in_range_for(m_data.at(i), j); ++j) { list << QString("%1").arg(m_data.at(i).at(j)); } s += list.join(delimiter) + "\n"; @@ -501,11 +497,11 @@ { QReadLocker locker(&m_lock); QString s; - for (int i = 0; i < m_data.size(); ++i) { + for (int i = 0; in_range_for(m_data, i); ++i) { sv_frame_t fr = m_startFrame + i * m_resolution; if (fr >= f0 && fr < f1) { QStringList list; - for (int j = 0; j < m_data.at(i).size(); ++j) { + for (int j = 0; in_range_for(m_data.at(i), j); ++j) { list << QString("%1").arg(m_data.at(i).at(j)); } s += list.join(delimiter) + "\n";
--- a/data/model/EditableDenseThreeDimensionalModel.h Fri Jan 22 12:46:42 2016 +0000 +++ b/data/model/EditableDenseThreeDimensionalModel.h Fri Jan 22 13:39:45 2016 +0000 @@ -194,7 +194,7 @@ QString extraAttributes = "") const; protected: - typedef QVector<Column> ValueMatrix; + typedef std::vector<Column> ValueMatrix; ValueMatrix m_data; // m_trunc is used for simple compression. If at least the top N
--- a/data/model/FFTModel.cpp Fri Jan 22 12:46:42 2016 +0000 +++ b/data/model/FFTModel.cpp Fri Jan 22 13:39:45 2016 +0000 @@ -98,9 +98,9 @@ { auto cplx = getFFTColumn(x); Column col; - col.reserve(int(cplx.size())); + col.reserve(cplx.size()); for (auto c: cplx) col.push_back(abs(c)); - return col; + return move(col); } float @@ -116,7 +116,8 @@ { Column col(getColumn(x)); float max = 0.f; - for (int i = 0; i < col.size(); ++i) { + int n = int(col.size()); + for (int i = 0; i < n; ++i) { if (col[i] > max) max = col[i]; } return max; @@ -313,7 +314,7 @@ } m_cached.push_back(sc); - return col; + return move(col); } bool @@ -388,10 +389,11 @@ } Column values = getColumn(x); + int nv = int(values.size()); float mean = 0.f; - for (int i = 0; i < values.size(); ++i) mean += values[i]; - if (values.size() > 0) mean = mean / float(values.size()); + for (int i = 0; i < nv; ++i) mean += values[i]; + if (nv > 0) mean = mean / float(values.size()); // For peak picking we use a moving median window, picking the // highest value within each continuous region of values that @@ -412,8 +414,8 @@ else binmin = 0; int binmax; - if (ymax + halfWin < values.size()) binmax = ymax + halfWin; - else binmax = values.size()-1; + if (ymax + halfWin < nv) binmax = ymax + halfWin; + else binmax = nv - 1; int prevcentre = 0; @@ -434,8 +436,8 @@ int actualSize = int(window.size()); if (type == MajorPitchAdaptivePeaks) { - if (ymax + halfWin < values.size()) binmax = ymax + halfWin; - else binmax = values.size()-1; + if (ymax + halfWin < nv) binmax = ymax + halfWin; + else binmax = nv - 1; } deque<float> sorted(window); @@ -455,7 +457,7 @@ inrange.push_back(centrebin); } - if (centre <= median || centrebin+1 == values.size()) { + if (centre <= median || centrebin+1 == nv) { if (!inrange.empty()) { int peakbin = 0; float peakval = 0.f;
--- a/transform/FeatureExtractionModelTransformer.cpp Fri Jan 22 12:46:42 2016 +0000 +++ b/transform/FeatureExtractionModelTransformer.cpp Fri Jan 22 13:39:45 2016 +0000 @@ -1007,8 +1007,7 @@ } else if (isOutput<EditableDenseThreeDimensionalModel>(n)) { - DenseThreeDimensionalModel::Column values = - DenseThreeDimensionalModel::Column::fromStdVector(feature.values); + DenseThreeDimensionalModel::Column values = feature.values; EditableDenseThreeDimensionalModel *model = getConformingOutput<EditableDenseThreeDimensionalModel>(n);