Slicer.cpp 1.47 KB
Newer Older
1 2
#include "Slicer.h"

3 4 5 6 7 8 9
Slicer::Slicer()
    : _idxStart(0)
    , _idxEnd(0)
    , _idxNext(0)
    , _idxPrevious(0)
    , _overlap(0)
    , _N(0)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
{}

void Slicer::setOverlap(uint32_t overlap)
{
    _overlap = overlap;
}

void Slicer::setN(uint32_t N)
{
    _N = N > 0 ? N : 1;
}

void Slicer::setStartIndex(int idxStart)
{
    _idxStart = idxStart;
}

uint32_t Slicer::overlap()
{
    return _overlap;
}

uint32_t Slicer::N()
{
    return _N;
}

int Slicer::startIndex()
{
    return _idxStart;
}

42
void Slicer::_updateIdx(long size)
43
{
44
    _overlap = _overlap < _N ? _overlap : _N-1;
45

46 47 48
    long maxStart  = size-_N;
    _idxStart = _idxStart <= maxStart   ? _idxStart : maxStart;
    _idxStart = _idxStart < 0           ? 0         : _idxStart;
49 50

    _idxEnd = _idxStart + _N - 1;
51
    _idxEnd = _idxEnd < size ? _idxEnd : size-1;
52 53

    _idxNext = _idxEnd + 1 - _overlap;
54 55
    _idxNext = _idxNext < 0       ? 0        : _idxNext;
    _idxNext = _idxNext < size    ? _idxNext : size-1;
56

57 58 59 60 61 62 63 64 65 66 67
    _idxPrevious = _idxStart + _overlap - _N;
    _idxPrevious = _idxPrevious < 0       ? 0            : _idxPrevious;
    _idxPrevious = _idxPrevious < size    ? _idxPrevious : size-1;

//    qDebug() << "size:         " << size;
//    qDebug() << "_N:           " << _N;
//    qDebug() << "_overlap:     " << _overlap;
//    qDebug() << "_idxStart:    " << _idxStart;
//    qDebug() << "_idxEnd:      " << _idxEnd;
//    qDebug() << "_idxNext:     " << _idxNext;
//    qDebug() << "_idxPrevious: " << _idxPrevious << "\n";
68
}