Ejemplo n.º 1
0
void FormGadget::drawProxy()
{
    if (!visible())
        return;
    if (form()->application().runningOnTreo600() && hasFocus())
        drawFocusRing();
    Graphics graphics(WinGetDrawWindow()); // form()->windowHandle()
    Rect rect;
    bounds(rect);
    bool db=doubleBuffer_;
    if (db)
    {
        Rect formBounds;
        form()->bounds(formBounds);
        Err error;
        WinHandle wh = WinCreateOffscreenWindow(formBounds.width(), formBounds.height(), nativeFormat, &error);
        if (errNone == error)
        {
            {
                Graphics offscreen(wh);
                ActivateGraphics active(offscreen);
                handleDraw(graphics);
                offscreen.copyArea(rect, graphics, rect.topLeft());
            }
            WinDeleteWindow(wh, false);
        }
        else
            db=false;
    }
    if (!db)
    {
        Graphics::ClipRectangleSetter setClip(graphics, rect);
        handleDraw(graphics);
    }
    fireDrawCompleted();
}
Ejemplo n.º 2
0
void handleKeyboard(unsigned char key, int x, int y)
{
        /* keyboard handler */
        switch(key) {
        case 'p':
                g_active_param=0; break;
        case 't':
                g_active_param=8; break;
        case 'a':
                g_active_param=1; break;
        case 'i':
                g_active_param=2; break;
        case 'g':
                g_active_param=4; break;
        case 'o':
                g_active_param=5; break;
        case 'w':
                g_active_param=6; break;
        case 'e':
                g_active_param=7; break;
        case 44: //,
                if (g_direct_compute==1) {g_direct_compute=0; break; }
                if (g_direct_compute==0) {g_direct_compute=1; break; }
        case 46: //.
                handleComputeDisplacements(); break;
        case 27:
                exit(1);
        default:
                printf("\nUnknown key pressed (Code %d).",key);
        }

        /* show new parameters and displacement field */
        showParams();
        handleDraw();
        return;
}
Ejemplo n.º 3
0
int main (int argc, char* argv[])
{
        int dims[10];
        char out_file[80];
/* ---------- set boundary and grid size ----------------------------------- */

        g_bx=1;
        g_by=1;

        g_hx=1;
        g_hy=sqrt(3)/2;

/* ---------- read in arguments -------------------------------------------- */


        if (argc <3) {
                fprintf(stderr, "Not sufficient arguments: \n");
                fprintf(stderr, "<APP> <LF H5 in file> <LF in dataset> <LF H5 out file>\n");
                exit(1);
        }
        strcpy(lf_h5,argv[1]);
        strcpy(lf_dataset,argv[2]);
        strcpy(out_file,argv[3]);
        /*TODO Group truth*/
        //strcpy(g_ref,argv[4]);


/* set default parameters */
        g_g_pixel_ratio = 1;

        g_g_max_disp=2.0;

        g_direct_compute=0;
        //
        g_e_sigma=1;
        //half kernel size
        g_m_alpha=2;

        g_m_type=0;

        g_active_param=1000;

        g_u_ref=NULL;
        g_v_ref=NULL;

        g_n_omega=1.95;

        g_n_warp_levels=6;
        g_n_warp_eta=0.5;

        g_n_iter = 800; // number of iteration




/* ---------- read in information of light field ------------------- */


        data = hdf5_read_lf(lf_h5, lf_dataset,W,H,S,T,C);

        //exit(1);
        g_nx=W;
        g_ny=H;
        /* extract two view */
        // RGB image from three views;
        float * view00 = new float[W*H*3];
        float * view03 = new float[W*H*3];
        float * view0_3 = new float[W*H*3];
        float * view30 = new float[W*H*3];
        float * view_30 = new float[W*H*3];
        // grayscale image from three view;
        float * img_c;
        float * img_l;
        float * img_r;
        float * img_u;
        float * img_d;
        // the center view index.
        int center = floor((S-1)/2.0);
        for(int j = 0; j<H; j++) {
                for(int i =0; i<W; i++) {
                        for(int c=0; c<3; c++) {
                                view00[j*W*3+i*3+c]=data[c*W*H*S*T + i*H*S*T + j*S*T + (center)*T + center];
                                view03[j*W*3+i*3+c]=data[c*W*H*S*T + i*H*S*T + j*S*T + (center)*T + center-5];
                                view0_3[j*W*3+i*3+c]=data[c*W*H*S*T + i*H*S*T + j*S*T + (center)*T + center-3];
                                view30[j*W*3+i*3+c]=data[c*W*H*S*T + i*H*S*T + j*S*T + (center)*T + center+3];
                                view_30[j*W*3+i*3+c]=data[c*W*H*S*T + i*H*S*T + j*S*T + (center)*T + center+5];
                        }
                }
        }
        img_c = convertRGBtoGray(W,H,view00);
        img_l = convertRGBtoGray(W,H,view_30);
        img_r = convertRGBtoGray(W,H,view30);
        img_d = convertRGBtoGray(W,H,view0_3);
        img_u = convertRGBtoGray(W,H,view03);
        free(view00);
        free(view03);
        free(view0_3);
        free(view30);
        free(view_30);
        /* Write gray image  */
        writeImageGray("view_c.png",W,H,img_c,"Image center");
        writeImageGray("view_l.png",W,H,img_l,"Image Left");
        writeImageGray("view_r.png",W,H,img_r,"Image Right");
        writeImageGray("view_u.png",W,H,img_u,"Image Up");
        writeImageGray("view_d.png",W,H,img_d,"Image Down");

/* ---------- memory allocation ------------------------------------ */

        ALLOC_MATRIX(2, g_nx+2*g_bx, g_ny+2*g_by, &g_f1,   &g_f2);
        ALLOC_MATRIX(2, g_nx+2*g_bx, g_ny+2*g_by, &g_f1_s, &g_f2_s);
        ALLOC_MATRIX(1, g_nx+2*g_bx, g_ny+2*g_by, &g_f2_bw);
        ALLOC_MATRIX(2, g_nx+2*g_bx, g_ny+2*g_by, &g_u,    &g_v);

        //if (argc==5)
        //        ALLOC_MATRIX(2, g_nx+2*g_bx, g_ny+2*g_by, &g_u_ref,   &g_v_ref);

        ALLOC_CUBIX(1, 2*g_nx+2*g_bx, g_ny+2*g_by, 3, &g_p6);
        ALLOC_CUBIX(1, g_nx+2*g_bx, g_ny+2*g_by, 3, &g_disp);
        //g_pixels = (GLubyte *) malloc (2*(g_nx+1)*g_ny*3*sizeof(GLubyte));
        g_pixels = new GLubyte[2*(g_nx+1)*g_ny*3*sizeof(GLubyte)];
        uvbuffer = new float[g_nx*g_ny*2];


/* ---------- read in image pair ------------------------------------------- */
        //
        // calculate_flow_write_img(img_c,img_l,"flow_left.png",out_file,"/flow/left");
        // calculate_flow_write_img(img_c,img_r,"flow_right.png",out_file,"/flow/right");
        // calculate_flow_write_img(img_c,img_u,"flow_up.png",out_file,"/flow/up");
        // calculate_flow_write_img(img_c,img_d,"flow_down.png",out_file,"/flow/down");
/* ---------- read in ground truth displacement field ---------------------- */

        //if (argc==5)
        //        read_barron_data(g_ref,g_u_ref,g_v_ref,g_nx,g_ny,g_bx,g_by);

//
/* ---------- M A I N   L O O P -------------------------------------------- */

        for(int j=0; j<g_ny; j++) {
                for(int i=0; i<g_nx; i++) {
                        g_f1[i+g_bx][j+g_by]= img_c[j*g_nx+i]*255;
                        g_f2[i+g_bx][j+g_by]= img_u[j*g_nx+i]*255;
                }
        }

// open OpenGL window */
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

        glutInitWindowSize((int)round(2*g_nx*g_g_pixel_ratio),
                           (int)round(g_ny*g_g_pixel_ratio));
        glutCreateWindow("CORRESPONDENCE PROBLEMS - VISUALISATION FRONTEND");

// register handle routines
        glutDisplayFunc(handleDraw);
        glutIdleFunc(handleComputeNothing);
        glutKeyboardFunc(handleKeyboard);
        glutSpecialFunc(handleKeyboardspecial);
        glutMouseFunc(handleMouse);
//
// main
        handleComputeDisplacements();
        handleDraw();
        showParams();
        glutMainLoop();




/* ---------- free memory -------------------------------------------------- */

        FREE_MATRIX (2, g_nx+2*g_bx, g_ny+2*g_by, g_f1,   g_f2);
        FREE_MATRIX (2, g_nx+2*g_bx, g_ny+2*g_by, g_f1_s, g_f2_s);
        FREE_MATRIX (1, g_nx+2*g_bx, g_ny+2*g_by, g_f2_bw);
        FREE_MATRIX (2, g_nx+2*g_bx, g_ny+2*g_by, g_u,    g_v);
        //
        // printf("free matrix  \n");
        //
        // //TODO handle ground truth.
        // // if (argc==5)
        // //         FREE_MATRIX(2,   g_nx+2*g_bx, g_ny+2*g_by, g_u_ref, g_v_ref);
        //
        FREE_CUBIX (1, 2*g_nx+2*g_bx, g_ny+2*g_by, 3, g_p6);
        FREE_CUBIX (1, g_nx+2*g_bx, g_ny+2*g_by, 3, g_disp);


        free(g_pixels);
        free(uvbuffer);

        printf("\n\n\n");


        return(0);
}
Ejemplo n.º 4
0
void handleKeyboardspecial(int key, int x, int y)
{
        /* keyboard handler */

        switch(key) {
        case GLUT_KEY_F1:
                /* call help menu */
                print_console_line();
                printf("\n\n F1     ........this help\n");
                printf(" F2     ........write out displacement field in colour code \n");
                printf(" F8     ........write out motion compensated 2nd frame \n");
                printf(" ESC    ........program termination\n");
                printf(" p      ........select presmoothing parameter\n");
                printf(" a      ........select smoothness weight\n");
                printf(" i      ........select number of iterations\n");
                printf(" o      ........select SOR overrelaxation parameter\n");
                printf(" w      ........select number of warping levels\n");
                printf(" e      ........select warping rescaling factor\n");
                printf(" g      ........select max displacement magnitude\n");
                printf(" up     ........increase active parameter\n");
                printf(" down   ........decrease active parameter\n");
                printf(" ,      ........direct computation on/off \n");
                printf(" .      ........compute displacement field \n");
                print_console_line();
                fflush(stdout);
                break;

        case GLUT_KEY_F2:
                /* write out displacement field */
                if (g_u_ref!=NULL)
                {
                        int i,j;
                        for (i=g_bx; i<g_nx+g_bx; i++)
                                for (j=g_by; j<g_ny+g_by; j++)
                                {
                                        if((g_u_ref[i][j]==100.0)&&(g_v_ref[i][j]==100.0))
                                        {
                                                g_u[i][j]=100.0;
                                                g_v[i][j]=100.0;
                                        }
                                }
                }
                write_ppm_blank_header("out.ppm",g_nx,g_ny);
                write_ppm_data("out.ppm",g_p6,g_nx,g_ny,g_bx+g_nx,g_by);
                write_ppm_blank_header("displacement.ppm",g_nx,g_ny);
                write_ppm_data("displacement.ppm",g_disp,g_nx,g_ny,g_bx,g_by);
                break;

        case GLUT_KEY_F8:
                /* write out motion compensated 2nd frame */
                backward_registration(g_f1,g_f2,g_f2_bw,g_u,g_v,
                                      g_nx,g_ny,g_bx,g_by,g_hx,g_hy);
                write_pgm_blank_header("frame2_bw.pgm",g_nx,g_ny);
                write_pgm_data("frame2_bw.pgm",g_f2_bw,g_nx,g_ny,g_bx,g_by);
                break;

        case GLUT_KEY_DOWN:
                /* decrease sigma */
                if (g_active_param==0)
                {
                        g_e_sigma-=0.1;
                        if (g_e_sigma<0.1)
                                g_e_sigma=0.1;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* decrease alpha */
                if (g_active_param==1)
                {
                        g_m_alpha--;
                        if (g_m_alpha<=0) g_m_alpha=1;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* decrease number of iterations */
                if (g_active_param==2)
                {
                        g_n_iter-=100;
                        if (g_n_iter<0)
                                g_n_iter=0;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* decrease displacement field magnitude (visualsiation) */
                if (g_active_param==4)
                {
                        if (g_g_max_disp>=0.01)
                                g_g_max_disp=g_g_max_disp/1.1;
                        break;
                }
                /* decrease omega */
                if (g_active_param==5)
                {
                        g_n_omega=g_n_omega-0.01;
                        if (g_n_omega<0.01)
                                g_n_omega=0.01;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* decrease number of warping levels */
                if (g_active_param==6)
                {
                        g_n_warp_levels-=1;
                        if (g_n_warp_levels<0)
                                g_n_warp_levels=0;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* decrease type */
                if (g_active_param==8)
                {
                        g_m_type-=1;
                        if (g_m_type<0)
                                g_m_type=0;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* decrease eta */
                if (g_active_param==7)
                {
                        g_n_warp_eta-=0.05;
                        if (g_n_warp_eta<0.05)
                                g_n_warp_eta=0.05;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }

        case GLUT_KEY_UP:
                /* increase sigma */
                if (g_active_param==0)
                {

                        g_e_sigma+=0.1;

                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* increase alpha */
                if (g_active_param==1)
                {
                        g_m_alpha++;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* increase number of iterations */
                if (g_active_param==2)
                {
                        g_n_iter+=100;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* increase displacement field magnitude (visualisation) */
                if (g_active_param==4)
                {
                        g_g_max_disp=g_g_max_disp*1.1;
                        break;
                }
                /* increase omega */
                if (g_active_param==5)
                {
                        g_n_omega+=0.01;
                        if (g_n_omega>1.99)
                                g_n_omega=1.99;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* decrease number of warping levels */
                if (g_active_param==6)
                {
                        g_n_warp_levels+=1;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* increase eta */
                if (g_active_param==7)
                {
                        g_n_warp_eta+=0.05;
                        if (g_n_warp_eta>0.95)
                                g_n_warp_eta=0.95;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
                /* increase type */
                if (g_active_param==8)
                {
                        g_m_type+=1;
                        if (g_m_type>10)
                                g_m_type=10;
                        if (g_direct_compute==1) handleComputeDisplacements(); break;
                }
        default:
                printf("\nUnknown key pressed (Code %d).",key);

        }

        /* show new parameters and displacement field */
        showParams();
        handleDraw();
        return;
}