| 1 | |
| 2 | #ifndef _RSPL1_H_ |
| 3 | |
| 4 | /* Single dimension regularized spline data structure */ |
| 5 | |
| 6 | /* |
| 7 | * Argyll Color Management System |
| 8 | * Author: Graeme W. Gill |
| 9 | * Date: 2000/10/29 |
| 10 | * |
| 11 | * Copyright 1996 - 2010 Graeme W. Gill |
| 12 | * All rights reserved. |
| 13 | * |
| 14 | * This material is licenced under the GNU GENERAL PUBLIC LICENSE Version 2 or later :- |
| 15 | * see the License2.txt file for licencing details. |
| 16 | * |
| 17 | * This is a simple 1D version of rspl, useful for standalone purposes. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * Might be nice to add support for simple rev lookup, so that |
| 23 | * standalone xcal can use it ?? |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | #ifdef __cplusplus |
| 28 | extern "C" { |
| 29 | #endif |
| 30 | |
| 31 | /* Make up for possible lack of rspl.h */ |
| 32 | #ifndef MXDI |
| 33 | # define MXDI 10 /* Maximum input dimensionality */ |
| 34 | # define MXDO 10 /* Maximum output dimensionality (Is not fully tested!!!) */ |
| 35 | #endif |
| 36 | |
| 37 | /* General data point position/value structure */ |
| 38 | typedef double datai[1]; |
| 39 | typedef double datao[1]; |
| 40 | typedef double ratai[1]; |
| 41 | typedef double ratao[1]; |
| 42 | |
| 43 | /* Interface coordinate value */ |
| 44 | typedef struct { |
| 45 | double p[1]; /* coordinate position */ |
| 46 | double v[1]; /* function values */ |
| 47 | } co; |
| 48 | |
| 49 | /* Interface coordinate value */ |
| 50 | typedef struct { |
| 51 | double p[1]; /* coordinate position */ |
| 52 | double v[1]; /* function values */ |
| 53 | double w; /* Weight to give this point, nominally 1.0 */ |
| 54 | } cow; |
| 55 | |
| 56 | #define RSPL_NOFLAGS 0 |
| 57 | |
| 58 | struct _rspl { |
| 59 | |
| 60 | /* Private: */ |
| 61 | int nig; /* number in interpolation grid */ |
| 62 | double gl,gh,gw;/* Interpolation grid scale low, high, grid cell width */ |
| 63 | double vl,vw; /* low & range */ |
| 64 | double xl,xh; /* Actual X data exremes low, high */ |
| 65 | double dl,dh; /* Actual Y Data scale low, high */ |
| 66 | double *x; /* Array of nig grid point scaled y values */ |
| 67 | |
| 68 | /* Public: */ |
| 69 | |
| 70 | /* destructor */ |
| 71 | void (*del)(struct _rspl *t); |
| 72 | |
| 73 | /* Initialise from scattered data. */ |
| 74 | /* Returns nz on error */ |
| 75 | int |
| 76 | (*fit_rspl)( |
| 77 | struct _rspl *s, /* this */ |
| 78 | int flags, /* (Not used) */ |
| 79 | co *d, /* Array holding position and function values of data points */ |
| 80 | int ndp, /* Number of data points */ |
| 81 | datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */ |
| 82 | datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */ |
| 83 | int *gres, /* Spline grid resolution, ncells = gres-1 */ |
| 84 | datao vlow, /* Data value low normalize, NULL = default 0.0 */ |
| 85 | datao vhigh, /* Data value high normalize - NULL = default 1.0 */ |
| 86 | double smooth, /* Smoothing factor, 0.0 = default 1.0 */ |
| 87 | double *avgdev, /* (Not used) */ |
| 88 | double **ipos /* (not used) */ |
| 89 | ); |
| 90 | |
| 91 | /* Initialise from scattered data with weighting. */ |
| 92 | /* Returns nz on error */ |
| 93 | int |
| 94 | (*fit_rspl_w)( |
| 95 | struct _rspl *s, /* this */ |
| 96 | int flags, /* (Not used) */ |
| 97 | cow *d, /* Array holding position and function values of data points */ |
| 98 | int ndp, /* Number of data points */ |
| 99 | datai glow, /* Grid low scale - will expand to enclose data, NULL = default 0.0 */ |
| 100 | datai ghigh, /* Grid high scale - will expand to enclose data, NULL = default 1.0 */ |
| 101 | int *gres, /* Spline grid resolution, ncells = gres-1 */ |
| 102 | datao vlow, /* Data value low normalize, NULL = default 0.0 */ |
| 103 | datao vhigh, /* Data value high normalize - NULL = default 1.0 */ |
| 104 | double smooth, /* Smoothing factor, 0.0 = default 1.0 */ |
| 105 | double *avgdev, /* (Not used) */ |
| 106 | double **ipos /* (not used) */ |
| 107 | ); |
| 108 | |
| 109 | /* Initialize the grid from a provided function. */ |
| 110 | /* Grid index values are supplied "under" in[] at *((int*)&in[-e-1]) */ |
| 111 | int |
| 112 | (*set_rspl)( |
| 113 | struct _rspl *s, /* this */ |
| 114 | int flags, /* (Not used) */ |
| 115 | void *cbntx, /* Opaque function context */ |
| 116 | void (*func)(void *cbntx, double *out, double *in), /* Function to set from */ |
| 117 | datai glow, /* Grid low scale, NULL = default 0.0 */ |
| 118 | datai ghigh, /* Grid high scale, NULL = default 1.0 */ |
| 119 | int gres[MXDI], /* Spline grid resolution */ |
| 120 | datao vlow, /* Data value low normalize, NULL = default 0.0 */ |
| 121 | datao vhigh /* Data value high normalize - NULL = default 1.0 */ |
| 122 | ); |
| 123 | |
| 124 | /* Do forward interpolation */ |
| 125 | /* Return 0 if OK, 1 if input was clipped to grid */ |
| 126 | int (*interp)( |
| 127 | struct _rspl *s, /* this */ |
| 128 | co *p); /* Input and output values */ |
| 129 | |
| 130 | /* Do forward 1d interpolation of and return the value. */ |
| 131 | double (*interp1)( /* Return value */ |
| 132 | struct _rspl *s, /* this */ |
| 133 | double in); /* Input value */ |
| 134 | |
| 135 | /* Return a pointer to the resolution array */ |
| 136 | int *(*get_res)(struct _rspl *s); |
| 137 | |
| 138 | }; typedef struct _rspl rspl; |
| 139 | |
| 140 | /* Create a new, empty rspl object */ |
| 141 | rspl *new_rspl(int flags, int di, int fdi); |
| 142 | |
| 143 | #ifdef __cplusplus |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | #define _RSPL1_H_ |
| 148 | #endif /* _RSPL1_H_ */ |
| 149 | |
| 150 |