NeighborsList Class Reference

#include <NeighborsList.h>

List of all members.


Detailed Description

Maintains a list of all neighbors and functions for building their voronoi diagram.


Public Member Functions

virtual ~NeighborsList ()
virtual int numInitStages () const
virtual void initialize (int stage)
virtual void handleMessage (cMessage *msg)
void initializeList (Point p, NodeHandle owner, double AOI_size)
void setDebug (bool debugOutput)
void addNode (Point p, NodeHandle node)
void updateNode (Point old_pos, Point new_pos, NodeHandle node)
void updateTimeStamp (Point p)
void removeNode (Point p)
void removeNodeByHandle (NodeHandle node)
void changePosition (Point p)
void buildVoronoi ()
void buildVoronoi (Point old_pos, Point new_pos)
void initIterator ()
Sitenext ()
void removeNeighbors ()
int getSize ()
void clearList ()

Protected Member Functions

void updateDisplayString ()

Protected Attributes

std::map< Point, SiteSites
std::map< Point, Site >::iterator itSites
std::map< Point, Site >::iterator itExtern
double AOI_size
Point pos
NodeHandle owner
bool debugOutput
double xmin
double xmax
double ymin
double ymax
double deltax
double deltay
Geometry geom
EdgeList edgelist
HeapPQ heap
Sitebottomsite


Constructor & Destructor Documentation

NeighborsList::~NeighborsList (  )  [virtual]

00338 {
00339     if(Sites.size()) Sites.clear();
00340 }


Member Function Documentation

void NeighborsList::addNode ( Point  p,
NodeHandle  node 
)

00066 {
00067     Enter_Method_Silent();
00068     if(node != owner) {
00069         for(itSites = Sites.begin(); itSites != Sites.end();) {
00070             if(itSites->second.addr == node) {
00071                 Sites.erase(itSites);
00072                 itSites = Sites.end();
00073             }
00074             else ++itSites;
00075         }
00076         Site temp_site;
00077         temp_site.coord = p;
00078         temp_site.addr = node;
00079 
00080         Sites.insert(std::make_pair(temp_site.coord, temp_site));
00081         updateDisplayString();
00082     }
00083 }

void NeighborsList::buildVoronoi ( Point  old_pos,
Point  new_pos 
)

00136 {
00137     Enter_Method_Silent();
00138     int sqrt_nsites = 0;
00139 
00140     // no use building with less than 2 sites
00141     if(Sites.size() < 2) return;
00142 
00143     // determine min/max site coordinates and reset all sites to UNDEF
00144     xmin = Sites.begin()->second.coord.x;
00145     xmax = Sites.begin()->second.coord.x;
00146     for(itSites = (++Sites.begin()); itSites != Sites.end(); ++itSites) {
00147         if(itSites->second.coord.x < xmin) xmin = itSites->second.coord.x;
00148         if(itSites->second.coord.x > xmax) xmax = itSites->second.coord.x;
00149         if(!(itSites->second.type & THIS)) itSites->second.type = UNDEF;
00150         sqrt_nsites++;
00151     }
00152     ymin = Sites.begin()->second.coord.y;
00153     ymax = (--Sites.end())->second.coord.y;
00154 
00155     // needed to determine appropriate hashtable size
00156     deltax = xmax - xmin;
00157     deltay = ymax - ymin;
00158     sqrt_nsites = (int)sqrt((double)(sqrt_nsites+4));
00159 
00160     // start to calculate the voronoi
00161     Site *newsite, *bot, *top, *temp, *p, *v;
00162     Point newintstar;
00163     int pm;
00164     Halfedge *lbnd, *rbnd, *llbnd, *rrbnd, *bisector;
00165     Edge *e;
00166 
00167     newintstar.x = newintstar.y = 0.0;
00168 
00169     itSites = Sites.begin();
00170 
00171     geom.initialize(deltax, deltay, pos, old_pos, new_pos, AOI_size);
00172     heap.PQinitialize(sqrt_nsites, ymin, deltay);
00173     bottomsite = &itSites->second;
00174     ++itSites;
00175     edgelist.initialize(sqrt_nsites, xmin, deltax, bottomsite);
00176 
00177     newsite = &itSites->second;
00178     ++itSites;
00179     while(1) {
00180         if(!heap.PQempty()) newintstar = heap.PQ_min();
00181 
00182         if(newsite != NULL && (heap.PQempty() || newsite->coord.y < newintstar.y || (newsite->coord.y == newintstar.y && newsite->coord.x < newintstar.x))) {
00183             lbnd = edgelist.ELleftbnd(&(newsite->coord));
00184             rbnd = edgelist.ELright(lbnd);
00185             bot = edgelist.rightreg(lbnd);
00186             e = geom.bisect(bot, newsite);
00187             bisector = edgelist.HEcreate(e, le);
00188             edgelist.ELinsert(lbnd, bisector);
00189             if ((p = geom.intersect(lbnd, bisector)) != NULL) {
00190                 heap.PQdelete(lbnd);
00191                 heap.PQinsert(lbnd, p, geom.dist(p, newsite));
00192             }
00193             lbnd = bisector;
00194             bisector = edgelist.HEcreate(e, re);
00195             edgelist.ELinsert(lbnd, bisector);
00196             if ((p = geom.intersect(bisector, rbnd)) != NULL) heap.PQinsert(bisector, p, geom.dist(p, newsite));
00197             if(itSites != Sites.end()) {
00198                 newsite = &itSites->second;
00199                 ++itSites;
00200             }
00201             else newsite = NULL;
00202         }
00203         else if (!heap.PQempty()) {
00204             lbnd = heap.PQextractmin();
00205             llbnd = edgelist.ELleft(lbnd);
00206             rbnd = edgelist.ELright(lbnd);
00207             rrbnd = edgelist.ELright(rbnd);
00208             bot = edgelist.leftreg(lbnd);
00209             top = edgelist.rightreg(rbnd);
00210             v = lbnd->vertex;
00211             geom.endpoint(lbnd->ELedge, lbnd->ELpm, v);
00212             geom.endpoint(rbnd->ELedge, rbnd->ELpm, v);
00213             edgelist.ELdelete(lbnd);
00214             heap.PQdelete(rbnd);
00215             edgelist.ELdelete(rbnd);
00216             pm = le;
00217             if (bot->coord.y > top->coord.y) {
00218                 temp = bot;
00219                 bot = top;
00220                 top = temp;
00221                 pm = re;
00222             }
00223             e = geom.bisect(bot, top);
00224             bisector = edgelist.HEcreate(e, pm);
00225             edgelist.ELinsert(llbnd, bisector);
00226             geom.endpoint(e, re-pm, v);
00227             if((p = geom.intersect(llbnd, bisector)) != NULL) {
00228                 heap.PQdelete(llbnd);
00229                 heap.PQinsert(llbnd, p, geom.dist(p, bot));
00230             }
00231             if ((p = geom.intersect(bisector, rrbnd)) != NULL) heap.PQinsert(bisector, p, geom.dist(p, bot));
00232         }
00233         else break;
00234     }
00235 
00236     // process the generated edgelist
00237     for(lbnd = edgelist.ELright(edgelist.ELleftend); lbnd != edgelist.ELrightend; lbnd = edgelist.ELright(lbnd)) {
00238         e = lbnd -> ELedge;
00239         geom.processEdge(e);
00240     }
00241     // process sites in order to determine our neighbors
00242     for(itSites = Sites.begin(); itSites != Sites.end();++itSites) {
00243         if(!(itSites->second.type & THIS)) {
00244             if(itSites->second.innerEdge[0] && !itSites->second.outerEdge) {
00245                 itSites->second.type |= NEIGHBOR;
00246                 // Debug output
00247                 if(debugOutput) ev << "  VAST: Site at [" << itSites->second.coord.x << ", " << itSites->second.coord.y << "] is a neighbor." << endl;
00248             }
00249             if(itSites->second.innerEdge[0] && itSites->second.outerEdge) {
00250                 itSites->second.type |= BOUNDARY;
00251                 // Debug output
00252                 if(debugOutput) ev << "  VAST: Site at [" << itSites->second.coord.x << ", " << itSites->second.coord.y << "] is a boundary neighbor." << endl;
00253             }
00254             if(!itSites->second.innerEdge[1] && itSites->second.innerEdge[2]) {
00255                 itSites->second.type |= NEW;
00256                 // Debug output
00257                 if(debugOutput) ev << "  VAST: Site at [" << itSites->second.coord.x << ", " << itSites->second.coord.y << "] is a new neighbor for site at " << new_pos.x << ":" << new_pos.y << "." << endl;
00258             }
00259         }
00260         // reset inner- and outeredge indicator
00261         itSites->second.innerEdge[0] = false;
00262         itSites->second.innerEdge[1] = false;
00263         itSites->second.innerEdge[2] = false;
00264         itSites->second.outerEdge = false;
00265     }
00266     // clean up
00267     edgelist.reset();
00268     heap.PQreset();
00269     geom.reset();
00270 }

void NeighborsList::buildVoronoi (  ) 

00273 {
00274     buildVoronoi(pos, pos);
00275 }

void NeighborsList::changePosition ( Point  p  ) 

00128 {
00129     Enter_Method_Silent();
00130     Sites.erase(pos);
00131     pos = p;
00132     initializeList(p, owner, AOI_size);
00133 }

void NeighborsList::clearList (  ) 

00332 {
00333     Enter_Method_Silent();
00334     if(Sites.size()) Sites.clear();
00335 }

int NeighborsList::getSize (  ) 

00326 {
00327     Enter_Method_Silent();
00328     return Sites.size();
00329 }

void NeighborsList::handleMessage ( cMessage *  msg  )  [virtual]

00038 {
00039     error("this module doesn't handle messages, it runs only in initialize()");
00040 }

void NeighborsList::initialize ( int  stage  )  [virtual]

00029 {
00030     // because of IPAddressResolver, we need to wait until interfaces are registered,
00031     // address auto-assignment takes place etc.
00032     if(stage != MIN_STAGE_OVERLAY) return;
00033 
00034     WATCH_MAP(Sites);
00035 }

void NeighborsList::initializeList ( Point  p,
NodeHandle  owner,
double  AOI_size 
)

00043 {
00044     Enter_Method_Silent();
00045     // Initializes the neigbors list.
00046     Site temp_site;
00047     temp_site.coord = p;
00048     temp_site.type = THIS;
00049     temp_site.addr = owner;
00050 
00051     Sites.insert(std::make_pair(temp_site.coord, temp_site));
00052     this->AOI_size = AOI_size;
00053     this->pos = p;
00054     this->owner = owner;
00055     updateDisplayString();
00056 }

void NeighborsList::initIterator (  ) 

00278 {
00279     Enter_Method_Silent();
00280     itExtern = Sites.begin();
00281 }

Site * NeighborsList::next (  ) 

00284 {
00285     Enter_Method_Silent();
00286     if(itExtern == Sites.end()) {
00287         return NULL;
00288     }    
00289     Site *temp = &(itExtern->second);
00290     ++itExtern;
00291     return temp;
00292 }

virtual int NeighborsList::numInitStages (  )  const [inline, virtual]

00046 { return MAX_STAGE_OVERLAY + 1; }

void NeighborsList::removeNeighbors (  ) 

00295 {
00296     Enter_Method_Silent();
00297     for(itSites = Sites.begin(); itSites != Sites.end();) {
00298         // if current site is no neighbor remove it else go on to next site
00299         if(itSites->second.type == UNDEF) {
00300             // Debug output
00301             if(debugOutput) ev << "  VAST: Site at [" << itSites->second.coord.x << ", " << itSites->second.coord.y << "] has been removed from list." << endl;
00302             Sites.erase(itSites++);
00303         }
00304         else ++itSites;
00305     }
00306     updateDisplayString();
00307 }

void NeighborsList::removeNode ( Point  p  ) 

00103 {
00104     Enter_Method_Silent();
00105     itSites = Sites.find(p);
00106     if(itSites != Sites.end()) {
00107         if(!(itSites->second.type & THIS)) Sites.erase(p);
00108     }
00109     updateDisplayString();
00110 }

void NeighborsList::removeNodeByHandle ( NodeHandle  node  ) 

00113 {
00114     Enter_Method_Silent();
00115     if(node != owner) {
00116         for(itSites = Sites.begin(); itSites != Sites.end();) {
00117             if(itSites->second.addr == node) {
00118                 Sites.erase(itSites);
00119                 itSites = Sites.end();
00120             }
00121             else ++itSites;
00122         }
00123     }
00124     updateDisplayString();
00125 }

void NeighborsList::setDebug ( bool  debugOutput  ) 

00059 {
00060     Enter_Method_Silent();
00061     this->debugOutput = debugOutput;
00062     geom.setDebug(debugOutput);
00063 }

void NeighborsList::updateDisplayString (  )  [protected]

00310 {
00311     // Displays the current number of neighbors in the list.
00312     if(ev.isGUI()) {
00313         std::stringstream cur;
00314         if (Sites.size() == 1) {
00315             cur << "1 neighbor";
00316         }
00317         else {
00318             cur << Sites.size() << " neigbors";
00319         }
00320         displayString().setTagArg("t", 0, cur.str().c_str());
00321         displayString().setTagArg("t", 2, "blue");
00322     }
00323 }

void NeighborsList::updateNode ( Point  old_pos,
Point  new_pos,
NodeHandle  node 
)

00086 {
00087     Enter_Method_Silent();
00088     itSites = Sites.find(old_pos);
00089     if(itSites != Sites.end()) {
00090         if(!(itSites->second.type & THIS)) Sites.erase(old_pos);
00091     }
00092     addNode(new_pos, node);
00093 }

void NeighborsList::updateTimeStamp ( Point  p  ) 

00096 {
00097     Enter_Method_Silent();
00098     itSites = Sites.find(p);
00099     if(itSites != Sites.end()) itSites->second.tstamp = simulation.simTime();
00100 }


Member Data Documentation

double NeighborsList::AOI_size [protected]

Site* NeighborsList::bottomsite [protected]

bool NeighborsList::debugOutput [protected]

double NeighborsList::deltax [protected]

double NeighborsList::deltay [protected]

EdgeList NeighborsList::edgelist [protected]

Geometry NeighborsList::geom [protected]

HeapPQ NeighborsList::heap [protected]

std::map<Point, Site>::iterator NeighborsList::itExtern [protected]

std::map<Point, Site>::iterator NeighborsList::itSites [protected]

NodeHandle NeighborsList::owner [protected]

Point NeighborsList::pos [protected]

std::map<Point, Site> NeighborsList::Sites [protected]

double NeighborsList::xmax [protected]

double NeighborsList::xmin [protected]

double NeighborsList::ymax [protected]

double NeighborsList::ymin [protected]


The documentation for this class was generated from the following files:
Generated on Wed Apr 4 13:37:06 2007 for ITM OverSim by  doxygen 1.4.7