ait-survey

simulation data - point cloud

Jan 23rd, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.49 KB | None | 0 0
  1. /***************************************************************************
  2. simulation data
  3.  
  4.  DSM floatデータ型で格納
  5.  read
  6.  2008/1/10
  7.  made by Yoshiyukiu Yamamoto
  8.  ver1.1 2009/3/7
  9.   ********************************************************************************/
  10. #include<stdio.h>
  11. #include<stdlib.h>
  12. #include<string.h>
  13. #include<math.h>
  14.  
  15. float RandomFloat(float a, float b);
  16.  
  17. int main(int argc,char *argv[])
  18. {      
  19.      
  20.     /*****************************************************
  21.           1.Definition of Variables
  22.     ******************************************************/
  23.     FILE *fpw;  //file pointer for input&output file
  24.     int no,i,j;
  25.     float x,y,z,lh;
  26.     float d;
  27.     unsigned char r,g,b;
  28.     double zy,azy,azr,zr;
  29.     int max;
  30.     float rand_min,rand_max;
  31.     float b_rad;
  32.      
  33.      /*****************************************************
  34.            2.command Line arguments processing
  35.     ******************************************************/
  36.     if(argc!=8)
  37.     {
  38.         fprintf(stderr,"Usage: %s (1)output_xyz FILENAME¥n(2)emit angle¥n(3)Inst height¥n(4)max¥n(5)rand_min¥n(6)rand_max¥n(7)b_radius¥n",argv[0]);
  39.                  exit(1);
  40.     }
  41.     printf("OPEN FILE NAME:%s\n",argv[1]);
  42.     printf("emit angle:%s\n",argv[2]);
  43.     printf("Inst height:%s\n",argv[3]);
  44.     printf("max:%s\n",argv[4]);
  45.     printf("rand_min:%s\n",argv[5]);
  46.     printf("rand_max:%s\n",argv[6]);
  47.     printf("boundary_radius:%s\n",argv[7]);
  48.    
  49.  
  50. /**********************************************************************************
  51.           **********************************************************************************
  52.           4.  FILE OPEN + Binary File Input
  53.           **********************************************************************************
  54.  ***************************************************************************************/
  55.  
  56.          // open input file
  57.       /*   if((fpr=fopen(argv[1],"r"))==NULL)
  58.         {
  59.                 printf("ファイルのオープンに失敗しました。プログラムを終了します。¥n");
  60.                 exit(1);
  61.          }
  62.          */
  63.          //write file
  64.     if((fpw=fopen(argv[1],"w"))==NULL)
  65.     {
  66.         fprintf(stderr,"DSM by GSI データファイル.raw¥n");
  67.         exit(1);
  68.     }
  69.    
  70.     azr=0;
  71.     azy=0;
  72.     zr=atof(argv[2]);//0.0006 angle
  73.     zy=atof(argv[2]);
  74.     lh=atof(argv[3]);//1.5
  75.     max=atoi(argv[4]);//2000
  76.     rand_min=atof(argv[5]);//-0.003
  77.     rand_max=atof(argv[6]);//+0.003
  78.     b_rad=atof(argv[7]);//2m
  79.     /*******************************************************
  80.          データの読み取り書き込み
  81.          *******************************************************/
  82.     /* データ処理 */
  83.     for(i=0;i<10473;i++)
  84.     {
  85.         for(j=0;j<max;j++)
  86.         {
  87.        
  88.             azr=zr*j;
  89.             azy=zy*i;
  90.             x=cos(azy)*lh*tan(azr);
  91.             y=sin(azy)*lh*tan(azr);
  92.            
  93.             //random
  94.             z=RandomFloat(rand_min,rand_max);
  95.            
  96.             r=127;
  97.             g=127;
  98.             b=127;
  99.            //printf("x=%f,y=%f,z=%f,r=%d,g=%d,b=%d¥n",x,y,z,r,g,b);
  100.             d=(float)pow((pow((double)x,2)+pow((double)y,2)),0.5);
  101.             if(d>0.866 && d<b_rad)
  102.             {
  103.                 fprintf(fpw,"%f %f %f %d %d %d\n",x,y,z,r,g,b);
  104.             }
  105.        
  106.         }
  107.     }
  108.        /* ファイル・クローズ*/
  109.           //fclose(fpr);
  110.     fclose(fpw);
  111.  }
  112.  
  113. float RandomFloat(float a, float b)
  114. {
  115.     float random = ((float) rand()) / (float) RAND_MAX;
  116.     float diff = b - a;
  117.     float r = random * diff;
  118.     return a + r;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment