00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef TAC_LUTABLEBLOCK_H
00012 #define TAC_LUTABLEBLOCK_H
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "tacStdBlock.h"
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #define tacLUTABLE_EXPECTED_PARAM 1
00041
00042
00043
00044
00045
00046 #define tacLUTABLE_FREE_PARAM_INDEX 1
00047
00048
00049
00050
00051
00052 typedef struct {
00053 double x;
00054 double y;
00055 }tacLUTABLE_DOUBLET;
00056
00057 typedef struct {
00058 unsigned short size;
00059 unsigned short index;
00060 tacLUTABLE_DOUBLET* function;
00061 }tacLUTABLE;
00062
00063
00064
00065
00066
00067 #define tacLUTableGetTable(pSelf) ((tacLUTABLE*) ((pSelf)->parameter))
00068
00069 #define tacLUTableSetPoint(pTable, index, abs, ord) \
00070 { \
00071 pTable->function[index].x = abs; \
00072 pTable->function[index].y = ord; \
00073 }
00074
00075 #define tacLUTableGetPoint(pTable, index, abs, ord) \
00076 { \
00077 abs = pTable->function[index].x; \
00078 ord = pTable->function[index].y; \
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094 STATUS tacLUTableBlockConstructor(tacSTDBLOCK* pSelf, tacSTDBLOCK_PARAM* parameter, tacERROR* error);
00095 STATUS tacLUTableBlockGetParameter(tacSTDBLOCK* pSelf, tacSTDBLOCK_PARAM* parameter, tacERROR* error);
00096 void tacLUTableBlockAlgorithm(tacSTDBLOCK* pSelf);
00097 void tacLUTableBlockDestructor(tacSTDBLOCK* pSelf);
00098
00099 STATUS tacLUTableCreateTable(tacLUTABLE* pTable, unsigned short size);
00100 void tacLUTableRemoveTable(tacLUTABLE* pTable);
00101
00102
00103
00104
00105
00106
00107
00108 static __inline__ unsigned short tacLUTableHunt (tacLUTABLE* pTable, double input)
00109 {
00110 unsigned short increment;
00111 unsigned short lower, higher, middle;
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 increment = 1;
00124
00125
00126 lower = pTable->index;
00127
00128 if (input >= pTable->function[lower].x)
00129 {
00130 higher = lower + 1;
00131
00132 while (input >= pTable->function[higher].x)
00133 {
00134 lower = higher;
00135 increment <<= 1;
00136 higher = lower + increment;
00137
00138 if (higher >= pTable->size)
00139 {
00140 higher = pTable->size;
00141 break;
00142 }
00143 }
00144 }
00145 else
00146 {
00147 higher = lower;
00148 lower -= 1;
00149
00150 while (input <= pTable->function[lower].x)
00151 {
00152 higher = lower;
00153 increment <<= 1;
00154 lower = higher - increment;
00155
00156 #if 0
00157 if (lower <= 0)
00158 {
00159 lower = 0;
00160 break;
00161 }
00162 #else
00163 if (increment >= higher)
00164 {
00165 lower = 0;
00166 break;
00167 }
00168 #endif
00169 }
00170 }
00171
00172
00173
00174
00175
00176
00177 while ((higher - lower) != 1)
00178 {
00179 middle = (higher + lower) >> 1;
00180
00181 if (input >= pTable->function[middle].x)
00182 {
00183 lower = middle;
00184 }
00185 else
00186 {
00187 higher = middle;
00188 }
00189 }
00190
00191
00192 pTable->index = lower;
00193
00194 return lower;
00195 }
00196
00197 static __inline__ double tacLUTableInterpolate (tacLUTABLE* pTable, double input)
00198 {
00199 unsigned short index = 0;
00200
00201 double y0, y1;
00202 double x0, x1;
00203
00204 if (input <= pTable->function[0].x)
00205 {
00206 return (pTable->function[0].y);
00207 }
00208 else if (input >= pTable->function[(pTable->size - 1)].x)
00209 {
00210 return (pTable->function[(pTable->size - 1)].y);
00211 }
00212 else
00213 {
00214 index = tacLUTableHunt(pTable, input);
00215
00216 x0 = pTable->function[index].x;
00217 y0 = pTable->function[index].y;
00218 x1 = pTable->function[index+1].x;
00219 y1 = pTable->function[index+1].y;
00220
00221
00222 return (y0 + ((input - x0) / (x1 - x0) * (y1 - y0)));
00223 }
00224 }
00225
00226 #endif