コード例 #1
0
ファイル: skeleton6-2.cpp プロジェクト: hardboiled/ray_tracer
void run()
{
    bool running = true;

    calculate_image();
    SDL_Flip(screen);

    while (running) {
        while(SDL_PollEvent(&event)) {
            if (event.type == SDL_KEYDOWN) {
                if (event.key.keysym.sym == SDLK_ESCAPE) {
                    running = false;
                }
            } else if(event.type == SDL_QUIT) {
                running = false;
            }
        }
    }
}
コード例 #2
0
ファイル: labao_zernike.c プロジェクト: mikeireland/labao
void compute_offsets_from_zernike(float *a, float *x, float *y)
{
	int i,j,k;
	aperture_pixel **pixels;
	float	**image;
	float	dx, dy, flux;
	float	test_a[NUM_ACTUATORS+1];
	float	cen_x, cen_y;
#ifdef TEST_ZERNIKE_1
	Window	phaseWindow;
	Window	imageWindow;

	phaseWindow = openWindow("Phase", 10, 10, 128, 128);
	imageWindow = openWindow("Image", 148, 10, 128, 128);
#endif

	/* First we need to know where the "center" is */

	test_a[0] = 1.0;
	for(i=1; i<=maxJ; i++) test_a[i] = 0.0;
	pixels = sub_aperture(15, maxJ, 0.0, 0.0, rho_size);
#ifdef TEST_ZERNIKE_1
	display_phase(phaseWindow, pixels, 2.0*M_PI, test_a, maxJ, 15, 
		8, LIN);
	display_image(imageWindow, pixels, 2.0*M_PI, test_a, maxJ, 15, 
		8, 5, LIN);
#endif
	image = calculate_image(pixels, 15, 5, maxJ, 2.0*M_PI, test_a);
	cen_x = 0.0;
	cen_y = 0.0;
	flux = 0.0;
	for(j = 1; j<=15; j++)
	{
	    for(k = 1; k<=15; k++)
	    {
		flux += image[j][k];
		cen_x += (image[j][k] * (float)j);
		cen_y += (image[j][k] * (float)k);
	    }
	}
	cen_x /= flux;
	cen_y /= flux;
#ifdef TEST_ZERNIKE_1
	message(system_window,"Center %.2f %.2f", cen_x, cen_y);
	usleep(TEST_ZERNIKE_1_DELAY);
#endif

	for(i=0; i<NUM_LENSLETS; i++)
	{
		/* Build a subaperture */

		pixels = sub_aperture(16, maxJ, rho[i], theta[i], rho_size);

#ifdef TEST_ZERNIKE_1
		display_phase(phaseWindow, pixels, 2.0*M_PI, a, maxJ, 15, 
				8, LIN);
		display_image(imageWindow, pixels, 2.0*M_PI, a, maxJ, 15, 
				8, 5, LIN);
#endif

		/* 
 		 * Work out the image 
 	 	 * This is predicated on the assumption that 
 		 * the image size is about 1 pixel. The calculate_image
 		 * function makes the airy size 2^imbedp2/npix, so
 		 * we hope that this works...
 		 */

		image = calculate_image(pixels, 15, 5, maxJ, 2.0*M_PI, a);

		/* Simmulate the WFS calculation */

		dx = 0.0;
		dy = 0.0;
		flux = 0.0;
		for(j = 1; j<=15; j++)
		{
		    for(k = 1; k<=15; k++)
		    {
			flux += image[j][k];
			dx += (image[j][k] * ((float)j - cen_x));
			dy += (image[j][k] * ((float)k - cen_y));
		    }
		}
		dx /= flux;
		dy /= flux;

		/* That should be all */

		x[i] = dx;
		y[i] = dy;

		/* Clear memory */

		free_sub_aperture(pixels,CENTROID_WINDOW_WIDTH);
		free_matrix(image, 1, 9, 1, 9);
#ifdef TEST_ZERNIKE_1
		message(system_window,"Lenslet %d Pos %.2f %.2f Flux %.2f",i, dx, dy, flux);
		usleep(TEST_ZERNIKE_1_DELAY);
#endif
	}

#ifdef TEST_ZERNIKE_1
	XDestroyWindow(theDisplay, phaseWindow);
#endif

} /* compute_centroid_offset_rho_theta() */