Geometry Class Reference

Geometry class. More...

#include <VastDefs.h>

List of all members.

Public Member Functions

void initialize (double deltax, double deltay, Vector2D center, Vector2D old_pos, Vector2D new_pos, double radius)
void reset ()
void setDebug (bool debugOutput)
Edgebisect (Site *s1, Site *s2)
Siteintersect (Halfedge *el1, Halfedge *el2)
void endpoint (Edge *e, int lr, Site *s)
void processEdge (Edge *e)
double dist (Site *s, Site *t)

Protected Member Functions

bool intersectCircleLine (Vector2D start, Vector2D dir, Vector2D center, bool lowerBound, bool upperBound)
bool intersectCircleSite (Site *s, Vector2D center)

Protected Attributes

std::vector< Site * > SITEVector
std::vector< Edge * > EDGEVector
double deltax
double deltay
double sq_radius
Vector2D center [3]
bool debugOutput
bool doDiscovery

Detailed Description

Geometry class.

Provides basic line inter- / bisecting and processing functions, needed to build the voronoi and determine neighborhood relationships.

Definition at line 124 of file VastDefs.h.


Member Function Documentation

Edge * Geometry::bisect ( Site s1,
Site s2 
)

Definition at line 313 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00314 {
00315     double dx, dy, adx, ady;
00316     Edge *newedge;
00317 
00318     newedge = new Edge;
00319 
00320     newedge->reg[0] = s1;
00321     newedge->reg[1] = s2;
00322     newedge->ep[0] = NULL;
00323     newedge->ep[1] = NULL;
00324 
00325     dx = s2->coord.x - s1->coord.x;
00326     dy = s2->coord.y - s1->coord.y;
00327     adx = dx > 0 ? dx : -dx;
00328     ady = dy > 0 ? dy : -dy;
00329     newedge->c = s1->coord.x * dx + s1->coord.y * dy + (dx*dx + dy*dy)*0.5;
00330     if(adx>ady) {
00331         newedge->a = 1.0;
00332         newedge->b = dy/dx;
00333         newedge->c /= dx;
00334     }
00335     else {
00336         newedge->b = 1.0;
00337         newedge->a = dx/dy;
00338         newedge->c /= dy;
00339     }
00340 
00341     EDGEVector.push_back(newedge);
00342     return newedge;
00343 }

double Geometry::dist ( Site s,
Site t 
)

Definition at line 392 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00393 {
00394     double dx, dy;
00395     dx = s->coord.x - t->coord.x;
00396     dy = s->coord.y - t->coord.y;
00397     return sqrt(dx*dx + dy*dy);
00398 }

void Geometry::endpoint ( Edge e,
int  lr,
Site s 
)

Definition at line 385 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00386 {
00387     e->ep[lr] = s;
00388     if(e->ep[re-lr] == NULL) return;
00389     processEdge(e);
00390 }

void Geometry::initialize ( double  deltax,
double  deltay,
Vector2D  center,
Vector2D  old_pos,
Vector2D  new_pos,
double  radius 
)

Definition at line 159 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00160 {
00161     this->deltay = deltay;
00162     this->deltax = deltax;
00163     this->center[0] = center;
00164     this->center[1] = old_pos;
00165     this->center[2] = new_pos;
00166     if((old_pos.x != new_pos.x) || (old_pos.y != new_pos.y)) doDiscovery = true;
00167     else doDiscovery = false;
00168     this->sq_radius = radius*radius;
00169 }

Site * Geometry::intersect ( Halfedge el1,
Halfedge el2 
)

Definition at line 345 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00346 {
00347     Edge *e1, *e2, *e;
00348     Halfedge *el;
00349     double d, xint, yint;
00350     int right_of_site;
00351     Site *v;
00352 
00353     e1 = el1->ELedge;
00354     e2 = el2->ELedge;
00355     if(e1 == NULL || e2 == NULL) return NULL;
00356     if(e1->reg[1] == e2->reg[1]) return NULL;
00357 
00358     d = e1->a * e2->b - e1->b * e2->a;
00359     if(-1.0e-10 < d && d < 1.0e-10) return NULL;
00360 
00361     xint = (e1->c * e2->b - e2->c * e1->b)/d;
00362     yint = (e2->c * e1->a - e1->c * e2->a)/d;
00363 
00364     if((e1->reg[1]->coord.y < e2->reg[1]->coord.y) || (e1->reg[1]->coord.y == e2->reg[1]->coord.y && e1->reg[1]->coord.x < e2->reg[1]->coord.x)) {
00365         el = el1;
00366         e = e1;
00367     }
00368     else {
00369         el = el2;
00370         e = e2;
00371     }
00372 
00373     right_of_site = xint >= e->reg[1]->coord.x;
00374     if((right_of_site && el->ELpm == le) || (!right_of_site && el->ELpm == re)) return NULL;
00375 
00376     v = new Site;
00377 
00378     v->coord.x = xint;
00379     v->coord.y = yint;
00380 
00381     SITEVector.push_back(v);
00382     return v;
00383 }

bool Geometry::intersectCircleLine ( Vector2D  start,
Vector2D  dir,
Vector2D  center,
bool  lowerBound,
bool  upperBound 
) [protected]

Definition at line 198 of file VastDefs.cc.

Referenced by processEdge().

00199 {
00200     Vector2D StartMinusCenter;
00201     double DirDotStartMinusCenter, DirSq, StartMinusCenterSq, discriminant;
00202     StartMinusCenter.x = start.x - center.x;
00203     StartMinusCenter.y = start.y - center.y;
00204     StartMinusCenterSq = StartMinusCenter.x * StartMinusCenter.x + StartMinusCenter.y * StartMinusCenter.y;
00205 
00206     DirDotStartMinusCenter = dir.x * StartMinusCenter.x + dir.y * StartMinusCenter.y;
00207     DirSq = dir.x * dir.x + dir.y * dir.y;
00208 
00209     discriminant = DirDotStartMinusCenter * DirDotStartMinusCenter - DirSq * (StartMinusCenterSq - sq_radius);
00210 
00211     if(discriminant <= 0.0f) return false;
00212     else if(lowerBound) {
00213         double s = (-DirDotStartMinusCenter - sqrtf(discriminant)) / DirSq;
00214         if(s < 0.0f) return false;
00215         else if(upperBound && s > 1.0f) return false;
00216     }
00217     return true;
00218 }

bool Geometry::intersectCircleSite ( Site s,
Vector2D  center 
) [protected]

Definition at line 188 of file VastDefs.cc.

Referenced by processEdge().

00189 {
00190     double sq_distance;
00191     Vector2D temp;
00192     temp.x = s->coord.x - center.x;
00193     temp.y = s->coord.y - center.y;
00194     sq_distance = temp.x*temp.x + temp.y*temp.y;
00195     return sq_distance < sq_radius ? true : false;
00196 }

void Geometry::processEdge ( Edge e  ) 

Definition at line 220 of file VastDefs.cc.

Referenced by Vast::buildVoronoi(), and endpoint().

00221 {
00222     bool leftEndpoint_In[3], rightEndpoint_In[3];
00223     int i, numTest;
00224     // test the edge just against our own AOI or also against AOI's of a moving neighbor
00225     numTest = doDiscovery ? 3 : 1;
00226 
00227     for(i = 0; i < numTest; i++) {
00228         if(e->ep[le]) leftEndpoint_In[i] = intersectCircleSite(e->ep[le], center[i]);
00229         else leftEndpoint_In[i] = false;
00230         if(e->ep[re]) rightEndpoint_In[i] = intersectCircleSite(e->ep[re], center[i]);
00231         else rightEndpoint_In[i] = false;
00232     }
00233     for(i = 0; i < numTest; i++) {
00234         if(leftEndpoint_In[i] || rightEndpoint_In[i]) {
00235             if(!e->reg[le]->innerEdge[i]) e->reg[le]->innerEdge[i] = true;
00236             if(!e->reg[re]->innerEdge[i]) e->reg[re]->innerEdge[i] = true;
00237         }
00238     }
00239     if(!leftEndpoint_In[0] || !rightEndpoint_In[0]) {
00240         if(!e->reg[le]->outerEdge) e->reg[le]->outerEdge = true;
00241         if(!e->reg[re]->outerEdge) e->reg[re]->outerEdge = true;
00242     }
00243     for(i = 0; i < numTest; i++) {
00244         if(!(leftEndpoint_In[i] || rightEndpoint_In[i])) {
00245             bool lineTest = false;
00246             if(e->ep[le] && e->ep[re]) {
00247                 Vector2D t_dir;
00248                 t_dir.x = e->ep[re]->coord.x - e->ep[le]->coord.x;
00249                 t_dir.y = e->ep[re]->coord.y - e->ep[le]->coord.y;
00250                 lineTest = intersectCircleLine(e->ep[le]->coord, t_dir, center[i], true, true);
00251             }
00252             if((e->ep[le] && !e->ep[re]) || (!e->ep[le] && e->ep[re])) {
00253                 Vector2D t_dir;
00254                 t_dir.x = e->b;
00255                 t_dir.y = -(e->a);
00256                 if(e->ep[le]) {
00257                     if(t_dir.x < 0.0f) {
00258                         t_dir.x = -t_dir.x;
00259                         t_dir.y = -t_dir.y;
00260                     }
00261                     lineTest = intersectCircleLine(e->ep[le]->coord, t_dir, center[i], true, false);
00262                 }
00263                 else {
00264                     if(t_dir.x >= 0.0f) {
00265                         t_dir.x = -t_dir.x;
00266                         t_dir.y = -t_dir.y;
00267                     }
00268                     lineTest = intersectCircleLine(e->ep[re]->coord, t_dir, center[i], true, false);
00269                 }
00270             }
00271             if(!(e->ep[le] || e->ep[re])) {
00272                 Vector2D t_start, t_dir;
00273                 if(e->b == 0.0f) {
00274                     t_start.x = e->c / e->a;
00275                     t_start.y = 0.0f;
00276                 }
00277                 else {
00278                     t_start.x = 0.0f;
00279                     t_start.y = e->c / e->b;
00280                 }
00281                 t_dir.x = e->b;
00282                 t_dir.y = -(e->a);
00283                 lineTest = intersectCircleLine(t_start, t_dir, center[i], false, false);
00284             }
00285 
00286             if(lineTest) {
00287                 if(!e->reg[le]->innerEdge[i]) e->reg[le]->innerEdge[i] = true;
00288                 if(!e->reg[re]->innerEdge[i]) e->reg[re]->innerEdge[i] = true;
00289             }
00290         }
00291     }
00292     // enhanced enclosing test
00293     e->reg[re]->enclosingSet.insert(e->reg[le]->addr);
00294     e->reg[le]->enclosingSet.insert(e->reg[re]->addr);
00295     
00296     // test if one of the nodes bisected by the edge is an enclosing neighbor
00297     if(e->reg[le]->type == THIS) {
00298         e->reg[re]->type |= ENCLOSING;
00299         // Debug output
00300         if(debugOutput) EV << "[Geometry::processEdge()]\n"
00301                            << "    Site at [" << e->reg[re]->coord.x << ", " << e->reg[re]->coord.y << "] is an enclosing neighbor."
00302                            << endl;
00303     }
00304     if(e->reg[re]->type == THIS) {
00305         e->reg[le]->type |= ENCLOSING;
00306         // Debug output
00307         if(debugOutput) EV << "[Geometry::processEdge()]\n"
00308                            << "    Site at [" << e->reg[le]->coord.x << ", " << e->reg[le]->coord.y << "] is an enclosing neighbor."
00309                            << endl;
00310     }
00311 }

void Geometry::reset (  ) 

Definition at line 171 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00172 {
00173     for(std::vector<Site*>::iterator itTemp = SITEVector.begin(); itTemp != SITEVector.end(); ++itTemp) {
00174         delete *itTemp;
00175     }
00176     for(std::vector<Edge*>::iterator itTemp = EDGEVector.begin(); itTemp != EDGEVector.end(); ++itTemp) {
00177         delete *itTemp;
00178     }
00179     SITEVector.clear();
00180     EDGEVector.clear();
00181 }

void Geometry::setDebug ( bool  debugOutput  ) 

Definition at line 183 of file VastDefs.cc.

Referenced by Vast::initializeOverlay().

00184 {
00185     this->debugOutput = debugOutput;
00186 }


Member Data Documentation

Vector2D Geometry::center[3] [protected]

Definition at line 142 of file VastDefs.h.

Referenced by processEdge().

bool Geometry::debugOutput [protected]

Definition at line 143 of file VastDefs.h.

Referenced by processEdge().

double Geometry::deltax [protected]

Definition at line 141 of file VastDefs.h.

double Geometry::deltay [protected]

Definition at line 141 of file VastDefs.h.

bool Geometry::doDiscovery [protected]

Definition at line 143 of file VastDefs.h.

Referenced by initialize(), and processEdge().

std::vector<Edge*> Geometry::EDGEVector [protected]

Definition at line 138 of file VastDefs.h.

Referenced by bisect(), and reset().

std::vector<Site*> Geometry::SITEVector [protected]

Definition at line 137 of file VastDefs.h.

Referenced by intersect(), and reset().

double Geometry::sq_radius [protected]

Definition at line 141 of file VastDefs.h.

Referenced by initialize(), intersectCircleLine(), and intersectCircleSite().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3