summaryrefslogtreecommitdiff
path: root/rspl/rspl1.h
blob: d5ea0b93a770cf313cfe282089c8a5a33b02bdb8 (plain)
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

#ifndef _RSPL1_H_

 /* Single dimension regularized spline data structure */

/* 
 * Argyll Color Correction System
 * Author: Graeme W. Gill
 * Date:   2000/10/29
 *
 * Copyright 1996 - 2010 Graeme W. Gill
 * All rights reserved.
 *
 * This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :-
 * see the License2.txt file for licencing details.
 *
 * This is a simple 1D version of rspl, useful for standalone purposes.
 *
 */

#ifdef __cplusplus
extern "C" {
#endif

/* General data point position/value structure */
typedef double datai[1];
typedef double datao[1];
typedef double ratai[1];
typedef double ratao[1];

/* Interface coordinate value */
typedef struct {
    double p[1];	/* coordinate position */
    double v[1];	/* function values */
} co;

/* Interface coordinate value */
typedef struct {
    double p[1];	/* coordinate position */
    double v[1];	/* function values */
	double w;		/* Weight to give this point, nominally 1.0 */
} cow;

#define RSPL_NOFLAGS 0

struct _rspl {

  /* Private: */
	int nig;		/* number in interpolation grid */
	double gl,gh,gw;/* Interpolation grid scale low, high, grid cell width */
	double vl,vw;	/* low & range */ 
	double xl,xh;	/* Actual X data exremes low, high */
	double dl,dh;	/* Actual Y Data scale low, high */
	double *x;		/* Array of nig grid point scaled y values */

  /* Public: */

	/* destructor */
	void (*del)(struct _rspl *t);

	/* Initialise from scattered data. */
	/* Returns nz on error */
	int
	(*fit_rspl)(
		struct _rspl *s,	/* this */
		int flags,		/* (Not used) */
		co *d,			/* Array holding position and function values of data points */
		int ndp,		/* Number of data points */
		datai glow,		/* Grid low scale - will expand to enclose data, NULL = default 0.0 */
		datai ghigh,	/* Grid high scale - will expand to enclose data, NULL = default 1.0 */
		int    *gres,	/* Spline grid resolution, ncells = gres-1 */
		datao vlow,		/* Data value low normalize, NULL = default 0.0 */
		datao vhigh,	/* Data value high normalize - NULL = default 1.0 */
		double smooth,	/* Smoothing factor, 0.0 = default 1.0 */
		double *avgdev, /* (Not used) */
		double **ipos 	/* (not used) */
	); 

	/* Initialise from scattered data with weighting. */
	/* Returns nz on error */
	int
	(*fit_rspl_w)(
		struct _rspl *s,	/* this */
		int flags,		/* (Not used) */
		cow *d,			/* Array holding position and function values of data points */
		int ndp,		/* Number of data points */
		datai glow,		/* Grid low scale - will expand to enclose data, NULL = default 0.0 */
		datai ghigh,	/* Grid high scale - will expand to enclose data, NULL = default 1.0 */
		int    *gres,	/* Spline grid resolution, ncells = gres-1 */
		datao vlow,		/* Data value low normalize, NULL = default 0.0 */
		datao vhigh,	/* Data value high normalize - NULL = default 1.0 */
		double smooth,	/* Smoothing factor, 0.0 = default 1.0 */
		double *avgdev, /* (Not used) */
		double **ipos 	/* (not used) */
	); 

	/* Do forward interpolation */
	/* Return 0 if OK, 1 if input was clipped to grid */
	int (*interp)(
		struct _rspl *s,	/* this */
		co *p);				/* Input and output values */

}; typedef struct _rspl rspl;

/* Create a new, empty rspl object */
rspl *new_rspl(int flags, int di, int fdi);

#ifdef __cplusplus
}
#endif

#define _RSPL1_H_
#endif /* _RSPL1_H_ */