OverSim
Geometry Class Reference

Geometry class. More...

#include <VastDefs.h>

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().

{
double dx, dy, adx, ady;
Edge *newedge;
newedge = new Edge;
newedge->reg[0] = s1;
newedge->reg[1] = s2;
newedge->ep[0] = NULL;
newedge->ep[1] = NULL;
dx = s2->coord.x - s1->coord.x;
dy = s2->coord.y - s1->coord.y;
adx = dx > 0 ? dx : -dx;
ady = dy > 0 ? dy : -dy;
newedge->c = s1->coord.x * dx + s1->coord.y * dy + (dx*dx + dy*dy)*0.5;
if(adx>ady) {
newedge->a = 1.0;
newedge->b = dy/dx;
newedge->c /= dx;
}
else {
newedge->b = 1.0;
newedge->a = dx/dy;
newedge->c /= dy;
}
EDGEVector.push_back(newedge);
return newedge;
}
double Geometry::dist ( Site s,
Site t 
)

Definition at line 392 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

{
double dx, dy;
dx = s->coord.x - t->coord.x;
dy = s->coord.y - t->coord.y;
return sqrt(dx*dx + dy*dy);
}
void Geometry::endpoint ( Edge e,
int  lr,
Site s 
)

Definition at line 385 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

{
e->ep[lr] = s;
if(e->ep[re-lr] == NULL) return;
}
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().

{
this->deltay = deltay;
this->deltax = deltax;
this->center[0] = center;
this->center[1] = old_pos;
this->center[2] = new_pos;
if((old_pos.x != new_pos.x) || (old_pos.y != new_pos.y)) doDiscovery = true;
else doDiscovery = false;
this->sq_radius = radius*radius;
}
Site * Geometry::intersect ( Halfedge el1,
Halfedge el2 
)

Definition at line 345 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

{
Edge *e1, *e2, *e;
Halfedge *el;
double d, xint, yint;
int right_of_site;
Site *v;
e1 = el1->ELedge;
e2 = el2->ELedge;
if(e1 == NULL || e2 == NULL) return NULL;
if(e1->reg[1] == e2->reg[1]) return NULL;
d = e1->a * e2->b - e1->b * e2->a;
if(-1.0e-10 < d && d < 1.0e-10) return NULL;
xint = (e1->c * e2->b - e2->c * e1->b)/d;
yint = (e2->c * e1->a - e1->c * e2->a)/d;
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)) {
el = el1;
e = e1;
}
else {
el = el2;
e = e2;
}
right_of_site = xint >= e->reg[1]->coord.x;
if((right_of_site && el->ELpm == le) || (!right_of_site && el->ELpm == re)) return NULL;
v = new Site;
v->coord.x = xint;
v->coord.y = yint;
SITEVector.push_back(v);
return v;
}
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().

{
Vector2D StartMinusCenter;
double DirDotStartMinusCenter, DirSq, StartMinusCenterSq, discriminant;
StartMinusCenter.x = start.x - center.x;
StartMinusCenter.y = start.y - center.y;
StartMinusCenterSq = StartMinusCenter.x * StartMinusCenter.x + StartMinusCenter.y * StartMinusCenter.y;
DirDotStartMinusCenter = dir.x * StartMinusCenter.x + dir.y * StartMinusCenter.y;
DirSq = dir.x * dir.x + dir.y * dir.y;
discriminant = DirDotStartMinusCenter * DirDotStartMinusCenter - DirSq * (StartMinusCenterSq - sq_radius);
if(discriminant <= 0.0f) return false;
else if(lowerBound) {
double s = (-DirDotStartMinusCenter - sqrtf(discriminant)) / DirSq;
if(s < 0.0f) return false;
else if(upperBound && s > 1.0f) return false;
}
return true;
}
bool Geometry::intersectCircleSite ( Site s,
Vector2D  center 
)
protected

Definition at line 188 of file VastDefs.cc.

Referenced by processEdge().

{
double sq_distance;
Vector2D temp;
temp.x = s->coord.x - center.x;
temp.y = s->coord.y - center.y;
sq_distance = temp.x*temp.x + temp.y*temp.y;
return sq_distance < sq_radius ? true : false;
}
void Geometry::processEdge ( Edge e)

Definition at line 220 of file VastDefs.cc.

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

{
bool leftEndpoint_In[3], rightEndpoint_In[3];
int i, numTest;
// test the edge just against our own AOI or also against AOI's of a moving neighbor
numTest = doDiscovery ? 3 : 1;
for(i = 0; i < numTest; i++) {
if(e->ep[le]) leftEndpoint_In[i] = intersectCircleSite(e->ep[le], center[i]);
else leftEndpoint_In[i] = false;
if(e->ep[re]) rightEndpoint_In[i] = intersectCircleSite(e->ep[re], center[i]);
else rightEndpoint_In[i] = false;
}
for(i = 0; i < numTest; i++) {
if(leftEndpoint_In[i] || rightEndpoint_In[i]) {
if(!e->reg[le]->innerEdge[i]) e->reg[le]->innerEdge[i] = true;
if(!e->reg[re]->innerEdge[i]) e->reg[re]->innerEdge[i] = true;
}
}
if(!leftEndpoint_In[0] || !rightEndpoint_In[0]) {
if(!e->reg[le]->outerEdge) e->reg[le]->outerEdge = true;
if(!e->reg[re]->outerEdge) e->reg[re]->outerEdge = true;
}
for(i = 0; i < numTest; i++) {
if(!(leftEndpoint_In[i] || rightEndpoint_In[i])) {
bool lineTest = false;
if(e->ep[le] && e->ep[re]) {
Vector2D t_dir;
t_dir.x = e->ep[re]->coord.x - e->ep[le]->coord.x;
t_dir.y = e->ep[re]->coord.y - e->ep[le]->coord.y;
lineTest = intersectCircleLine(e->ep[le]->coord, t_dir, center[i], true, true);
}
if((e->ep[le] && !e->ep[re]) || (!e->ep[le] && e->ep[re])) {
Vector2D t_dir;
t_dir.x = e->b;
t_dir.y = -(e->a);
if(e->ep[le]) {
if(t_dir.x < 0.0f) {
t_dir.x = -t_dir.x;
t_dir.y = -t_dir.y;
}
lineTest = intersectCircleLine(e->ep[le]->coord, t_dir, center[i], true, false);
}
else {
if(t_dir.x >= 0.0f) {
t_dir.x = -t_dir.x;
t_dir.y = -t_dir.y;
}
lineTest = intersectCircleLine(e->ep[re]->coord, t_dir, center[i], true, false);
}
}
if(!(e->ep[le] || e->ep[re])) {
Vector2D t_start, t_dir;
if(e->b == 0.0f) {
t_start.x = e->c / e->a;
t_start.y = 0.0f;
}
else {
t_start.x = 0.0f;
t_start.y = e->c / e->b;
}
t_dir.x = e->b;
t_dir.y = -(e->a);
lineTest = intersectCircleLine(t_start, t_dir, center[i], false, false);
}
if(lineTest) {
if(!e->reg[le]->innerEdge[i]) e->reg[le]->innerEdge[i] = true;
if(!e->reg[re]->innerEdge[i]) e->reg[re]->innerEdge[i] = true;
}
}
}
// enhanced enclosing test
e->reg[re]->enclosingSet.insert(e->reg[le]->addr);
e->reg[le]->enclosingSet.insert(e->reg[re]->addr);
// test if one of the nodes bisected by the edge is an enclosing neighbor
if(e->reg[le]->type == THIS) {
e->reg[re]->type |= ENCLOSING;
// Debug output
if(debugOutput) EV << "[Geometry::processEdge()]\n"
<< " Site at [" << e->reg[re]->coord.x << ", " << e->reg[re]->coord.y << "] is an enclosing neighbor."
<< endl;
}
if(e->reg[re]->type == THIS) {
e->reg[le]->type |= ENCLOSING;
// Debug output
if(debugOutput) EV << "[Geometry::processEdge()]\n"
<< " Site at [" << e->reg[le]->coord.x << ", " << e->reg[le]->coord.y << "] is an enclosing neighbor."
<< endl;
}
}
void Geometry::reset ( )

Definition at line 171 of file VastDefs.cc.

Referenced by Vast::buildVoronoi().

{
for(std::vector<Site*>::iterator itTemp = SITEVector.begin(); itTemp != SITEVector.end(); ++itTemp) {
delete *itTemp;
}
for(std::vector<Edge*>::iterator itTemp = EDGEVector.begin(); itTemp != EDGEVector.end(); ++itTemp) {
delete *itTemp;
}
SITEVector.clear();
EDGEVector.clear();
}
void Geometry::setDebug ( bool  debugOutput)

Definition at line 183 of file VastDefs.cc.

Referenced by Vast::initializeOverlay().

{
}

Member Data Documentation

Vector2D Geometry::center[3]
protected

Definition at line 142 of file VastDefs.h.

Referenced by initialize(), and processEdge().

bool Geometry::debugOutput
protected

Definition at line 143 of file VastDefs.h.

Referenced by processEdge(), and setDebug().

double Geometry::deltax
protected

Definition at line 141 of file VastDefs.h.

Referenced by initialize().

double Geometry::deltay
protected

Definition at line 141 of file VastDefs.h.

Referenced by initialize().

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: