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 >
C/C++ Source or Header  |  1996-01-31  |  3KB  |  99 lines

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. #define ERROR_ABORT2(string,arg) {fprintf(stderr,"asc2isra_edgels: ");\
  7.   fprintf(stderr,string,arg); fprintf(stderr,"\n"); return(1);}
  8.  
  9. void  write_isr_file_beginning(FILE *out, int numedges)
  10. {
  11.   int i;
  12.   fprintf(out,"ISR3.2XY fileVersion: 2 %d tokens",numedges+4);
  13.   fprintf(out," 4 tokentypes 14 maximum tokentype index\n\n");
  14.   fprintf(out,"6 Line2D\n10 TokenArray\n13 CoordSys2D\n14 Transform2D\n\n");
  15.   fprintf(out,"<token #0 type 10 TokenArray>\n");
  16.   fprintf(out,"TokenArray:: (%d tokens)",numedges);
  17.   fprintf(out," coord = <token #1 type 13 CoordSys2D>\n");
  18.   for(i=2;i<numedges+2;i++)
  19.     fprintf(out,"<token #%d type 6 Line2D>\n",i);
  20.   fprintf(out,"\n<token #1 type 13 CoordSys2D>\n");
  21.   fprintf(out,"CoordSys2D:: base2sys = <token #%d",numedges+2);
  22.   fprintf(out," type 14 Transform2D>\n");
  23.   fprintf(out,"   sys2base = <token #%d type 14 Transform2D>\n",numedges+3);
  24.   return;
  25. }
  26.  
  27. void  write_isr_file_edgel(FILE *out, int i, int j, int index,
  28.                float mag, float theta)
  29. {
  30.   float dx, dy, x, y;
  31.  
  32.   fprintf(out,"\n<token #%d type 6 Line2D>\n",index);
  33.   dy = sin(theta)/2.0;  dx = cos(theta)/2.0;
  34.   x = (float)i+ 0.5;  y = (float)j+ 0.5;
  35.   fprintf(out,"Line2D from (%f, %f) to (%f, %f)\n",x-dx,y-dy,x+dx,y+dy);
  36.   fprintf(out,"Theta = %f, Contrast = %f, Disp = 0\n",theta,mag);
  37.   fprintf(out,"Length = 1, Region = 0\n");
  38.   fprintf(out,"coord =<token #-1 type -1 NULL>\n");
  39.  
  40.   return;
  41. }
  42.  
  43.  
  44. void  write_isr_file_edgel_info(FILE *out, int index, float x1, float y1, 
  45.              float x2, float y2, float theta, float mag)
  46. {
  47.   fprintf(out,"\n<token #%d type 6 Line2D>\n",index);
  48.   fprintf(out,"Line2D from (%f, %f) to (%f, %f)\n",x1,y1,x2,y2);
  49.   fprintf(out,"Theta = %f, Contrast = %f, Disp = 0\n",theta,mag);
  50.   fprintf(out,"Length = 1, Region = 0\n");
  51.   fprintf(out,"coord =<token #-1 type -1 NULL>\n");
  52.  
  53.   return;
  54. }
  55.  
  56.  
  57. void  write_isr_file_ending(FILE *out,  int numedges, int xdim, int ydim)
  58. {
  59.   float scale;
  60.   scale = (float)((xdim > ydim) ? xdim-1 : ydim-1);
  61.   fprintf(out,"\n<token #%d type 14 Transform2D>\n",numedges+2);
  62.   fprintf(out,"Transform2D::\n");
  63.   fprintf(out,"%f 0 0\n0 %f 0\n0 0 1\n",scale,scale);
  64.   fprintf(out,"\n<token #%d type 14 Transform2D>\n",numedges+3);
  65.   fprintf(out,"Transform2D::\n");
  66.   fprintf(out,"%f 0 0\n0 %f 0\n0 0 1\n",1.0/scale,1.0/scale);
  67.  
  68.   return;
  69. }
  70.  
  71. int main(int argc,char *argv[])
  72. {
  73.   int i, index;
  74.   char in_filename[100],out_filename[100];
  75.   FILE *infile=NULL, *outfile=NULL;
  76.   int numedges=0;
  77.   int sx, sy, ex, ey;
  78.   float x1,y1,x2,y2,theta,mag,len;
  79.  
  80.   sscanf(argv[1],"%s",in_filename);
  81.   if ((infile=fopen(in_filename,"r"))==NULL)
  82.     ERROR_ABORT2("can't open input file %s",out_filename);
  83.   sscanf(argv[2],"%s",out_filename);
  84.   if ((outfile=fopen(out_filename,"w"))==NULL) 
  85.     ERROR_ABORT2("can't open output file %s",out_filename);
  86.   fscanf(infile,"%d %d %d %d %d",&numedges,&sx,&sy,&ex,&ey);
  87.   write_isr_file_beginning(outfile, numedges);
  88.   for (i=0, index = 2; i < numedges; i++) {
  89.     fscanf(infile,"%f %f %f %f %f %f %f",&x1,&y1,&x2,&y2,&theta,&mag,&len);
  90.     write_isr_file_edgel_info(outfile,index++,x1,y1,x2,y2,theta,mag);
  91.   }
  92.  
  93.   write_isr_file_ending(outfile,numedges,ex,ey);
  94.   fclose(infile);
  95.   fclose(outfile);
  96.   return(0);
  97. }
  98.  
  99.