File: Interpolation.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (215 lines) | stat: -rw-r--r-- 6,851 bytes parent folder | download
1
2
3
4
5
6
7
8
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/***************************************************************************
        Interpolation.h  -  Interpolation types
                             -------------------
    begin                : Sat Feb 03 2001
    copyright            : (C) 2001 by Thomas Eschenbacher
    email                : Thomas Eschenbacher <thomas.eschenbacher@gmx.de>
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef INTERPOLATION_H
#define INTERPOLATION_H

#include "config.h"
#include "libkwave_export.h"

#include <QtGlobal>
#include <QString>
#include <QStringList>
#include <QVector>

#include "libkwave/TypesMap.h"

namespace Kwave
{

    class Curve;

    typedef enum {
        INTPOL_LINEAR = 0,
        INTPOL_SPLINE,
        INTPOL_NPOLYNOMIAL,
        INTPOL_POLYNOMIAL3,
        INTPOL_POLYNOMIAL5,
        INTPOL_POLYNOMIAL7,
        INTPOL_SAH
    } interpolation_t;

    /**
     * Interpolation types
     */
    class LIBKWAVE_EXPORT Interpolation
    {
    public:
        /** Constructor, initializes type by enum type */
        explicit Interpolation(Kwave::interpolation_t type = INTPOL_LINEAR);

        /** Destructor. */
        virtual ~Interpolation();

        bool prepareInterpolation(const Kwave::Curve &points);

        QVector<double> interpolation(const Kwave::Curve &points,
                                      unsigned int len);

        QVector<double> limitedInterpolation(const Kwave::Curve &points,
                                             unsigned int len);

        /**
         * Returns a single point of the interpolation.
         */
        double singleInterpolation(double pos);

        /**
         * Same as getSingleInterpolation, but return value
         * will be limited to be [0...1]
         * @see #singleInterpolation
         * @param pos ???
         * @return interpolated value [0...1]
         */
        double singleLimitedInterpolation(double pos);

        /**
         * Returns the if of a type through it's name.
         * @param name the short name of the interpolation,
         *             like used in a command
         * @return the interpolation
         */
        static Kwave::interpolation_t find(const QString &name)
        {
            return m_interpolation_map.findFromName(name);
        }

        /**
         * Returns the name of an interpolation (non-localized).
         * @param type the type to get the name of
         */
        static QString name(Kwave::interpolation_t type);

        /**
         * Returns an alphabetically sorted list of verbose
         * interpolation type names, useful for providing a list
         * of available types in the gui.
         * @param localized if true, the list will contain localized
         *        names (useful for filling combo boxes)
         */
        static QStringList descriptions(bool localized = false);

        /** Sets a new interpolation tpye */
        inline void setType (Kwave::interpolation_t t) {
            m_type = t;
        }

        /** Returns the currently interpolation selected type */
        inline Kwave::interpolation_t type() {
            return m_type;
        }

        /** Translates an index in an interpolation type */
        static inline Kwave::interpolation_t findByIndex(int index) {
            return m_interpolation_map.findFromData(index);
        }

        /**
         * Little private class for initialized map. Used
         * to translate interpolation_t into verbose name
         * and vice-versa.
         */
        class InterpolationMap:
            public Kwave::TypesMap<Kwave::interpolation_t, int >
        {
        public:

            /** Constructor */
            explicit InterpolationMap()
                :TypesMap<Kwave::interpolation_t, int >()
            {
                fill();
            }

            /** filling function for the map. */
            void fill() override;
        };

    private:

        /** Returns the number of points **/
        unsigned int count();

        /**
         * ???
         * @param points curve with points for interpolation
         * @param x receives all x coordinates ???
         * @param y receives all y coordinates ???
         */
        void createFullPolynom(const Kwave::Curve &points,
                               QVector<double> &x,
                               QVector<double> &y);

        /**
         * ???
         * @param x array of x coordinates
         * @param y array of y coordinates
         * @param ab array for return values
         * @param n ???
         */
        void get2Derivate(const QVector<double> &x,
                          const QVector<double> &y,
                          QVector<double> &ab, unsigned int n);

        /**
         * ???
         * @param points curve with points for interpolation
         * @param x array of x coordinates
         * @param y array of y coordinates
         * @param pos ???
         * @param degree ???
         */
        void createPolynom (const Kwave::Curve &points,
                            QVector<double> &x,
                            QVector<double> &y,
                            int pos, unsigned int degree);

    private:

        /**  List of points to be interpolated. */
        const Kwave::Curve *m_curve;

        /** ??? used for temporary purposes */
        QVector<double> m_x;

        /** ??? used for temporary purposes */
        QVector<double> m_y;

        /** ??? used for temporary purposes */
        QVector<double> m_der;

        /** Map with type and name of interpolations */
        static InterpolationMap m_interpolation_map;

        /** Type of the interpolation. */
        Kwave::interpolation_t m_type;

    };

    //***********************************************************************
    static inline Kwave::interpolation_t &operator ++(Kwave::interpolation_t &i)
    {
        return (i = (i == INTPOL_SAH) ?
            INTPOL_LINEAR :
            Kwave::interpolation_t(i + 1) );
    }

}

#endif /* INTERPOLATION_H */

//***************************************************************************
//***************************************************************************