Skip to content

Commit 1f598e2

Browse files
author
camilo
committed
added interp1
1 parent b37940a commit 1f598e2

File tree

2 files changed

+676
-0
lines changed

2 files changed

+676
-0
lines changed

include/qinterp1.h

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*!
2+
* @file qinterp1.hp
3+
* @author J. Camilo Gomez C.
4+
* @version 1.01
5+
* @note This file is part of the qLibs distribution.
6+
* @brief Class for a set of one-dimensional interpolators
7+
**/
8+
9+
#ifndef QCRC_H
10+
#define QCRC_H
11+
12+
#ifdef __cplusplus
13+
extern "C" {
14+
#endif
15+
16+
#include <stdlib.h>
17+
#include <stdint.h>
18+
19+
/** @addtogroup qinterp1 1D Interpolation
20+
* @brief One-dimensional interpolation class.
21+
* @{
22+
*/
23+
24+
/**
25+
* @brief An enum with all the available interpolation methods.
26+
*/
27+
typedef enum {
28+
QINTERP1_NEXT = 0, /*!< Return the next neighbor.*/
29+
QINTERP1_PREVIOUS, /*!< Return the previous neighbor.*/
30+
QINTERP1_NEAREST, /*!< Return the nearest neighbor.*/
31+
QINTERP1_LINEAR, /*!< Linear interpolation from nearest neighbors.*/
32+
QINTERP1_SINE, /*!< Sine interpolation.*/
33+
QINTERP1_CUBIC, /*!< Cubic interpolation.*/
34+
QINTERP1_HERMITE, /*!< Piecewise cubic Hermite interpolation.*/
35+
QINTERP1_SPLINE, /*!< Catmull spline interpolation.*/
36+
QINTERP1_CONSTRAINED_SPLINE, /*!< A special kind of spline that doesn't overshoot.*/
37+
QINTERP1_MAX,
38+
} qInterp1Method_t;
39+
40+
41+
42+
typedef struct {
43+
float (*method)( const float x,
44+
const float * const tx,
45+
const float * const ty,
46+
const size_t tableSize );
47+
const float *xData;
48+
const float *yData;
49+
size_t dataSize;
50+
} qInterp1_t;
51+
52+
/**
53+
* @brief Setup and initialize the 1D interpolation instance.
54+
* @param[in] i A pointer to the interpolation instance.
55+
* @param[in] xTable An array of size @a sizeTable with the x points sorted in ascending order.
56+
* @param[in] yTable An array of size @a sizeTable with the y points.
57+
* @param[in] sizeTable The number of points in @a xTable @a yTable
58+
* @return 1 on success, otherwise return 0.
59+
*/
60+
int qInterp1_Setup( qInterp1_t * const i,
61+
const float * const xTable,
62+
const float * const yTable,
63+
const size_t sizeTable );
64+
65+
/**
66+
* @brief Set the data table for the 1D interpolation instance.
67+
* @param[in] i A pointer to the interpolation instance.
68+
* @param[in] xTable An array of size @a sizeTable with the x points sorted in ascending order.
69+
* @param[in] yTable An array of size @a sizeTable with the y points.
70+
* @param[in] sizeTable The number of points in @a xTable @a yTable
71+
* @return 1 on success, otherwise return 0.
72+
*/
73+
int qInterp1_SetData( qInterp1_t * const i,
74+
const float * const xTable,
75+
const float * const yTable,
76+
const size_t sizeTable );
77+
78+
/**
79+
* @brief Specify the interpolation method to use.
80+
* @param[in] i A pointer to the interpolation instance.
81+
* @param[in] m The interpolation method.
82+
* @return 1 on success, otherwise return 0.
83+
*/
84+
int qInterp1_SetMethod( qInterp1_t * const i,
85+
const qInterp1Method_t m );
86+
87+
88+
/**
89+
* @brief Interpolate input point @a x to determine the value of @a y
90+
* at the points @a xi using the current method. If value is beyond
91+
* the endpoints, extrapolation is performed using the current method.
92+
* @param[in] i A pointer to the interpolation instance.
93+
* @param[in] x The input point.
94+
* @return @c The interpolated-extrapolated @a y value.
95+
*/
96+
float qInterp1_Get( qInterp1_t * const i,
97+
const float x );
98+
99+
/** @}*/
100+
101+
#ifdef __cplusplus
102+
}
103+
#endif
104+
105+
#endif

0 commit comments

Comments
 (0)