ait-survey

inner_angle.cpp

Feb 12th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. /*rvi program
  2.  
  3. band3:
  4. http://aitech.ac.jp/~y-yama/data/rvi/band3.raw.zip
  5. band4:
  6. http://aitech.ac.jp/~y-yama/data/rvi/band4.raw.zip
  7. 512*512
  8. unsigned char
  9.  
  10. made by Yoshiyuki Yamamoto
  11. ver1.0 2004/5/30*/
  12.  
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <time.h>
  18. #include <math.h>
  19.  
  20. int main(int argc,char *argv[])
  21. {
  22.     FILE *fpi1,*fpi2,*fpo;
  23.              
  24.     int i,j,height,width;  
  25.     unsigned char dn1,dn2;
  26.     float dn3;              
  27.     float *file1;
  28.     //float *file3;          
  29.     //float start,end;
  30.     float xo,yo,zo,x1,y1,z1,x2,y2,z2;
  31.     float vox,voy,voz,v1x,v1y,v1z;
  32.     float cos;
  33.    
  34.     float start,end;
  35.     start=clock();
  36.  
  37.     if(argc!=5)
  38.     {
  39.         fprintf(stderr,"Usage: %s\n(1)Input_points_filename\n(2)width\n(3)height(4)output_filename\n",argv[0]);
  40.         exit(1);
  41.     }
  42.  
  43.     printf("OPEN R FILE NAME:%s\n",argv[1]);
  44.     //printf("OPEN NIR FILE NAME:\%s\n",argv[2]);
  45.     //printf("OPEN OUTPUT FILE NAME:%s\n",argv[3]);
  46.  
  47.     width = atoi(argv[2]); printf("W = %d,", width);    
  48.     height = atoi(argv[3]); printf("H = %d\n", height);
  49.     //header=atoi(argv[6]);printf("header=%d\n",header);
  50.  
  51.     file1= (float *)malloc(width*height*sizeof(float));
  52.     //file2= (unsigned char *)malloc(width*height*sizeof(char));
  53.     //file3= (float *)malloc(width*height*sizeof(float));
  54.  
  55.     /*----------------ì¸óÕRâÊëúÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉìäJén----------------------*/
  56.     if((fpi1=fopen(argv[1],"rb"))==NULL)
  57.     {       /*ÉtÉ@ÉCÉãÇÃÉIÅ[ÉvÉì*/
  58.             fprintf(stderr,"input file open error\n");
  59.         exit(1);
  60.         }
  61.  
  62.     fread((float *)file1,sizeof(float),width*height,fpi1);
  63.  
  64.     if((fpo=fopen(argv[4],"w"))==NULL)
  65.     {    
  66.             fprintf(stderr,"output file open error\n");
  67.         exit(1);
  68.         }
  69.    
  70.         //fread((float *)file3,sizeof(float),width*height,fpo);
  71.  
  72.     for(i=0;i<height-2;i++)
  73.     {
  74.         for(j=0;j<1;j++)
  75.         {
  76.             xo=file1[i*width+j];
  77.             yo=file1[i*width+j+1];
  78.             zo=file1[i*width+j+2];
  79.             x1=file1[(i+1)*width+j];
  80.             y1=file1[(i+1)*width+j+1];
  81.             z1=file1[(i+1)*width+j+2];
  82.             x2=file1[(i+2)*width+j];
  83.             y2=file1[(i+2)*width+j+1];
  84.             z2=file1[(i+2)*width+j+2];         
  85.             //vector o
  86.             vox=xo-x1;//a-b
  87.             voy=yo-y1;//a-b
  88.             voz=zo-z1;//a-b
  89.             //vector 1
  90.             v1x=x2-x1;
  91.             v1y=y2-y1;
  92.             v1z=z2-z1;
  93.             //calculation of cos
  94.             cos=(vox*v1x+voy*v1y)/sqrt(vox*vox+voy*voy)/sqrt(v1x*v1x+v1y*v1y);
  95.             printf("%d cos=%f\n",i,cos);
  96.             fprintf(fpo,"%f\n",cos);
  97.  
  98.                 //dn3=(float)dn2/(float)dn1;
  99.                 //fwrite(&dn3,sizeof(float),1,fpo); /*míPà ïWçÇÉfÅ[É^ÇÃèëÇ´çûÇ›*/
  100.         }
  101.     }
  102.     free(file1);
  103.     //free(file2);
  104.     //free(file3);
  105.     fclose(fpi1);
  106.     //fclose(fpi2);
  107.     fclose(fpo);
  108.     end=clock();
  109.  
  110.     printf("start%fïb\n",start/1000);
  111.     printf("end%fïb\n",end/1000);
  112.     printf("duration%fïb\n",(end-start)/1000);
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment