#include <math.h>
#include "junkmath.h"
#include "sadie_byte.h"
#include "sadie_short.h"
#include "chain.h"
#include "mosaic.h"
#include "trees_profile.h"
#include <stdio.h>
Compounds  
struct  boundarycontext 
struct  BOUNDER 
struct  boundpoint 
A point in a temporary temporary ring boundary representation. More...  
struct  imagecontext 
struct  rbnode 
struct  RECTANGLE 
A rectangle aligned with the x and y axes. More...  
struct  SUMSTATE 
struct  WIDTHS 
Defines  
#define  crashandburn(e) {fprintf(stderr,"Panic: %s!\n",e) ;exit(2) ;} \ 
Stopgap error handler.  
#define  INIT_LEN 512 
Initial size of the extensible ring width array.  
#define  NOT_AN_ANGLE HUGE_VAL 
Missing boundary angles and ring widths.  
#define  TINY (1e16) 
Threshold for judging the equality of angles and distances.  
#define  MISSING_BRIGHTNESS DARKNESS 
Missing brightness profile value (which may also be a data value).  
#define  MID_GRAY ((PIXEL)127.0) 
Median of range of possible brightness values.  
#define  NCOEFF 4 
Number of polynomial coefficients to derive temporary warped subimages.  
#define  NPOINTS 4 
Number of control points used to derive temporary warped subimages.  
#define  MAX_BOUND_ANGLE (0.45*M_PI) 
Maximum allowed difference between boundary angles from different methods.  
#define  SEARCH_TOLERANCE 0.35 
Angular interval within which to search for points on a boundary.  
#define  MATCH_TOLERANCE 0.125 
Tolerance for accepting the angles associated with points as equal.  
#define  MEASURE_TOLERANCE 0.083333333 
Match the angles associated with points to the line connecting them.  
#define  SRADIUS 5 
Number of points defining local neighborhoods on boundaries.  
#define  SUBIMAGE_MARGIN_FRACTION 0.125 
Fractional size of the margin at the edge of the warped subimage.  
#define  mosaic_point(M, I, R, C) (M>data[0][R  I>voffset[C]][C]) 
Accesses a point in a mosaic image through its index.  
#define  project_on_principal_axis(P, A, X, Y, Z) 
Projects a point onto the principal axis of a boundary.  
#define  rb_balance(U, D) 
Help rebalance a redblack tree.  
#define  make_rotator(U, D) 
Generates either of the two noderotation functions for a redblack tree.  
Typedefs  
typedef boundpoint  BOUNDPOINT 
A point in a temporary temporary ring boundary representation. 
We're assuming that all the previous phases of TREES are complete: that it has acquired images, assembled them into a mosaic, and identified the ring boundaries. This has one interface visible to the rest of TREES, the function CHAIN_RINGWIDTHS,

Stopgap error handler. This doesn't just abort the functions defined in this file, or the thread running them, but the entire process running TREES. 

Value: static void \ rb_rotate_##U (RBNODE**root, RBNODE*sub) \ { \ RBNODE * tmp; \ tmp = sub>D; \ sub>D = tmp>U; \ if(tmp>U != NULL) \ tmp>U>parent = sub; \ tmp>parent = sub>parent; \ if(sub == *root) \ { \ *root = tmp; \ } \ else if (sub == sub>parent>U) \ { \ sub>parent>U = tmp; \ } \ else \ { \ sub>parent>D = tmp; \ } \ tmp>U = sub; \ sub>parent = tmp; \ } \ The two rotations are completely symmetrical, except that the roles of right and left nodes are interchanged, so this macro is a code template for generating either a right or a left rotation (note that the function names are part of what's substituted). A rotation essentially operates on a group of three nodes, initially at three different levels in the tree. Two of the nodes move closer to the root, one in the opposite direction, so we end up with just two levels after the transformation.


Median of range of possible brightness values. This assumes an 8bit grayscale, and should really be an imagespecific variable. 

Accesses a point in a mosaic image through its index.


Missing boundary angles and ring widths. The values are outside the range possible for actual data. 

Value: X = P>xpos  A>centroid.xpos; \ Y = P>ypos  A>centroid.ypos; \ Z = Y*cos(A>centroid.theta) + X*sin(A>centroid.theta)


Value: tmp = sub>parent>parent>D; \ if((tmp!=NULL) &&(tmp>rbcolor==red) ) \ { \ sub>parent>rbcolor = black; \ tmp>rbcolor = black; \ sub>parent>parent>rbcolor = red; \ sub = sub>parent>parent; \ } \ else \ { \ if (sub == sub>parent>D) \ { \ sub = sub>parent; \ rb_rotate_##U (root,sub) ; \ } \ sub>parent>rbcolor = black; \ sub>parent>parent>rbcolor = red; \ rb_rotate_##D (root, sub>parent>parent) ; \ } \ Rebalancing involves two operations that are completely symmetrical, except that the roles of left and right links are interchanged, so this macro can generate the code for either operation. Rebalancing depends on the parent of the parent of the node being considerd, and the adjustment may be a simple recoloring of nodes, or it may involve changing their relative positions (with the current node moving closer to the root), in which case we distinguish two subcases, depending on whether the current node and its immediate parent change places, before it changes levels.
