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

0001 /*
0002     File                 : XYInterpolationCurve.h
0003     Project              : LabPlot
0004     Description          : A xy-curve defined by an interpolation
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 XYINTERPOLATIONCURVE_H
0012 #define XYINTERPOLATIONCURVE_H
0013 
0014 #include "backend/worksheet/plots/cartesian/XYAnalysisCurve.h"
0015 extern "C" {
0016 #include "backend/nsl/nsl_interp.h"
0017 }
0018 #include <gsl/gsl_version.h>
0019 
0020 class XYInterpolationCurvePrivate;
0021 
0022 class XYInterpolationCurve : public XYAnalysisCurve {
0023     Q_OBJECT
0024 
0025 public:
0026     enum class PointsMode { Auto, Multiple, Custom };
0027     struct InterpolationData {
0028         InterpolationData(){};
0029 
0030         nsl_interp_type type{nsl_interp_type_linear}; // type of interpolation
0031         nsl_interp_pch_variant variant{nsl_interp_pch_variant_finite_difference}; // variant of cubic Hermite interpolation
0032         double tension{0.0}, continuity{0.0}, bias{0.0}; // TCB values
0033         nsl_interp_evaluate evaluate{nsl_interp_evaluate_function}; // what to evaluate
0034         size_t npoints{100}; // nr. of points
0035         XYInterpolationCurve::PointsMode pointsMode{PointsMode::Auto}; // mode to interpret points
0036         bool autoRange{true}; // use all data?
0037         // TODO: use Range
0038         QVector<double> xRange{0, 0}; // x range for interpolation
0039     };
0040 
0041     explicit XYInterpolationCurve(const QString& name);
0042     ~XYInterpolationCurve() override;
0043 
0044     void recalculate() override;
0045 
0046     QIcon icon() const override;
0047     void save(QXmlStreamWriter*) const override;
0048     bool load(XmlStreamReader*, bool preview) override;
0049 
0050     CLASS_D_ACCESSOR_DECL(InterpolationData, interpolationData, InterpolationData)
0051     typedef XYAnalysisCurve::Result InterpolationResult;
0052     virtual const XYAnalysisCurve::Result& result() const override;
0053 
0054     typedef XYInterpolationCurvePrivate Private;
0055 
0056 protected:
0057     XYInterpolationCurve(const QString& name, XYInterpolationCurvePrivate* dd);
0058 
0059 private:
0060     Q_DECLARE_PRIVATE(XYInterpolationCurve)
0061 
0062 Q_SIGNALS:
0063     void interpolationDataChanged(const XYInterpolationCurve::InterpolationData&);
0064 };
0065 
0066 #endif