parkertomatoes / lttb-cpp

C++ implementation of the Largest Triangle Three Buckets (LTTB) downsampling algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C++ Implementation of the Largest Triangle Three Buckets (LTTB) Downsampling Algorithm

This is a straightforward C++ port of the reference implementation of the Largest Triangle Three Buckets (LTTB) downsampling algorithm described in the paper "Downsampling time series for visual representation" by Sveinn Steinarsson. It is a single header, with a single class template that allows using different structures and data types.

How To Install

Simply add the lttb.hpp header to your project. There are no binaries to install, and no dependencies outside the standard library.

How To Use

Create a typedef to specify your time series datapoint type

#include "lttb.hpp"

struct ExamplePoint {
    float x;
    float y;
};

using PointLttb = LargestTriangleThreeBuckets<ExamplePoint, float, &ExamplePoint::x, &ExamplePoint::y>

Then use the static method Downsample in the class. It can be used with iterators

std::vector<ExamplePoint> in = GetYourInputsFromSomewhere();
std::vector<ExamplePoint> out;
PointLttb::Downsample(in.begin(), in.size(), std::back_inserter(out), 50);

...or pointers:

ExamplePoint in[500];
GetYourInputsFromSomewhere(in);
ExamplePoint out[50];
PointLttb::Downsample(in, 500, out, 50);

About

C++ implementation of the Largest Triangle Three Buckets (LTTB) downsampling algorithm

License:MIT License


Languages

Language:C++ 96.9%Language:CMake 3.1%