00001 #ifndef BOUNDARY_H
00002 #define BOUNDARY_H 1
00003
00004 #include "project_utilities.h"
00005
00006 BEGIN_C_DECLARATIONS
00007
00011 #define INIT_LEN 512
00012
00017 #define NOT_AN_ANGLE -HUGE_VAL
00018 #define NOT_A_WIDTH -HUGE_VAL
00019
00023 #define TINY (1e-16)
00024
00028 #define MISSING_BRIGHTNESS DARKNESS
00029
00035 #define MID_GRAY ((PIXEL)127.0)
00036
00040 #define NCOEFF 4
00041
00045 #define NPOINTS 4
00046
00050 #define MAX_BOUND_ANGLE (0.45*M_PI)
00051
00055 #define SEARCH_TOLERANCE 0.35
00056
00060 #define MATCH_TOLERANCE 0.125
00061
00065 #define MEASURE_TOLERANCE 0.083333333
00066
00070 #define SRADIUS 5
00071 #define SDIAMETER (2*SRADIUS+1)
00072
00077 #define SUBIMAGE_MARGIN_FRACTION 0.125
00078
00079
00080
00081
00082
00090 #define mosaic_point(M,I,R,C) (M->data[0][R - I->voffset[C]][C])
00091
00100 #define project_on_principal_axis(P,A,X,Y,Z) X = P->xpos - A->centroid.xpos; \
00101 Y = P->ypos - A->centroid.ypos; \
00102 Z = Y*cos(A->centroid.theta) + X*sin(A->centroid.theta)
00103
00119 #define rb_balance(U,D) tmp = sub->parent->parent->D; \
00120 if((tmp!=NULL) &&(tmp->rbcolor==red) ) \
00121 { \
00122 sub->parent->rbcolor = black; \
00123 tmp->rbcolor = black; \
00124 sub->parent->parent->rbcolor = red; \
00125 sub = sub->parent->parent; \
00126 } \
00127 else \
00128 { \
00129 if (sub == sub->parent->D) \
00130 { \
00131 sub = sub->parent; \
00132 rb_rotate_##U (root,sub) ; \
00133 } \
00134 sub->parent->rbcolor = black; \
00135 sub->parent->parent->rbcolor = red; \
00136 rb_rotate_##D (root, sub->parent->parent) ; \
00137 } \
00138
00139
00153 #define make_rotator(U,D) static void \
00154 rb_rotate_##U (RBNODE**root, RBNODE*sub) \
00155 { \
00156 RBNODE * tmp; \
00157 tmp = sub->D; \
00158 sub->D = tmp->U; \
00159 if(tmp->U != NULL) \
00160 tmp->U->parent = sub; \
00161 tmp->parent = sub->parent; \
00162 if(sub == *root) \
00163 { \
00164 *root = tmp; \
00165 } \
00166 else if (sub == sub->parent->U) \
00167 { \
00168 sub->parent->U = tmp; \
00169 } \
00170 else \
00171 { \
00172 sub->parent->D = tmp; \
00173 } \
00174 tmp->U = sub; \
00175 sub->parent = tmp; \
00176 } \
00177
00178
00181 typedef struct
00182 {
00183 double minx;
00184 double miny;
00185 double maxx;
00186 double maxy;
00187 } RECTANGLE;
00188
00192 typedef struct boundpoint
00193 {
00194 double xpos;
00195 double ypos;
00196 double theta;
00197 int valid;
00198 struct boundpoint *next;
00199 } BOUNDPOINT;
00200
00201 typedef enum
00202 { red = 0, black = 1 } rbcolortype;
00203
00204 typedef struct rbnode
00205 {
00206 rbcolortype rbcolor;
00207 double key;
00208 BOUNDPOINT *point;
00209 struct rbnode *parent;
00210 struct rbnode *left;
00211 struct rbnode *right;
00212 } RBNODE;
00213
00214 typedef struct
00215 {
00216 RECTANGLE enclosure;
00217 BOUNDPOINT centroid;
00218 BOUNDPOINT *points;
00219 BOUNDPOINT *endpoint;
00220 RBNODE *point_index;
00221 int stale;
00222 } BOUNDER;
00223
00224 typedef struct
00225 {
00226 double *d;
00227 int n;
00228 int block;
00229 } WIDTHS;
00230
00231 typedef struct
00232 {
00233 long double xsum;
00234 long double xsumsq;
00235 long double ysum;
00236 long double ysumsq;
00237 long double prodsum;
00238 int n;
00239 } SUMSTATE;
00240
00241 typedef struct imagecontext
00242 {
00243 void *image;
00244 void *imageindex;
00245 double (*accessor) (double, double, struct imagecontext *);
00246 } IMAGE_CONTEXT;
00247
00248 #define image_access(X,Y,I) (I->accessor(X, Y, I))
00249
00250 typedef struct boundarycontext
00251 {
00252 void *points;
00253 int hasnext;
00254 int prevx;
00255 int prevy;
00256 double xpos;
00257 double ypos;
00258 int valid;
00259 int nterms;
00260 double *xc;
00261 double *yc;
00262 struct boundarycontext *(*iterator) (struct boundarycontext *);
00263 } BOUNDARY_CONTEXT;
00264
00265 #define iterate(B) (B = B->iterator(B))
00266
00267 double find_width (BOUNDER * in, BOUNDER * out, IMAGE_CONTEXT * mosaic,
00268 PROFILE_LIST * last_ringprofile);
00269
00270 BOUNDER * make_boundary (BOUNDARY_CONTEXT * bcon);
00271
00272 void discard_boundary (BOUNDER * bound);
00273
00274 void initialize_mosaic_context (IMAGE_BYTE * im, MOSAIC_INDEX * imindex,
00275 IMAGE_CONTEXT * newcontext);
00276
00277 void initialize_chaincode_context (LIST_NODE * chain_boundary,
00278 BOUNDARY_CONTEXT * newcontext);
00279
00280 void initialize_image_context (IMAGE * im, IMAGE_CONTEXT * newcontext);
00281
00282 void build_index (BOUNDER * bound);
00283
00284 void demolish_index (RBNODE * ix);
00285
00286 END_C_DECLARATIONS
00287
00288 #endif