queso-0.53.0
Public Member Functions | Private Attributes | List of all members
ANNkd_leaf Class Reference

#include <kd_tree.h>

Inheritance diagram for ANNkd_leaf:
Inheritance graph
[legend]
Collaboration diagram for ANNkd_leaf:
Collaboration graph
[legend]

Public Member Functions

 ANNkd_leaf (int n, ANNidxArray b)
 
 ~ANNkd_leaf ()
 
virtual void getStats (int dim, ANNkdStats &st, ANNorthRect &bnd_box)
 
virtual void print (int level, ostream &out)
 
virtual void dump (ostream &out)
 
virtual void ann_search (ANNdist)
 
virtual void ann_pri_search (ANNdist)
 
virtual void ann_FR_search (ANNdist)
 
- Public Member Functions inherited from ANNkd_node
virtual ~ANNkd_node ()
 

Private Attributes

int n_pts
 
ANNidxArray bkt
 

Detailed Description

Definition at line 91 of file kd_tree.h.

Constructor & Destructor Documentation

ANNkd_leaf::ANNkd_leaf ( int  n,
ANNidxArray  b 
)
inline

Definition at line 96 of file kd_tree.h.

References n_pts.

99  {
100  n_pts = n; // number of points in bucket
101  bkt = b; // the bucket
102  }
int n_pts
Definition: kd_tree.h:93
ANNidxArray bkt
Definition: kd_tree.h:94
ANNkd_leaf::~ANNkd_leaf ( )
inline

Definition at line 104 of file kd_tree.h.

104 { } // destructor (none)

Member Function Documentation

void ANNkd_leaf::ann_FR_search ( ANNdist  box_dist)
virtual

Implements ANNkd_node.

Definition at line 148 of file kd_fix_rad_search.cpp.

References ANN_ALLOW_SELF_MATCH, ANN_COORD, ANN_FLOP, ANN_LEAF, ANN_POW, ANN_PTS, ANN_SUM, ANNkdFRDim, ANNkdFRPts, ANNkdFRPtsInRange, ANNkdFRPtsVisited, ANNkdFRQ, ANNkdFRSqRad, bkt, ANNmin_k::insert(), and n_pts.

149 {
150  register ANNdist dist; // distance to data point
151  register ANNcoord* pp; // data coordinate pointer
152  register ANNcoord* qq; // query coordinate pointer
153  register ANNcoord t;
154  register int d;
155 
156  for (int i = 0; i < n_pts; i++) { // check points in bucket
157 
158  pp = ANNkdFRPts[bkt[i]]; // first coord of next data point
159  qq = ANNkdFRQ; // first coord of query point
160  dist = 0;
161 
162  for(d = 0; d < ANNkdFRDim; d++) {
163  ANN_COORD(1) // one more coordinate hit
164  ANN_FLOP(5) // increment floating ops
165 
166  t = *(qq++) - *(pp++); // compute length and adv coordinate
167  // exceeds dist to k-th smallest?
168  if( (dist = ANN_SUM(dist, ANN_POW(t))) > ANNkdFRSqRad) {
169  break;
170  }
171  }
172 
173  if (d >= ANNkdFRDim && // among the k best?
174  (ANN_ALLOW_SELF_MATCH || dist!=0)) { // and no self-match problem
175  // add it to the list
176  ANNkdFRPointMK->insert(dist, bkt[i]);
177  ANNkdFRPtsInRange++; // increment point count
178  }
179  }
180  ANN_LEAF(1) // one more leaf node visited
181  ANN_PTS(n_pts) // increment points visited
182  ANNkdFRPtsVisited += n_pts; // increment number of points visited
183 }
ANNdist ANNkdFRSqRad
#define ANN_LEAF(n)
Definition: ANNperf.h:132
#define ANN_PTS(n)
Definition: ANNperf.h:135
double ANNcoord
Definition: ANN.h:158
const ANNbool ANN_ALLOW_SELF_MATCH
Definition: ANN.h:235
#define ANN_SUM(x, y)
Definition: ANN.h:362
int ANNkdFRPtsVisited
int n_pts
Definition: kd_tree.h:93
ANNidxArray bkt
Definition: kd_tree.h:94
int ANNkdFRPtsInRange
#define ANN_FLOP(n)
Definition: ANNperf.h:131
ANNpointArray ANNkdFRPts
void insert(PQKkey kv, PQKinfo inf)
Definition: pr_queue_k.h:99
ANNmin_k * ANNkdFRPointMK
#define ANN_COORD(n)
Definition: ANNperf.h:136
double ANNdist
Definition: ANN.h:159
ANNpoint ANNkdFRQ
int ANNkdFRDim
#define ANN_POW(v)
Definition: ANN.h:360
void ANNkd_leaf::ann_pri_search ( ANNdist  box_dist)
virtual

Implements ANNkd_node.

Definition at line 181 of file kd_pr_search.cpp.

References ANN_ALLOW_SELF_MATCH, ANN_COORD, ANN_FLOP, ANN_LEAF, ANN_POW, ANN_PTS, ANN_SUM, ANNprDim, ANNprPts, ANNprQ, ANNptsVisited, bkt, ANNmin_k::insert(), ANNmin_k::max_key(), and n_pts.

182 {
183  register ANNdist dist; // distance to data point
184  register ANNcoord* pp; // data coordinate pointer
185  register ANNcoord* qq; // query coordinate pointer
186  register ANNdist min_dist; // distance to k-th closest point
187  register ANNcoord t;
188  register int d;
189 
190  min_dist = ANNprPointMK->max_key(); // k-th smallest distance so far
191 
192  for (int i = 0; i < n_pts; i++) { // check points in bucket
193 
194  pp = ANNprPts[bkt[i]]; // first coord of next data point
195  qq = ANNprQ; // first coord of query point
196  dist = 0;
197 
198  for(d = 0; d < ANNprDim; d++) {
199  ANN_COORD(1) // one more coordinate hit
200  ANN_FLOP(4) // increment floating ops
201 
202  t = *(qq++) - *(pp++); // compute length and adv coordinate
203  // exceeds dist to k-th smallest?
204  if( (dist = ANN_SUM(dist, ANN_POW(t))) > min_dist) {
205  break;
206  }
207  }
208 
209  if (d >= ANNprDim && // among the k best?
210  (ANN_ALLOW_SELF_MATCH || dist!=0)) { // and no self-match problem
211  // add it to the list
212  ANNprPointMK->insert(dist, bkt[i]);
213  min_dist = ANNprPointMK->max_key();
214  }
215  }
216  ANN_LEAF(1) // one more leaf node visited
217  ANN_PTS(n_pts) // increment points visited
218  ANNptsVisited += n_pts; // increment number of points visited
219 }
#define ANN_LEAF(n)
Definition: ANNperf.h:132
#define ANN_PTS(n)
Definition: ANNperf.h:135
ANNpoint ANNprQ
PQKkey max_key()
Definition: pr_queue_k.h:90
ANNmin_k * ANNprPointMK
double ANNcoord
Definition: ANN.h:158
int ANNprDim
const ANNbool ANN_ALLOW_SELF_MATCH
Definition: ANN.h:235
#define ANN_SUM(x, y)
Definition: ANN.h:362
int ANNptsVisited
Definition: ANN.cpp:191
int n_pts
Definition: kd_tree.h:93
ANNidxArray bkt
Definition: kd_tree.h:94
ANNpointArray ANNprPts
#define ANN_FLOP(n)
Definition: ANNperf.h:131
void insert(PQKkey kv, PQKinfo inf)
Definition: pr_queue_k.h:99
#define ANN_COORD(n)
Definition: ANNperf.h:136
double ANNdist
Definition: ANN.h:159
#define ANN_POW(v)
Definition: ANN.h:360
void ANNkd_leaf::ann_search ( ANNdist  box_dist)
virtual

Implements ANNkd_node.

Definition at line 172 of file kd_search.cpp.

References ANN_ALLOW_SELF_MATCH, ANN_COORD, ANN_FLOP, ANN_LEAF, ANN_POW, ANN_PTS, ANN_SUM, ANNkdDim, ANNkdPts, ANNkdQ, ANNptsVisited, bkt, ANNmin_k::insert(), ANNmin_k::max_key(), and n_pts.

173 {
174  register ANNdist dist; // distance to data point
175  register ANNcoord* pp; // data coordinate pointer
176  register ANNcoord* qq; // query coordinate pointer
177  register ANNdist min_dist; // distance to k-th closest point
178  register ANNcoord t;
179  register int d;
180 
181  min_dist = ANNkdPointMK->max_key(); // k-th smallest distance so far
182 
183  for (int i = 0; i < n_pts; i++) { // check points in bucket
184 
185  pp = ANNkdPts[bkt[i]]; // first coord of next data point
186  qq = ANNkdQ; // first coord of query point
187  dist = 0;
188 
189  for(d = 0; d < ANNkdDim; d++) {
190  ANN_COORD(1) // one more coordinate hit
191  ANN_FLOP(4) // increment floating ops
192 
193  t = *(qq++) - *(pp++); // compute length and adv coordinate
194  // exceeds dist to k-th smallest?
195  if( (dist = ANN_SUM(dist, ANN_POW(t))) > min_dist) {
196  break;
197  }
198  }
199 
200  if (d >= ANNkdDim && // among the k best?
201  (ANN_ALLOW_SELF_MATCH || dist!=0)) { // and no self-match problem
202  // add it to the list
203  ANNkdPointMK->insert(dist, bkt[i]);
204  min_dist = ANNkdPointMK->max_key();
205  }
206  }
207  ANN_LEAF(1) // one more leaf node visited
208  ANN_PTS(n_pts) // increment points visited
209  ANNptsVisited += n_pts; // increment number of points visited
210 }
#define ANN_LEAF(n)
Definition: ANNperf.h:132
#define ANN_PTS(n)
Definition: ANNperf.h:135
PQKkey max_key()
Definition: pr_queue_k.h:90
double ANNcoord
Definition: ANN.h:158
ANNmin_k * ANNkdPointMK
Definition: kd_search.cpp:83
const ANNbool ANN_ALLOW_SELF_MATCH
Definition: ANN.h:235
#define ANN_SUM(x, y)
Definition: ANN.h:362
int ANNptsVisited
Definition: ANN.cpp:191
int n_pts
Definition: kd_tree.h:93
ANNidxArray bkt
Definition: kd_tree.h:94
#define ANN_FLOP(n)
Definition: ANNperf.h:131
int ANNkdDim
Definition: kd_search.cpp:79
void insert(PQKkey kv, PQKinfo inf)
Definition: pr_queue_k.h:99
#define ANN_COORD(n)
Definition: ANNperf.h:136
double ANNdist
Definition: ANN.h:159
ANNpoint ANNkdQ
Definition: kd_search.cpp:80
ANNpointArray ANNkdPts
Definition: kd_search.cpp:82
#define ANN_POW(v)
Definition: ANN.h:360
void ANNkd_leaf::dump ( ostream &  out)
virtual

Implements ANNkd_node.

Definition at line 144 of file kd_dump.cpp.

References KD_TRIVIAL, and n_pts.

146 {
147  if (this == KD_TRIVIAL) { // canonical trivial leaf node
148  out << "leaf 0\n"; // leaf no points
149  }
150  else{
151  out << "leaf " << n_pts;
152  for (int j = 0; j < n_pts; j++) {
153  out << " " << bkt[j];
154  }
155  out << "\n";
156  }
157 }
int n_pts
Definition: kd_tree.h:93
ANNkd_leaf * KD_TRIVIAL
Definition: kd_tree.cpp:50
ANNidxArray bkt
Definition: kd_tree.h:94
void ANNkd_leaf::getStats ( int  dim,
ANNkdStats st,
ANNorthRect bnd_box 
)
virtual

Implements ANNkd_node.

Definition at line 147 of file kd_tree.cpp.

References ANN_AR_TOOBIG, annAspectRatio(), ANNkdStats::n_lf, ANNkdStats::n_tl, ANNkdStats::reset(), and ANNkdStats::sum_ar.

151 {
152  st.reset();
153  st.n_lf = 1; // count this leaf
154  if (this == KD_TRIVIAL) st.n_tl = 1; // count trivial leaf
155  double ar = annAspectRatio(dim, bnd_box); // aspect ratio of leaf
156  // incr sum (ignore outliers)
157  st.sum_ar += float(ar < ANN_AR_TOOBIG ? ar : ANN_AR_TOOBIG);
158 }
float sum_ar
Definition: ANNperf.h:55
int n_tl
Definition: ANNperf.h:51
const double ANN_AR_TOOBIG
Definition: kd_tree.cpp:145
ANNkd_leaf * KD_TRIVIAL
Definition: kd_tree.cpp:50
void reset(int d=0, int n=0, int bs=0)
Definition: ANNperf.h:59
double annAspectRatio(int dim, const ANNorthRect &bnd_box)
Definition: kd_util.cpp:52
int dim
Definition: ann2fig.cpp:81
int n_lf
Definition: ANNperf.h:50
void ANNkd_leaf::print ( int  level,
ostream &  out 
)
virtual

Implements ANNkd_node.

Definition at line 82 of file kd_tree.cpp.

References bkt, and n_pts.

85 {
86 
87  out << " ";
88  for (int i = 0; i < level; i++) // print indentation
89  out << "..";
90 
91  if (this == KD_TRIVIAL) { // canonical trivial leaf node
92  out << "Leaf (trivial)\n";
93  }
94  else{
95  out << "Leaf n=" << n_pts << " <";
96  for (int j = 0; j < n_pts; j++) {
97  out << bkt[j];
98  if (j < n_pts-1) out << ",";
99  }
100  out << ">\n";
101  }
102 }
int n_pts
Definition: kd_tree.h:93
ANNkd_leaf * KD_TRIVIAL
Definition: kd_tree.cpp:50
ANNidxArray bkt
Definition: kd_tree.h:94

Member Data Documentation

ANNidxArray ANNkd_leaf::bkt
private

Definition at line 94 of file kd_tree.h.

Referenced by ann_FR_search(), ann_pri_search(), ann_search(), and print().

int ANNkd_leaf::n_pts
private

Definition at line 93 of file kd_tree.h.

Referenced by ann_FR_search(), ann_pri_search(), ann_search(), and print().


The documentation for this class was generated from the following files:

Generated on Thu Jun 11 2015 13:52:33 for queso-0.53.0 by  doxygen 1.8.5