Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <GLUT/glut.h>
- #include <time.h>
- /* keep the picture data*/
- #define IMGFILE "depth_combine48_cunbus.bmp"
- #define CHANNEL 3 // color(R, G, B)
- FILE *fp1,*fp2,*fp3,*fp4,*fp5,*fp6,*fp7,*fp8,*fp9,*fp10;
- int i,j;
- int width; // width of picture
- int height; // height of picture
- float *file1,*file2,*file3,*file4,*file5,*file6,*file7,*file8,*file9,*file10;
- GLuint texture; // texture number
- GLubyte* image; // keep the BMP data
- void loadImage(const char* filepath); // read BMP
- float shiftX,shiftY;
- float mouseX,mouseY;
- float x=0.2;
- float y=0.2;
- float g_pressed = 0;
- float r;
- int WIDTH,HEIGHT;
- int WIDTH1,HEIGHT1;
- float dn1,dn2,dn3,dn4,dn5,dn6,dn7,dn8,dn9,dn10;
- int b;
- float total1,total2,total3,total4,total5,total6,total7,total8,total9,total10;
- float average1,average2,average3,average4,average5,average6,average7,average8,average9,average10;
- float start, end;
- void display(void)
- {
- /*diaplay the picture */
- glEnable(GL_TEXTURE_2D);
- glClear(GL_COLOR_BUFFER_BIT);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTranslated(-0.5,-0.5,0);
- glBegin(GL_QUADS);
- glTexCoord2f(1.0, 0.0); glVertex2f(1.0, 0.0);//position
- glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0);
- glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 1.0);
- glTexCoord2f(0.0, 0.0); glVertex2f(0.0, 0.0);
- glDisable(GL_TEXTURE_2D);
- glEnd();
- glTranslated(0.5,0.5,0);
- glBegin(GL_LINE_LOOP);
- glVertex2d(-x+shiftX, -y+shiftY);//左下
- glVertex2d(x+shiftX, -y+shiftY);//右下
- glVertex2d(x+shiftX, y+shiftY);//右上
- glVertex2d(-x+shiftX, y+shiftY);//カーソルの左上
- //printf("ShiftX1 = %f : ShiftY1 = %f\n" , -x+shiftX , -y+shiftY);//左下
- //printf("ShiftX2 = %f : ShiftY2 = %f\n" , x+shiftX , -y+shiftY);//右下
- //printf("ShiftX3 = %f : ShiftY3 = %f\n" , x+shiftX , y+shiftY);//右上
- printf("ShiftX4 = %f : ShiftY4 = %f\n" , -x+shiftX , y+shiftY);//左上
- //printf("b=%d\n",b);
- printf("HEIGHT = %d : WIDTH = %d : HEIGHT1 = %d : WIDTH1 = %d : y+shiftY = %f : -x+shiftX = %f : b=%d \n" , HEIGHT,WIDTH,HEIGHT1,WIDTH1,y+shiftY,-x+shiftX,b);
- total1=0;
- //total2=0;
- //total3=0;
- //total4=0;
- //total5=0;
- //total6=0;
- //total7=0;
- //total8=0;
- //total9=0;
- //total10=0;
- for(i= -(int)((float)HEIGHT*(y+shiftY))+b ;i<(int)(-(float)HEIGHT*(y+shiftY))+b+HEIGHT1;i++)
- {
- //printf("i=%d\n",i);
- //printf("i2=%d\n",-HEIGHT*(int)(y+shiftY)+b);
- for(j=(int)((float)WIDTH*(-x+shiftX))+b;j<(int)((float)WIDTH*(-x+shiftX))+b+WIDTH1;j++)
- {
- // printf("j=%d\n",j);
- // printf("check-7\n");
- // printf("position=%d\n",(i-(WIDTH-HEIGHT)/2)*WIDTH+j);
- //printf("position=%d¥n",(i-WIDTH1)*HEIGHT1+(j-HEIGHT1+((WIDTH-HEIGHT)/2)));
- dn1=file1[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- total1=total1+dn1;
- //dn2=file2[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total2=total2+dn2;
- //dn3=file3[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total3=total3+dn3;
- //dn4=file4[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total4=total4+dn4;
- //dn5=file5[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total5=total5+dn5;
- //dn6=file6[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total6=total6+dn6;
- //dn7=file7[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total7=total7+dn7;
- //dn8=file8[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total8=total8+dn8;
- //dn9=file9[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total9=total9+dn9;
- //dn10=file10[(i-(WIDTH-HEIGHT)/2)*WIDTH+j];
- //total10=total10+dn1;
- }
- }
- // printf("total1=%f\n",total1);
- // printf("total2=%f\n",total2);
- //printf("total3=%f\n",total3);
- // printf("total4=%f\n",total4);
- // printf("total5=%f\n",total5);
- //printf("total6=%f\n",total6);
- // printf("total7=%f\n",total7);
- // printf("total8=%f\n",total8);
- //printf("total9=%f\n",total9);
- // printf("total10=%f\n",total10);
- average1=total1/(float)(WIDTH1*HEIGHT1);
- //average2=total2/(float)(WIDTH1*HEIGHT1);
- //average3=total3/(float)(WIDTH1*HEIGHT1);
- //average4=total4/(float)(WIDTH1*HEIGHT1);
- //average5=total5/(float)(WIDTH1*HEIGHT1);
- //average6=total6/(float)(WIDTH1*HEIGHT1);
- //average7=total7/(float)(WIDTH1*HEIGHT1);
- //average8=total8/(float)(WIDTH1*HEIGHT1);
- //average9=total9/(float)(WIDTH1*HEIGHT1);
- //average10=total10/(float)(WIDTH1*HEIGHT1);
- printf("the average water depth is %f m\n " ,average1 );//averave1
- if(average1>0 && average1<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average1>=400.0 && average1<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average1>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- /*
- printf("the average water depth is %f m\n " ,average2 );//average2
- if(average2>0 && average2<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average2>=400.0 && average2<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average2>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average3 );//average3
- if(average3>0 && average3<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average3>=400.0 && average3<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average3>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average4 );//averave4
- if(average4>0 && average4<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average4>=400.0 && average4<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average4>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average5 );//averave5
- if(average5>0 && average5<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average5>=400.0 && average5<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average5>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average6 );//averave6
- if(average6>0 && average6<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average6>=400.0 && average6<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average6>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average7 );//averave7
- if(average7>0 && average7<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average7>=400.0 && average7<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average7>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average8 );//averave1
- if(average8>0 && average8<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average8>=400.0 && average8<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average8>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average9 );//averave1
- if(average9>0 && average9<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average9>=400.0 && average9<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average9>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- printf("the average water depth is %f m\n " ,average10 );//averave1
- if(average10>0 && average10<400.0)
- {
- printf("the averave depth water is so deep\n");
- }
- else if(average10>=400.0 && average10<1000.0)
- {
- printf("the averave depth water is too deep\n");
- }
- else if(average10>1000.0)
- {
- printf("the averave depth water is fucking deep \n");
- }
- */
- end=clock();
- printf("start %f /sec \n " ,start/1000000);
- printf("end %f /sec \n " ,end/1000000);
- printf("star to end %f /sec \n " ,(end-start)/1000000);
- glEnd();
- glutSwapBuffers();
- }
- void myInit(void)
- {
- /* necessary setting for before create window*/
- //window1//
- glutInitWindowSize(600, 600); // setting for window size
- glutInitWindowPosition(0, 0); // window position
- glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); // setting display mode
- glutCreateWindow("OpenGL");// create window
- glClearColor (0.0, 0.0, 0.0, 1.0); // window back color
- glutDisplayFunc(display);
- //create texture
- loadImage(IMGFILE);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 8);
- glGenTextures(1, &texture);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
- width, height, 0, GL_RGB,
- GL_UNSIGNED_BYTE, image);
- free(image);
- }
- void keyboard(unsigned char key, int x, int y) //keyboard setting
- {
- switch (key)
- {
- case 'q':
- case 'Q':
- case '\033':
- exit(0);
- default:
- break;
- }
- }
- void mouse(int btn, int state, int x, int y) //mouze setting
- {
- if(btn == GLUT_LEFT_BUTTON == state == GLUT_DOWN) //when press the left button
- {
- mouseX = x;
- mouseY = y;
- g_pressed = 1;
- }
- else if(btn == GLUT_LEFT_BUTTON == state ==GLUT_UP) //when take off the left button
- g_pressed = 0;
- }
- void motion(int x, int y) //controll the motion by the mouse
- {
- {
- shiftX = (float)((x - mouseX)/320);
- shiftY = (float)(-(y - mouseY)/320);
- start =clock();
- glutPostRedisplay();
- }
- /* printf("X = %d : Y = %d\n" , x , y); //diplay the position of coordinate
- printf("ShiftX = %f : ShiftY = %f\n" , shiftX , shiftY); //display the amount of the shift
- printf("mouseX = %f : mouseY = %f \n" , -x+shiftX , mouseY);
- //printf("mouseX = %f : mouseY = %f \n" , mouseX , mouseY); //display the mouseX and mouseY
- printf("wx = %f : wy = %f \n" , get_wx , get_wy);
- // printf("windowX = %f : windowY = %f \n" , get_wx , get_wy);
- printf("windowW = %f : windowH = %f \n" , get_ww , get_wh);
- */
- }
- int main(int argc, char* argv[])
- {
- // printf("check-1\n");
- if(argc!=4)
- {
- fprintf(stderr,"Usage: %s\n(1)input file name\n(2)input file name\n(3)input file name\n(4)WIDTH\n(5)HEIGHT\n",argv[0]);
- exit(1);
- }
- r=1/(2*x);
- printf("r = %f \n",r);
- WIDTH = atoi(argv[2]); printf("W = %d,", WIDTH);
- HEIGHT = atoi(argv[3]); printf("H = %d\n", HEIGHT);
- WIDTH1=WIDTH/(int)r;
- HEIGHT1=WIDTH/(int)r;
- b=WIDTH/2;
- file1= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file2= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file3= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file4= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file5= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file6= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file7= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file8= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file9= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- //file10= (float *)malloc(WIDTH*HEIGHT*sizeof(float));
- if((fp1=fopen(argv[1],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- /*
- if((fp2=fopen(argv[2],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp3=fopen(argv[3],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp4=fopen(argv[4],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp5=fopen(argv[5],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp6=fopen(argv[6],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp7=fopen(argv[7],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp8=fopen(argv[8],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp9=fopen(argv[9],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- if((fp10=fopen(argv[10],"rb"))==NULL)
- {
- fprintf(stderr,"input file open error\n");
- exit(1);
- }
- */
- fread((float *)file1,sizeof(float),WIDTH*HEIGHT,fp1);
- //fread((float *)file2,sizeof(float),WIDTH*HEIGHT,fp2);
- //fread((float *)file3,sizeof(float),WIDTH*HEIGHT,fp3);
- //fread((float *)file4,sizeof(float),WIDTH*HEIGHT,fp4);
- //fread((float *)file5,sizeof(float),WIDTH*HEIGHT,fp5);
- //fread((float *)file6,sizeof(float),WIDTH*HEIGHT,fp6);
- //fread((float *)file7,sizeof(float),WIDTH*HEIGHT,fp7);
- //fread((float *)file8,sizeof(float),WIDTH*HEIGHT,fp8);
- //fread((float *)file9,sizeof(float),WIDTH*HEIGHT,fp9);
- //fread((float *)file10,sizeof(float),WIDTH*HEIGHT,fp10);
- printf("check-10\n");
- glutInit(&argc, argv);
- myInit();
- glutKeyboardFunc(keyboard); //when need keyboard function
- glutMouseFunc(mouse); //when need mouse function
- glutMotionFunc(motion); //when need mouse motion function
- glutDisplayFunc(display); //when need to set about display function
- //glutIdleFunc(idle_func);
- glutMainLoop();
- return 0;
- free(file1);
- //free(file2);
- //free(file3);
- //free(file4);
- //free(file5);
- //free(file6);
- //free(file7);
- //free(file8);
- //free(file9);
- //free(file10);
- fclose(fp1);
- //fclose(fp2);
- //fclose(fp3);
- //fclose(fp4);
- //fclose(fp5);
- //fclose(fp6);
- //fclose(fp7);
- //fclose(fp8);
- //fclose(fp9);
- //fclose(fp10);
- }
- void loadImage(const char* filepath)
- {
- int i;
- int size; // size of picture (width , height, color)
- FILE* fp;
- /* read file */
- fp = fopen(filepath, "rb"); //read binary
- if (fp == NULL)
- {
- fprintf(stderr, "%sfail loading\n", filepath);
- exit(EXIT_FAILURE);
- }
- /* get width and height */
- fseek(fp, 18, SEEK_SET); //move fp to place where has been put width of picture
- fread(&width, 4, 1, fp);
- fread(&height, 4, 1, fp);
- /* read data of picture */
- fseek(fp, 54, SEEK_SET); //move fp to place where has been put dataof the picture
- size = width * height * CHANNEL;
- image = (GLubyte* ) malloc(size);
- if (image == NULL)
- {
- fprintf(stderr, "fail to keep the memory\n");
- exit(EXIT_FAILURE);
- }
- for (i = 0; i < size; ++i)
- fread(&image[i], sizeof(GLubyte), 1, fp);
- /* exit */
- fclose(fp);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement