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>
- #include <math.h>
- /* keep the picture data*/
- #define IMGFILE "depth_combine48_cunbus_conv.bmp"
- #define CHANNEL 3 // color(R, G, B)
- FILE *fp1,*fp2,*fp3,*fp4,*fp5;
- int i,j;
- float min;
- float max;
- int width; // width of picture
- int height; // height of picture
- float *file1,*file2,*file3,*file4,*file5;
- GLuint texture; // texture number
- GLubyte* image; // keep the BMP data
- void loadImage(const char* filepath); // read BMP
- float shiftX,shiftY;//for motion
- float mouseX,mouseY;//mouse
- float x=0.1;
- float y=0.1;
- float g_pressed = 0;//for mouse
- float r;
- float sum,sum2,sum3;
- float std;
- float i_first,j_first;
- int WIDTH,HEIGHT;
- int WIDTH1,HEIGHT1;
- float dn1,dn2,dn3,dn4,dn5;
- int b;
- float total1,total2,total3,total4,total5;//total
- float average1,average2,average3,average4,average5;//average
- float start, end;//for calculating processing
- 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);//at the lower left
- glVertex2d(x+shiftX, -y+shiftY);//at the lower right
- glVertex2d(x+shiftX, y+shiftY);//at the upper rught
- glVertex2d(-x+shiftX, y+shiftY);//at the upper left
- //printf("ShiftX1 = %f : ShiftY1 = %f\n" , -x+shiftX , -y+shiftY);//at the lower left of square
- //printf("ShiftX2 = %f : ShiftY2 = %f\n" , x+shiftX , -y+shiftY);//at the lower right of square
- //printf("ShiftX3 = %f : ShiftY3 = %f\n" , x+shiftX , y+shiftY);//at the upper right of square
- //printf("ShiftX4 = %f : ShiftY4 = %f\n" , -x+shiftX , y+shiftY);//at the upper left of square
- //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;
- */
- i_first=-(int)((float)HEIGHT*(y+shiftY))+b;
- j_first=(int)((float)WIDTH*(-x+shiftX))+b;
- min=file1[0];
- max=file1[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;
- if(min>dn1)
- {
- min=dn1;
- }
- if(max<dn1)
- {
- max=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;
- */
- }
- }
- //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);
- 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);
- printf("The average1 water depth is %f m\n " ,average1 );//DOCUMENTATION
- printf("the minimum water depth is %f m\n " ,min );
- printf("the maximum water depth is %f m\n " ,max );
- printf("Standard deviation of the maximum water depth is %f m\n " ,sum3);
- if(average1>0 && average1<20.0)
- {
- printf("The average water depth is under 20m. Some ships and dredgers may be able to pass here\n");
- }
- else if (average1>0 && average1<400.0)
- {
- printf("The average water depth is so deep\n");
- }
- else if(average1>=400.0 && average1<1000.0)
- {
- printf("The average water depth is too deep\n");
- }
- else if(average1>1000.0)
- {
- printf("The average water depth is too deep,we dont neet to care about water depth \n");
- }
- else if(average1<0)
- {
- printf("The average water depth is under 0m. this means there are alomost land\n");
- }
- /*
- printf("The average2 water depth is %f m\n " ,average2 );//average2
- if(average2>0 && average2<400.0)
- {
- printf("The average2 water depth is so deep\n");
- }
- else if(average2>=400.0 && average2<1000.0)
- {
- printf("The average2 water depth is too deep\n");
- }
- else if(average2>1000.0)
- {
- printf("The average2 water depth is fucking deep \n");
- }
- else if(average2<0)
- {
- printf("The average2 water depth is under 0m this means there are alomost land\n");
- }
- printf("The average3 water depth is %f m\n " ,average3 );//average3
- if(average3>0 && average3<400.0)
- {
- printf("The average3 water depth is so deep\n");
- }
- else if(average3>=400.0 && average3<1000.0)
- {
- printf("The average3 water depth is too deep\n");
- }
- else if(average3>1000.0)
- {
- printf("The average3 water depth is fucking deep \n");
- }
- else if(average3<0)
- {
- printf("The average3 water depth is under 0m this means there are alomost land\n");
- }
- printf("The average4 water depth is %f m\n " ,average4 );//averave4
- if(average4>0 && average4<400.0)
- {
- printf("The average4 water depth is so deep\n");
- }
- else if(average4>=400.0 && average4<1000.0)
- {
- printf("The average4 water depth is too deep\n");
- }
- else if(average4>1000.0)
- {
- printf("The average4 water depth is fucking deep \n");
- }
- else if(average4<0)
- {
- printf("The average4 water depth is under 0m this means there are alomost land\n");
- }
- printf("The average5 water depth is %f m\n " ,average5 );//averave5
- if(average5>0 && average5<400.0)
- {
- printf("The average5 water depth is so deep\n");
- }
- else if(average5>=400.0 && average5<1000.0)
- {
- printf("The average5 water depth is too deep\n");
- }
- else if(average5>1000.0)
- {
- printf("The average5 water depth is fucking deep \n");
- }
- else if(average5<0)
- {
- printf("The average5 water depth is under 0m this means there are alomost land\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=(int)((float)WIDTH/r);
- HEIGHT1=(int)((float)WIDTH/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));
- 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);
- }
- */
- 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);
- 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);
- fclose(fp1);
- //fclose(fp2);
- //fclose(fp3);
- //fclose(fp4);
- //fclose(fp5);
- }
- 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