src/defs.h

00001 
00002 
00003 /* defs.h -- commonly used defines for the Crystal Image application */
00004 
00005 
00006 #ifndef __IMAGER_DEFS_H
00007 #define __IMAGER_DEFS_H
00008 
00009 
00010 #include <gtk/gtk.h>
00011 #include <gdk_imlib.h>
00012 #include <gdk/gdk.h>
00013 
00014 #include <sys/types.h>
00015 
00016 
00017 
00018 /* If we want to use the DICOM code, define the following symbol: */
00019 
00020 #define _DICOM_
00021 #define MAXPOINTSONARAY 600
00022 
00023 
00024 
00025 /* The only non-standard element is the RGB triplet */
00026 
00027 typedef struct
00028 {
00029         unsigned char red;
00030         unsigned char green;
00031         unsigned char blue;
00032 }
00033 rgbtriplet;
00034 
00035 /* HSV gets a nice struct as well */
00036 
00037 typedef struct
00038 {
00039         short hue;                              /* Range may be -359 to +359 */
00040         unsigned char sat;
00041         unsigned char val;
00042 }
00043 hsvtriplet;
00044 
00045 
00046 /* The result of a lsq fit */
00047 
00048 
00049 typedef struct
00050 {
00051         double H;
00052         double intcpt;
00053         double r;
00054 }
00055 fitresult;
00056 
00057 
00058 
00059 /*
00060         The buffer may be any of the following types: char (8-bit unsigned), short
00061         (16-bit signed), RGB (24-bit coded as 3 chars for each R,G,B), float (23
00062         bit)
00063 */
00064 
00065 typedef enum { B_CHAR, B_SHORT, B_RGB, B_FLOAT } TYPE_SELECTOR;
00066 
00067 
00068 /* Interpolation may be performed using the following methods: */
00069 
00070 typedef enum { INTP_NN, INTP_BILIN, INTP_BICUB, 
00071                                 INTP_SPLINE2, INTP_SPLINE3, INTP_SPLINE4, INTP_SPLINE5 } interpol_method;
00072 
00073 /*
00074         For morphological operations, we define the operations here
00075 */
00076 
00077 typedef enum { M_BYPASS, M_PATCH, M_ERODE, M_SOFTERODE, M_RANK, M_SOFTDILATE, M_DILATE, M_BOUNDERODE } MORPHOP;
00078 
00079 
00080 /*
00081         We have two undo options - stack in memory or on disk 
00082 */
00083 
00084 typedef enum { U_NONE, U_MEMORY, U_DISK } UNDO_TYPE;
00085 
00086 /*
00087         Enumerate file types that can be detected through the header
00088 */
00089 
00090 typedef enum { FTYPE_NONE, FTYPE_TIFFI, FTYPE_TIFFM, FTYPE_VSRT, FTYPE_VFLT, FTYPE_DCM, FTYPE_PGM, FTYPE_PPM } FTYPE;
00091 
00092 
00093 /* 
00094         A calibration wedge has the following parameters :
00095 */
00096 
00097 typedef struct
00098 {
00099         double Dmin;    /* Background intensity */
00100         double Dmax;    /* Maximum intensity */
00101         double Mu;              /* Attenuation factor */
00102         char calibrated; /* Set to 1 if valid calibration available */
00103 }
00104 wedge_data;
00105 
00106 
00107 
00108 /* This is our actual image structure. The structure contains the image
00109    dimensions in x,y,z; the image type (see enum above); the min and max values
00110    (float: use maxval.fmax; short and char: use maxval.imax; rgb: also use
00111    maxval.imax, but contains the max of the triplet); and finally a pointer to
00112    the data array
00113 */
00114 
00115 typedef struct 
00116 {
00117                 long xmax;
00118                 long ymax; 
00119                 long zmax;
00120                 TYPE_SELECTOR imgtype;
00121                 int uid;
00122                 union { int imax; float fmax; } maxval; /* for scaling purposes */
00123                 union { int imin; float fmin; } minval; /* handle char and int identical */
00124                 void* data;
00125 }
00126 image_type;
00127 
00128 
00129 
00130 /*
00131         Different methods of thresholding
00132 */
00133 
00134 typedef enum { TH_BINARY, TH_SOFT, TH_HARD, TH_SOFTSYM, TH_HARDSYM } THRESHOLD_TYPE;
00135 
00136 
00137 typedef struct
00138 {
00139         int r;
00140         int g;
00141         int b;
00142         float t;
00143         float u;
00144         THRESHOLD_TYPE thresh_type;
00145         char success;
00146         image_type* img;                /* Image to operate the threshold on */
00147 }
00148 thresh_struct;
00149 
00150 /* The following is used in the findcluster algorithms */
00151 
00152 typedef struct
00153 {
00154         int size;
00155         long cog_x;
00156         long cog_y;
00157         long cog_z;
00158         int bbox_x1;
00159         int bbox_y1;
00160         int bbox_z1;
00161         int bbox_x2;
00162         int bbox_y2;
00163         int bbox_z2;
00164         int size1;
00165         int size2;
00166         int flags;
00167         float compactness;      /* Compactness of cluster */
00168         float aspect;           /* Aspect ratio of cluster */
00169         float irreg;            /* Irregularity (cv) of boundary */
00170 } 
00171 cluster_type;
00172 
00173 
00174 typedef struct
00175 {
00176         int x;
00177         int y;
00178 }
00179 vertex;
00180 
00181 
00182 typedef struct
00183 {
00184         float x;
00185         float y;
00186 }
00187 vertexf;
00188 
00189 
00190 typedef struct
00191 {
00192         int x;
00193         int y;
00194         int z;
00195 }
00196 vertex3d;
00197 
00198 /* This type is primarily used in statistics/measure functions */
00199 
00200 typedef struct
00201 {
00202         long n;
00203         double Sx;
00204         double Sxx;
00205         double SxR, SxG, SxB, SxxR, SxxG, SxxB;
00206 }
00207 stat_type;
00208 
00209 
00210 
00211 #define ROI_MAXVERTICES 1000
00212 
00213 
00214 typedef enum { ROI_NONE, ROI_RECT, ROI_POLY, ROI_CIRCLE } roi_enum;
00215 
00216 
00217 typedef struct
00218 {
00219         roi_enum roi_mode; /* 0: no ROI; 1=rect; 2=polygon; 3=circular polygon */
00220         int bbox_x1;
00221         int bbox_x2;
00222         int bbox_y1;
00223         int bbox_y2;
00224         int numvertices;
00225         int radius,xc,yc;
00226         int xi[ROI_MAXVERTICES];        /* Wastes some memory and limits polygons to 1000 vertices */
00227         int yi[ROI_MAXVERTICES];        /* but makes life dramatically easier */
00228         int centfromspider_x;
00229         int centfromspider_y;
00230 }
00231 roi_type;
00232 
00233 
00234 /* This structure is used for the spider op segmentation and related algorithms */
00235 
00236 typedef struct  
00237 {
00238         float endpoints[2][2];
00239         int startx;
00240         int starty;
00241         int endx;
00242         int endy;
00243         int numPixels;          /* length of ray */
00244         int XPixelCoords[MAXPOINTSONARAY];
00245         int YPixelCoords[MAXPOINTSONARAY];
00246         float pixelValues[MAXPOINTSONARAY]; /* sampled gray values along ray trace */
00247         float vtxRadialPosition;
00248         int vtxXPixelCoord;       /* So these will change based on the edge detection mechanism */
00249         int vtxYPixelCoord;
00250         int maxXPixelCoord;       /* these hold the closest local maximum */
00251         int maxYPixelCoord;
00252         int vtxPixelIndex;
00253         int maxPixelIndex;
00254         float vtxPixelValue;    /* Pixel value at the intersection */
00255         float maxPixelValue;    /* Pixel value at local max */
00256         float vtxOutsideValue;  /* avg value from intersection to end of ray */
00257         int validVertex ;         /*  IF zero, include this vertex.  If 1 do not */
00258         float angleinrads;        /* angle of a specific ray */
00259         float rotmatrix[2][2]; 
00260         float slope;
00261         float normalslope;
00262 } ray;
00263 
00264 
00265 
00266 /* To complete the information, here is the structure of a 
00267         GdkImlibImage, copied from gdk_imlib_types.h, just for info purposes,
00268         thus ifdef'd away. DON'T ENABLE IT      */
00269         
00270 #ifndef TRUE
00271 struct _GdkImlibImage
00272 {
00273     gint             rgb_width, rgb_height;
00274     unsigned char      *rgb_data;
00275     unsigned char      *alpha_data;
00276     gchar              *filename;
00277         /* the below information is private */
00278     gint                width, height;
00279     GdkImlibColor       shape_color;
00280     GdkImlibBorder      border;
00281     GdkPixmap          *pixmap;
00282     GdkBitmap          *shape_mask;
00283     gchar               cache;
00284     GdkImlibColorModifier mod, rmod, gmod, bmod;
00285     GdkImlibModifierMap *map;
00286     int                 ref_count;
00287     GHashTable          *pixmaps;
00288 };
00289 #endif
00290 
00291 
00292 
00293 /*====================================================
00294 
00295         G L O B A L   V A R I A B L E S 
00296 
00297 ======================================================*/
00298 
00299 /* Let's have one image that can be globally accessed */
00300 
00301 image_type mainimg;
00302 image_type backupimg;
00303 char mainimg_name[255];
00304 
00305 /* ... one image buffer for the secondary display ... */
00306 
00307 image_type s_img;
00308 
00309 /* ... image(s) and other variables for the undo functions ... */
00310 
00311 #define UNDO_MAX        10              /* Maximum of 10 undo levels on disk */
00312 image_type undo_mem;            /* One backup image in memory */
00313 char undo_path[1024];           /* Where to store disk backup images */
00314 UNDO_TYPE undo_function;        /* Undo on disk or in memory */
00315 int undo_level;                         /* How many images we have on disk */
00316 int undo_cnt;                           /* Number of undo image */
00317 char **undo_stack;                      /* file names of undo images */
00318 pid_t cimage_pid;                       /* Process ID of this Crystal Image instance */
00319 
00320 
00321 /* ... and one imlib image and some associated variables */
00322 
00323 gint cur_w, cur_h;      /* A most unfortunate legacy from the previous version.
00324                                                         These should be ALWAYS identical to mainimg.xmax and mainimg.ymax */
00325 gint xofs, yofs;        /* Crop offsets for non-autosize mode */
00326 GdkImlibImage  *im;
00327 int autosize;           /* display fixed size or scale with display size */
00328 int autoscale;          /* expand contrast or display 1:1 gray values */
00329 int file_ok;            /* Set to 1 if a file is in memory */
00330 int cur_slice;          /* Slice that is currently visible */
00331 int next_uid;           /* Unique ID for each allocated image */
00332 int debuglevel;         /* Tells how much debug junk we want to see */
00333 char tiffreport;        /* Use to disable the import report */
00334 float tiffsave_dpi;     /* value to set the dpi tag to when saving tiffs */
00335 int stat_window_exists;
00336 interpol_method intp_pref;              /* Preferred interpolation method */
00337 int spl_cache_invalidate;               /* Sline interpolation: Cache validation flag */
00338 GdkCursor* crosshair_cursor;    /* over display windows */
00339 GdkCursor* grab_cursor;                 /* When grabbing a vertex */
00340 char browspath[1024];                   /* Path to browser, for help files */
00341 char helppath[1024];                    /* Path to help files */
00342 char dsopath[1024];                             /* Path to DSO files */
00343 char imager_sv_path[1024];              /* Path to external standalone 3D viewer */
00344 
00345 void (*zslice_callback) (void); /* A function that gets called whenever
00346                                                                         the z-slice button has been changed */
00347 
00348 /* LUTs for red, green, blue (display only!) */
00349 
00350 unsigned char redlut[256];
00351 unsigned char greenlut[256];
00352 unsigned char bluelut[256];
00353 unsigned char use_lut;
00354 
00355 
00356 #define CLICKSTACK_MAX  5
00357 #define MAXVERTICES     360
00358 
00359 vertex3d clickstack[CLICKSTACK_MAX];    /* Recent click positions */
00360 int clickstack_last;    /* Pointer to the last entry of the click stack */
00361 int display_clickstack; /* Display segments of the click stack marching-ants style */
00362 
00363 GtkWidget *secondaryimg;        /* secondary image drawing area */
00364 GtkWidget *secondwnd;           /* secondary image toplevel window */
00365 GdkImlibImage* s_im;            /* secondary image imlib structure */
00366 int secw, sech;                         /* Secondary image size */
00367 int     secondaryimage_exists;  /* flag for the "close" operation */
00368 int graphwindow_exists;         /* as above, but for graph display */
00369 
00370 /* Rays from SpiderOp */
00371 
00372 ray rayforspider[MAXVERTICES];
00373 ray raystoconnectvtx[MAXVERTICES];
00374 ray rayforvertices[MAXVERTICES];
00375 int numspiderlegs;
00376 int numvertices;
00377 int spider_active;                      /* Set to TRUE when the spider window is open */
00378 int snake_active;                       /* Set to TRUE when the snake window is open */
00379 
00380 /* Macro interpreter */
00381 
00382 int macrorun;   /* Flag indicates that a macro is running */
00383 float mac_user[100];    /* Macro "user" data array */
00384 
00385 
00386 
00387 /* Some macro definitions and mini-functions that I commonly use */
00388 
00389 /* ehmm... seems that glib defines these, so double-check that
00390    the definitions are what we expect */
00391 
00392 #ifndef MIN
00393 #define MIN(X,Y)        ((X)>(Y)? (Y): (X))
00394 #endif
00395 
00396 #ifndef MAX
00397 #define MAX(X,Y)        ((X)<(Y)? (Y): (X))
00398 #endif
00399 
00400 #define SIN(X)          (sin((X)*1.7453295199e-2))
00401 #define COS(X)          (cos((X)*1.7453295199e-2))
00402 
00403 #define SIGN(X)         ((X)<0? -1 : 1)         /* simplified sign, zero counts as positive */
00404 
00405 #define SQR(X)          ((X)*(X))
00406 #define CUB(X)          ((X)*(X)*(X))
00407 #define SAFELOG10(X)    ((X)<1e-50? -50: log10(X))
00408 #define SAFELOG(X)      ((X)<1e-50? -115.13: log(X))
00409 
00410 #define ARITHM(X,Y)             ((X)*(X)+(Y)*(Y))
00411 
00412 #define SDEV(SX,SXX,N)  ((N)>1? sqrt(((SXX)-((SX)*(SX)/((N))))/((N)-1)): 0)
00413 
00414 /* We count any floating-point number below 1e-15 as zero. This macro can be used to query */
00415 /* TODO: There is a better way now, in imgbif.c the function nonzero (img,x,y,z) */
00416 
00417 #define F_ISZERO(F)             ( fabs(F) < 1e-15? 1 : 0 )
00418 
00419 #define DATALEN(T)              ( (T)==B_SHORT? 2: (T)==B_FLOAT? 4: (T)==B_RGB? 3: 1 )
00420 
00421 /* The next are the weight factors for conversion of RGB to gray.
00422    We use the standard YUV system factors here. In fact, a simple
00423    extension to a 3x3 matrix would give the complete YUV conversion.
00424    Note the sum of all three weights MUST be unity */
00425 
00426 #define REDWEIGHT       0.299
00427 #define GREENWEIGHT     0.587
00428 #define BLUEWEIGHT      0.114
00429 
00430 #define PI                      3.141592654
00431 #define TWOPI           6.283185307
00432 #define SQ2                     1.414213562
00433 
00434 /* Use float or double for matrix computations... */
00435 
00436 #define MFLOAT          double
00437 
00438 #endif

Generated on Sat Nov 15 23:24:49 2008 for Crystal Image by  doxygen 1.5.3