Mercurial > hg > svcore
changeset 533:55ad231c9db7
* try some qvectors
author | Chris Cannam |
---|---|
date | Thu, 22 Jan 2009 17:58:33 +0000 |
parents | 59dd6d1bcfb0 |
children | 6038cb6fcd30 |
files | data/model/DenseThreeDimensionalModel.h data/model/EditableDenseThreeDimensionalModel.cpp data/model/EditableDenseThreeDimensionalModel.h data/model/FFTModel.cpp data/model/FFTModel.h transform/FeatureExtractionModelTransformer.cpp |
diffstat | 6 files changed, 35 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/data/model/DenseThreeDimensionalModel.h Thu Jan 22 17:39:04 2009 +0000 +++ b/data/model/DenseThreeDimensionalModel.h Thu Jan 22 17:58:33 2009 +0000 @@ -22,7 +22,7 @@ #include "base/RealTime.h" #include <QMutex> -#include <vector> +#include <QVector> class DenseThreeDimensionalModel : public Model, public TabularModel @@ -64,12 +64,12 @@ */ virtual bool isColumnAvailable(size_t column) const = 0; - typedef std::vector<float> Column; + typedef QVector<float> Column; /** * Get data from the given column of bin values. */ - virtual void getColumn(size_t column, Column &result) const = 0; + virtual Column getColumn(size_t column) const = 0; /** * Get the single data point from the n'th bin of the given column.
--- a/data/model/EditableDenseThreeDimensionalModel.cpp Thu Jan 22 17:39:04 2009 +0000 +++ b/data/model/EditableDenseThreeDimensionalModel.cpp Thu Jan 22 17:58:33 2009 +0000 @@ -77,7 +77,7 @@ model->m_haveExtents = m_haveExtents; for (size_t i = 0; i < m_data.size(); ++i) { - model->setColumn(i, m_data[i]); + model->setColumn(i, m_data.at(i)); } return model; @@ -137,19 +137,21 @@ m_maximum = level; } -void -EditableDenseThreeDimensionalModel::getColumn(size_t index, - Column &result) const +EditableDenseThreeDimensionalModel::Column +EditableDenseThreeDimensionalModel::getColumn(size_t index) const { QMutexLocker locker(&m_mutex); + Column result; + if (index < m_data.size()) { - result = m_data[index]; + result = m_data.at(index); } else { result.clear(); } while (result.size() < m_yBinCount) result.push_back(m_minimum); + return result; } float @@ -158,10 +160,10 @@ QMutexLocker locker(&m_mutex); if (index < m_data.size()) { - const Column &s = m_data[index]; + const Column &s = m_data.at(index); // std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size() // << std::endl; - if (n < s.size()) return s[n]; + if (n < s.size()) return s.at(n); } return m_minimum; @@ -251,19 +253,19 @@ bool EditableDenseThreeDimensionalModel::shouldUseLogValueScale() const { - std::vector<float> sample; - std::vector<int> n; + QVector<float> sample; + QVector<int> n; for (int i = 0; i < 10; ++i) { size_t index = i * 10; if (index < m_data.size()) { - const Column &c = m_data[index]; + const Column &c = m_data.at(index); while (c.size() > sample.size()) { sample.push_back(0.f); n.push_back(0); } for (int j = 0; j < c.size(); ++j) { - sample[j] += c[j]; + sample[j] += c.at(j); ++n[j]; } } @@ -274,7 +276,7 @@ if (n[j]) sample[j] /= n[j]; } - return LogRange::useLogScale(sample); + return LogRange::useLogScale(sample.toStdVector()); } void @@ -311,8 +313,8 @@ QString s; for (size_t i = 0; i < m_data.size(); ++i) { QStringList list; - for (size_t j = 0; j < m_data[i].size(); ++j) { - list << QString("%1").arg(m_data[i][j]); + for (size_t j = 0; j < m_data.at(i).size(); ++j) { + list << QString("%1").arg(m_data.at(i).at(j)); } s += list.join(delimiter) + "\n"; } @@ -353,9 +355,9 @@ for (size_t i = 0; i < m_data.size(); ++i) { out << indent + " "; out << QString("<row n=\"%1\">").arg(i); - for (size_t j = 0; j < m_data[i].size(); ++j) { + for (size_t j = 0; j < m_data.at(i).size(); ++j) { if (j > 0) out << " "; - out << m_data[i][j]; + out << m_data.at(i).at(j); } out << QString("</row>\n"); out.flush();
--- a/data/model/EditableDenseThreeDimensionalModel.h Thu Jan 22 17:39:04 2009 +0000 +++ b/data/model/EditableDenseThreeDimensionalModel.h Thu Jan 22 17:58:33 2009 +0000 @@ -18,6 +18,8 @@ #include "DenseThreeDimensionalModel.h" +#include <vector> + class EditableDenseThreeDimensionalModel : public DenseThreeDimensionalModel { Q_OBJECT @@ -90,7 +92,7 @@ /** * Get the set of bin values at the given column. */ - virtual void getColumn(size_t x, Column &) const; + virtual Column getColumn(size_t x) const; /** * Get a single value, from the n'th bin of the given column. @@ -120,7 +122,7 @@ QString extraAttributes = "") const; protected: - typedef std::vector<Column> ValueMatrix; + typedef QVector<Column> ValueMatrix; ValueMatrix m_data; std::vector<QString> m_binNames;
--- a/data/model/FFTModel.cpp Thu Jan 22 17:39:04 2009 +0000 +++ b/data/model/FFTModel.cpp Thu Jan 22 17:58:33 2009 +0000 @@ -161,11 +161,13 @@ return isOK() ? m_server->getModel()->getSampleRate() : 0; } -void -FFTModel::getColumn(size_t x, Column &result) const +FFTModel::Column +FFTModel::getColumn(size_t x) const { Profiler profiler("FFTModel::getColumn", false); + Column result; + result.clear(); size_t h = getHeight(); result.reserve(h); @@ -181,6 +183,8 @@ } else { for (size_t i = 0; i < h; ++i) result.push_back(0.f); } + + return result; } QString @@ -261,7 +265,7 @@ return peaks; } - getColumn(x, values); + values = getColumn(x); float mean = 0.f; for (int i =0; i < values.size(); ++i) mean += values[i];
--- a/data/model/FFTModel.h Thu Jan 22 17:39:04 2009 +0000 +++ b/data/model/FFTModel.h Thu Jan 22 17:58:33 2009 +0000 @@ -136,7 +136,7 @@ virtual float getMaximumLevel() const { return 1.f; // Can't provide } - virtual void getColumn(size_t x, Column &result) const; + virtual Column getColumn(size_t x) const; virtual QString getBinName(size_t n) const; virtual bool shouldUseLogValueScale() const {
--- a/transform/FeatureExtractionModelTransformer.cpp Thu Jan 22 17:39:04 2009 +0000 +++ b/transform/FeatureExtractionModelTransformer.cpp Thu Jan 22 17:58:33 2009 +0000 @@ -716,7 +716,8 @@ } else if (isOutput<EditableDenseThreeDimensionalModel>()) { - DenseThreeDimensionalModel::Column values = feature.values; + DenseThreeDimensionalModel::Column values = + DenseThreeDimensionalModel::Column::fromStdVector(feature.values); EditableDenseThreeDimensionalModel *model = getConformingOutput<EditableDenseThreeDimensionalModel>();