Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++
1.5 KB
Raw Blame
/*
 *  SPDX-FileCopyrightText: 2017 Dmitry Kazakov <[email protected]>
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "KisRollingMeanAccumulatorWrapper.h"

#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>

using namespace boost::accumulators;

struct KisRollingMeanAccumulatorWrapper::Private {
    Private(int windowSize)
        : accumulator(tag::rolling_window::window_size = windowSize)
    {
    }

    accumulator_set<qreal, stats<tag::lazy_rolling_mean> > accumulator;
};


KisRollingMeanAccumulatorWrapper::KisRollingMeanAccumulatorWrapper(int windowSize)
    : m_d(new Private(windowSize))
{
}

KisRollingMeanAccumulatorWrapper::~KisRollingMeanAccumulatorWrapper()
{
}

void KisRollingMeanAccumulatorWrapper::operator()(qreal value)
{
    m_d->accumulator(value);
}

qreal KisRollingMeanAccumulatorWrapper::rollingMean() const
{
    return boost::accumulators::rolling_mean(m_d->accumulator);
}

qreal KisRollingMeanAccumulatorWrapper::rollingMeanSafe() const
{
    return boost::accumulators::rolling_count(m_d->accumulator) > 0 ?
        boost::accumulators::rolling_mean(m_d->accumulator) : 0;
}

int KisRollingMeanAccumulatorWrapper::rollingCount() const
{
    return boost::accumulators::rolling_count(m_d->accumulator);
}

void KisRollingMeanAccumulatorWrapper::reset(int windowSize)
{
    m_d->accumulator =
        accumulator_set<qreal, stats<tag::lazy_rolling_mean>>(
            tag::rolling_window::window_size = windowSize);
}