Slicer.h 2.36 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
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    ();


private:
51
    void _updateIdx(long size);
52 53 54 55 56

    long          _idxStart;
    long          _idxEnd;
    long          _idxNext;
    long          _idxPrevious;
57 58
    long          _overlap;
    long          _N;
59 60 61 62 63 64

};

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

65
    _updateIdx(source.size());
66 67 68 69 70
    WaypointManager::Utils::extract(source, slice, _idxStart, _idxEnd);
}

template <class Container1, class Container2>
void Slicer::next(const Container1 &source, Container2 &slice){
71
    _updateIdx(source.size());
72 73 74 75 76 77 78
    setStartIndex(_idxNext);
    update(source, slice);
}


template <class Container1, class Container2>
void Slicer::previous(const Container1 &source, Container2 &slice){
79
    _updateIdx(source.size());
80 81 82 83 84 85 86 87 88 89
    setStartIndex(_idxPrevious);
    update(source, slice);
}


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