1 |
greg |
2.4 |
/* RCSid $Id: interp2d.h,v 2.3 2013/02/09 20:56:40 greg Exp $ */ |
2 |
greg |
2.1 |
/* |
3 |
greg |
2.4 |
* Header for interpolation of anisotropic samples on 2-D plane. |
4 |
greg |
2.1 |
* |
5 |
|
|
* G.Ward Feb 2013 |
6 |
|
|
*/ |
7 |
|
|
|
8 |
greg |
2.3 |
#ifndef _RAD_INTERP2D_H_ |
9 |
|
|
#define _RAD_INTERP2D_H_ |
10 |
|
|
|
11 |
|
|
#ifdef __cplusplus |
12 |
|
|
extern "C" { |
13 |
|
|
#endif |
14 |
|
|
|
15 |
greg |
2.4 |
#define NI2DSMF 0.42f /* minimal smoothing factor */ |
16 |
greg |
2.1 |
|
17 |
|
|
#define NI2DIR (2*4) /* # interpolation directions */ |
18 |
|
|
|
19 |
|
|
/* Data structure for interpolant */ |
20 |
|
|
typedef struct { |
21 |
|
|
int ns; /* number of sample positions */ |
22 |
greg |
2.4 |
float dmin; /* minimum diameter (default=1) */ |
23 |
greg |
2.1 |
float smf; /* smoothing factor (def=NI2DSMF) */ |
24 |
greg |
2.4 |
unsigned short (*da)[NI2DIR]; /* anisotropic distances (private) */ |
25 |
greg |
2.1 |
float spt[1][2]; /* sample positions (extends struct) */ |
26 |
|
|
} INTERP2; |
27 |
|
|
|
28 |
|
|
/* Allocate a new set of interpolation samples (caller assigns spt[] array) */ |
29 |
|
|
extern INTERP2 *interp2_alloc(int nsamps); |
30 |
|
|
|
31 |
greg |
2.2 |
/* Resize interpolation array (caller must assign any new values) */ |
32 |
|
|
extern INTERP2 *interp2_realloc(INTERP2 *ip, int nsamps); |
33 |
|
|
|
34 |
greg |
2.1 |
/* Assign full set of normalized weights to interpolate the given location */ |
35 |
|
|
extern int interp2_weights(float wtv[], INTERP2 *ip, double x, double y); |
36 |
|
|
|
37 |
|
|
/* Get normalized weights and indexes for n best samples in descending order */ |
38 |
|
|
extern int interp2_topsamp(float wt[], int si[], const int n, |
39 |
|
|
INTERP2 *ip, double x, double y); |
40 |
|
|
/* Free interpolant */ |
41 |
|
|
extern void interp2_free(INTERP2 *ip); |
42 |
greg |
2.2 |
|
43 |
|
|
/* (Re)compute anisotropic basis function interpolant (normally automatic) */ |
44 |
|
|
extern int interp2_analyze(INTERP2 *ip); |
45 |
greg |
2.3 |
|
46 |
greg |
2.4 |
/*************************************************************** |
47 |
|
|
* Typical use is to allocate an INTERP2 struct and assign the |
48 |
|
|
* spt[] array with the ordered sample locations in x & y. (The |
49 |
|
|
* actual orientation of the axes is not important so long as |
50 |
|
|
* the application is consistent.) During interpolation, either |
51 |
|
|
* interp2_weights() is called to obtain a normalized weighting |
52 |
|
|
* vector for all the samples, or interp2_topsamp() is called to |
53 |
|
|
* get the most important N samples for the specified location. |
54 |
|
|
* The weights (and indexes in the case of interp2_topsamp) |
55 |
|
|
* are then used as coefficients for corresponding sample values |
56 |
|
|
* in a vector sum together that interpolates the function at that |
57 |
|
|
* location. Between the initial allocation call and the first |
58 |
|
|
* weight evaluation, the dmin member may be adjusted to |
59 |
|
|
* the distance under which samples will start to merge. If this |
60 |
|
|
* parameter is later changed, interp2_analyze() should be called |
61 |
|
|
* to recompute the interpolant. |
62 |
|
|
* The smf member sets the smoothing factor for interpolation. |
63 |
|
|
* The default setting of NI2DSMF produces near-optimal |
64 |
|
|
* interpolation when well-separated sample values are known |
65 |
|
|
* precisely. If a greater degree of mixing is desired, this |
66 |
|
|
* paremter may be increased and it will affect the next call |
67 |
|
|
* to interp2_weights() or interp2_topsamp(). |
68 |
|
|
**************************************************************/ |
69 |
|
|
|
70 |
greg |
2.3 |
#ifdef __cplusplus |
71 |
|
|
} |
72 |
|
|
#endif |
73 |
|
|
#endif /* !_RAD_INTERP2D_H_ */ |