void annBnds2Box(

	const ANNorthRect	&bnd_box,		// enclosing box

	int					dim,			// dimension of space

	int					n_bnds,			// number of bounds

	ANNorthHSArray		bnds,			// bounds array

	ANNorthRect			&inner_box)		// inner box (returned)

{

	annAssignRect(dim, inner_box, bnd_box);		// copy bounding box to inner



	for (int i = 0; i < n_bnds; i++) {

		bnds[i].project(inner_box.lo);			// project each endpoint

		bnds[i].project(inner_box.hi);

	}

}
Beispiel #2
0
ANNdecomp tryCentroidShrink(			// try a centroid shrink
	ES_INFO*			es_info,
	ANNpointArray		pa,				// point array
	ANNidxArray			pidx,			// point indices to store in subtree
	int					n,				// number of points
	int					dim,			// dimension of space
	const ANNorthRect	&bnd_box,		// current bounding box
	ANNkd_splitter		splitter,		// splitting procedure
	ANNorthRect			&inner_box)		// inner box if shrinking (returned)
{
	int n_sub = n;						// number of points in subset
	int n_goal = (int) (n*BD_FRACTION); // number of point in goal
	int n_splits = 0;					// number of splits needed
										// initialize inner box to bounding box
	annAssignRect(dim, inner_box, bnd_box);

	while (n_sub > n_goal) {			// keep splitting until goal reached
		int cd;							// cut dim from splitter (ignored)
		ANNcoord cv;					// cut value from splitter (ignored)
		int n_lo;						// number of points on low side
										// invoke splitting procedure
		(*splitter)(es_info, pa, pidx, inner_box, n_sub, dim, cd, cv, n_lo);
		n_splits++;						// increment split count

		if (n_lo >= n_sub/2) {			// most points on low side
			inner_box.hi[cd] = cv;		// collapse high side
			n_sub = n_lo;				// recurse on lower points
		}
		else {							// most points on high side
			inner_box.lo[cd] = cv;		// collapse low side
			pidx += n_lo;				// recurse on higher points
			n_sub -= n_lo;
		}
	}
    if (n_splits > dim*BD_MAX_SPLIT_FAC)// took too many splits
		return SHRINK;					// shrink to final subset
	else
		return SPLIT;
}