changeset 182:f75f8a1cd7b1

* Some dull work to continue unifying the fft model and editable dense 3d model interfaces
author Chris Cannam
date Mon, 09 Oct 2006 10:49:46 +0000
parents 9c652f2c39b1
children 146eb9e35baa
files data/fileio/CSVFileReader.cpp data/model/DenseThreeDimensionalModel.h data/model/EditableDenseThreeDimensionalModel.cpp data/model/EditableDenseThreeDimensionalModel.h data/model/FFTModel.cpp data/model/FFTModel.h
diffstat 6 files changed, 102 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/CSVFileReader.cpp	Fri Oct 06 16:53:25 2006 +0000
+++ b/data/fileio/CSVFileReader.cpp	Mon Oct 09 10:49:46 2006 +0000
@@ -227,7 +227,7 @@
 
 	} else if (modelType == CSVFormatDialog::ThreeDimensionalModel) {
 
-	    DenseThreeDimensionalModel::BinValueSet values;
+	    DenseThreeDimensionalModel::Column values;
 
 	    for (int i = 0; i < tidyList.size(); ++i) {
 
@@ -254,7 +254,7 @@
 	    std::cerr << "Setting bin values for count " << lineno << ", frame "
 		      << frameNo << ", time " << RealTime::frame2RealTime(frameNo, sampleRate) << std::endl;
 
-	    model3->setBinValues(frameNo, values);
+	    model3->setColumn(frameNo / model3->getResolution(), values);
 	}
 
 	++lineno;
--- a/data/model/DenseThreeDimensionalModel.h	Fri Oct 06 16:53:25 2006 +0000
+++ b/data/model/DenseThreeDimensionalModel.h	Mon Oct 09 10:49:46 2006 +0000
@@ -28,41 +28,77 @@
 
 public:
     /**
-     * Return the number of sample frames covered by each set of bins.
+     * Return the number of sample frames covered by each column of bins.
      */
     virtual size_t getResolution() const = 0;
 
     /**
-     * Return the number of bins in each set of bins.
+     * Return the number of columns of bins in the model.
      */
-    virtual size_t getYBinCount() const = 0; 
+    virtual size_t getWidth() const = 0;
 
     /**
-     * Return the minimum value of the value in each bin.
+     * Return the number of bins in each column.
+     */
+    virtual size_t getHeight() const = 0; 
+
+    /**
+     * Return the minimum permissible value in each bin.
      */
     virtual float getMinimumLevel() const = 0;
 
     /**
-     * Return the maximum value of the value in each bin.
+     * Return the maximum permissible value in each bin.
      */
     virtual float getMaximumLevel() const = 0;
 
-    typedef std::vector<float> BinValueSet;
+    /**
+     * Return true if there are data available for the given column.
+     * This should return true only if getBinValues(windowStartFrame)
+     * would not have to do any substantial work to calculate its
+     * return values.  If this function returns false, it may still be
+     * possible to get the bin values for that column, but they may
+     * have to be calculated.
+     */
+    virtual bool isColumnAvailable(size_t column) const = 0;
+
+    typedef std::vector<float> Column;
 
     /**
-     * Get the set of bin values at the given sample frame (i.e. the
-     * windowStartFrame/getWindowSize()'th set of bins).
+     * Get data from the given column of bin values.
      */
-    virtual void getBinValues(long windowStartFrame, BinValueSet &result) const = 0;
+    virtual void getColumn(size_t column, Column &result) const = 0;
 
     /**
-     * Get a single value, the one at the n'th bin of the set of bins
-     * starting at the given sample frame.
+     * Get the single data point from the n'th bin of the given column.
      */
-    virtual float getBinValue(long windowStartFrame, size_t n) const = 0;
+    virtual float getValueAt(size_t column, size_t n) const = 0;
 
+    /**
+     * Get the name of a given bin (i.e. a label to associate with
+     * that bin across all columns).
+     */
     virtual QString getBinName(size_t n) const = 0;
 
+    /**
+     * Utility function to query whether a given bin is greater than
+     * its (vertical) neighbours.
+     */
+    bool isLocalPeak(size_t x, size_t y) {
+        float value = getValueAt(x, y);
+        if (y > 0 && value < getValueAt(x, y - 1)) return false;
+        if (y < getHeight() - 1 && value < getValueAt(x, y + 1)) return false;
+        return true;
+    }
+
+    /**
+     * Utility function to query whether a given bin is greater than a
+     * certain threshold.
+     */
+    bool isOverThreshold(size_t x, size_t y, float threshold) {
+        return getValueAt(x, y) > threshold;
+    }
+
     virtual int getCompletion() const = 0;
 
 protected:
--- a/data/model/EditableDenseThreeDimensionalModel.cpp	Fri Oct 06 16:53:25 2006 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.cpp	Mon Oct 09 10:49:46 2006 +0000
@@ -70,7 +70,7 @@
     model->m_maximum = m_maximum;
 
     for (size_t i = 0; i < m_data.size(); ++i) {
-	model->setBinValues(i * m_resolution, m_data[i]);
+	model->setColumn(i, m_data[i]);
     }
 
     return model;
@@ -89,13 +89,19 @@
 }
 
 size_t
-EditableDenseThreeDimensionalModel::getYBinCount() const
+EditableDenseThreeDimensionalModel::getWidth() const
+{
+    return m_data.size();
+}
+
+size_t
+EditableDenseThreeDimensionalModel::getHeight() const
 {
     return m_yBinCount;
 }
 
 void
-EditableDenseThreeDimensionalModel::setYBinCount(size_t sz)
+EditableDenseThreeDimensionalModel::setHeight(size_t sz)
 {
     m_yBinCount = sz;
 }
@@ -125,14 +131,12 @@
 }
 
 void
-EditableDenseThreeDimensionalModel::getBinValues(long windowStart,
-                                                 BinValueSet &result) const
+EditableDenseThreeDimensionalModel::getColumn(size_t index,
+                                              Column &result) const
 {
     QMutexLocker locker(&m_mutex);
-    
-    long index = windowStart / m_resolution;
 
-    if (index >= 0 && index < long(m_data.size())) {
+    if (index < m_data.size()) {
 	result = m_data[index];
     } else {
 	result.clear();
@@ -142,15 +146,12 @@
 }
 
 float
-EditableDenseThreeDimensionalModel::getBinValue(long windowStart,
-                                                size_t n) const
+EditableDenseThreeDimensionalModel::getValueAt(size_t index, size_t n) const
 {
     QMutexLocker locker(&m_mutex);
-    
-    long index = windowStart / m_resolution;
 
-    if (index >= 0 && index < long(m_data.size())) {
-	const BinValueSet &s = m_data[index];
+    if (index < m_data.size()) {
+	const Column &s = m_data[index];
         std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size()
                   << std::endl;
 	if (n < s.size()) return s[n];
@@ -160,15 +161,13 @@
 }
 
 void
-EditableDenseThreeDimensionalModel::setBinValues(long windowStart,
-					 const BinValueSet &values)
+EditableDenseThreeDimensionalModel::setColumn(size_t index,
+                                              const Column &values)
 {
     QMutexLocker locker(&m_mutex);
 
-    long index = windowStart / m_resolution;
-
-    while (index >= long(m_data.size())) {
-	m_data.push_back(BinValueSet());
+    while (index >= m_data.size()) {
+	m_data.push_back(Column());
     }
 
     bool newExtents = (m_data.empty() && (m_minimum == m_maximum));
@@ -187,6 +186,9 @@
 
     m_data[index] = values;
 
+    long windowStart = index;
+    windowStart *= m_resolution;
+
     if (m_notifyOnAdd) {
 	if (allChange) {
 	    emit modelChanged();
--- a/data/model/EditableDenseThreeDimensionalModel.h	Fri Oct 06 16:53:25 2006 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.h	Mon Oct 09 10:49:46 2006 +0000
@@ -48,14 +48,19 @@
     virtual void setResolution(size_t sz);
 
     /**
+     * Return the number of columns.
+     */
+    virtual size_t getWidth() const;
+
+    /**
      * Return the number of bins in each set of bins.
      */
-    virtual size_t getYBinCount() const; 
+    virtual size_t getHeight() const; 
 
     /**
      * Set the number of bins in each set of bins.
      */
-    virtual void setYBinCount(size_t sz);
+    virtual void setHeight(size_t sz);
 
     /**
      * Return the minimum value of the value in each bin.
@@ -77,24 +82,25 @@
      */
     virtual void setMaximumLevel(float sz);
 
-    typedef std::vector<float> BinValueSet;
+    /**
+     * Return true if there are data available for the given column.
+     */
+    virtual bool isColumnAvailable(size_t x) const { return x < getWidth(); }
 
     /**
-     * Get the set of bin values at the given sample frame (i.e. the
-     * windowStartFrame/getResolution()'th set of bins).
+     * Get the set of bin values at the given column.
      */
-    virtual void getBinValues(long windowStartFrame, BinValueSet &result) const;
+    virtual void getColumn(size_t x, Column &) const;
 
     /**
-     * Get a single value, the one at the n'th bin of the set of bins
-     * starting at the given sample frame.
+     * Get a single value, from the n'th bin of the given column.
      */
-    virtual float getBinValue(long windowStartFrame, size_t n) const;
+    virtual float getValueAt(size_t x, size_t n) const;
 
     /**
-     * Set the entire set of bin values at the given sample frame.
+     * Set the entire set of bin values at the given column.
      */
-    virtual void setBinValues(long windowStartFrame, const BinValueSet &values);
+    virtual void setColumn(size_t x, const Column &values);
 
     virtual QString getBinName(size_t n) const;
     virtual void setBinName(size_t n, QString);
@@ -111,7 +117,7 @@
 				QString extraAttributes = "") const;
 
 protected:
-    typedef std::vector<BinValueSet> ValueMatrix;
+    typedef std::vector<Column> ValueMatrix;
     ValueMatrix m_data;
 
     std::vector<QString> m_binNames;
--- a/data/model/FFTModel.cpp	Fri Oct 06 16:53:25 2006 +0000
+++ b/data/model/FFTModel.cpp	Mon Oct 09 10:49:46 2006 +0000
@@ -79,10 +79,8 @@
 }
 
 void
-FFTModel::getBinValues(long windowStartFrame, BinValueSet &result) const
+FFTModel::getColumn(size_t x, Column &result) const
 {
-    if (windowStartFrame < 0) windowStartFrame = 0;
-    size_t x = windowStartFrame / getResolution();
     result.clear();
     size_t height(getHeight());
     for (size_t y = 0; y < height; ++y) {
@@ -90,14 +88,6 @@
     }
 }
 
-float
-FFTModel::getBinValue(long windowStartFrame, size_t n) const
-{
-    if (windowStartFrame < 0) windowStartFrame = 0;
-    size_t x = windowStartFrame / getResolution();
-    return const_cast<FFTModel *>(this)->getMagnitudeAt(x, n);
-}
-
 QString
 FFTModel::getBinName(size_t n) const
 {
--- a/data/model/FFTModel.h	Fri Oct 06 16:53:25 2006 +0000
+++ b/data/model/FFTModel.h	Mon Oct 09 10:49:46 2006 +0000
@@ -32,12 +32,6 @@
              size_t fillFromColumn = 0);
     ~FFTModel();
 
-    size_t getWidth() const {
-        return m_server->getWidth() >> m_xshift;
-    }
-    size_t getHeight() const {
-        return m_server->getHeight() >> m_yshift;
-    }
     float getMagnitudeAt(size_t x, size_t y) {
         return m_server->getMagnitudeAt(x << m_xshift, y << m_yshift);
     }
@@ -53,23 +47,23 @@
     void getValuesAt(size_t x, size_t y, float &real, float &imaginary) {
         m_server->getValuesAt(x << m_xshift, y << m_yshift, real, imaginary);
     }
-    bool isColumnReady(size_t x) {
+    bool isColumnAvailable(size_t x) const {
         return m_server->isColumnReady(x << m_xshift);
     }
-    bool isLocalPeak(size_t x, size_t y) {
-        float mag = getMagnitudeAt(x, y);
-        if (y > 0 && mag < getMagnitudeAt(x, y - 1)) return false;
-        if (y < getHeight() - 1 && mag < getMagnitudeAt(x, y + 1)) return false;
-        return true;
-    }
-    bool isOverThreshold(size_t x, size_t y, float threshold) {
-        return getMagnitudeAt(x, y) > threshold;
-    }
 
     size_t getFillExtent() const { return m_server->getFillExtent(); }
 
     // DenseThreeDimensionalModel and Model methods:
     //
+    virtual size_t getWidth() const {
+        return m_server->getWidth() >> m_xshift;
+    }
+    virtual size_t getHeight() const {
+        return m_server->getHeight() >> m_yshift;
+    }
+    virtual float getValueAt(size_t x, size_t y) const {
+        return const_cast<FFTModel *>(this)->getMagnitudeAt(x, y);
+    }
     virtual bool isOK() const {
         return m_server && m_server->getModel();
     }
@@ -92,8 +86,7 @@
     virtual float getMaximumLevel() const {
         return 1.f; // Can't provide
     }
-    virtual void getBinValues(long windowStartFrame, BinValueSet &result) const;
-    virtual float getBinValue(long windowStartFrame, size_t n) const;
+    virtual void getColumn(size_t x, Column &result) const;
     virtual QString getBinName(size_t n) const;
 
     virtual int getCompletion() const { return m_server->getFillCompletion(); }