Annotation of researchv10no/cmd/bcp/stdocr.h, revision 1.1.1.1

1.1       root        1: /* Copyright (c) 1989, 1990 AT&T --- All Rights Reserved.              */
                      2: /* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T.                */
                      3: /* The copyright notice does not imply actual or intended publication. */
                      4: /* AUTHORS:                                            */
                      5: /*     H. S. Baird - ATT-BL MH - first versions        */
                      6: /* stdocr.h -- conventional OCGR constants, typedefs, and file formats
                      7:  NOTE: sensitive to prior:
                      8:        `#define MAIN 1'
                      9:        `#define CPU ?'
                     10:        `#define OS ?' */
                     11: 
                     12: extern int errno;      /* UNIX system call error number */
                     13: 
                     14: #ifndef MAIN
                     15: #define MAIN 0
                     16: #endif
                     17: 
                     18: #define FWRI (T)       /* use machine-independent format for dim-file writes */
                     19: #define FRDI (T)       /* use machine-independent format for dim-file reads */
                     20: 
                     21: #ifndef PI
                     22: #define PI 3.1415926535
                     23: #endif
                     24: 
                     25: extern int Readvax;    /* T. Thompson flag:  see Coord.c */
                     26: 
                     27: #include "limits.h"    /* machine-dependent numeric extreme values */
                     28: #include "fioi.h"      /* machine-independent types and binary I/O */
                     29: #include "boole.h"     /* boolean type */
                     30: #include "Units.h"     /* OCR-specific units */
                     31: #include "Coord.h"     /* scanner coordinates & basic geometry */
                     32: #include "ric.h"       /* ricoh scanner page & file formats */
                     33: 
                     34: /* 5620 dimensions, in dots */
                     35: #define Width5620 800
                     36: #define Height5620 1024
                     37: 
                     38: /* used (in clc.c) to compute absolute maximum value of natural 
                     39:    log values used in Bayesian binary weights */
                     40: #define LOG_ABS_MAX 3.0
                     41: 
                     42: #define Merit float            /* heuristic ``merit'' takes on values in [0,1] */
                     43: /* machine-independent I/O:  range [0.0-1.0], precision .0000153 */
                     44: #define fwri_Merit(F,V) fwri_uint2((F),((V)*USHRT_MAX))
                     45: #define frdi_Merit(F) (frdi_uint2(F)/(Merit)USHRT_MAX)
                     46: 
                     47: #define Prob float             /* ``probability'' takes on values in [0,1] */
                     48: /* machine-independent I/O:  range [0.0-1.0], precision .0000153 */
                     49: #define fwri_Prob(F,V) fwri_uint2((F),((V)*USHRT_MAX))
                     50: #define frdi_Prob(F) (frdi_uint2(F)/(Prob)USHRT_MAX)
                     51: 
                     52: #define Pts float              /* text-size units: ``points'' (1/72) inch */
                     53: /* machine-independent I/O:  range [0,655.36], precision 0.01 ([0,9.1] inches) */
                     54: #define fwri_Pts(F,V) fwri_uint2((F),((V)*100.0))
                     55: #define frdi_Pts(F) (frdi_uint2(F)/100.0)
                     56: 
                     57: #define Ems float              /* em-space units */
                     58: /* machine-independent I/O:  range [-32.768,32.767], precision 0.001 */
                     59: #define fwri_Ems(F,V) fwri_int2((F),((V)*1000.0))
                     60: #define frdi_Ems(F) (frdi_int2(F)/1000.0)
                     61: 
                     62: /* class name - long enough to be a unix file name */
                     63: #define Cln_len (14)           /* maximum no. chars (DIRSIZ in some UNIX's) */
                     64: #define Cln_lenp (Cln_len+1)   /* maximum size of array */
                     65: typedef char Cln[Cln_lenp];
                     66: #define fwri_Cln(F,S) fwri_str((F),(S))
                     67: #define frdi_Cln(F,S) frdi_strn((F),(S),Cln_lenp)
                     68: 
                     69: /* font name */
                     70: #define Fontn_len (Cln_len)            /* maximum no. chars */
                     71: #define Fontn_lenp (Cln_lenp)          /* maximum size of array */
                     72: typedef char Fontn[Fontn_lenp];
                     73: #define fwri_Fontn(F,S) fwri_str((F),(S))
                     74: #define frdi_Fontn(F,S) frdi_strn((F),(S),Fontn_lenp)
                     75: 
                     76: typedef struct ClassId {
                     77:        Fontn f;        /* font name */
                     78:        Pts s;          /* size in points */
                     79:        Cln c;          /* printable symbol name (``class-name'') */
                     80:        short v;        /* symbol variant no. 0,1,... */
                     81:        } ClassId;
                     82: 
                     83: #define Init_ClassId {"",0.0,"",0}
                     84: #if MAIN
                     85: ClassId empty_ClassId = Init_ClassId;
                     86: #else
                     87: extern ClassId empty_ClassId;
                     88: #endif
                     89: char *classid_toa();   /* in chcln.c */
                     90: #define eq_classid(a,b) ((!strcmp((a).f,(b).f))&&((a).s==(b).s)&&(!strcmp((a).c,(b).c))&&((a).v==(b).v))
                     91: 
                     92: #define fwri_ClassId(F,P) { \
                     93:        fwri_Fontn((F),(P)->f); \
                     94:        fwri_Pts((F),(P)->s); \
                     95:        fwri_Cln((F),(P)->c); \
                     96:        fwri_uint1((F),(P)->v); \
                     97:        }
                     98: #define frdi_ClassId(F,P) ( feof(F)? 0: ( \
                     99:        frdi_Fontn((F),(P)->f), \
                    100:        (P)->s=frdi_Pts(F), \
                    101:        frdi_Cln((F),(P)->c), \
                    102:        (P)->v=frdi_uint1(F), \
                    103:        (ferror(F)? -errno: 1) ) )
                    104: 
                    105: /* Convert variant no. to ASCII character, and vice versa */
                    106: #define vtoc(V) (((V)<=9)?('0'+(V)):(((V)<=35)?('a'+((V)-10)):('A'+((V)-36))))
                    107: #define ctov(C) ((((C)>='0')&&((C)<='9'))?((C)-'0'):((((C)>='a')&&((C)<='z'))?(10+((C)-'a')):(36+((C)-'A'))))
                    108: 
                    109: /* parametric values: */
                    110: #define Pval float
                    111: /* machine-independent I/O:  precision 0.0001 & range [-838.8608,838.8607] */
                    112: #define fwri_Pval(F,V) fwri_int4((F),(V)*1000.0)
                    113: #define frdi_Pval(F) (frdi_int4(F)/1000.0)
                    114: 
                    115: typedef struct {       /* parametric point */
                    116:        Pval x;
                    117:        Pval y;
                    118:        } Pp;
                    119: 
                    120: #define Init_Zero_Pp {0.0,0.0}
                    121: #if MAIN
                    122: Pp zero_Pp = Init_Zero_Pp;
                    123: #else
                    124: extern Pp zero_Pp;
                    125: #endif
                    126: 
                    127: #define fwri_Pp(F,P) { fwri_Pval((F),(P)->x); fwri_Pval((F),(P)->y); }
                    128: #define frdi_Pp(F,P) ( feof(F)? 0: ( \
                    129:        (P)->x=frdi_Pval(F), \
                    130:        (P)->y=frdi_Pval(F), \
                    131:        (ferror(F)? -errno: 1) ) )
                    132: 
                    133: /* metrics:  ABSS, EUCL, MAXV */
                    134: #define ABSS 'a'
                    135: #define EUCL 'e'
                    136: #define MAXV 'm'
                    137: typedef short Metric;
                    138: 
                    139: #define fwri_Metric(F,V) fwri_ch((F),(V))
                    140: #define frdi_Metric(F) (frdi_ch(F))
                    141: 
                    142: /* a vectorized blob file is a sequence of blob-descriptions.
                    143:    a blob-description is a sequence of "vector" records; there are two
                    144:    types of blob descriptions:
                    145:        DOT:
                    146:                'D'-vector (with bounding box)
                    147:        CHAR:
                    148:                'C'-vector, followed by:
                    149:                        one 'B'-vector (bounding-box), and
                    150:                        any number of: 'S' (stroke),
                    151:                                       'G' (edge),
                    152:                                       'O' (hole),
                    153:                                       'A' (arc),
                    154:                                       'C' (corner),
                    155:                                       'P' (end-point), and
                    156:                                       'V' & 'W' (boundary angles - 1 each),
                    157:                        and terminated with one 'E' vector (giving classname)
                    158:    */
                    159: 
                    160: #define Vrec_len 5
                    161: typedef short Vrec[Vrec_len];
                    162:    
                    163: /* subshape values */
                    164: /* #define U 0     uninitialized */
                    165: #define NA (SHRT_MAX)  /* deliberately not-assigned (classifier failure) */
                    166: 
                    167: #define Dim short      /* specifies dimension 1,..,MaxDim */
                    168: #define MaxDim 4
                    169: 
                    170: #define fwri_Dim(F,V) fwri_uint1((F),(V))
                    171: #define frdi_Dim(F) (frdi_uint1(F))
                    172: 
                    173: #define Seq int                /* sequence nos;  indices into tables */
                    174: #define FISeq 0                /* first value */
                    175: #define NLSeq -1       /* conventional NULL value */
                    176: #define S1Seq 0200000000  /* special bit 1 of Seq */
                    177: #define S2Seq 0100000000  /* special bit 2 of Seq */
                    178: #define NSSeq 0077777777  /* non-special bits */
                    179: 
                    180: #define fwri_Seq(F,V) fwri_int4((F),(V))
                    181: #define frdi_Seq(F) (frdi_int4(F))
                    182: 
                    183: typedef short Liv;     /* limit value: scaled and truncated from floating-pt */
                    184: #define Liv_MAX (SHRT_MAX)
                    185: #define Liv_MIN (SHRT_MIN)
                    186: 
                    187: #define fwri_Liv(F,V) fwri_int2((F),(V))
                    188: #define frdi_Liv(F) (frdi_int2(F))
                    189: 
                    190: typedef short Lit;     /* limit type, two flavors: */
                    191: #define MN 0           /*      min:  MN < v */
                    192: #define MX 1           /*      max:  v <= MX */
                    193: 
                    194: typedef Liv Ivl[2];    /* interval:  ( Ivl[MN], Ivl[MX] ] */
                    195: 
                    196: typedef Ivl Rec[MaxDim];   /* rectangular parallelopiped of limits in DIM-space */
                    197: 
                    198: /* a normalized blob file is a sequence of:
                    199:        Nb_h    header, followed by Nb_h.ss of:
                    200:                Nb_s    contour shapes */
                    201: typedef struct {
                    202:        ClassId ci;     /* class name */
                    203:        Bbx bb;         /* bounding box */
                    204:        Pval rsz;       /* raw character size (Ems) */
                    205:        Pval bht;       /* height-above-baseline (Ems) */
                    206:        Pval rwd;       /* width (Ems) */
                    207:        Pval rar;       /* area (square-Ems) */
                    208:        Pval rpe;       /* perimiter (Ems) */
                    209:        Pval asp;       /* aspect ratio (h/w) */
                    210:        Pval blk;       /* fraction of Bbx area that is black */
                    211:        Pval per;       /* perimeter of blob as multiple of Bbx perim */
                    212:        Pval gale;      /* Gale's feature:  incl. angle 'tween 2 longest sides */
                    213:        short ss;       /* no. of shapes to follow */
                    214:        } Nb_h;
                    215: 
                    216: #define MAX_SHAPES_EACH        1024    /* Max no. shapes per Blob/Char/item */
                    217: 
                    218: /* Shape is tiny (below threshold, may be pruned):  a flag ORed into shape type */
                    219: #define Sh_tiny (0x80)
                    220: 
                    221: /* Shape types: */
                    222: #define U 0    /* uninitialized */
                    223: #define Sh_FI 1        /* first shape no. */
                    224: #define Sh_B 1 /* blob (connected black region) */
                    225: #define Sh_H 2 /* hole (connected white region) */
                    226: #define Sh_S 3 /* stroke (undirected line-segment) */
                    227: #define Sh_E 4 /* edge (directed line-segment along boundary) */
                    228: #define Sh_C 5  /* concavity (intrusion from convex hull): its `cover' edge */
                    229: #define Sh_D 6  /* direction and depth of concavity */
                    230: #define Sh_A 7 /* locally-maximal convex arc (encloses black) */
                    231: #define Sh_V 8  /* locally-maximal concave arc (encloses white) */
                    232: #define Sh_P 9 /* endpoint (0-junction) */
                    233: #define Sh_T 10        /* detail (left- and right-facing ticks) */
                    234: #define Sh_X 11 /* crossing (X) */
                    235: #define Sh_Y 12 /* global scalar variables, combined */
                    236: #define Sh_Z 13 /* more global scalar variables, combined */
                    237: #define Sh_LA 13 /* last of variable-no-of-occurences shape-types */
                    238: #define Sh_MNY (Sh_LA+1)
                    239: #define SHS_MNY (Sh_MNY)
                    240: 
                    241: #if (MAIN)
                    242:        /* shape-names, given shape-type */
                    243:        char Sh_nam[SHS_MNY] =
                    244:        {'U', 'B', 'H', 'S', 'E', 'C', 'D', 'A', 'V', 'P', 'T', 'X', 'Y', 'Z'};
                    245:        /* "dimension" -- no parameters in normalized form */
                    246:        short Sh_dim[SHS_MNY] =
                    247:        { 0,   3,   3,   4,   4,   4,   4,   4,   4,   4,   3,   2,   3,   1};
                    248:        /* absolute minimum parametric values possible -- must be >= -1.0
                    249:           (see norm.c & fiodict.c) */
                    250:        Pval Sh_MN[SHS_MNY][MaxDim]
                    251:                   = { { 0.0,  0.0,  0.0,  0.0},        /* U */
                    252:                       {-0.5, -0.5, -0.5/*see mkd*/},   /* B */
                    253:                       {-0.5, -0.5, -0.5/*see mkd*/},   /* H */
                    254:                       {-0.5, -0.5, -0.5, -0.5},        /* S */
                    255:                       {-0.5, -0.5, -0.5, -0.5},        /* E */
                    256:                       {-0.5, -0.5, -0.5, -0.5},        /* C */
                    257:                       {-0.5, -0.5, -0.5, -0.5},        /* D */
                    258:                       {-0.5, -0.5, -0.5, -0.5},        /* A */
                    259:                       {-0.5, -0.5, -0.5, -0.5},        /* V */
                    260:                       {-0.5, -0.5, -0.5, -0.5},        /* P */
                    261:                       {-0.5, -0.5, -0.5},              /* T */
                    262:                       {-0.5, -0.5},                    /* X */
                    263:                       {-0.5, -0.5, -0.5},              /* Y */
                    264:                       {-0.5}                           /* Z */
                    265:                         };
                    266:        /* absolute maximum parametric value possible -- must be <= 1.0
                    267:           (see norm.c & fiodict.c) */
                    268:        Pval Sh_MX[SHS_MNY][MaxDim]
                    269:                   = { { 0.0,  0.0,  0.0,  0.0},        /* U */
                    270:                       {0.5, 0.5, 1.0/*see mkd*/},      /* B */
                    271:                       {0.5, 0.5, 1.0/*see mkd*/},      /* H */
                    272:                       {0.5, 0.5, 0.5, 0.5},            /* S */
                    273:                       {0.5, 0.5, 0.5, 0.5},            /* E */
                    274:                       {0.5, 0.5, 0.5, 0.5},            /* C */
                    275:                       {0.5, 0.5, 0.5, 0.5},            /* D */
                    276:                       {0.5, 0.5, 0.5, 0.5},            /* A */
                    277:                       {0.5, 0.5, 0.5, 0.5},            /* V */
                    278:                       {0.5, 0.5, 0.5, 0.5},            /* P */
                    279:                       {0.5, 0.5, 0.5},                 /* T */
                    280:                       {0.5, 0.5},                      /* X */
                    281:                       {0.5, 0.5, 0.5},                 /* Y */
                    282:                       {0.5}                            /* Z */
                    283:                         };
                    284:        /* minimum magnitude of (r,i) part of certain shapes */
                    285:        Pval A_ri_minmag = 0.25;
                    286:        Pval P_ri_minmag = 0.25;
                    287: #else
                    288:        extern char Sh_nam[];
                    289:        extern short Sh_dim[];
                    290:        extern Pval Sh_MN[][MaxDim];
                    291:        extern Pval Sh_MX[][MaxDim];
                    292:        extern Pval A_ri_minmag;
                    293:        extern Pval P_ri_minmag;
                    294: #endif
                    295: 
                    296: #define MIN_SD 0.001   /* minimum std-dev permitted */
                    297: 
                    298: typedef Pval Spar[MaxDim];     /* shape parameters */
                    299: 
                    300: typedef struct Nb_s {
                    301:        short t;        /* shape type: one of U S O A C etc, perhaps |Sh_tiny */
                    302:        Spar p;         /* parametric values */
                    303:        } Nb_s;
                    304: 
                    305: /* indices into parametric values */
                    306: /* blobs */
                    307: #define B_x 0  /* (x,y) location of dot wrt bounding-box */
                    308: #define B_y 1
                    309: #define B_r 2  /* size of dot */
                    310: /* holes */
                    311: #define H_x 0  /* (x,y) location of center wrt bounding-box */
                    312: #define H_y 1
                    313: #define H_r 2  /* size of hole */
                    314: /* strokes */
                    315: #define S_x 0  /* (x,y) location of stroke center wrt bounding box */
                    316: #define S_y 1
                    317: #define S_r 2  /* (r,i) real-imag parts of rotation-length vector; */
                    318: #define S_i 3   /*   rotation angle *2 since strokes have only [0,PI] range */
                    319: /* edges */
                    320: #define E_x 0  /* (x,y) location of edge center wrt bounding box */
                    321: #define E_y 1
                    322: #define E_r 2  /* (r,i) real-imag parts of direction-length vector */
                    323: #define E_i 3 
                    324: /* concavity hull edge */
                    325: #define C_x 0  /* (x,y) location of center of hull-bdy edge wrt bounding-box */
                    326: #define C_y 1
                    327: #define C_r 2  /* (r,i) real-imag parts of hull-bdy edge */
                    328: #define C_i 3
                    329: /* concavity depth & direction */
                    330: #define D_x 0  /* (x,y) location of center of depth & direction vector */
                    331: #define D_y 1
                    332: #define D_r 2  /* (r,i) real-imag parts of depth & direction vector */
                    333: #define D_i 3
                    334: /* locally-maximal convex arc */
                    335: #define A_x 0  /* (x,y) location of center of enclosed area */
                    336: #define A_y 1
                    337: #define A_r 2  /* (r,i) real-imag parts of `incompleteness' vector */
                    338: #define A_i 3
                    339: /* locally-maximal concave arc */
                    340: #define V_x 0  /* (x,y) location of center of enclosed area */
                    341: #define V_y 1
                    342: #define V_r 2  /* (r,i) real-imag parts of `incompleteness' vector */
                    343: #define V_i 3
                    344: /* endpoint */
                    345: #define P_x 0  /* (x,y) location of center of hull-bdy wrt bounding-box */
                    346: #define P_y 1
                    347: #define P_r 2  /* (r,i) real-imag parts of direction-depth vector */
                    348: #define P_i 3
                    349: /* ticks:  left-, right-, top-, & bottom-facing extrema near ends */
                    350: #define T_x 0  /* signed distance from centroid along principal axis */
                    351: #define T_y 1  /* signed perpendicular distance from axis */
                    352: #define T_a 2  /* angle of principal axis, within worst-case range */
                    353: /* crossings */
                    354: #define X_x 0  /* (x,y) location of crossing wrt bounding-box */
                    355: #define X_y 1
                    356: /* global scalars, combined */
                    357: #define Y_a 0  /* log(aspect_ratio=hgt/wid) */
                    358: #define Y_b 1  /* ratio of area to bbx_area */
                    359: #define Y_p 2  /* ratio of perimeter to bbx_perimeter */
                    360: /* global scalars, combined (more) */
                    361: #define Z_g 0  /* Gale's feature: included angle between two longest bdy edges */
                    362: 
                    363: /* scalar features field indices */
                    364: #define SF_RSZ 0       /* relative size (height in ems) */
                    365: #define SF_BHT 1       /* height above baseline (ems) */
                    366: #define SF_RWD 2       /* relative width (ems) */
                    367: #define SF_RAR 3       /* relative area (square-ems) */
                    368: #define SF_RPE 4       /* relative perimeter (ems) */
                    369: #define SF_ASP 5       /* aspect-ratio */
                    370: #define SF_BLK 6       /* fraction of Bbx that is black */
                    371: #define SF_PER 7       /* ratio of perimeter to BBx per */
                    372: #define SF_GALE 8      /* Gale's feature: incl. ang. between 2 longest edges */
                    373: #define SF_N 8         /* index of last var that's not an occurrence-count */
                    374: #define SF_MNY (SF_N+Sh_LA+1)
                    375: 
                    376: #if MAIN
                    377:        /* ``Is this feature available early enough to be used in fast scalar-
                    378:           feature preclassifier?'' (Must not depend on shape analysis.) */
                    379:        boolean SFfeature[SF_MNY] = {
                    380:                F, F, F, F, F, T, T, T, F,
                    381:                T, T, T, T, T, T, T, T, T, T, T, F, F };
                    382:        /* ``Is this feature discrete (integer-valued)?'' (Affects construction
                    383:           of scalar-decision tree preclassifier.) */
                    384:        boolean SFdiscrete[SF_MNY] = {
                    385:                F, F, F, F, F, F, F, F, F,
                    386:                T, T, T, T, T, T, T, T, T, T, T, T, T };
                    387: #else
                    388:        extern boolean SFfeature[];
                    389:        extern boolean SFdiscrete[];
                    390: #endif
                    391: 
                    392: typedef Pval SFv[SF_MNY];
                    393: 
                    394: /* blob tracer (boundary angles) features field indices */
                    395: #define TR_MNY 8
                    396: 
                    397: typedef Pval TRv[TR_MNY];
                    398: 
                    399: /* tracer decision-tree header */
                    400: typedef struct TRtr {
                    401:        struct SFdnode *TRd;    /* array of decision-nodes */
                    402:        struct Cl ***clist;     /* list of (class-ptr)-lists */
                    403:        } TRtr;
                    404: 
                    405: /* Ss - sub-shape list-item */
                    406: typedef struct Ss {
                    407:        Seq seq;        /* globally unique sequence no */
                    408:        Seq shs;        /* shape-hdr seq no */
                    409:        Seq cls;        /* class sequence no */
                    410:        short no;       /* sub-shape number (0,1,2..., NA) */
                    411:        float focc;     /* fraction of training set w/ >=1 occurrence */
                    412:        float fdup;     /* fraction of training set w/ >=2 occurrence */
                    413:        Spar me;        /* mean parameters */
                    414:        Spar sd;        /* std-dev parameters */
                    415:        Spar min;       /* min limits (for fast checking) */
                    416:        Spar max;       /* max limits (for fast checking) */
                    417:        Rec r;          /* rectangular parallelopiped in Liv space */
                    418:        Pval fr;        /* fraction of training set covered */
                    419:        short nuse;     /* for current blob, no. uses */
                    420:        float nocc;     /* occurrences: no. blobs with >=1 of these */
                    421:        float ndup;     /* duplicates: no. blobs with >=2 of these */
                    422:        float mind;     /* minimum scaled distance from cluster among uses */
                    423:        float merit;    /* merit score resulting from 'nuse' matches to this */
                    424:        struct Ss *ne;  /* ptr to next in list */
                    425:        } Ss;
                    426: 
                    427: #define MAX_SS 8192    /* see 'kdt.h' for reasons */
                    428: 
                    429: /* BMask:  1-d, variable-length packed bitstring (N = no. bits).  The string
                    430:    is stored in an array of (unsigned int).  It is often accessed via a fast
                    431:    ascending sequence of 'short' pointers (unsigned short *) or (unsigned char *):
                    432:    in these cases, enough are used to completely cover all the (unsigned int)s,
                    433:    even though that may be more than enough, to ensure that the result is
                    434:    insensitive to machine-dependent short-order-in-ints and char-order-in-shorts.
                    435:       BMask_ni(N)    no. unsigned ints holding bit-data
                    436:       BMask_si(N)    no. unsigned shorts covering bit-data (exactly 2x _ni)
                    437:       BMask_ci(N)    no. unsigned chars covering bit-data (exactly 4x _ni)
                    438:       BMask_size(N)  total no. bytes in, or pointed to by BMask:
                    439:                        sizeof(n) + sizeof(mny) + sizeof(r) + sizeof(malloc space) 
                    440:       */
                    441: #define BMask_ni(N) (((N)+(8*sizeof(unsigned int))-1)/(8*sizeof(unsigned int)))
                    442: #define BMask_si(N) (2*BMask_ni(N))
                    443: #define BMask_ci(N) (4*BMask_ni(N))
                    444: #define BMask_size(N) (3*sizeof(unsigned int)+(BMask_ci((N))))
                    445: 
                    446: typedef struct BMask {
                    447:        unsigned int n;                 /* no. of bits stored (==N above) */
                    448:        unsigned int mny;               /* no. bits set to 1 */
                    449:        unsigned int r;                 /* represents `r' BMasks altogether */
                    450:        union { /* packed bits: 0th bit is 01 */
                    451:                unsigned int *i;        /* malloc space: int [Bmask_ni] */
                    452:                unsigned short *s;      /* malloc space: short [Bmask_si] */
                    453:                int ii;                 /* index into (unsigned int)[] array */
                    454:                int si;                 /* index into (unsigned short)[] array */
                    455:                } u;
                    456:        } BMask;
                    457: 
                    458: #define Init_BMask {0,0,0,}
                    459: #if MAIN
                    460:        BMask empty_BMask = Init_BMask;
                    461: #else
                    462:        extern BMask empty_BMask;
                    463: #endif
                    464: 
                    465: 
                    466: typedef struct BMasks {
                    467:        unsigned short mny;     /* no. BMasks */
                    468:        unsigned short r;       /* represents `r' BMasks altogether */
                    469:        unsigned short shallow; /* 0 <= shallow <= mny */
                    470:        unsigned short alloc;   /* no. items allocated in .a[] */
                    471:        union { BMask *a;       /* array[mny] of BMasks */
                    472:                int bi;         /* index into (BMask)[] array */
                    473:                } u;
                    474:        } BMasks;
                    475: 
                    476: #define Init_BMasks {0,0,0,0,}
                    477: #if MAIN
                    478:        BMasks empty_BMasks = Init_BMasks;
                    479: #else
                    480:        extern empty_BMasks;
                    481: #endif
                    482: 
                    483: /* Sh - shape list-item */
                    484: typedef struct Sh {
                    485:        Seq seq;        /* unique sequence no. */
                    486:        short t;        /* shape type: S, H, X, etc */
                    487:        short nss;      /* no. sub-shapes in the list */
                    488:        float mess;     /* mean no. sub-shapes in training set */
                    489:        float sdss;     /* std-dev of sub-shapes in training set */
                    490:        float NAocc;    /* prob at least one shape not-assigned */
                    491:        float NAdup;    /* prob more than one not-assigned */
                    492:        Ss NAss;        /* "not-assigned" data */
                    493:        Ss *fi;         /* first sub-shape  */
                    494:        Ss *la;         /* last sub-shape */
                    495:        struct Sh *ne;  /* next shape */
                    496:        } Sh;
                    497: 
                    498: /* Cl - class list-item */
                    499: typedef struct Cl {
                    500:        Seq seq;        /* unique sequence no. 0,1,... */
                    501:        Cln c;          /* class name */
                    502:        float shNA;     /* fraction of shapes unassigned */
                    503:        float blDP;     /* fraction of blobs w/ >=1 duplicate shape-match*/
                    504:        float blAL;     /* average extra alternate shape-matches / blob */
                    505:        SFv sf_me;      /* scalar-features:  means, std-devs */
                    506:        SFv sf_sd;
                    507:        BMask bm;       /* canonical BMask */
                    508:        BMasks bms;     /* additional representative BMask records */
                    509:        Sh *sha[Sh_MNY];        /* table of pointers to shape-types */
                    510:        Sh *fi;                 /* first owned shape */
                    511:        Sh *la;                 /* last owned shape */
                    512:        short unmat[Sh_MNY];    /* counts of unmatched shapes/shape-type */
                    513:        struct Ssm *ssmfi;      /* first sub-shape match for this class */
                    514:        TRtr *tr;               /* pointer to tracer decision tree (if any) */
                    515:        TRv tr_me;              /* tracer-features:  means, std-devs */
                    516:        TRv tr_sd;
                    517:        float m_me;             /* mean, std-err of merit (in training set) */
                    518:        float m_sd;
                    519:        float bayes;    /* Bayesian merit: a posteriori log-probability */
                    520:        Merit m01;      /* Haming, etc. merit in range [0,1] */
                    521:        Merit merit;    /* sort and truncate based on this merit */
                    522:        short pass;     /* the last classification method this class passed */
                    523:        int ch_mny;     /* No. Chars of this class in a subset */
                    524:        int ss_mny;     /* No. Chars with given feature */
                    525:        boolean force_reseg;    /* forcibly resegment Chars of this Class */
                    526:        struct Cl *ne;  /* next class */
                    527:        } Cl;
                    528: 
                    529: /* MAX_CL (max no. of classes) is defined in CPU.h */
                    530: #define MAX_SH (MAX_CL*SH_MNY)
                    531: 
                    532: typedef struct Classes {
                    533:        int mny;        /* number of items in array */
                    534:        Cl **clpa;      /* Cl *clpa[cl_mny+1]: NULL-term'd array of ptrs */
                    535:        } Classes;
                    536: #define Init_Classes {0,NULL}
                    537: #if MAIN
                    538: Classes empty_Classes = Init_Classes;
                    539: #else
                    540: extern Classes empty_Classes;
                    541: #endif
                    542: 
                    543: typedef struct Ssm {   /* sub-shape match record */
                    544:        Seq isn;        /* input shape sequence no (w/in blob) */
                    545:        Cl *clp;        /* owning class, shape, sub-shape... */
                    546:        Sh *shp;
                    547:        Ss *ssp;
                    548:        float mind;     /* distance to closest assigned sub-shape */
                    549:        boolean alt;    /* T if this is an alternative (not the first) */
                    550:        struct Ssm *ne; /* next, prior ptrs in list */
                    551:        struct Ssm *pr;
                    552:        } Ssm;
                    553: 
                    554: /* return pathname of OCR directory; if environment variable OCRDIR
                    555:    is set, it is used; otherwise #defined variable OCRDIR is used. */
                    556: #if MAIN
                    557: char *getenv();
                    558: char *ocrdir()
                    559: {   char *ocrdir_ev;
                    560:        if((ocrdir_ev=getenv("OCRDIR"))!=NULL) {
                    561:                return(ocrdir_ev);
                    562:                }
                    563:        else return(OCRDIR);
                    564:        }
                    565: #else
                    566: char *ocrdir();
                    567: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.