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 120 of file VastDefs.h.


Member Function Documentation

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

Definition at line 309 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

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

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

Definition at line 388 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00389 {
00390     double dx, dy;
00391     dx = s->coord.x - t->coord.x;
00392     dy = s->coord.y - t->coord.y;
00393     return sqrt(dx*dx + dy*dy);
00394 }

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

Definition at line 381 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

00382 {
00383     e->ep[lr] = s;
00384     if(e->ep[re-lr] == NULL) return;
00385     processEdge(e);
00386 }

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 341 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

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

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     // test if one of the nodes bisected by the edge is an enclosing neighbor
00293     if(e->reg[le]->type == THIS) {
00294         e->reg[re]->type |= ENCLOSING;
00295         // Debug output
00296         if(debugOutput) EV << "[Geometry::processEdge()]\n"
00297                            << "    Site at [" << e->reg[re]->coord.x << ", " << e->reg[re]->coord.y << "] is a enclosing neighbor."
00298                            << endl;
00299     }
00300     if(e->reg[re]->type == THIS) {
00301         e->reg[le]->type |= ENCLOSING;
00302         // Debug output
00303         if(debugOutput) EV << "[Geometry::processEdge()]\n"
00304                            << "    Site at [" << e->reg[le]->coord.x << ", " << e->reg[le]->coord.y << "] is a enclosing neighbor."
00305                            << endl;
00306     }
00307 }

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 138 of file VastDefs.h.

Referenced by processEdge().

bool Geometry::debugOutput [protected]

Definition at line 139 of file VastDefs.h.

Referenced by processEdge().

double Geometry::deltax [protected]

Definition at line 137 of file VastDefs.h.

double Geometry::deltay [protected]

Definition at line 137 of file VastDefs.h.

bool Geometry::doDiscovery [protected]

Definition at line 139 of file VastDefs.h.

Referenced by initialize(), and processEdge().

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

Definition at line 134 of file VastDefs.h.

Referenced by bisect(), and reset().

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

Definition at line 133 of file VastDefs.h.

Referenced by intersect(), and reset().

double Geometry::sq_radius [protected]

Definition at line 137 of file VastDefs.h.

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


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

Generated on Tue Sep 8 17:26:58 2009 for OverSim by  doxygen 1.5.8