/************************************************************************* * Coastline Matching Algorithm - CMA * version 0.1 alpha * * (c) Summer School in Image Processing, Szeged, 1999 * Joonas Lehtinen, email: jole@jole.fi, www: http://jole.fi/ (Finland) * Jozsef Galajda, email: galajdaj@dragon.klte.hu (Hungary) * Marcell Nagy, email: nmc@visualxt.ipan.sztaki.hu (Hungary) * Róbert Ványi, email: h531774@stud.u-szeged.hu (Hungary) *************************************************************************/ #ifndef cma_h #define cma_h #include #include #include #define PIX2 (M_PI * 2) /* Initialize acrhitecture specific types */ typedef unsigned short U16; typedef unsigned long U32; typedef unsigned char U8; /* Global variables *****************************************************/ extern FILE *logfile; /* Type definitions *****************************************************/ /* Parameters parsing structure */ typedef struct { FILE *mapfile; FILE *submapfile; FILE *resultfile; FILE *logfile; int no_start_points; int no_end_points; int walk_stepsize; } parameters; typedef struct tcoordinatelist { int x,y; struct tcoordinatelist *next; } coordinatelist; typedef struct tpath { float length; float angle; /* in radians (positive is cw and neg ccw) */ struct tpath *next; } path; /* Function protypes ****************************************************/ /* Load PGM file . This function also allocates the image buffer */ void load_pgm(FILE *in, U8 **pic, int *width, int *height, int *maxcolor); /* Save PGM */ void save_pgm(FILE *out, U8 *pic, int width, int height, int maxcolor); /* Argument parsing */ void print_usage_help(); int parse_arguments(int argc, char **argv, parameters *p); /* Draws a line from (x1,y1) to (x2,y2) into img of size iw x ih * The color of the line is color, but if the color is negative, a black-white - line is drawn with (-color)^2 long segments */ void draw_line(U8 *img, int iw, int ih, int color, int x1, int y1, int x2, int y2); /* Created a coordinatelist from a image with only single thin line */ coordinatelist *create_coordinatelist(U8 *img, int width, int height, int seed_x, int seed_y, int spacing); /* Map clearing routine */ /* clears img (a image of size width x height) and gives endpoint of a coastline */ void clear_map(U8 *img, int width, int height, int *seed_x, int *seed_y); /* Code a list of inflaction points to a path (containing lengths and angles) */ path *path_coding(coordinatelist *plist); /* Move (x,y) to direction dir len units. direction is given in radians, * coordinate-system is screen coordinates and angles in radians. dir 0 * points to north and the angle increases to cw direction */ void step(float *x, float *y, float len, float dir); /* Find the nearest match for subcoastline using brute-force * Returns the error of the best match and the starting and ending-points * (as walking distances on the coastline). You also have to give a pointer * to a proper parameter structure, so that one can give parameters to * searching algorithm from commandline. */ float brute_force_matching(path *coast, path *subcoast, float *start, float *end, parameters *param); /* Returns the lenght of a path calculated by walking along it */ float pedestrian_path_length(path *p); /* Error calculation */ /* start and end are distances measured along * the coastline from its start. The error value is returned. */ /* If the outfile != NULL, a output image is saved */ float path_error(float start, float end, path *coastpath, path *subcoastpath, parameters *param, FILE *outfile); /*Reverse the order of a path - returns the new path */ path* invert_path(path* List); /* Error handling and memory allocation macros **************************/ #define TERMINATE(msg) \ {fprintf(stderr,"ERROR(%i @ %s): %s\n",__LINE__,__FILE__,msg); \ exit(1);} #define WARNING(msg) \ fprintf(stderr,"WARNING(%i @ %s): %s\n",__LINE__,__FILE__,msg) #define MALLOC(pointer,len) \ if (!((void *) pointer = (void *)malloc(len))) { \ TERMINATE("Memory allocation failed");} #define ABS(x) ((x) >= 0 ? (x) : -(x) ) #endif