home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
vis-ftp.cs.umass.edu
/
vis-ftp.cs.umass.edu.tar
/
vis-ftp.cs.umass.edu
/
pub
/
Software
/
ASCENDER
/
ascendMar8.tar
/
UMass
/
BoldtNew
/
asc2isra_edgels.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-31
|
3KB
|
99 lines
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ERROR_ABORT2(string,arg) {fprintf(stderr,"asc2isra_edgels: ");\
fprintf(stderr,string,arg); fprintf(stderr,"\n"); return(1);}
void write_isr_file_beginning(FILE *out, int numedges)
{
int i;
fprintf(out,"ISR3.2XY fileVersion: 2 %d tokens",numedges+4);
fprintf(out," 4 tokentypes 14 maximum tokentype index\n\n");
fprintf(out,"6 Line2D\n10 TokenArray\n13 CoordSys2D\n14 Transform2D\n\n");
fprintf(out,"<token #0 type 10 TokenArray>\n");
fprintf(out,"TokenArray:: (%d tokens)",numedges);
fprintf(out," coord = <token #1 type 13 CoordSys2D>\n");
for(i=2;i<numedges+2;i++)
fprintf(out,"<token #%d type 6 Line2D>\n",i);
fprintf(out,"\n<token #1 type 13 CoordSys2D>\n");
fprintf(out,"CoordSys2D:: base2sys = <token #%d",numedges+2);
fprintf(out," type 14 Transform2D>\n");
fprintf(out," sys2base = <token #%d type 14 Transform2D>\n",numedges+3);
return;
}
void write_isr_file_edgel(FILE *out, int i, int j, int index,
float mag, float theta)
{
float dx, dy, x, y;
fprintf(out,"\n<token #%d type 6 Line2D>\n",index);
dy = sin(theta)/2.0; dx = cos(theta)/2.0;
x = (float)i+ 0.5; y = (float)j+ 0.5;
fprintf(out,"Line2D from (%f, %f) to (%f, %f)\n",x-dx,y-dy,x+dx,y+dy);
fprintf(out,"Theta = %f, Contrast = %f, Disp = 0\n",theta,mag);
fprintf(out,"Length = 1, Region = 0\n");
fprintf(out,"coord =<token #-1 type -1 NULL>\n");
return;
}
void write_isr_file_edgel_info(FILE *out, int index, float x1, float y1,
float x2, float y2, float theta, float mag)
{
fprintf(out,"\n<token #%d type 6 Line2D>\n",index);
fprintf(out,"Line2D from (%f, %f) to (%f, %f)\n",x1,y1,x2,y2);
fprintf(out,"Theta = %f, Contrast = %f, Disp = 0\n",theta,mag);
fprintf(out,"Length = 1, Region = 0\n");
fprintf(out,"coord =<token #-1 type -1 NULL>\n");
return;
}
void write_isr_file_ending(FILE *out, int numedges, int xdim, int ydim)
{
float scale;
scale = (float)((xdim > ydim) ? xdim-1 : ydim-1);
fprintf(out,"\n<token #%d type 14 Transform2D>\n",numedges+2);
fprintf(out,"Transform2D::\n");
fprintf(out,"%f 0 0\n0 %f 0\n0 0 1\n",scale,scale);
fprintf(out,"\n<token #%d type 14 Transform2D>\n",numedges+3);
fprintf(out,"Transform2D::\n");
fprintf(out,"%f 0 0\n0 %f 0\n0 0 1\n",1.0/scale,1.0/scale);
return;
}
int main(int argc,char *argv[])
{
int i, index;
char in_filename[100],out_filename[100];
FILE *infile=NULL, *outfile=NULL;
int numedges=0;
int sx, sy, ex, ey;
float x1,y1,x2,y2,theta,mag,len;
sscanf(argv[1],"%s",in_filename);
if ((infile=fopen(in_filename,"r"))==NULL)
ERROR_ABORT2("can't open input file %s",out_filename);
sscanf(argv[2],"%s",out_filename);
if ((outfile=fopen(out_filename,"w"))==NULL)
ERROR_ABORT2("can't open output file %s",out_filename);
fscanf(infile,"%d %d %d %d %d",&numedges,&sx,&sy,&ex,&ey);
write_isr_file_beginning(outfile, numedges);
for (i=0, index = 2; i < numedges; i++) {
fscanf(infile,"%f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&theta,&mag,&len);
write_isr_file_edgel_info(outfile,index++,x1,y1,x2,y2,theta,mag);
}
write_isr_file_ending(outfile,numedges,ex,ey);
fclose(infile);
fclose(outfile);
return(0);
}