Changeset - 2e6f48de66b4
[Not reviewed]
default
0 2 0
Hasan Yavuz Ă–ZDERYA - 10 years ago 2015-08-15 15:24:42
hy@ozderya.net
cache bounding rectangle
2 files changed with 25 insertions and 1 deletions:
0 comments (0 inline, 0 general)
framebuffer.cpp
Show inline comments
 
@@ -21,12 +21,14 @@
 

	
 
FrameBuffer::FrameBuffer(size_t size)
 
{
 
    _size = size;
 
    data = new double[_size]();
 
    headIndex = 0;
 

	
 
    _boundingRect.setCoords(0, 0, size, 0);
 
}
 

	
 
FrameBuffer::~FrameBuffer()
 
{
 
    delete data;
 
}
 
@@ -57,12 +59,15 @@ void FrameBuffer::resize(size_t size)
 

	
 
    // data is ready, clean and re-point
 
    delete data;
 
    data = newData;
 
    headIndex = 0;
 
    _size = size;
 

	
 
    // update the bounding rectangle
 
    _boundingRect.setRight(_size);
 
}
 

	
 
void FrameBuffer::addSamples(double* samples, size_t size)
 
{
 
    unsigned shift = size;
 
    if (shift < _size)
 
@@ -104,12 +109,29 @@ void FrameBuffer::addSamples(double* sam
 
        for (size_t i = 0; i < _size; i++)
 
        {
 
            data[i] = samples[i+x];
 
        }
 
        headIndex = 0;
 
    }
 

	
 
    // update bounding rectangle
 
    double minValue = 0;
 
    double maxValue = 0;
 
    for (size_t i = 0; i < _size; i++)
 
    {
 
        if (data[i] > maxValue)
 
        {
 
            maxValue = data[i];
 
        }
 
        else if (data[i] < minValue)
 
        {
 
            minValue = data[i];
 
        }
 
    }
 
    _boundingRect.setTop(minValue);
 
    _boundingRect.setBottom(maxValue);
 
}
 

	
 
void FrameBuffer::clear()
 
{
 
    for (size_t i=0; i < _size; i++) data[i] = 0.;
 
}
 
@@ -123,13 +145,13 @@ QPointF FrameBuffer::sample(size_t i) co
 
{
 
    return QPointF(i, _sample(i));
 
}
 

	
 
QRectF FrameBuffer::boundingRect() const
 
{
 
    return qwtBoundingRect(*this);
 
    return _boundingRect;
 
}
 

	
 
double FrameBuffer::_sample(size_t i) const
 
{
 
    size_t index = headIndex + i;
 
    if (index >= _size) index -= _size;
framebuffer.h
Show inline comments
 
@@ -41,10 +41,12 @@ public:
 

	
 
private:
 
    size_t _size; // size of `data`
 
    double* data;
 
    size_t headIndex; // indicates the actual `0` index of the ring buffer
 

	
 
    QRectF _boundingRect;
 

	
 
    double _sample(size_t i) const;
 
};
 

	
 
#endif // FRAMEBUFFER_H
0 comments (0 inline, 0 general)