Example #1
0
/**
 * Setup a VBO for a curved surface with vertex positions, float normals
 * and byte normals.
 */
static void
setup_vbo(void)
{
	const float radius = 20.0;
	int i, j;
	GLuint vbo;
	struct vertex *vbo_data;
	const unsigned num_verts = (NumSections + 1) * 2;
	const unsigned vbo_size = sizeof(struct vertex) * num_verts;

	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	glBufferData(GL_ARRAY_BUFFER, vbo_size, NULL, GL_STATIC_DRAW);
	vbo_data = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);

	for (i = j = 0; i <= NumSections; i++) {
		float a = (float) i / (NumSections) * M_PI * 2.0;
		float x = cos(a);
		float z = sin(a);

		vbo_data[j].pos[0] = radius * x;
		vbo_data[j].pos[1] = -10.0;
		vbo_data[j].pos[2] = radius * z;
		vbo_data[j].nf[0] = x;
		vbo_data[j].nf[1] = 0;
		vbo_data[j].nf[2] = z;
		vbo_data[j].nb[0] = float_to_byte(x);
		vbo_data[j].nb[1] = 0;
		vbo_data[j].nb[2] = float_to_byte(z);
		vbo_data[j].ns[0] = float_to_short(x);
		vbo_data[j].ns[1] = 0;
		vbo_data[j].ns[2] = float_to_short(z);
		j++;

		vbo_data[j].pos[0] = radius * x;
		vbo_data[j].pos[1] = 10.0;
		vbo_data[j].pos[2] = radius * z;
		vbo_data[j].nf[0] = x;
		vbo_data[j].nf[1] = 0;
		vbo_data[j].nf[2] = z;
		vbo_data[j].nb[0] = float_to_byte(x);
		vbo_data[j].nb[1] = 0;
		vbo_data[j].nb[2] = float_to_byte(z);
		vbo_data[j].ns[0] = float_to_short(x);
		vbo_data[j].ns[1] = 0;
		vbo_data[j].ns[2] = float_to_short(z);
		j++;
	}

	glUnmapBuffer(GL_ARRAY_BUFFER);
}
Example #2
0
// dump the image acording to the state of the viewport
static void pan_exposer(struct FTR *f, int b, int m, int x, int y)
{
	struct pan_state *e = f->userdata;

	if (e->do_preview) {dump_preview(f); return;}

	// for every pixel in the window
	for (int j = 0; j < f->h; j++)
	for (int i = 0; i < f->w; i++)
	{
		// compute the position of this pixel in the image
		double p[2];
		window_to_image(p, e, i, j);

		// evaluate the color value of the image at this position
		float c[3];
		pixel(c, e, p[0], p[1]);

		// transform the value into RGB using the contrast change (a,b)
		unsigned char *dest = f->rgb + 3 * (j * f->w + i);
		for (int l = 0; l < 3; l++)
			dest[l] = float_to_byte(e->a * c[l] + e->b);
	}
	f->changed = 1;
}
Example #3
0
// draw the image warped by the current homography
static void draw_warped_image(struct FTR *f)
{
	struct viewer_state *e = f->userdata;

	int w = e->iw;
	int h = e->ih;
	int pd = e->pd;

	double         H[3][3];   obtain_current_homography(H, e);
	

	float *img = malloc(pd*(f->w)*(f->h)*sizeof(float));
	float *img_f = malloc(pd*(f->w)*(f->h)*sizeof(float));

	extrapolator_t OUT      = obtain_extrapolator(e);
	interpolator_t EVAL     = obtain_interpolator(e);

if(e->interpolation_order == 0){
	for (int j = 0; j < f->h; j++){
	for (int i = 0; i < f->w; i++){
			double p[2] = {i, j};
			apply_homography_1pt(p, H, p);
			p[0] = (p[0] - 0.5) * w / (w - 1.0);
			p[1] = (p[1] - 0.5) * h / (h - 1.0);
			for (int l = 0; l < 3; l++){
				int idx = l + 3 * (f->w * j + i);
				float v = EVAL(e->img, w, h, e->pd, p[0], p[1], l, OUT);
				f->rgb[idx] = v;
			}
		}
	}
	}
	
if(e->interpolation_order==1){
	clock_t debutcpu,fincpu;
	double debutreal,finreal;
	debutcpu = clock();
	debutreal = omp_get_wtime();
	apply_homography_decomp(e->img,img_f,w,h,pd,f->w,f->h,H);
	for(int i=0;i<pd*(f->w)*(f->h);i++){(f->rgb)[i]=float_to_byte(img_f[i]);}
	fincpu = clock();
	finreal = omp_get_wtime();
	printf("cputime :%fs\ntime : %fs\n",(double)(fincpu-debutcpu)/CLOCKS_PER_SEC,(double)(finreal-debutreal));
	}

}
Example #4
0
// draw the image warped by the current homography
static void draw_warped_image(struct FTR *f)
{
	struct viewer_state *e = f->userdata;

	int w = e->iw;
	int h = e->ih;

	double         H[3][3];   obtain_current_homography(H, e);
	
/*	H[0][0]=0.107933;
H[0][1]=0.000899;
H[0][2]=-3.784855;
H[1][0]=-0.747116;
H[1][1]=0.778536;
H[1][2]=19.920756;
H[2][0]=-0.000941;
H[2][1]=-0.000131;
H[2][2]=1.;*/
	
	
	extrapolator_t OUT      = obtain_extrapolator(e);
	interpolator_t EVAL     = obtain_interpolator(e);

if(e->interpolation_order == 0){
	for (int j = 0; j < f->h; j++){
	for (int i = 0; i < f->w; i++){
			double p[2] = {i, j};
			apply_homography(p, H, p);
			p[0] = (p[0] - 0.5) * w / (w - 1.0);
			p[1] = (p[1] - 0.5) * h / (h - 1.0);
			for (int l = 0; l < 3; l++){
				int idx = l + 3 * (f->w * j + i);
				float v = EVAL(e->img, w, h, e->pd, p[0], p[1], l, OUT);
				f->rgb[idx] = v;
			}
		}
	}
	}
	
if(e->interpolation_order==1){
	float *img_f = malloc(3*(f->w)*(f->h)*sizeof(float));
	for(int i=0;i<(f->w)*(f->h)*3;i++){img_f[i]=0;}
	clock_t debutcpu,fincpu;
	debutcpu = clock();

	if(e->pd==3){
        apply_homo_ground_truth(e->img,img_f,w,h,f->w,f->h,H);
	}else{//suppose pd=1
        float *img3 = malloc(3*w*h*sizeof(float));
        for(int i=0;i<w*h;i++){
            for(int l = 0;l<3;l++){
                img3[3*i+l]=e->img[i];
            }
        }
        apply_homo_ground_truth(img3,img_f,w,h,f->w,f->h,H);
	}
	for(int i=0;i<3*(f->w)*(f->h);i++){(f->rgb)[i]=float_to_byte(img_f[i]);}
	
	fincpu = clock();
	printf("cputime :%fs\n",(double)(fincpu-debutcpu)/CLOCKS_PER_SEC);

	}

}