Slicer.h 2.46 KB
Newer Older
1 2 3 4 5 6 7
#pragma once

#include <assert.h>
#include <iostream>

#include "Utils.h"

8
//! @brief Helper class for slicing containers.
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 66 67 68 69
class Slicer
{
public:
    Slicer();


protected:
    // Slicing.
    template <class Container1, class Container2>
    void update     (const Container1 &source, Container2 &slice);
    template <class Container1, class Container2>
    void next       (const Container1 &source, Container2 &slice);
    template <class Container1, class Container2>
    void previous   (const Container1 &source, Container2 &slice);
    template <class Container1, class Container2>
    void reset      (const Container1 &source, Container2 &slice);

public:
    // Slicing parameters.
    //! @brief Sets the overlap.
    //!
    //! @param overlap The number of overlapping vertices
    //! between on and the next slice.
    void setOverlap            (uint32_t overlap);
    //! @brief Sets the number of vertices per slice.
    //!
    //! @param N The number of vertices per slice.
    void setN   (std::uint32_t N);
    //! @brief Sets the start index.
    //!
    //! @param idxStart The start index.
    void setStartIndex         (int idxStart);

    //! @return Returns the overlap.
    uint32_t      overlap       ();
    //! @return Returns the number of vertices per slice N.
    uint32_t      N             ();
    //! @return Returns the start index.
    int           startIndex    ();

    Slicer &operator=(const Slicer &other);


private:
    void _updateIdx(std::size_t size);

    long          _idxStart;
    long          _idxEnd;
    long          _idxNext;
    long          _idxPrevious;
    uint32_t      _overlap;
    uint32_t      _N;
    bool          _idxValid;
    bool          _atEnd;


};

template <class Container1, class Container2>
void Slicer::update(const Container1 &source, Container2 &slice){

70
    _updateIdx(source.size());
71 72 73 74 75
    WaypointManager::Utils::extract(source, slice, _idxStart, _idxEnd);
}

template <class Container1, class Container2>
void Slicer::next(const Container1 &source, Container2 &slice){
76
    _updateIdx(source.size());
77 78 79 80 81 82 83
    setStartIndex(_idxNext);
    update(source, slice);
}


template <class Container1, class Container2>
void Slicer::previous(const Container1 &source, Container2 &slice){
84
    _updateIdx(source.size());
85 86 87 88 89 90 91 92 93 94
    setStartIndex(_idxPrevious);
    update(source, slice);
}


template <class Container1, class Container2>
void Slicer::reset(const Container1 &source, Container2 &slice){
    setStartIndex(0);
    update(source, slice);
}