www.pudn.com > 医学算法.rar > sim.c


#include	

/*
	sim - simulate ellipse field images

	Carl Crawford
	Purdue University
	W. Lafayette, IN 47907

	Oct. 24, 1980

 */

/*
	syntax: sim [options]

	VARIABLES						DEFAULT
	n:	picture dimension				64
	m:	number of ellipses				all
	q:	quadrant reconstruction				entire
	theta:	rotation					0.0
	y:	line (invokes -l)				0.0
	if:	input file name					gen.d
	of:	output file name				pic.r
	lf:	line file name (invokes -l)			line
	gx:	x start for grid				-1.0
	gy:	y start for grid				1.0
	gs:	grid size					2.0

	FLAGS							DEFAULT
	-p:	don't print program status			off
	-l:	line reconstruction				off

 */

#define	ME	10	/* max number of ellipses */
#define	MN	512	/* max image size */

float	gridx	= -1.0;	/* start location for grid */
float	gridy	= 1.0;	/* start location for grid */
float   grids   = 2.0;  /* grid size */
int	line;		/* 1 = line reconstruction */
int	quad;		/* non-zero = quatrant reconstruction */
char	*ifn	= "gen.d";	/* input file name */
char	*ofn	= "pic.r";	/* output file name */
char	*lfn	= "line";	/* line file name */
int	m	= 1;	/* number of ellipses */
int	ms;		/* 1 = m set */
int	n	= 64;	/* image size */
float	pic[MN];	/* line of image */
int	print	= 1;	/* 1 = print program status */
float   yl      = 0.0;  /* y intercept of line */
float	alpha	= 0.0;	/* image rotation */
float	sin(),cos(),atof();
float	pi	= 3.141592654;
FILE	*ifd,*ofd;
float	x[ME];		/* ellipse parameters */
float	y[ME];
float	theta[ME];
float	c[ME];
float	a[ME];
float	b[ME];
float	c1[ME];
float	c2[ME];
float	c3[ME];
float	c4[ME];
float	a2,b2,sint,cost;
float	yt,yt2,xt,yp,xp,gridd,xs,ys;
int	ll;

char	*table[] = {
		"n",
		"m",
		"q",
		"theta",
		"y",
		"if",
		"of",
		"lf",
		"gx",
		"gy",
		"gs",
		0
	};

main(argc,argv)
	int	argc;
	char	**argv;
{
	register	i,j,l;
	char	cc;

	while(++argv,--argc){
		if(**argv == '-')while(cc = *++*argv)switch(cc){
	
			case 'p':	/* print program status */
				print = 0;
				break;
			case 'l':	/* line reconstuction */
				line = 1;
				break;
			default:
				fprintf(stderr,"bad flag -%c\n",cc);
				exit(1);
		}

		else switch(comm(*argv)){

			case 1:		/* n */
				n = atoi(*argv + 2);
				break;
			case 2:		/* m */
				m = atoi(*argv + 2);
				ms = 1;
				break;
			case 3:		/* q */
				quad = atoi(*argv + 2);
				break;
			case 4:		/* theta */
				alpha = atof(*argv+6);
				break;
			case 5:		/* y */
				yl = atof(*argv + 2);
				line = 1;
				break;
			case 6:		/* if */
				ifn = *argv + 3;
				break;
			case 7:		/* of */
				ofn = lfn = *argv + 3;
				break;
			case 8:		/* lf */
				ofn = lfn = *argv + 3;
				line = 1;
				break;
			case 9:		/* gx */
				gridx = atof(*argv + 3);
				break;
			case 10:	/* gy */
				gridy = atof(*argv + 3);
				break;
			case 11:	/* gs */
				grids = atof(*argv + 3);
				break;
		}
	}

	if(n < 1 || n > MN){
		fprintf(stderr,"bad image size\n");
		exit(1);
	}

	if(m < 1 || m > ME){
		fprintf(stderr,"bad ellipse count\n");
		exit(1);
	}

	if((ifd = fopen(ifn,"r")) == NULL){
		fprintf(stderr,"can't open: %s\n",ifn);
		exit(1);
	}

	if(line)ofn = lfn;
	if((ofd = fopen(ofn,"w")) == NULL){
		fprintf(stderr,"can't create: %s\n",ofn);
		exit(1);
	}

	for(i=0;i ME){
			fprintf(stderr,"too many ellipses\n");
			exit(1);
		}
		if(!m){
			fprintf(stderr,"emtpy input file\n");
			exit(1);
		}
	}
	fclose(ifd);
	switch(quad){      /* set up for quadrant reconstructions */

	case 0:     /* normal */
	    break;
	case 1:
	    grids = 1.0;    gridx = 0.0;    gridy = 1.0;
	    break;
	case 2:
	    grids = 1.0;    gridx = -1.0;   gridy = 1.0;
	    break;
	case 3:
	    grids = 1.0;    gridx = -1.0;   gridy = 0.0;
	    break;
	case 4:
	    grids = 1.0;    gridx = 0.0;    gridy = 0.0;
	    break;
	default:
	    fprintf(stderr,"bad quadrant\n");
	    exit(1);
	}
	if(print){
		printf("SIM DATA\n\n");
		printf("n = %d\n",n);
		printf("m = %d\n",m);
		printf("gx = %f\n",gridx);
		printf("gy = %f\n",gridy);
		printf("gs = %f\n",grids);
		printf("theta = %f\n",alpha);
		printf("input file: %s\n",ifn);
		printf("output file: %s\n",ofn);
		if(line){
			printf("line reconstruction at y = %f\n",yl);
		}
		if(quad){
			printf("quadrant reconstruction\n");
		}
		printf("\nELLIPSE DATA\n");
		printf("\n      x         y        theta        c          a          b\n");
		for(i=0;i