File indexing completed on 2025-01-26 03:34:21

0001 /*
0002     File                 : XYSmoothCurve.h
0003     Project              : LabPlot
0004     Description          : A xy-curve defined by a smooth
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2016-2021 Stefan Gerlach <stefan.gerlach@uni.kn>
0007     SPDX-FileCopyrightText: 2017 Alexander Semke <alexander.semke@web.de>
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef XYSMOOTHCURVE_H
0012 #define XYSMOOTHCURVE_H
0013 
0014 #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h"
0015 
0016 extern "C" {
0017 #include "backend/nsl/nsl_smooth.h"
0018 }
0019 
0020 class XYSmoothCurvePrivate;
0021 
0022 class XYSmoothCurve : public XYAnalysisCurve {
0023     Q_OBJECT
0024 
0025 public:
0026     struct SmoothData {
0027         SmoothData(){};
0028 
0029         nsl_smooth_type type{nsl_smooth_type_moving_average}; // type of smoothing
0030         size_t points{5}; // number of points
0031         nsl_smooth_weight_type weight{nsl_smooth_weight_uniform}; // type of weight
0032         double percentile{0.5}; // percentile for percentile filter (0.0 .. 1.0)
0033         int order{2}; // order for Savitzky-Golay filter
0034         nsl_smooth_pad_mode mode{nsl_smooth_pad_none}; // mode of padding for edges
0035         double lvalue{0.0}, rvalue{0.0}; // values for constant padding
0036         bool autoRange{true}; // use all data?
0037         // TODO: use Range
0038         QVector<double> xRange{0., 0.}; // x range for integration
0039     };
0040 
0041     explicit XYSmoothCurve(const QString& name);
0042     ~XYSmoothCurve() override;
0043 
0044     void recalculate() override;
0045     QIcon icon() const override;
0046     void save(QXmlStreamWriter*) const override;
0047     bool load(XmlStreamReader*, bool preview) override;
0048 
0049     const AbstractColumn* roughsColumn() const;
0050     CLASS_D_ACCESSOR_DECL(SmoothData, smoothData, SmoothData)
0051 
0052     typedef XYAnalysisCurve::Result SmoothResult;
0053     virtual const XYAnalysisCurve::Result& result() const override;
0054 
0055     typedef XYSmoothCurvePrivate Private;
0056 
0057 protected:
0058     XYSmoothCurve(const QString& name, XYSmoothCurvePrivate* dd);
0059 
0060 private:
0061     Q_DECLARE_PRIVATE(XYSmoothCurve)
0062 
0063 Q_SIGNALS:
0064     void smoothDataChanged(const XYSmoothCurve::SmoothData&);
0065 };
0066 
0067 #endif