Slicer.cpp 1.23 KB
Newer Older
1 2 3 4 5 6 7 8 9 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#include "Slicer.h"

Slicer::Slicer():
    _idxValid(false)
  , _atEnd(false)
{}

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

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

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

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

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

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

void Slicer::_updateIdx(std::size_t size)
{
    _idxValid = true;
    _atEnd    = false;
    if ( _idxStart >= long(size)-1 ) {
        _idxStart   = long(size)-1;
        _idxEnd     = _idxStart;
        _idxNext    = _idxStart;
        _atEnd      = true;
        return;
    }

    _idxStart = _idxStart < 0 ? 0 : _idxStart;

    _idxEnd = _idxStart + _N - 1;
    _idxEnd = _idxEnd < long(size) ? _idxEnd : size-1;

    _idxNext = _idxEnd + 1 - _overlap;
    _idxNext = _idxNext < 0    ? 0        : _idxNext;
    _idxNext = _idxNext < long(size) ? _idxNext : size-1;

    _idxPrevious = _idxStart - 1 + _overlap;
    _idxPrevious = _idxPrevious < 0    ? 0            : _idxPrevious;
    _idxPrevious = _idxPrevious < long(size) ? _idxPrevious : size-1;
}