ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/interp2d.h
Revision: 2.10
Committed: Sat Feb 13 16:49:18 2021 UTC (3 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, HEAD
Changes since 2.9: +2 -1 lines
Log Message:
feat: added client data pointer for caller convenience

File Contents

# User Rev Content
1 greg 2.10 /* RCSid $Id: interp2d.h,v 2.9 2013/02/15 19:15:16 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 greg 2.9 #define NI2DIM 16 /* size of influence map */
19 greg 2.1
20     /* Data structure for interpolant */
21     typedef struct {
22     int ns; /* number of sample positions */
23 greg 2.4 float dmin; /* minimum diameter (default=1) */
24 greg 2.1 float smf; /* smoothing factor (def=NI2DSMF) */
25 greg 2.7 float smin[2]; /* sample minima */
26 greg 2.8 float smax[2]; /* sample maxima */
27     float grid2; /* grid diameter squared */
28 greg 2.10 void *c_data; /* client data pointer */
29 greg 2.7 struct interp2_samp {
30     unsigned short dia[NI2DIR];
31 greg 2.9 unsigned short infl[NI2DIM];
32 greg 2.7 } *da; /* direction array (private) */
33 greg 2.1 float spt[1][2]; /* sample positions (extends struct) */
34     } INTERP2;
35    
36     /* Allocate a new set of interpolation samples (caller assigns spt[] array) */
37     extern INTERP2 *interp2_alloc(int nsamps);
38    
39 greg 2.2 /* Resize interpolation array (caller must assign any new values) */
40     extern INTERP2 *interp2_realloc(INTERP2 *ip, int nsamps);
41    
42 greg 2.5 /* Set minimum distance under which samples will start to merge */
43     extern void interp2_spacing(INTERP2 *ip, double mind);
44    
45     /* Modify smoothing parameter by the given factor */
46     extern void interp2_smooth(INTERP2 *ip, double sf);
47    
48 greg 2.1 /* Assign full set of normalized weights to interpolate the given location */
49     extern int interp2_weights(float wtv[], INTERP2 *ip, double x, double y);
50    
51     /* Get normalized weights and indexes for n best samples in descending order */
52     extern int interp2_topsamp(float wt[], int si[], const int n,
53     INTERP2 *ip, double x, double y);
54     /* Free interpolant */
55     extern void interp2_free(INTERP2 *ip);
56 greg 2.2
57     /* (Re)compute anisotropic basis function interpolant (normally automatic) */
58     extern int interp2_analyze(INTERP2 *ip);
59 greg 2.3
60 greg 2.7 /* Compute unnormalized weight for a position relative to a sample */
61     double interp2_wti(INTERP2 *ip, const int i, double x, double y);
62    
63 greg 2.4 /***************************************************************
64     * Typical use is to allocate an INTERP2 struct and assign the
65     * spt[] array with the ordered sample locations in x & y. (The
66     * actual orientation of the axes is not important so long as
67     * the application is consistent.) During interpolation, either
68     * interp2_weights() is called to obtain a normalized weighting
69     * vector for all the samples, or interp2_topsamp() is called to
70     * get the most important N samples for the specified location.
71     * The weights (and indexes in the case of interp2_topsamp)
72 greg 2.6 * are then used as coefficients for corresponding sample
73     * values in a vector sum that interpolates the function at
74     * that location.
75 greg 2.5 * The minimum distance between sample positions defaults to 1.0.
76 greg 2.6 * Values spaced closer than this will be merged/averaged.
77     * The interp2_spacing() call may be used to alter this distance,
78 greg 2.5 * causing the interpolant to be recalculated during the
79 greg 2.6 * next call to the sampling functions.
80 greg 2.5 * The default smoothing factor NI2DSMF provides near-optimal
81     * interpolation when well-separated values are known
82 greg 2.6 * precisely. Increase this setting by a factor > 1
83 greg 2.5 * with the interp2_smooth() call if greater mixing is desired.
84 greg 2.6 * A call of interp2_smooth(ip,0) resets to the minimum
85 greg 2.5 * default. It is not possible to "sharpen" the data.
86 greg 2.4 **************************************************************/
87    
88 greg 2.3 #ifdef __cplusplus
89     }
90     #endif
91     #endif /* !_RAD_INTERP2D_H_ */