Exemplo n.º 1
0
bool KDTree::rayintersectsbox(FSBoundingBox *box)
{
double pmin, pmax, tmin, tmax;
double dtemp;

//  Get the parametric distance along each direction from the min point to
//  the min and max box planes.  If the min dist is grater than the max
//  dist, we have to swap them.  Keep a running total of the max min and the
//  min max.  The ray intersects the box iff tmin <= tmax and tmax >= 0.0.
//  Otherwise, the ray misses the box or points away from the box (with the
//  starting point outside).

  tmin = (box->xmin - rayxstart)/dx;
  tmax = (box->xmax - rayxstart)/dx;
  if ( tmin > tmax ) {
  dtemp = tmin; tmin = tmax; tmax = dtemp;
  }
  pmin = (box->ymin - rayystart)/dy;
  pmax = (box->ymax - rayystart)/dy;
  if ( pmin > pmax ) {
  dtemp = pmin; pmin = pmax; pmax = dtemp;
  }
  tmin = MAXX(pmin,tmin);
  tmax = MINN(pmax,tmax);

  if ( tmin > tmax ) return false;
  
  pmin = (box->zmin - rayzstart)/dz;
  pmax = (box->zmax - rayzstart)/dz;
  if ( pmin > pmax ) {
  dtemp = pmin; pmin = pmax; pmax = dtemp;
  }
  tmin = MAXX(pmin,tmin);
  tmax = MINN(pmax,tmax);
  
  if ( (tmax < 0.0) || (tmin > tmax) ) return false;
  
  return true;
}
Exemplo n.º 2
0
void data_cl_realloc(framebuffer_t *fb, size_t buffer_size)
{
	cl_int ret;
	size_t orig_as, new_as;

	ret = clFinish(fb->clctx.command_queue);
	CL_ERR_NORET("clFinish in data_cl_realloc()", ret);

	// free CL buffer
	ret = clReleaseMemObject(fb->data_cl);
	CL_ERR_NORET("clReleaseMemObject (in data_cl_realloc, for fb->data_cl)", ret);

	// Calculate the new allocation size
	orig_as = new_as = fb->data_cl_as;
	do
	{
		new_as += (1LL << log2_ffo64(fb->data_cl_as+buffer_size) - (fb->data_cl_as+buffer_size > 200<<20 ? 3 : 2));	// Increment by 33%-50% or 17%-25% above 200 MB
	}
	while (new_as < fb->data_cl_as + buffer_size);

	// Allocate the CL buffer and shrink it if needed
	do
	{
		fb->data_cl = clCreateBuffer(fb->clctx.context, CL_MEM_READ_WRITE, new_as, NULL, &ret);
		if (ret != CL_SUCCESS)			// if it's too much
			new_as -= 8 << 20;		// remove 8 MB
	}
	while (ret != CL_SUCCESS);

	if (new_as < fb->data_cl_as)
		fprintf_rl(stderr, "data_cl_realloc() made fb->data_cl smaller, %g MB to %g MB\n", (double) fb->data_cl_as / sq(1024.), (double) new_as / sq(1024.));

	// Resize the local buffer and copy it back
	alloc_enough(&fb->data, new_as, &fb->data_cl_as, 1, 1.);
	fb->data_cl_as = new_as;
	cl_copy_buffer_to_device(*fb, fb->data, 0, MINN(orig_as, fb->data_cl_as));	// enqueue copy of everything

	//fprintf_rl(stdout, "data_cl resized to %g MB\n", (double) fb->data_cl_as / sq(1024.));
}
Exemplo n.º 3
0
int InsidePolygon(GLfloat x, GLfloat y, int N, GLfloat* polygon)
{
	int counter = 0;
	int i;
	GLfloat xinters;
	//Point p1,p2;
	GLfloat x1, y1, x2, y2;
	
	x1 = polygon[0];
	y1 = polygon[1];
	for (i=1;i<=N;i++) {
		x2 = polygon[2*(i % N)];
		y2 = polygon[2*(i % N)+1];
		if (y > MINN(y1,y2)) {
			if (y <= MAXX(y1,y2)) {
				if (x <= MAXX(x1,x2)) {
					if ( fabs(y1 - y2) > 1e-8 ) {
						xinters = (y-y1)*(x2-x1)/(y2-y1)+x1;
						if ( fabs(x1 - x2)<1e-8 || x <= xinters)
							counter++;
					}
				}
			}
		}
		x1 = x2;
		y1 = y2;
	}
	
	return (counter %2 != 0);
	
	/*
	if (counter % 2 == 0)
		return(OUTSIDE);
	else
		return(INSIDE);*/
}