//Key function (the angle are using 0~2pi, all the length is mm) Matrix RayCast(double ang_x, double ang_y, double ang_z, double res_height, double res_width, double distance) { //result image data int res_height_pixel = int(res_height/data_field.pixel_space+1); int res_width_pixel = int(res_width/data_field.pixel_space+1); cout<<res_height_pixel<<" "<<res_width_pixel<<endl; Matrix result; result.Init(res_height_pixel,res_width_pixel); Matrix u0,v0,g0; //rotate matrix Matrix mat_rotate = get_rotate(ang_x, ang_y, ang_z); //init horizon direction u0.Init(1,3); u0.elmt[0][0] = 0; u0.elmt[0][1] = 1; u0.elmt[0][2] = 0; //init vertical direction v0.Init(1,3); v0.elmt[0][0] = 0; v0.elmt[0][1] = 0; v0.elmt[0][2] = 1; //init view direction g0.Init(1,3); g0.elmt[0][0] = -1; g0.elmt[0][1] = 0; g0.elmt[0][2] = 0; //after rotate Matrix u = u0*mat_rotate; Matrix v = v0*mat_rotate; Matrix g = g0*mat_rotate; cout<<"g:"<<endl; g.Show(); //center location of the project image Matrix s; s = g*distance; ZERO(s.elmt[0][0]); ZERO(s.elmt[0][1]); ZERO(s.elmt[0][2]); cout<<"s:"<<endl; s.Show(); //lower left location of the project image Matrix e; e = s-v*(res_height/2)-u*(res_width/2); cout<<"e:"<<endl; e.Show(); Matrix coor; coor.Init(1,3); //*****test // while(true){ // cin>>coor.elmt[0][0]>>coor.elmt[0][1]>>coor.elmt[0][2]; // cout<<GetGrayValue(coor,g,data_field.pixel_space)<<endl;; // } // //calculate each pixel int time = 0; for (int i = 0 ; i < res_height_pixel ; i++) { for (int j = 0 ; j < res_width_pixel ; j++) { coor = e+v*(i*data_field.pixel_space)+u*(j*data_field.pixel_space); // cout<<"****** "<<i<<" "<<j<<" "<<endl; // coor.Show(); // result.elmt[i][j] = GetGrayValue(); result.elmt[i][j] = GetGrayValue(coor,g,data_field.pixel_space); // cout<<"value: "<<result.elmt[i][j]<<endl; // getchar(); } // getchar(); } namedWindow( "Display window", WINDOW_NORMAL ); Slice res; res.mat = &result; // res.Z_Verse(); imshow( "Display window", res.Matrix2Image()); waitKey(0); return result; }