2 #define obbox TOKEN_PASTE(obbox_ ,D)
3 #define obbox_calc TOKEN_PASTE(PREFIXED_NAME(obbox_calc_),D)
4 #define obbox_test TOKEN_PASTE(obbox_test_ ,D)
5 #define hash_data TOKEN_PASTE(findpts_local_hash_data_,D)
6 #define hash_index TOKEN_PASTE(hash_index_ ,D)
7 #define hash_setfac TOKEN_PASTE(hash_setfac_ ,D)
8 #define hash_range TOKEN_PASTE(hash_range_ ,D)
9 #define hash_count TOKEN_PASTE(hash_count_ ,D)
10 #define hash_opt_size TOKEN_PASTE(hash_opt_size_ ,D)
11 #define hash_bb TOKEN_PASTE(hash_bb_ ,D)
12 #define hash_build TOKEN_PASTE(hash_build_ ,D)
13 #define hash_free TOKEN_PASTE(hash_free_ ,D)
14 #define findpts_el_data TOKEN_PASTE(findpts_el_data_ ,D)
15 #define findpts_el_pt TOKEN_PASTE(findpts_el_pt_ ,D)
16 #define findpts_el_setup TOKEN_PASTE(PREFIXED_NAME(findpts_el_setup_),D)
17 #define findpts_el_free TOKEN_PASTE(PREFIXED_NAME(findpts_el_free_ ),D)
18 #define findpts_el TOKEN_PASTE(PREFIXED_NAME(findpts_el_ ),D)
19 #define findpts_el_eval TOKEN_PASTE(PREFIXED_NAME(findpts_el_eval_ ),D)
20 #define findpts_el_start TOKEN_PASTE(findpts_el_start_ ,D)
21 #define findpts_el_points TOKEN_PASTE(findpts_el_points_ ,D)
22 #define findpts_local_data TOKEN_PASTE(findpts_local_data_,D)
23 #define map_points_to_els TOKEN_PASTE(map_points_to_els_ ,D)
24 #define findpts_local_setup TOKEN_PASTE(PREFIXED_NAME(findpts_local_setup_),D)
25 #define findpts_local_free TOKEN_PASTE(PREFIXED_NAME(findpts_local_free_ ),D)
26 #define findpts_local TOKEN_PASTE(PREFIXED_NAME(findpts_local_ ),D)
27 #define findpts_local_eval TOKEN_PASTE(PREFIXED_NAME(findpts_local_eval_ ),D)
88 const sint i0 =
ifloor( (r.min - p->bnd[d].
min) * p->fac[d] );
89 const uint i1 =
iceil ( (r.max - p->bnd[d].
min) * p->fac[d] );
90 ir.
min = i0<0 ? 0 : i0;
91 ir.
max = i1<p->hash_n ? i1 : p->hash_n;
97 const struct obbox *
const obb,
const uint nel,
113 const struct obbox *
const obb,
const uint nel,
116 uint nl=1, nu=ceil(pow(max_size-nel,1.0/
D));
119 uint nm = nl+(nu-nl)/2, nmd = nm*nm, size;
122 if(size<=max_size) nl=nm,size_low=size;
else nu=nm;
129 const struct obbox *
const obb,
const uint nel)
134 for(d=0;d<
D;++d) bnd[d]=obb[0].
x[d];
135 for(el=1;el<nel;++el)
138 for(d=0;d<
D;++d) p->
bnd[d]=bnd[d];
145 const struct obbox *
const obb,
const uint nel,
155 for(el=0;el<nel;++el) {
158 #define FOR_LOOP() do { uint i,j; WHEN_3D(uint k;) \
159 WHEN_3D(for(k=ir[2].min;k<ir[2].max;++k)) \
160 for(j=ir[1].min;j<ir[1].max;++j) \
161 for(i=ir[0].min;i<ir[0].max;++i) \
162 ++count[(WHEN_3D(k*hn)+j)*hn+i]; \
167 sum=hnd+1, max=count[0];
170 max = count[
i]>max?count[
i]:
max;
175 for(el=0;el<nel;++el) {
178 #define FOR_LOOP() do { uint i,j; WHEN_3D(uint k;) \
179 WHEN_3D(for(k=ir[2].min;k<ir[2].max;++k)) \
180 for(j=ir[1].min;j<ir[1].max;++j) \
181 for(i=ir[0].min;i<ir[0].max;++i) { \
182 uint index = (WHEN_3D(k*hn)+j)*hn+i; \
183 p->offset[p->offset[index+1]-count[index]]=el; \
205 const double *
const elx[
D],
206 const unsigned n[D],
const uint nel,
207 const unsigned m[D],
const double bbox_tol,
208 const uint max_hash_size,
209 const unsigned npt_max,
const double newt_tol)
212 unsigned ntot=
n[0];
for(d=1;d<
D;++d) ntot*=
n[d];
214 for(d=0;d<
D;++d) fd->
elx[d]=
elx[d];
230 struct array *
const map,
231 uint *
const code_base ,
const unsigned code_stride ,
232 const double *
const x_base[
D],
const unsigned x_stride[D],
237 const double *xp[
D];
uint *code=code_base;
238 unsigned d;
for(d=0;d<
D;++d) xp[d]=x_base[d];
240 for(index=0;index<npt;++index) {
241 double x[
D];
for(d=0;d<
D;++d) x[d]=*xp[d];
246 for(; elp!=ele; ++elp) {
247 const uint el = *elp;
258 xp[d] = (
const double*)((
const char*)xp[d]+ x_stride[d]);
259 code = (
uint*)( (
char*)code +code_stride );
271 #define AT(T,var,i) \
272 (T*)( (char*)var##_base +(i)*var##_stride )
273 #define CAT(T,var,i) \
274 (const T*)((const char*)var##_base +(i)*var##_stride )
275 #define CATD(T,var,i,d) \
276 (const T*)((const char*)var##_base[d]+(i)*var##_stride[d])
279 uint *
const code_base ,
const unsigned code_stride ,
280 uint *
const el_base ,
const unsigned el_stride ,
281 double *
const r_base ,
const unsigned r_stride ,
282 double *
const dist2_base ,
const unsigned dist2_stride ,
283 const double *
const x_base[
D],
const unsigned x_stride[D],
292 const unsigned npt_max = fd->
fed.npt_max;
294 for(p=map.
ptr;p!=pe;) {
296 const double *
elx[
D];
298 for(d=0;d<
D;++d) elx[d]=fd->
elx[d]+el_off;
303 for(i=0,q=p;i<npt_max && q->
el==
el;++q) {
306 for(d=0;d<
D;++d) fpt[i].
x[d]=*
CATD(
double,
x,q->
index,d);
310 for(i=0,q=p;i<npt_max && q->
el==
el;++q) {
313 double *dist2 =
AT(
double,dist2,index);
316 || fpt[i].flags==(1u<<(2*D))
317 || fpt[i].dist2<*dist2) {
318 double *r =
AT(
double,r,index);
322 *dist2 = fpt[
i].dist2;
323 for(d=0;d<
D;++d) r[d]=fpt[i].r[d];
336 double *
const out_base,
const unsigned out_stride,
337 const uint *
const el_base,
const unsigned el_stride,
338 const double *
const r_base,
const unsigned r_stride,
343 const unsigned npt_max = fed->npt_max;
347 const double *
const in_el = in+el*fd->
ntot;
350 for(i=0,q=p;i<npt_max && q<npt && *
CAT(
uint,el,q)==el;++q) ++i;
352 CAT(
double, r,p), r_stride, i,
355 }
while(p<npt && *
CAT(
uint,el,p)==el);
363 #undef findpts_local_eval
365 #undef findpts_local_free
366 #undef findpts_local_setup
367 #undef map_points_to_els
368 #undef findpts_local_data
369 #undef findpts_el_points
370 #undef findpts_el_start
371 #undef findpts_el_eval
373 #undef findpts_el_free
374 #undef findpts_el_setup
375 #undef findpts_el_data
static double sum(struct xxt *data, double v, uint n, uint tag)
static struct dbl_range dbl_range_merge(struct dbl_range a, struct dbl_range b)
#define tmalloc(type, count)
#define findpts_local_setup
#define array_reserve(T, a, min)
#define findpts_local_free
#define CATD(T, var, i, d)
#define tcalloc(type, count)
#define array_init(T, a, max)
static double elx[NR *NS]
#define findpts_local_eval
#define sarray_sort(T, A, n, field, is_long, buf)
static ulong hash_index_aux(double low, double fac, ulong n, double x)
static sint iceil(double x)
#define map_points_to_els
static sint ifloor(double x)
struct findpts_el_data fed
#define findpts_el_points