home *** CD-ROM | disk | FTP | other *** search
- /*
- * proc_pol.c
- *
- * Practical Algorithms for Image Analysis
- *
- * Copyright (c) 1997, 1998, 1999 MLMSoftwareGroup, LLC
- */
-
- /*
- * PROC(ess)_POLY(gon)
- *
- * polygon analysis:
- * -----------------
- * evaluate curvature points
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include "ip.h"
-
- #define ON_MODE 1
- #define OFF_MODE 0
- #define C_HEIGHT 10
- #define C_WIDTH 10
- #define C_COLOR 255
-
-
- #define N2_LIMIT 64L
- #define MAX_ZRFD 15L
- #define N_MOMENTS 15
- #define N_MODE_PARMS 2
-
- #define ENLARGE 1.0
- #define NOLOOP 0
- #define MAX_ROW 2048
- #define LOOP_COMPLETE 8.0
-
- #define SQ2 1.414213562
- #define ZERO 0.0
- #define FABS(a) ((a) > ZERO ? (a) : - (a))
-
- #define ON 1
- #define OFF 0
- #define SHIFT_CENTROID ON
- #define SAVE_SHAPE OFF
-
- #define EVAL_CURV_EN OFF /* evaluate curv. energy */
- #define POLY_FIT ON /* invoke Wall-Danielsson fit */
- #define DRAW_BDY_ONLY OFF /* draws reconstructed polygonal contour */
-
- #define DISPLAY_DATA
- #define FILE_EXT ".zdt"
-
-
- /* globals */
- //extern int page;
- extern char *in_filename;
-
-
- struct polygon *
- select_poly (struct polygon *poly_head, Image * imgIO, int value)
- {
- struct polygon *current_poly;
-
- int c, k;
-
- int rad_mode = OFF, tan_mode = OFF;
-
- float *a_n = NULL, *b_n = NULL;
-
- int n_mom = N_MOMENTS;
- int n_mp = N_MODE_PARMS;
-
- double av_dirn = 0.0;
-
- struct Bdy bd, *bdp = &bd;
- struct spoint cursor, *pc = &cursor;
- FILE *fOut;
- char in_buf[IN_BUF_LEN];
- char *strptr;
-
- /*
- * cycle through list of boundary polygons
- */
- printf ("...enter n to cycle, y to select poly...\n");
- current_poly = poly_head;
- for (;;) {
- pc->x = current_poly->first_x;
- pc->y = current_poly->first_y;
- printf ("poly starting at (%d, %d) select?(y/n) ", pc->x, pc->y);
- if ((c = readlin (in_buf)) == 'y')
- break;
- if ((current_poly = current_poly->next_poly) == NULL) {
- printf ("At end of polygon list!! Return to first polygon?(y/n) ");
- if ((c = readlin (in_buf)) == 'n')
- return (current_poly);
- else
- current_poly = poly_head;
- }
- }
-
- printf ("...curvature points delta_phik[] and delta_lk[]:\n");
-
- printf (" delta_phik:\n");
- for (k = 0; k < current_poly->poly_points; k++) {
- printf ("%7.2f ", *(current_poly->d_phi_ptr + k));
- if ((k + 1) % 8 == 0)
- printf ("\n");
- }
- printf ("\n delta_lk:\n");
- for (k = 0; k < current_poly->poly_points; k++) {
- printf ("%7.2f ", *(current_poly->d_l_ptr + k));
- if ((k + 1) % 8 == 0)
- printf ("\n");
- }
-
- c = 0;
- printf ("\n...write curvature points to file file (%s)?(y/n)", FILE_EXT);
- while ((c != 'y') && (c != 'n'))
- c = readlin (in_buf);
- if (c == 'y') {
- printf ("...enter filename: ");
- readlin (in_buf);
- if (((strptr = strstr (in_buf, FILE_EXT)) && (strptr != (in_buf + strlen (in_buf) - strlen (FILE_EXT)))) || !strptr)
- strcat (in_buf, FILE_EXT);
- if ((fOut = fopen (in_buf, "w")) == NULL) {
- puts ("\n...cannot open output file");
- exit (1);
- }
- fprintf (fOut, "#Curvature points for image file %s\n", in_filename);
- fprintf (fOut, "%d\n", current_poly->poly_points);
- for (k = 0; k < current_poly->poly_points; k++) {
- fprintf (fOut, "%d %f\n", (int) *(current_poly->d_phi_ptr + k), *(current_poly->d_l_ptr + k));
- }
- fclose (fOut);
- }
- return (current_poly);
- }
-