/Users/craigcornelius/Projects/SPRING Mac Release 0.2/cyberware.h

Go to the documentation of this file.
00001 #ifndef CYBERWARE_HEADER
00002 #define CYBERWARE_HEADER
00003 
00004 /* globals */
00005 
00006 /* Internal types, These modules all assume the following types:
00007  *
00008  *      char                    1 byte signed integer, -128...127
00009  *      unsigned char   1 byte unsigned integer, 0...255
00010  *      short                   2 byte signed integer, -32,768...32,767
00011  *      unsigned short  2 byte unsigned integer, 0...65,535
00012  *      long                    4 byte signed integer, -2,147,483,648...2,147,483,647
00013  *      unsigned long   4 byte unsigned integer, 0...4,294,967,295
00014  *      real                    a real variable natural to the machine
00015  *      int                             at least as long as short
00016  *      unsigned int    at least as long as unsigned short
00017  *      
00018  *      All other types are to be enclosed in #ifdefs.
00019  */
00020 typedef float real;
00021 
00022 /* file constants, unpacked */
00023 
00024 //#define MAXR          (0x00007fff<<gs->rshift)
00025 #define MAXRGS(gs)      (0x00007fff<<(gs)->rshift)
00026 #define MINR            0
00027 //#define VOID          (0xffff8000<<gs->rshift)
00028 #define VOIDGS(gs)      (0xffff8000<<(gs)->rshift)
00029 
00030 #ifndef NULL
00031 #define NULL    0                               /* null address */
00032 #endif
00033 
00034 /* math tools */
00035 
00036 #define MAX(a,b)        ((a)>(b)?(a):(b))               /* return greater of a and b */
00037 #define MIN(a,b)        ((a)<(b)?(a):(b))               /* return lesser of a and b */
00038 #define ABS(i)          ((i)<0?-(i):(i))                /* integer absolute value */
00039 #define DELTA(a,b)      (ABS((a)-(b)))                  /* int absolute difference */
00040 #define SCALE(n,s)      ((((n)*(s))+50)/100)    /* int scale n by s percent */
00041 #define WRAPP(n,m)      (if((n)>=(m))(n)-=(m))  /* modulo positive wrap */
00042 #define WRAPN(n,m)      (if((n)<0)(n)+=(m))             /* modulo positive wrap */
00043 
00044 /* unit conversions */
00045 
00046 #define UMTOI(um)       ((real)(um)*3.937e-5)   /* microns (um) to float inch */
00047 #define ITOUM(um)       ((int)((um)*2.54e4))    /* inches to int microns */
00048 #define URTOD(ur)       ((real)(ur)*5.7296e-5)  /* urads to float degrees */
00049 #define DTOUR(deg)      ((int)((deg)*1.74533e4) /* degrees to int urads */
00050 #define DTOR(deg)       ((deg)*1.7453292e-2)    /* degrees to float radians */
00051 #define RTOD(rad)       ((rad)*57.295779)               /* radians to float degrees */
00052 #define URTOR(ur)       ((real)(ur)*1.e-6)              /* radians to urads */
00053 #define RTOUR(ur)       (int)((ur)*1.e6)                /* radians to urads */
00054 
00055 /* this structure defines 'grid file format'.  the file consists of
00056  * a parameter table followed immediatly by the data table.  the offset
00057  * to the start of the data table is the second parameter and is therefore
00058  * fifth thru eighth bytes of the file (msb first).
00059  *
00060  * the parameters nlg and nlt are important for accessing the data.  nlg
00061  * is the number of longitude entries in the table.  nlt is the number of
00062  * latitudes in the table.  nlt * nlg * 2 gives the number of bytes in the
00063  * table.
00064  *
00065  * the table is a set of radius values in a cylindrical coordinate space.
00066  * each radius value is stored in a 2 byte integer which when shifted
00067  * left by RSHIFT bits yields a radius in microns (4 byte long integer).
00068  * the radius values are stored in longitudnal groups of nlt values.  there
00069  * are nlg of these groups, one for each longitude of the cylinder.
00070  *
00071  * the functions GETR() and PUTR() defined below are usually all that is
00072  * required to fetch and store values in the table when it is in memory.
00073  * the parameters ltincr and lgincr define the distance between adjacent
00074  * latitudes (microns) and adjacent longitudes (microradians) respectively.
00075  *
00076  * There are two formats for this header, one portable, one not so
00077  * portable.  The older non-portable type is binary and has the value
00078  * 122 decimal ('z') in the fifth byte.  The portable header has a 'r'
00079  * in the fifth byte.  The portable header is in ascii and has the form
00080  * [name=value],... where name is a defined ascii symbol and value is a
00081  * string value for the symbol.  Format is variable and assignments are
00082  * separated by white space or commas.
00083  *
00084  * See header.c for details.
00085  */
00086 
00087 #define NAMELEN         40
00088 #define CREATE_MODE     0644            /* create image files with this mode */
00089 
00090 typedef struct {
00091 
00092         /* internal private variables */
00093         short *base;                    /* base of data buffer */
00094         long offset;                            /* file offset to start of data, bytes */
00095 
00096         /* file parameters */
00097         char name[NAMELEN];                     /* subject name */
00098         long time;                                      /* original creation time */
00099         short camera;                           /* camera obj_id number */
00100         short setup;                            /* camera setup code */
00101         char saved;                                     /* file has been saved since modified */
00102         char valid;                                     /* file buffer is valid */
00103 
00104         /* data parameters */
00105         short nlt;                                      /* number of latitude intervals */
00106         short nlg;                                      /* number of longitude intervals */
00107         short rshift;                           /* shift to compress/expand radius data */
00108         short lgshift;                          /* shift to extract longitude from addr */
00109         long flags;                                     /* misc file state flags, see below */
00110         long ltincr;                            /* distance between latitudes, um */
00111         long lgincr;                            /* distance between longitudes, urad */
00112         long ltsize;                            /* nlat * ltincr, um */
00113         long lgsize;                            /* nlg * lgincr, urad (always 2pi in urads) */
00114 
00115         /* user parameters */
00116         char filled;                            /* fill flag, useless */
00117         short smoothed;                         /* smooth pass counter */
00118         short ltmin, ltmax;                     /* latitude window limits, inclusive */
00119         short lgmin, lgmax;                     /* longitude window limits, inclusive */
00120         long rmin, rmax;                        /* radius range, from last run of rminmax */
00121 #       ifdef IRIS
00122                 long float scale;               /* current scale */
00123                 long float rprop;               /* current radius proportion */
00124 #       else
00125                 double scale;                   /* current scale */
00126                 double rprop;                   /* current radius proportion */
00127 #       endif
00128 } GSPEC;
00129 
00130 /* macros for standardizing the use of the grid data. gs is a pointer to the
00131  * applicable GSSPEC table.  index is the offset of a data item in the
00132  * data. lt and lg are latitude and longitude indicies. r is the radius
00133  * in microns (um) of a data point. z is a position along the cylindrical
00134  * axis in microns. a is an angular coordinate around the cylinder in 
00135  * microradians (urad).
00136  *
00137  * INDEX generates an index value from latitude and logitude indicies.
00138  * ADDR returns the absolute address of a data item.
00139  * PUTR and GETR are used to store and retrieve data from the image.
00140  */
00141 
00142 #define INDEX(gs, lt, lg)       ((lg) * (gs)->nlt + (lt))
00143 #define ADDR(gs, lt, lg)        ((gs)->base + INDEX(gs, lt, lg))
00144 
00145 #ifdef _WIN32
00146 #       define GETR(gs, lt, lg)              getr(gs,lt,lg)
00147 #       define PUTR(gs, lt, lg, r)       putr(gs,lt,lg,r)
00148 #else
00149 #       define PUTR(gs, lt, lg, r)      (*ADDR(gs, lt, lg) = (r) >> (gs)->rshift)
00150 #       define GETR(gs, lt, lg) ((int)*ADDR(gs, lt, lg) << (gs)->rshift)
00151 #endif
00152 
00153 /* flag bits for gs->flags */
00154 
00155 #define FLAG_RESERVED   0x000000ff      /* older files have ones here, ignore */
00156 #define FLAG_CARTESIAN  0x00000100      /* data is cartesian (vs. cyl) */
00157 #define FLAG_OLDHEADER  0x00000200      /* please write file with old header */
00158 #define FLAG_BILATERAL  0x00000400      /* bilateral image, ie: nus hands */
00159 #define FLAG_COLOR              0x00000800      /* image has associated color file */
00160 #define FLAG_THETARIGHT 0x00001000      /* theta is right hand rule */
00161 #define FLAG_INSIDE_OUT 0x00002000      /* inside surface is outside */
00162 
00163 /* non-int public functions */
00164 GSPEC *cyread(GSPEC* gs, int fd);       /* read data file from fd */
00165 int cywrite(GSPEC* gs, int fd); /* write data file to fd */
00166 void cyfree(GSPEC* gs);         /* free private resources */
00167 extern GSPEC *gsallo();
00168 extern int cywrite(GSPEC* gs, int fd);
00169 extern void cyfree(GSPEC* gs);
00170 extern long getr(GSPEC* gs, int lt, int lg);
00171 extern void putr(GSPEC* gs, int lt, int lg, int r);
00172 extern int geget();
00173 extern int gsget();
00174 extern int gdget();
00175 extern int gdput();
00176 extern int gsput();
00177 extern int gdallo();
00178 extern long getheader();
00179 extern int getvalue();
00180 extern int makegsheader();
00181 extern int writegsheader();
00182 
00183 #endif

Generated on Thu Aug 30 11:03:13 2007 for SPRING Mac by  doxygen 1.5.3