Exemple #1
0
void calc_polynomial_point(DATA *d, DPOINT *pt) {
	static DATA *bl = NULL;
	int j, k;

	bl = block_discr(bl, get_block_p(), pt);
	for (j = 0; j < d->n_X; j++) {
		if (d->colX[j] < -1)
			/* do eventual block averaging here: */
			for (k = 0, pt->X[j] = 0.0; k < bl->n_list; k++)
				pt->X[j] += bl->list[k]->u.weight *
						calc_polynomial(bl->list[k], d->colX[j]);
	}
}
Exemple #2
0
float	inter_sphere(t_obj *object, t_ray *ray, t_inter *inter)
{
	t_sphere	*sphere;
	t_vect		pos;
	float		tmp;

	sphere = (t_sphere*)(object->obj);

	tmp = calc_polynomial(sphere, ray);
	if (tmp != -1)
	{
		pos = add_vect(ray->o, mult_float(ray->dir, tmp));
		tmp = magnitude(sub_vect(pos, ray->o));
		if (inter->dist == -1 || tmp < inter->dist)
		{
			inter->pos = pos;
			inter->normal = div_float(sub_vect(inter->pos, sphere->c),
											sphere->r);
			inter->dist = tmp;
			inter->obj = object;
		}
	}
	return (tmp);
}
Exemple #3
0
static double *get_maskX(DATA **data, DPOINT *p,
		unsigned int row, unsigned int col) {
	static double *d = NULL;
	static int totX = 0, *posMask = NULL;
	int i, j, k, l;
	static DATA *bl = NULL;
	static GRIDMAP **local_masks = NULL;

	if (data == NULL) {
		if (d != NULL) {
			efree(d);
			d = NULL;
			efree(posMask);
			posMask = NULL;
			local_masks = NULL;
			totX = 0;
		}
		return NULL;
	}
	if (d == NULL) { /* first time calling */
		for (i = 0, totX = 0; i < get_n_vars(); i++) 
			totX += data[i]->n_X;
		posMask = (int *) emalloc(totX * sizeof(int));
		d = (double *) emalloc(totX * sizeof(double));
		for (i = 0, k = 0; i < get_n_vars(); i++) {
			for (j = 0; j < data[i]->n_X; j++) {
				if (data[i]->colX[j] > 0)
					posMask[k] = 1;
				if (data[i]->colX[j] == 0)
					posMask[k] = 0;
				if (data[i]->colX[j] < -1)
					posMask[k] = -1;
				k++;
			}
		}
		if (get_mode() == STRATIFY) {
			if (get_n_masks() > 1)
				local_masks = masks + 1; /* skip the first (= strata) map */
		} else
			local_masks = masks;
	}

 	bl = block_discr(bl, get_block_p(), p);
 	/* bl is a single point-list with p if IS_POINT(p) */
	for (i = 0, k = 0; i < get_n_vars(); i++) {
		for (j = 0; j < data[i]->n_X; j++) {
			if (data[i]->colX[j] < -1) {
				/* do eventual block averaging here: */
				for (l = 0, d[k] = 0.0; l < bl->n_list; l++)
					d[k] += bl->list[l]->u.weight *
							calc_polynomial(bl->list[l], data[i]->colX[j]);
			}
			k++;
		}
	}

	for (i = 0, j = 0; i < totX; i++) {
		switch(posMask[i]) {
			case -1:
				/* is done above */
				break;
			case 1:
				if (map_cell_is_mv(local_masks[j], row, col))
					ErrMsg(ER_IMPOSVAL, "missing value in one of the mask maps");
				d[i] = map_get_cell(local_masks[j], row, col);
				j++;
				break;
			case 0:
				d[i] = (double) 1.0;
				break;
			default:
				ErrMsg(ER_IMPOSVAL, "get_maskX()");
				break;
		}
	}
	return d;
}