#include <QuonPRDefs.h>
Definition at line 71 of file QuonPRDefs.h.
Public Member Functions | |
| PRTreeNode (QPRBoundingBox region, PRTreeNode *parent) | |
| void | add (QPRSite *site) |
| void | remove (const Vector2D p) |
| QPRSite * | findBindingNeighbor (const Vector2D p, int direction, int maxdepth) |
| QPRSite * | findNearestNeighbor (const Vector2D p) const |
| int | getDepth (const Vector2D p, int depth=0) const |
| int | getDepth (const PRTreeNode *node, int depth=0) const |
Public Attributes | |
| QPRBoundingBox | region |
| QPRSite * | contents |
| PRTreeNode * | parent |
| PRTreeNode * | child [4] |
Private Member Functions | |
| void | collapse () |
| std::ostream & | print (std::ostream &Stream, int depth=0) const |
Friends | |
| std::ostream & | operator<< (std::ostream &Stream, const PRTreeNode &node) |
| PRTreeNode::PRTreeNode | ( | QPRBoundingBox | region, | |
| PRTreeNode * | parent | |||
| ) |
| void PRTreeNode::add | ( | QPRSite * | site | ) |
Definition at line 217 of file QuonPRDefs.cc.
Referenced by add(), QuonPR::addSite(), and QuonPR::updateThisSite().
00218 { 00219 int i = region.getChildNum(site->position); 00220 if(child[i] == NULL) { 00221 child[i] = new PRTreeNode(region.getQuadrant(i), this); 00222 child[i]->contents = site; 00223 site->PRNode = child[i]; 00224 00225 if(contents != NULL) { 00226 i = region.getChildNum(contents->position); 00227 if(child[i] == NULL) { 00228 child[i] = new PRTreeNode(region.getQuadrant(i), this); 00229 child[i]->contents = contents; 00230 contents->PRNode = child[i]; 00231 } 00232 else { 00233 child[i]->add(contents); 00234 } 00235 contents = NULL; 00236 } 00237 } 00238 else { 00239 child[i]->add(site); 00240 } 00241 }
| void PRTreeNode::remove | ( | const Vector2D | p | ) |
Definition at line 243 of file QuonPRDefs.cc.
Referenced by QuonPR::addSite(), QuonPR::deleteSite(), QuonPR::purgeSites(), remove(), and QuonPR::updateThisSite().
00244 { 00245 int i = region.getChildNum(p); 00246 if(child[i]->contents != NULL && child[i]->contents->position == p) { 00247 delete child[i]; 00248 child[i] = NULL; 00249 collapse(); 00250 } 00251 else { 00252 child[i]->remove(p); 00253 } 00254 }
Definition at line 256 of file QuonPRDefs.cc.
Referenced by QuonPR::classifySites().
00257 { 00258 if(!region.collide(p)) { 00259 return NULL; 00260 } 00261 int depth = 0; 00262 PRTreeNode* node = this; 00263 while(depth < maxdepth && node->child[node->region.getChildNum(p)] != NULL) { 00264 node = node->child[node->region.getChildNum(p)]; 00265 ++depth; 00266 } 00267 00268 int reverseDirection = (direction + 4) % 8; 00269 int childNum = node->region.getChildNum(p); 00270 Vector2D pNear = node->region.shiftCenter(PRDirection(reverseDirection)); 00271 if(node->contents != NULL) { 00272 return node->contents; 00273 } 00274 else { 00275 if((depth == maxdepth) || 00276 (childNum == reverseDirection / 2) || 00277 ((reverseDirection % 2 == 1) && (childNum == ((reverseDirection + 1) % 8) / 2))) { 00278 return node->findNearestNeighbor(pNear); 00279 } 00280 else { 00281 QPRBoundingBox box = node->region.getQuadrant(node->region.getChildNum(p)); 00282 return findBindingNeighbor(box.shiftCenter(PRDirection(direction)), direction, getDepth(node) + 1); 00283 } 00284 } 00285 }
Definition at line 287 of file QuonPRDefs.cc.
Referenced by findBindingNeighbor(), and findNearestNeighbor().
00288 { 00289 if(contents != NULL) { 00290 return contents; 00291 } 00292 else { 00293 QPRSite* temp = NULL; 00294 QPRSite* best = NULL; 00295 double distance = QINFINITY; 00296 for(int i=0; i<4; i++) { 00297 if(child[i] != NULL) { 00298 temp = child[i]->findNearestNeighbor(p); 00299 if(temp->position.distanceSqr(p) < distance) { 00300 distance = temp->position.distanceSqr(p); 00301 best = temp; 00302 } 00303 } 00304 } 00305 return best; 00306 } 00307 }
| int PRTreeNode::getDepth | ( | const Vector2D | p, | |
| int | depth = 0 | |||
| ) | const |
Definition at line 309 of file QuonPRDefs.cc.
Referenced by QuonPR::classifySites(), findBindingNeighbor(), and getDepth().
00310 { 00311 if(contents != NULL && contents->position == p) { 00312 return depth; 00313 } 00314 else { 00315 return child[region.getChildNum(p)]->getDepth(p, depth + 1); 00316 } 00317 }
| int PRTreeNode::getDepth | ( | const PRTreeNode * | node, | |
| int | depth = 0 | |||
| ) | const |
Definition at line 319 of file QuonPRDefs.cc.
00320 { 00321 if(this == node) { 00322 return depth; 00323 } 00324 else { 00325 return child[region.getChildNum(node->region.center)]->getDepth(node, depth + 1); 00326 } 00327 }
| void PRTreeNode::collapse | ( | ) | [private] |
Definition at line 334 of file QuonPRDefs.cc.
Referenced by collapse(), and remove().
00335 { 00336 int childNum = -1; 00337 for(int i=0; i<4; i++) { 00338 if(child[i] != NULL) { 00339 if(childNum < 0) { 00340 childNum = i; 00341 } 00342 else { 00343 childNum = -1; 00344 break; 00345 } 00346 } 00347 } 00348 if(childNum >= 0 && child[childNum]->contents != NULL) { 00349 contents = child[childNum]->contents; 00350 delete child[childNum]; 00351 child[childNum] = NULL; 00352 contents->PRNode = this; 00353 if(parent != NULL) { 00354 parent->collapse(); 00355 } 00356 } 00357 }
| std::ostream & PRTreeNode::print | ( | std::ostream & | Stream, | |
| int | depth = 0 | |||
| ) | const [private] |
Definition at line 359 of file QuonPRDefs.cc.
Referenced by operator<<(), and print().
00360 { 00361 if(contents == NULL) { 00362 if(parent == NULL) { 00363 Stream << "#" << endl; 00364 } 00365 else { 00366 Stream << "|" << endl; 00367 } 00368 for(int i=0; i<4; i++) { 00369 for(int j=0; j<depth; j++) { 00370 Stream << " "; 00371 } 00372 Stream << "|=="; 00373 if(child[i] != NULL) { 00374 child[i]->print(Stream, depth + 1); 00375 } 00376 else { 00377 Stream << "]" << endl; 00378 } 00379 } 00380 } 00381 else { 00382 if(parent == NULL) { 00383 Stream << "#" << endl << "|=="; 00384 } 00385 Stream << "> " << *contents << endl; 00386 } 00387 return Stream; 00388 }
| std::ostream& operator<< | ( | std::ostream & | Stream, | |
| const PRTreeNode & | node | |||
| ) | [friend] |
Definition at line 75 of file QuonPRDefs.h.
Referenced by add(), QuonPR::classifySites(), findBindingNeighbor(), getDepth(), remove(), and QuonPR::updateThisSite().
Definition at line 76 of file QuonPRDefs.h.
Referenced by add(), collapse(), findBindingNeighbor(), findNearestNeighbor(), getDepth(), QuonPR::initializeOverlay(), print(), PRTreeNode(), and remove().
Definition at line 78 of file QuonPRDefs.h.
Referenced by add(), collapse(), findBindingNeighbor(), findNearestNeighbor(), getDepth(), print(), PRTreeNode(), and remove().
1.5.5