The Cuik KD-Tree Library


test-cuik-kdtree.c
Go to the documentation of this file.
1 #include "cuik-kdtree.h"
2 #include "random.h"
3 #include "definitions.h"
4 #include "vector.h"
5 
6 #include <stdio.h>
7 #include <time.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <math.h>
11 #include <sys/resource.h>
12 #ifdef _MPNN
13  #include <DNN/ANN_C.h>
14 #endif
15 
16 //#define FIXED_SET
17 
18 #ifdef FIXED_SET
19 double _point[38][8]={
20  {-1.262280,2.039516,-1.241662,-1.121883,1.464420,-2.198507,1.457702,-1.109374 },
21  {-1.237220,1.936589,-1.034433,-1.362698,1.509152,-2.025385,1.470437,-1.237948 },
22  {-1.013849,1.950820,-1.295149,-1.183568,1.455763,-2.055501,1.515250,-1.356307 },
23  {-1.482196,2.007648,-0.996732,-1.283119,1.534123,-2.183768,1.385654,-0.987308 },
24  {-1.500418,2.097868,-1.220372,-1.033085,1.478405,-2.344629,1.351986,-0.864703 },
25  {-1.058694,2.038497,-1.494067,-0.945908,1.372108,-2.234390,1.524408,-1.210050 },
26  {-0.798914,1.929518,-1.574707,-0.976722,1.373544,-2.116169,1.558028,-1.453671 },
27  {-0.945818,2.037145,-1.752772,-0.721324,1.236064,-2.330143,1.579138,-1.212565 },
28  {-1.271433,2.116328,-1.528064,-0.812196,1.331857,-2.393527,1.459837,-0.966149 },
29  {-1.741267,2.010276,-0.887950,-1.279929,1.584056,-2.287866,1.257626,-0.759013 },
30  {-1.501615,1.884796,-0.762412,-1.528952,1.543581,-2.035084,1.412669,-1.072706 },
31  {-1.264555,1.811661,-0.803575,-1.606490,1.510936,-1.867359,1.477011,-1.320378 },
32  {-1.003100,1.834422,-1.071949,-1.441231,1.496033,-1.862884,1.501577,-1.483956 },
33  {-1.645768,2.140992,-1.346015,-0.834454,1.431947,-2.503390,1.247494,-0.654193 },
34  {-0.772193,1.827176,-1.340938,-1.248031,1.463509,-1.909529,1.518583,-1.600614 },
35  {-1.170367,2.110745,-1.780438,-0.590770,1.168126,-2.476101,1.524563,-0.960380 },
36  {-1.443594,2.150651,-1.626567,-0.630068,1.254252,-2.545875,1.376031,-0.740363 },
37  {-0.772232,1.705545,-1.111414,-1.513798,1.491066,-1.702485,1.482258,-1.724730 },
38  {-1.019783,1.707103,-0.855377,-1.681259,1.484966,-1.688372,1.489860,-1.578979 },
39  {-0.534333,1.802012,-1.741788,-0.900786,1.350070,-2.073238,1.555067,-1.650844 },
40  {-1.760679,1.875779,-0.639120,-1.535263,1.580386,-2.148980,1.310228,-0.841421 },
41  {-1.495381,1.733306,-0.544721,-1.760710,1.500579,-1.881177,1.453162,-1.170318 },
42  {-1.810300,2.087329,-1.079026,-1.044453,1.559473,-2.440484,1.162465,-0.600172 },
43  {-1.984806,1.987968,-0.813940,-1.252543,1.641118,-2.384327,1.089403,-0.526641 },
44  {-1.697993,2.147238,-1.551797,-0.593581,1.306569,-2.632096,1.192044,-0.503621 },
45  {-1.880391,2.122402,-1.298290,-0.781258,1.482256,-2.588584,1.056138,-0.421648 },
46  {-0.928724,2.033960,-1.978375,-0.483489,1.057093,-2.442046,1.627235,-1.132694 },
47  {-0.681670,1.919328,-1.901170,-0.672762,1.202390,-2.265498,1.618211,-1.428134 },
48  {-1.256384,1.658986,-0.596002,-1.835289,1.462431,-1.699324,1.492230,-1.425470 },
49  {-0.543469,1.673458,-1.361725,-1.324151,1.484989,-1.760384,1.469352,-1.832039 },
50  {-1.363260,2.127833,-1.865133,-0.407814,1.059721,-2.613543,1.444583,-0.719095 },
51  {-2.039651,2.055739,-1.027143,-1.002035,1.620787,-2.517956,0.964684,-0.367795 },
52  {-2.007873,1.841635,-0.545726,-1.522485,1.626393,-2.256107,1.166803,-0.605743 },
53  {-1.780364,1.712648,-0.399743,-1.762945,1.524117,-2.026988,1.367265,-0.902002 },
54  {-1.028464,1.558295,-0.645619,-1.909291,1.426565,-1.515046,1.478929,-1.673280 },
55  {-0.795581,1.580700,-0.896500,-1.754151,1.464109,-1.517622,1.451276,-1.816512 },
56  {-1.643063,1.578628,-0.275135,-1.936803,1.435267,-1.851053,1.461556,-1.088357 },
57  {-0.538870,1.554160,-1.151812,-1.573927,1.493638,-1.553494,1.414819,-1.951598 }
58 };
59 
60 double _q[8]={-0.419985,1.755759,-1.993156,-0.661874,1.224372,-2.184798,1.589697,-1.651615 };
61 #endif
62 
82 #define POINTS_ON_SPHERE 0
83 
89 #define N_POINTS 50000
90 
96 #define DIM 8
97 
103 #define TOPOLOGY TOPOLOGY_S
104 
110 #define POINTS_IN_LEAF 25
111 
119 #define SAMPLING_EXPANSION 1.0
120 
126 #define R 2.0
127 
134 #define REP 1000
135 
136 
142 #define N_OPTIONS 9
143 
156 int CmpUInt(const void *a,const void *b);
157 
165 double getTime();
166 
167 /**********************************************************************************************/
168 /**********************************************************************************************/
169 
170 int CmpUInt(const void *a,const void *b)
171 {
172  return(*((unsigned int*)a)-*((unsigned int*)b));
173 }
174 
175 double getTime()
176 {
177  struct rusage usage;
178 
179  getrusage(RUSAGE_SELF,&usage);
180 
181  /* Accumulate the user and system time and convert to miliseconds */
182  return((double)(usage.ru_utime.tv_sec +usage.ru_stime.tv_sec )*1000.0+
183  (double)(usage.ru_utime.tv_usec+usage.ru_stime.tv_usec)/1000.0);
184 }
185 
186 /**********************************************************************************************/
187 /**********************************************************************************************/
188 
208 int main(int argc, char **arg)
209 {
210  char *option[N_OPTIONS]={"-h","-n","-d","-t","-l","-r","-m","-s","-e"};
211 
212  unsigned int nPoints,dim,tpg,pLeaf,rep;
213  double searchR,expansion;
214 
215  /* The two kd-trees to compare */
216  TKDtree *Mkdt;
217  #ifdef _MPNN
218  TKDTree *Ykdt;
219  #endif
220 
221  /* Several auxiliary variables */
222  boolean found;
223  unsigned int i,j;
224  double **point,*q;
225  Trectangle ambient;
226  unsigned int *topology;
227  unsigned int id;
228  double l,u,d,r2;
229  unsigned int *nn,n,m;
230  double *dst,dMin;
231  unsigned int idMin;
232 
233  /* Random seed */
234  unsigned int ri;
235 
236  /* To measure time */
237  time_t t;
238  double tStart,tEnd;
239 
240  /* Set the parameters to the default values */
241  nPoints=N_POINTS;
242  dim=DIM;
243  tpg=TOPOLOGY;
244  pLeaf=POINTS_IN_LEAF;
245  expansion=SAMPLING_EXPANSION;
246  searchR=R;
247  rep=REP;
248 
249  /* Process the input parameters, if any */
250  i=1;
251  while (i<argc)
252  {
253  found=FALSE;
254  j=0;
255  while((!found)&&(j<N_OPTIONS))
256  {
257  if (strcmp(arg[i],option[j])==0)
258  {
259  switch(j)
260  {
261  case 0: /* -h */
262  fprintf(stderr,"cuik-kdtree test program\n");
263  fprintf(stderr,"Usage: \n");
264  fprintf(stderr," test-cuik-kdtree <option> <ooption> <option> ...\n");
265  fprintf(stderr,"Options: \n");
266  fprintf(stderr," -n <value> Number of random points to generate.\n");
267  fprintf(stderr," Default value: %u\n",N_POINTS);
268  fprintf(stderr," -d <value> Dimension of the points to generate.\n");
269  fprintf(stderr," Default value: %u\n",DIM);
270  fprintf(stderr," -t <R|S> Topology (R or S) of the points to generate.\n");
271  fprintf(stderr," The same topology is used for all the dimensions.\n");
272  fprintf(stderr," Default value: %s\n",(TOPOLOGY==TOPOLOGY_R?"R":"S"));
273  fprintf(stderr," -l <value> Maximum number of points in each leaf.\n");
274  fprintf(stderr," Default value: %u\n",POINTS_IN_LEAF);
275  fprintf(stderr," -r <value> Search radius (for the in-ball queries).\n");
276  fprintf(stderr," Default value: %f\n",R);
277  fprintf(stderr," -m <value> Number of reptetions to gather execution times.\n");
278  fprintf(stderr," Default value: %u\n",REP);
279  fprintf(stderr," -e <value> Sampling expansion (not used so far in the test).\n");
280  fprintf(stderr," Default value: %f\n",SAMPLING_EXPANSION);
281  fprintf(stderr," -s <value> Random seed.\n");
282  fprintf(stderr," Default value: arbitrarily fixed\n");
283  fprintf(stderr," -h This help.\n");
284  fprintf(stderr,"Examples: \n");
285  fprintf(stderr," test-cuik-kdtree\n");
286  fprintf(stderr," test-cuik-kdtree -t R -r 0.75\n");
287  fprintf(stderr," test-cuik-kdtree -n 100000\n");
288  exit(EXIT_SUCCESS);
289  break;
290 
291  case 1: /* -n */
292  found=TRUE;
293  i++;
294  nPoints=(unsigned int)atoi(arg[i]);
295  if (nPoints<2)
296  {
297  fprintf(stderr,"Too smalll number of points (-n).\n");
298  exit(EXIT_FAILURE);
299  }
300  break;
301 
302  case 2: /* -d */
303  found=TRUE;
304  i++;
305  dim=(unsigned int)atoi(arg[i]);
306  if (dim<1)
307  {
308  fprintf(stderr,"Too smalll dimension (-d).\n");
309  exit(EXIT_FAILURE);
310  }
311  break;
312 
313  case 3: /* -t */
314  found=TRUE;
315  i++;
316 
317  if (arg[i][0]=='R')
318  tpg=TOPOLOGY_R;
319  else
320  {
321  if (arg[i][0]=='S')
322  tpg=TOPOLOGY_S;
323  else
324  {
325  fprintf(stderr,"Unknown topology (-t).\n");
326  exit(EXIT_FAILURE);
327  }
328  }
329  break;
330 
331  case 4: /* -l */
332  found=TRUE;
333  i++;
334  pLeaf=(unsigned int)atoi(arg[i]);
335  if (pLeaf<1)
336  {
337  fprintf(stderr,"Too smalll number of points in each leaf (-l).\n");
338  exit(EXIT_FAILURE);
339  }
340  break;
341 
342  case 5: /* -r */
343  found=TRUE;
344  i++;
345  searchR=(double)atof(arg[i]);
346  if (searchR<=0)
347  {
348  fprintf(stderr,"The search radius must be positive (-r).\n");
349  exit(EXIT_FAILURE);
350  }
351  break;
352 
353  case 6: /* -m */
354  found=TRUE;
355  i++;
356  rep=(unsigned int)atoi(arg[i]);
357  if (rep<1)
358  {
359  fprintf(stderr,"The number of repetitions must be positive (-m).\n");
360  exit(EXIT_FAILURE);
361  }
362  break;
363 
364  case 7: /* -s */
365  found=TRUE;
366  i++;
367  ri=(unsigned int)atof(arg[i]);
368  break;
369 
370  case 8: /* -e */
371  found=TRUE;
372  i++;
373  expansion=atof(arg[i]);
374  break;
375  }
376  }
377  j++;
378  }
379 
380  if (!found)
381  {
382  fprintf(stderr,"Unknown command line option %s.\nUse -h for help.\n",arg[i]);
383  exit(EXIT_FAILURE);
384  }
385  i++;
386  }
387 
388  /* Init the random number generator */
389  t=time(NULL); /* Get the time at which input files have been read */
390  ri=(unsigned int)t;
391  //ri=1386189846;
392  randomSet(ri);
393 
394  #ifdef FIXED_SET
395  tpg=TOPOLOGY_R;
396  nPoints=38;
397  dim=8;
398  searchR=0.4*2;
399  #endif
400 
401  /* Print information about */
402  printf("\n\n************************************************************\n");
403  printf("Parameters\n");
404  printf(" Random seed : %u\n",ri);
405  printf(" Topology : %s\n",(tpg==TOPOLOGY_R?"R":"S"));
406  printf(" No. points : %u\n",nPoints);
407  printf(" Dimension : %u\n",dim);
408  printf(" Points in leaf: %u\n",pLeaf);
409  printf(" Search radius : %f\n",searchR);
410  if (rep>1)
411  printf(" Repetitions : %u\n",rep);
412  printf("\n");
413 
414  /* define the ambient space */
415  InitRectangle(dim,NULL,NULL,&ambient);
416 
417  if (tpg==TOPOLOGY_R)
418  {
419  l=-1-(POINTS_ON_SPHERE?0.1:0);
420  u=+1+(POINTS_ON_SPHERE?0.1:0);
421  topology=NULL;
422  }
423  else
424  {
425  l=-M_PI;
426  u=+M_PI;
427  NEW(topology,dim,unsigned int);
428  for(i=0;i<dim;i++)
429  topology[i]=tpg; /* == TOPOLOGY_S */
430  }
431  for(i=0;i<dim;i++)
432  {
433  SetRectangleLowerLimit(i,l,&ambient);
434  SetRectangleUpperLimit(i,u,&ambient);
435  }
436 
437  /* Define the points: uniform distribution on a dim-sphere */
438  printf("Generating %u random points\n\n",nPoints);
439 
440  NEW(point,nPoints,double*);
441  for(i=0;i<nPoints;i++)
442  {
443  NEW(point[i],dim,double);
444  #if (POINTS_ON_SPHERE)
445  for(j=0;j<dim;j++)
446  point[i][j]=randomNormal();
447  VectorNormalize(dim,point[i]);
448  #else
449  #ifdef FIXED_SET
450  for(j=0;j<dim;j++)
451  point[i][j]=_point[i][j];
452  #else
453  RandomPointInRectangle(point[i],&ambient);
454  #endif
455  #endif
456  }
457 
458  /* Build the two kd-trees */
459  printf("Building kd-tree\n");
460  #ifdef _MPNN
461  tStart=getTime();
462  if (topology==NULL)
463  Ykdt=CreateKDTree(dim);
464  else
465  Ykdt=CreateKDTreeT(dim,(int *)topology);
466  for(i=0;i<nPoints;i++)
467  AddPoint2KDTree(point[i],Ykdt);
468  tEnd=getTime();
469  printf(" MPNN : %7.3f ms\n",tEnd-tStart);
470  printf(" MPNN x point: %7.3f ms\n",(tEnd-tStart)/(double)nPoints);
471  #endif
472 
473  tStart=getTime();
474  for(i=0;i<nPoints;i++)
475  {
476  if (i==0)
477  Mkdt=InitKDTree(&ambient,topology,pLeaf,expansion,1,&(point[i]),&i);
478  else
479  AddPoint2KDtree(point[i],i,&Mkdt);
480  }
481  tEnd=getTime();
482  printf(" Cuik : %7.3f ms\n",tEnd-tStart);
483  printf(" Cuik x point: %7.3f ms\n\n",(tEnd-tStart)/(double)nPoints);
484  //printf(" Height : %u (%u)\n\n",Mkdt->height,(unsigned int)ceil(1+log2((double)nPoints/(double)pLeaf)));
485 
486  //PrintKDtree(stdout,1,Mkdt);
487 
488  #if (PLOTKDT)
489  if (dim==3)
490  PlotKDtree("kdtree.gcl",POINTS_ON_SPHERE,Mkdt);
491  #endif
492 
493  /* Define the query point */
494  printf("Defining the query point\n\n");
495  NEW(q,dim,double);
496  #ifdef FIXED_SET
497  for(j=0;j<dim;j++)
498  q[j]=_q[j];
499  #else
500  RandomPointInRectangle(q,&ambient);
501  #endif
502 
503  /* Query the trees */
504  #ifdef _MPNN
505  printf("Searching NN\n");
506  printf(" MPNN kd-tree : ");
507  QueryKDTree(q,(int *)&id,&d,Ykdt);
508  printf("%u\n",id);
509  #endif
510 
511  printf(" Cuik kd-tree : ");
512  NearestNeighbour(q,Mkdt);
513  printf("%u\n",id);
514 
515  printf(" Brute-force search: ");
516  dMin=INF;
517  for(i=0;i<nPoints;i++)
518  {
519  d=VectorSquaredDistanceTopologyMin(dMin,dim,topology,point[i],q);
520  if (d<dMin)
521  {
522  idMin=i;
523  dMin=d;
524  }
525  }
526  printf("%u\n\n",idMin);
527 
528  printf("Searching in-ball\n");
529  #ifdef _MPNN
530  printf(" MPNN kd-tree : ");
531  QueryKDTreeR(q,searchR,(int *)(&n),(int **)(&nn),&dst,Ykdt);
532  if (n>0)
533  {
534  qsort(nn,n,sizeof(unsigned int),CmpUInt);
535  printf("[%u] ",n);
536  if (n>10)
537  {
538  for(i=0;i<5;i++)
539  printf("%u ",nn[i]);
540  printf("... ");
541  for(i=n-5;i<n;i++)
542  printf("%u ",nn[i]);
543  }
544  else
545  {
546  for(i=0;i<n;i++)
547  printf("%u ",nn[i]);
548  }
549  if (n>0)
550  {
551  free(nn);
552  free(dst);
553  }
554  }
555  else
556  printf("no point");
557  printf("\n");
558  #endif
559 
560  printf(" Cuik kd-tree : ");
561  NeighboursInBall(q,searchR,&n,&nn,Mkdt);
562  if (n>0)
563  {
564  qsort(nn,n,sizeof(unsigned int),CmpUInt);
565  printf("[%u] ",n);
566  if (n>10)
567  {
568  for(i=0;i<5;i++)
569  printf("%u ",nn[i]);
570  printf("... ");
571  for(i=n-5;i<n;i++)
572  printf("%u ",nn[i]);
573  }
574  else
575  {
576  for(i=0;i<n;i++)
577  printf("%u ",nn[i]);
578  }
579  if (n>0)
580  free(nn);
581  }
582  else
583  printf("no point");
584  printf("\n");
585 
586  printf(" Brute-force search: ");
587  r2=searchR*searchR;
588  n=0;
589  m=100;
590  NEW(nn,m,unsigned int);
591  for(i=0;i<nPoints;i++)
592  {
593  if (VectorSquaredDistanceTopologyMin(r2,dim,topology,point[i],q)<r2)
594  {
595  if (n==m)
596  MEM_DUP(nn,m,unsigned int);
597  nn[n]=i;
598  n++;
599  }
600  }
601  if (n>0)
602  {
603  printf("[%u] ",n);
604  if (n>10)
605  {
606  for(i=0;i<5;i++)
607  printf("%u ",nn[i]);
608  printf("... ");
609  for(i=n-5;i<n;i++)
610  printf("%u ",nn[i]);
611  }
612  else
613  {
614  for(i=0;i<n;i++)
615  printf("%u ",nn[i]);
616  }
617  }
618  else
619  printf("no point");
620  free(nn);
621  printf("\n\n");
622 
623  /* If we have to collect statistics about the execution time.... */
624  if (rep>1)
625  {
626  printf("Average time per NN query\n");
627 
628  #ifdef _MPNN
629  tStart=getTime();
630  for(j=0;j<rep;j++)
631  {
632  RandomPointInRectangle(q,&ambient);
633  QueryKDTree(q,(int *)&id,&d,Ykdt);
634  }
635  tEnd=getTime();
636  printf(" MPNN : %f ms\n",(tEnd-tStart)/(double)rep);
637  #endif
638 
639  tStart=getTime();
640  for(j=0;j<rep;j++)
641  {
642  RandomPointInRectangle(q,&ambient);
643  id=NearestNeighbour(q,Mkdt);
644  }
645  tEnd=getTime();
646  printf(" Cuik : %f ms\n",(tEnd-tStart)/(double)rep);
647 
648  tStart=getTime();
649  for(j=0;j<rep;j++)
650  {
651  dMin=INF;
652  for(i=0;i<nPoints;i++)
653  {
654  d=VectorSquaredDistanceTopologyMin(dMin,dim,topology,point[i],q);
655  if (d<dMin)
656  {
657  idMin=i;
658  dMin=d;
659  }
660  }
661  }
662  tEnd=getTime();
663  printf(" Brute-force: %f ms\n\n",(tEnd-tStart)/(double)rep);
664 
665  printf("Average time per in-ball query\n");
666 
667  #ifdef _MPNN
668  tStart=getTime();
669  for(j=0;j<rep;j++)
670  {
671  RandomPointInRectangle(q,&ambient);
672  QueryKDTreeR(q,searchR,(int *)(&n),(int **)(&nn),&dst,Ykdt);
673  if (n>0)
674  {
675  free(nn);
676  free(dst);
677  }
678  }
679  tEnd=getTime();
680  printf(" MPNN : %f ms\n",(tEnd-tStart)/(double)rep);
681  #endif
682 
683  tStart=getTime();
684  for(j=0;j<rep;j++)
685  {
686  RandomPointInRectangle(q,&ambient);
687  NeighboursInBall(q,searchR,&n,&nn,Mkdt);
688  if (n>0)
689  free(nn);
690  }
691  tEnd=getTime();
692  printf(" Cuik : %f ms\n",(tEnd-tStart)/(double)rep);
693 
694  tStart=getTime();
695  for(j=0;j<rep;j++)
696  {
697  RandomPointInRectangle(q,&ambient);
698  n=0;
699  m=100;
700  NEW(nn,m,unsigned int);
701  for(i=0;i<nPoints;i++)
702  {
703  if (VectorSquaredDistanceTopologyMin(r2,dim,topology,point[i],q)<r2)
704  {
705  if (n==m)
706  MEM_DUP(nn,m,unsigned int);
707  nn[n]=i;
708  n++;
709  }
710  }
711  free(nn);
712  }
713  tEnd=getTime();
714  printf(" Brute force: %f ms\n\n",(tEnd-tStart)/(double)rep);
715  }
716 
717  /* Release the information */
718  free(q);
719 
720  for(i=0;i<nPoints;i++)
721  free(point[i]);
722  free(point);
723 
724  if (topology!=NULL)
725  free(topology);
726  DeleteRectangle(&ambient);
727 
728  DeleteKDtree(Mkdt);
729  #ifdef _MPNN
730  DeleteKDTree(Ykdt);
731  #endif
732 
733  return(EXIT_SUCCESS);
734 }
#define N_OPTIONS
Number of command line options.
#define POINTS_IN_LEAF
Maximum number of points in a leaf.
void RandomPointInRectangle(double *c, Trectangle *b)
Returns the a random point along the selected dimensions.
Definition: rectangle.c:145
#define R
Search radius.
#define TOPOLOGY
Topology.
void VectorNormalize(unsigned int s, double *v)
Normalizes a vector.
Definition: vector.c:58
#define TRUE
TRUE.
Definition: definitions.h:161
double randomNormal()
Returns a random double acording to a normal distribution.
Definition: random.c:38
void PlotKDtree(char *fname, boolean sphere, TKDtree *kdt)
Plots a kd-tree.
void SetRectangleLowerLimit(unsigned int i, double l, Trectangle *b)
Set the lower limit.
Definition: rectangle.c:123
#define N_POINTS
Number of points.
void DeleteRectangle(Trectangle *b)
Destructor.
Definition: rectangle.c:375
void DeleteKDtree(TKDtree *kdt)
Deletes a KD-tree.
Definition: cuik-kdtree.c:833
#define INF
Infinite.
Definition: definitions.h:141
#define REP
Number of queries.
double getTime()
Gets the time in miliseconds.
#define TOPOLOGY_R
One of the possible topologies.
Definition: definitions.h:180
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: definitions.h:87
#define POINTS_ON_SPHERE
Method to generate the random points.
Definition of constants and macros used in several parts of the library.
Headers of the kd-tree implementation.
#define DIM
Dimension.
#define SAMPLING_EXPANSION
Sampling area expansion.
void SetRectangleUpperLimit(unsigned int i, double u, Trectangle *b)
Set the upper limit.
Definition: rectangle.c:130
A rectangle.
Definition: rectangle.h:26
void InitRectangle(unsigned int dim, double *l, double *u, Trectangle *b)
Initializes a rectangle.
Definition: rectangle.c:20
double VectorSquaredDistanceTopologyMin(double t2, unsigned int s, unsigned int *tp, double *v1, double *v2)
Computes the squared distance of two points.
Definition: vector.c:17
#define TOPOLOGY_S
One of the possible topologies.
Definition: definitions.h:188
Definition of basic operations between points.
#define FALSE
FALSE.
Definition: definitions.h:170
int main(int argc, char **arg)
Main body of the test program for the cuik-kdtree library.
Definition of basic randomization functions.
unsigned int NearestNeighbour(double *point, TKDtree *kdt)
Determines the nearest-neighbour for a point.
Definition: cuik-kdtree.c:714
void NeighboursInBall(double *point, double r, unsigned int *n, unsigned int **ids, TKDtree *kdt)
Neighbours in a ball.
Definition: cuik-kdtree.c:730
#define M_PI
Pi.
Definition: definitions.h:24
TKDtree * InitKDTree(Trectangle *ambient, unsigned int *topology, unsigned int m, double r, unsigned int n, double **points, unsigned int *ids)
Initializes a kd-tree from a set of points.
Definition: cuik-kdtree.c:544
void AddPoint2KDtree(double *point, unsigned int id, TKDtree **kdt)
Adds a point to a kd-tree.
Definition: cuik-kdtree.c:582
#define MEM_DUP(_var, _n, _type)
Duplicates a previously allocated memory space.
Definition: definitions.h:123
int CmpUInt(const void *a, const void *b)
Compares two unsigned integers.
A KD-tree.
Definition: cuik-kdtree.h:52
void randomSet(unsigned int seed)
Sets the random seed.
Definition: random.c:25