1 #if !defined( LUTMAP_INCLUDED ) /* Include this file only once */ 2 #define LUTMAP_INCLUDED 3 /* 4 *+ 5 * Name: 6 * lutmap.h 7 8 * Type: 9 * C include file. 10 11 * Purpose: 12 * Define the interface to the LutMap class. 13 14 * Invocation: 15 * #include "lutmap.h" 16 17 * Description: 18 * This include file defines the interface to the LutMap class and 19 * provides the type definitions, function prototypes and macros, 20 * etc. needed to use this class. 21 * 22 * The LutMap class implements Mappings which transform 23 * 1-dimensional coordinates using linear interpolation in a lookup 24 * table. 25 26 * Inheritance: 27 * The LutMap class inherits from the Mapping class. 28 29 * Attributes Over-Ridden: 30 * None. 31 32 * New Attributes Defined: 33 * None. 34 35 * Methods Over-Ridden: 36 * Public: 37 * None. 38 * 39 * Protected: 40 * astMapMerge 41 * Simplify a sequence of Mappings. 42 * astTransform 43 * Apply a LutMap to transform a set of points. 44 45 * New Methods Defined: 46 * Public: 47 * None. 48 * 49 * Protected: 50 * None. 51 52 * Other Class Functions: 53 * Public: 54 * astIsALutMap 55 * Test class membership. 56 * astLutMap 57 * Create a LutMap. 58 * 59 * Protected: 60 * astCheckLutMap 61 * Validate class membership. 62 * astInitLutMap 63 * Initialise a LutMap. 64 * astInitLutMapVtab 65 * Initialise the virtual function table for the LutMap class. 66 * astLoadLutMap 67 * Load a LutMap. 68 69 * Macros: 70 * None. 71 72 * Type Definitions: 73 * Public: 74 * AstLutMap 75 * LutMap object type. 76 * 77 * Protected: 78 * AstLutMapVtab 79 * LutMap virtual function table type. 80 81 * Feature Test Macros: 82 * astCLASS 83 * If the astCLASS macro is undefined, only public symbols are 84 * made available, otherwise protected symbols (for use in other 85 * class implementations) are defined. This macro also affects 86 * the reporting of error context information, which is only 87 * provided for external calls to the AST library. 88 89 * Copyright: 90 * Copyright (C) 1997-2006 Council for the Central Laboratory of the 91 * Research Councils 92 93 * Licence: 94 * This program is free software: you can redistribute it and/or 95 * modify it under the terms of the GNU Lesser General Public 96 * License as published by the Free Software Foundation, either 97 * version 3 of the License, or (at your option) any later 98 * version. 99 * 100 * This program is distributed in the hope that it will be useful, 101 * but WITHOUT ANY WARRANTY; without even the implied warranty of 102 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 103 * GNU Lesser General Public License for more details. 104 * 105 * You should have received a copy of the GNU Lesser General 106 * License along with this program. If not, see 107 * <http://www.gnu.org/licenses/>. 108 109 * Authors: 110 * RFWS: R.F. Warren-Smith (Starlink) 111 112 * History: 113 * 8-JUL-1997 (RFWS): 114 * Original version. 115 * 8-JAN-2003 (DSB): 116 * Added protected astInitLutMapVtab method. 117 *- 118 */ 119 120 /* Include files. */ 121 /* ============== */ 122 /* Interface definitions. */ 123 /* ---------------------- */ 124 #include "mapping.h" /* Coordinate mappings (parent class) */ 125 126 #if defined(astCLASS) /* Protected */ 127 #include "pointset.h" /* Sets of points/coordinates */ 128 #include "channel.h" /* I/O channels */ 129 #endif 130 131 /* C header files. */ 132 /* --------------- */ 133 #if defined(astCLASS) /* Protected */ 134 #include <stddef.h> 135 #endif 136 137 /* Macros */ 138 /* ====== */ 139 140 /* Define a dummy __attribute__ macro for use on non-GNU compilers. */ 141 #ifndef __GNUC__ 142 # define __attribute__(x) /*NOTHING*/ 143 #endif 144 145 /* Type Definitions. */ 146 /* ================= */ 147 /* LutMap structure. */ 148 /* ------------------ */ 149 /* This structure contains all information that is unique to each 150 object in the class (e.g. its instance variables). */ 151 typedef struct AstLutMap { 152 153 /* Attributes inherited from the parent class. */ 154 AstMapping mapping; /* Parent class structure */ 155 156 /* Attributes specific to objects in this class. */ 157 double *lut; /* Pointer to lookup table */ 158 double *luti; /* Reduced lookup table for inverse trans. */ 159 double inc; /* Input increment between table entries */ 160 double last_fwd_in; /* Last input value (forward transfm.) */ 161 double last_fwd_out; /* Last output value (forward transfm.) */ 162 double last_inv_in; /* Last input value (inverse transfm.) */ 163 double last_inv_out; /* Last output value (inverse transfm.) */ 164 double start; /* Input value for first table entry */ 165 int *flagsi; /* Flags indicating adjacent bad values */ 166 int *indexi; /* Translates reduced to original indices */ 167 int lutinterp; /* Interpolation method */ 168 int nlut; /* Number of table entries */ 169 int nluti; /* Reduced number of table entries */ 170 } AstLutMap; 171 172 /* Virtual function table. */ 173 /* ----------------------- */ 174 /* This table contains all information that is the same for all 175 objects in the class (e.g. pointers to its virtual functions). */ 176 #if defined(astCLASS) /* Protected */ 177 typedef struct AstLutMapVtab { 178 179 /* Properties (e.g. methods) inherited from the parent class. */ 180 AstMappingVtab mapping_vtab; /* Parent class virtual function table */ 181 182 /* A Unique identifier to determine class membership. */ 183 AstClassIdentifier id; 184 185 /* Properties (e.g. methods) specific to this class. */ 186 int (*GetLutInterp)( AstLutMap *, int * ); 187 int (* TestLutInterp)( AstLutMap *, int * ); 188 void (* ClearLutInterp)( AstLutMap *, int * ); 189 void (* SetLutInterp)( AstLutMap *, int, int * ); 190 double *(* GetLutMapInfo)( AstLutMap *, double *, double *, int *, int * ); 191 192 } AstLutMapVtab; 193 194 #if defined(THREAD_SAFE) 195 196 /* Define a structure holding all data items that are global within this 197 class. */ 198 typedef struct AstLutMapGlobals { 199 AstLutMapVtab Class_Vtab; 200 int Class_Init; 201 char GetAttrib_Buff[ 101 ]; 202 } AstLutMapGlobals; 203 204 #endif 205 206 #endif 207 208 /* Function prototypes. */ 209 /* ==================== */ 210 /* Prototypes for standard class functions. */ 211 /* ---------------------------------------- */ 212 astPROTO_CHECK(LutMap) /* Check class membership */ 213 astPROTO_ISA(LutMap) /* Test class membership */ 214 215 /* Constructor. */ 216 #if defined(astCLASS) /* Protected. */ 217 AstLutMap *astLutMap_( int, const double [], double, double, const char *, int *, ...); 218 #else 219 AstLutMap *astLutMapId_( int, const double [], double, double, const char *, ... )__attribute__((format(printf,5,6))); 220 #endif 221 222 #if defined(astCLASS) /* Protected */ 223 224 /* Initialiser. */ 225 AstLutMap *astInitLutMap_( void *, size_t, int, AstLutMapVtab *, const char *, int, const double *, double, double, int * ); 226 227 /* Vtab initialiser. */ 228 void astInitLutMapVtab_( AstLutMapVtab *, const char *, int * ); 229 230 /* Loader. */ 231 AstLutMap *astLoadLutMap_( void *, size_t, AstLutMapVtab *, const char *, AstChannel *, int * ); 232 233 /* Thread-safe initialiser for all global data used by this module. */ 234 #if defined(THREAD_SAFE) 235 void astInitLutMapGlobals_( AstLutMapGlobals * ); 236 #endif 237 238 #endif 239 240 /* Prototypes for member functions. */ 241 /* -------------------------------- */ 242 # if defined(astCLASS) /* Protected */ 243 int astGetLutInterp_( AstLutMap *, int * ); 244 int astTestLutInterp_( AstLutMap *, int * ); 245 void astClearLutInterp_( AstLutMap *, int * ); 246 void astSetLutInterp_( AstLutMap *, int, int * ); 247 double *astGetLutMapInfo_( AstLutMap *, double *, double *, int *, int * ); 248 #endif 249 250 /* Function interfaces. */ 251 /* ==================== */ 252 /* These macros are wrap-ups for the functions defined by this class 253 to make them easier to invoke (e.g. to avoid type mis-matches when 254 passing pointers to objects from derived classes). */ 255 256 /* Interfaces to standard class functions. */ 257 /* --------------------------------------- */ 258 /* Some of these functions provide validation, so we cannot use them 259 to validate their own arguments. We must use a cast when passing 260 object pointers (so that they can accept objects from derived 261 classes). */ 262 263 /* Check class membership. */ 264 #define astCheckLutMap(this) astINVOKE_CHECK(LutMap,this,0) 265 #define astVerifyLutMap(this) astINVOKE_CHECK(LutMap,this,1) 266 267 /* Test class membership. */ 268 #define astIsALutMap(this) astINVOKE_ISA(LutMap,this) 269 270 /* Constructor. */ 271 #if defined(astCLASS) /* Protected. */ 272 #define astLutMap astINVOKE(F,astLutMap_) 273 #else 274 #define astLutMap astINVOKE(F,astLutMapId_) 275 #endif 276 277 #if defined(astCLASS) /* Protected */ 278 279 /* Initialiser. */ 280 #define \ 281 astInitLutMap(mem,size,init,vtab,name,nlut,lut,start,inc) \ 282 astINVOKE(O,astInitLutMap_(mem,size,init,vtab,name,nlut,lut,start,inc,STATUS_PTR)) 283 284 /* Vtab Initialiser. */ 285 #define astInitLutMapVtab(vtab,name) astINVOKE(V,astInitLutMapVtab_(vtab,name,STATUS_PTR)) 286 /* Loader. */ 287 #define astLoadLutMap(mem,size,vtab,name,channel) \ 288 astINVOKE(O,astLoadLutMap_(mem,size,vtab,name,astCheckChannel(channel),STATUS_PTR)) 289 #endif 290 291 /* Interfaces to public member functions. */ 292 /* -------------------------------------- */ 293 /* Here we make use of astCheckLutMap to validate LutMap pointers 294 before use. This provides a contextual error report if a pointer 295 to the wrong sort of Object is supplied. */ 296 #if defined(astCLASS) /* Protected */ 297 298 #define astClearLutInterp(this) \ 299 astINVOKE(V,astClearLutInterp_(astCheckLutMap(this),STATUS_PTR)) 300 #define astGetLutInterp(this) \ 301 astINVOKE(V,astGetLutInterp_(astCheckLutMap(this),STATUS_PTR)) 302 #define astSetLutInterp(this,value) \ 303 astINVOKE(V,astSetLutInterp_(astCheckLutMap(this),value,STATUS_PTR)) 304 #define astTestLutInterp(this) \ 305 astINVOKE(V,astTestLutInterp_(astCheckLutMap(this),STATUS_PTR)) 306 #define astGetLutMapInfo(this,start,inc,nlut) \ 307 astINVOKE(V,astGetLutMapInfo_(astCheckLutMap(this),start,inc,nlut,STATUS_PTR)) 308 309 #endif 310 311 #endif 312 313 314 315 316 317