queso-0.57.0
Functions | Variables
ann_sample.cpp File Reference

Go to the source code of this file.

Functions

void getArgs (int argc, char **argv)
 
bool readPt (istream &in, ANNpoint p)
 
void printPt (ostream &out, ANNpoint p)
 
int main (int argc, char **argv)
 

Variables

int k = 1
 
int dim = 2
 
double eps = 0
 
int maxPts = 1000
 
istream * dataIn = NULL
 
istream * queryIn = NULL
 

Function Documentation

void getArgs ( int  argc,
char **  argv 
)
int main ( int  argc,
char **  argv 
)

Definition at line 78 of file ann_sample.cpp.

References annAllocPt(), annAllocPts(), annClose(), ANNkd_tree::annkSearch(), dataIn, dim, eps, getArgs(), k, maxPts, printPt(), queryIn, and readPt().

79 {
80  int nPts; // actual number of data points
81  ANNpointArray dataPts; // data points
82  ANNpoint queryPt; // query point
83  ANNidxArray nnIdx; // near neighbor indices
84  ANNdistArray dists; // near neighbor distances
85  ANNkd_tree* kdTree; // search structure
86 
87  getArgs(argc, argv); // read command-line arguments
88 
89  queryPt = annAllocPt(dim); // allocate query point
90  dataPts = annAllocPts(maxPts, dim); // allocate data points
91  nnIdx = new ANNidx[k]; // allocate near neigh indices
92  dists = new ANNdist[k]; // allocate near neighbor dists
93 
94  nPts = 0; // read data points
95 
96  cout << "Data Points:\n";
97  while (nPts < maxPts && readPt(*dataIn, dataPts[nPts])) {
98  printPt(cout, dataPts[nPts]);
99  nPts++;
100  }
101 
102  kdTree = new ANNkd_tree( // build search structure
103  dataPts, // the data points
104  nPts, // number of points
105  dim); // dimension of space
106 
107  while (readPt(*queryIn, queryPt)) { // read query points
108  cout << "Query point: "; // echo query point
109  printPt(cout, queryPt);
110 
111  kdTree->annkSearch( // search
112  queryPt, // query point
113  k, // number of near neighbors
114  nnIdx, // nearest neighbors (returned)
115  dists, // distance (returned)
116  eps); // error bound
117 
118  cout << "\tNN:\tIndex\tDistance\n";
119  for (int i = 0; i < k; i++) { // print summary
120  dists[i] = sqrt(dists[i]); // unsquare distance
121  cout << "\t" << i << "\t" << nnIdx[i] << "\t" << dists[i] << "\n";
122  }
123  }
124  delete [] nnIdx; // clean things up
125  delete [] dists;
126  delete kdTree;
127  annClose(); // done with ANN
128 
129  return EXIT_SUCCESS;
130 }
bool readPt(istream &in, ANNpoint p)
Definition: ann_sample.cpp:61
void printPt(ostream &out, ANNpoint p)
Definition: ann_sample.cpp:69
DLL_API void annClose()
Definition: kd_tree.cpp:221
double eps
Definition: ann_sample.cpp:55
istream * dataIn
Definition: ann_sample.cpp:58
int k
Definition: ann_sample.cpp:53
ANNcoord * ANNpoint
Definition: ANN.h:375
double ANNdist
Definition: ANN.h:159
int ANNidx
Definition: ANN.h:175
DLL_API ANNpoint annAllocPt(int dim, ANNcoord c=0)
Definition: ANN.cpp:110
ANNpoint * ANNpointArray
Definition: ANN.h:376
int dim
Definition: ann2fig.cpp:81
void getArgs(int argc, char **argv)
Definition: ann2fig.cpp:146
istream * queryIn
Definition: ann_sample.cpp:59
void annkSearch(ANNpoint q, int k, ANNidxArray nn_idx, ANNdistArray dd, double eps=0.0)
Definition: kd_search.cpp:89
int maxPts
Definition: ann_sample.cpp:56
ANNdist * ANNdistArray
Definition: ANN.h:377
DLL_API ANNpointArray annAllocPts(int n, int dim)
Definition: ANN.cpp:117
ANNidx * ANNidxArray
Definition: ANN.h:378
void printPt ( ostream &  out,
ANNpoint  p 
)

Definition at line 69 of file ann_sample.cpp.

References dim.

Referenced by main().

70 {
71  out << "(" << p[0];
72  for (int i = 1; i < dim; i++) {
73  out << ", " << p[i];
74  }
75  out << ")\n";
76 }
int dim
Definition: ann2fig.cpp:81
bool readPt ( istream &  in,
ANNpoint  p 
)

Definition at line 61 of file ann_sample.cpp.

References dim.

Referenced by main().

62 {
63  for (int i = 0; i < dim; i++) {
64  if(!(in >> p[i])) return false;
65  }
66  return true;
67 }
int dim
Definition: ann2fig.cpp:81

Variable Documentation

istream* dataIn = NULL
int dim = 2

Definition at line 54 of file ann_sample.cpp.

double eps = 0

Definition at line 55 of file ann_sample.cpp.

Referenced by QUESO::BaseVectorRV< V, M >::estimateENT_ANN(), and main().

int k = 1
int maxPts = 1000

Definition at line 56 of file ann_sample.cpp.

Referenced by annMaxPtsVisit(), and main().

istream* queryIn = NULL

Definition at line 59 of file ann_sample.cpp.

Referenced by main().


Generated on Sat Apr 22 2017 14:04:37 for queso-0.57.0 by  doxygen 1.8.5