PTreeNode Class Reference

#include <QuonPDefs.h>

List of all members.


Detailed Description

Definition at line 70 of file QuonPDefs.h.


Public Member Functions

 PTreeNode (PTreeNode *parent)
void add (QPSite *site)
void reset ()
QPSite * findNearestNeighbor (const Vector2D p) const

Public Attributes

QPSite * contents
PTreeNode * parent
PTreeNode * child [4]

Private Member Functions

int getQuadrant (const Vector2D p) const

Constructor & Destructor Documentation

PTreeNode::PTreeNode ( PTreeNode *  parent  ) 

Definition at line 137 of file QuonPDefs.cc.

Referenced by add().

00138 {
00139     this->parent = parent;
00140     contents = NULL;
00141     child[0] = NULL;
00142     child[1] = NULL;
00143     child[2] = NULL;
00144     child[3] = NULL;
00145 }


Member Function Documentation

void PTreeNode::add ( QPSite *  site  ) 

Definition at line 147 of file QuonPDefs.cc.

Referenced by add(), and QuonP::classifySites().

00148 {
00149     if(contents == NULL) {
00150         contents = site;
00151     }
00152     else {
00153         int i = getQuadrant(site->position);
00154         if(child[i] == NULL) {
00155             child[i] = new PTreeNode(this);
00156         }
00157         child[i]->add(site);
00158     }
00159 }

void PTreeNode::reset (  ) 

Definition at line 161 of file QuonPDefs.cc.

Referenced by QuonP::classifySites(), and reset().

00162 {
00163     for(int i=0; i<4; i++) {
00164         if(child[i] != NULL) {
00165             child[i]->reset();
00166             delete child[i];
00167             child[i] = NULL;
00168         }
00169     }
00170     contents = NULL;
00171 }

QPSite * PTreeNode::findNearestNeighbor ( const Vector2D  p  )  const

Definition at line 173 of file QuonPDefs.cc.

Referenced by QuonP::classifySites(), and findNearestNeighbor().

00174 {
00175     QPSite* temp = NULL;
00176     QPSite* best = contents;
00177     double distance = contents->position.distanceSqr(p);
00178     for(int i=0; i<4; i++) {
00179         if(child[i] != NULL) {
00180             temp = child[i]->findNearestNeighbor(p);
00181             if(temp->position.distanceSqr(p) < distance) {
00182                 best = temp;
00183                 distance = temp->position.distanceSqr(p);
00184             }
00185         }
00186     }
00187     return best;
00188 }

int PTreeNode::getQuadrant ( const Vector2D  p  )  const [private]

Definition at line 190 of file QuonPDefs.cc.

Referenced by add().

00191 {
00192     int quadrant;
00193     if(p.x > contents->position.x) {
00194         if(p.y < contents->position.y) {
00195             quadrant = 2;
00196         }
00197         else {
00198             quadrant = 1;
00199         }
00200     }
00201     else {
00202         if(p.y < contents->position.y) {
00203             quadrant = 3;
00204         }
00205         else {
00206             quadrant = 0;
00207         }
00208     }
00209     return quadrant;
00210 }


Member Data Documentation

Definition at line 74 of file QuonPDefs.h.

Referenced by add(), findNearestNeighbor(), getQuadrant(), PTreeNode(), and reset().

Definition at line 75 of file QuonPDefs.h.

Definition at line 76 of file QuonPDefs.h.

Referenced by add(), QuonP::classifySites(), findNearestNeighbor(), PTreeNode(), and reset().


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

Generated on Wed Mar 25 16:32:53 2009 for OverSim by  doxygen 1.5.5