#include <VastDefs.h>
Public Member Functions | |
EdgeList () | |
Standard constructor. | |
void | initialize (int sqrt_nsites, double xmin, double deltax, Site *bottomsite) |
Initializes the list before building the diagram. | |
void | reset () |
Resets the list for further use. | |
Halfedge * | HEcreate (Edge *e, int pm) |
Creates a halfedge from a given edge. | |
void | ELinsert (Halfedge *lb, Halfedge *new_he) |
Inserts a new halfedge to the list. | |
Halfedge * | ELgethash (int b) |
Get an entry from the list by number. | |
Halfedge * | ELleftbnd (Vector2D *p) |
Get an entry from the list by point. | |
void | ELdelete (Halfedge *he) |
Delete an entry from the list. | |
Halfedge * | ELright (Halfedge *he) |
Get right neighbor of an edge. | |
Halfedge * | ELleft (Halfedge *he) |
Get left neighbor of an edge. | |
Site * | leftreg (Halfedge *he) |
Get site left of an edge. | |
Site * | rightreg (Halfedge *he) |
Get site right of an edge. | |
int | right_of (Halfedge *el, Vector2D *p) |
Determines if a point is right of an halfedge. | |
Public Attributes | |
Halfedge * | ELleftend |
Halfedge * | ELrightend |
Protected Attributes | |
int | ELhashsize |
int | totalsearch |
int | ntry |
int | HEcount |
double | xmin |
double | deltax |
Halfedge ** | ELhash |
Halfedge ** | HEmemmap |
Site * | bottomsite |
EdgeList class.
Maintains the edges found while building the voronoi diagram.
Definition at line 153 of file VastDefs.h.
EdgeList::EdgeList | ( | ) |
Standard constructor.
Definition at line 400 of file VastDefs.cc.
00401 { 00402 ELhash = NULL; 00403 }
void EdgeList::ELdelete | ( | Halfedge * | he | ) |
Halfedge * EdgeList::ELgethash | ( | int | b | ) |
Get an entry from the list by number.
@param b An integer. @return Returns halfedge number b.
Definition at line 462 of file VastDefs.cc.
Referenced by ELleftbnd().
Inserts a new halfedge to the list.
@param lb lower bound for this edge. @param new_he A new halfedge to be added to the list.
Definition at line 453 of file VastDefs.cc.
Referenced by Vast::buildVoronoi().
Get left neighbor of an edge.
@param he A halfedge. @return Returns left neighbor of halfedge he.
Definition at line 562 of file VastDefs.cc.
Referenced by Vast::buildVoronoi(), and ELinsert().
00563 { 00564 return he->ELleft; 00565 }
Get an entry from the list by point.
@param p A pointer to a point. @return Returns halfedge nearest to p.
Definition at line 518 of file VastDefs.cc.
Referenced by Vast::buildVoronoi().
00519 { 00520 int i, bucket; 00521 Halfedge *he; 00522 00523 /* Use hash table to get close to desired halfedge */ 00524 bucket = (int)((p->x - xmin) / deltax) * ELhashsize; 00525 if(bucket < 0) bucket =0; 00526 if(bucket >= ELhashsize) bucket = ELhashsize - 1; 00527 he = ELgethash(bucket); 00528 if(he == NULL) { 00529 for(i=1; 1; i++) { 00530 if((he = ELgethash(bucket-i)) != NULL) break; 00531 if((he = ELgethash(bucket+i)) != NULL) break; 00532 } 00533 totalsearch++; 00534 } 00535 ntry++; 00536 /* Now search linear list of halfedges for the corect one */ 00537 if(he == ELleftend || (he != ELrightend && right_of(he, p))) { 00538 do {he = he->ELright;} while(he != ELrightend && right_of(he, p)); 00539 he = he->ELleft; 00540 } 00541 else do {he = he->ELleft;} while(he != ELleftend && !right_of(he, p)); 00542 00543 /* Update hash table and reference counts */ 00544 if(bucket > 0 && bucket < ELhashsize-1) { 00545 ELhash[bucket] = he; 00546 } 00547 return he; 00548 }
Get right neighbor of an edge.
@param he A halfedge. @return Returns right neighbor of halfedge he.
Definition at line 557 of file VastDefs.cc.
Referenced by Vast::buildVoronoi(), and ELdelete().
00558 { 00559 return he->ELright; 00560 }
Creates a halfedge from a given edge.
@param e A pointer to an edge. @param pm Determins wether the halfedge represents the left or right "side" of the given edge (le/re). @return Returns the created halfedge.
Definition at line 437 of file VastDefs.cc.
Referenced by Vast::buildVoronoi(), and initialize().
00438 { 00439 Halfedge *answer = new Halfedge; 00440 answer->ELedge = e; 00441 answer->ELpm = pm; 00442 00443 HEmemmap[HEcount++] = answer; 00444 if(HEcount%ELhashsize == 0) { 00445 Halfedge **Temp = new Halfedge*[HEcount + ELhashsize]; 00446 for(int i=0; i<HEcount; i++) Temp[i] = HEmemmap[i]; 00447 delete[] HEmemmap; 00448 HEmemmap = Temp; 00449 } 00450 return answer; 00451 }
void EdgeList::initialize | ( | int | sqrt_nsites, | |
double | xmin, | |||
double | deltax, | |||
Site * | bottomsite | |||
) |
Initializes the list before building the diagram.
@param sqrt_nsites Squareroot of the total number of sites. @param xmin Min x coordinate of all sites. @param deltax xmin+deltax is max x coordinate of all sites. @param bottomsite A pointer to the bottom site of the sites list.
Definition at line 405 of file VastDefs.cc.
Referenced by Vast::buildVoronoi().
00406 { 00407 int i; 00408 00409 HEcount = 0; 00410 ELhashsize = 2 * sqrt_nsites; 00411 00412 HEmemmap = new Halfedge*[ELhashsize]; 00413 00414 ELhash = new Halfedge*[ELhashsize]; 00415 for(i=0; i<ELhashsize; i++) ELhash[i] = NULL; 00416 ELleftend = HEcreate(NULL, 0); 00417 ELrightend = HEcreate(NULL, 0); 00418 ELleftend->ELleft = NULL; 00419 ELleftend->ELright = ELrightend; 00420 ELrightend->ELleft = ELleftend; 00421 ELrightend->ELright = NULL; 00422 ELhash[0] = ELleftend; 00423 ELhash[ELhashsize-1] = ELrightend; 00424 this->xmin = xmin; 00425 this->deltax = deltax; 00426 this->bottomsite = bottomsite; 00427 }
Get site left of an edge.
@param he A halfedge. @return Returns site left of halfedge he.
Definition at line 568 of file VastDefs.cc.
Referenced by Vast::buildVoronoi().
void EdgeList::reset | ( | ) |
Resets the list for further use.
Definition at line 429 of file VastDefs.cc.
Referenced by Vast::buildVoronoi().
Determines if a point is right of an halfedge.
@param he A halfedge. @param p A point. @return Returns 1 if point p is right of halfedge el, 0 otherwise.
Definition at line 476 of file VastDefs.cc.
Referenced by ELleftbnd().
00477 { 00478 Edge *e; 00479 Site *topsite; 00480 int right_of_site, above, fast; 00481 double dxp, dyp, dxs, t1, t2, t3, yl; 00482 00483 e = el->ELedge; 00484 topsite = e->reg[1]; 00485 right_of_site = p->x > topsite->coord.x; 00486 if(right_of_site && el->ELpm == le) return 1; 00487 if(!right_of_site && el->ELpm == re) return 0; 00488 00489 if(e->a == 1.0) { 00490 dyp = p->y - topsite->coord.y; 00491 dxp = p->x - topsite->coord.x; 00492 fast = 0; 00493 if((!right_of_site && (e->b < 0.0)) || (right_of_site && (e->b >= 0.0))) { 00494 above = dyp >= e->b * dxp; 00495 fast = above; 00496 } 00497 else { 00498 above = p->x + p->y * e->b > e->c; 00499 if(e->b < 0.0) above = !above; 00500 if(!above) fast = 1; 00501 } 00502 if(!fast) { 00503 dxs = topsite->coord.x - (e->reg[0])->coord.x; 00504 above = e->b * (dxp*dxp - dyp*dyp) < dxs * dyp * (1.0 + 2.0*dxp/dxs + e->b*e->b); 00505 if(e->b < 0.0) above = !above; 00506 } 00507 } 00508 else { 00509 yl = e->c - e->a * p->x; 00510 t1 = p->y - yl; 00511 t2 = p->x - topsite->coord.x; 00512 t3 = yl - topsite->coord.y; 00513 above = t1*t1 > t2*t2 + t3*t3; 00514 } 00515 return el->ELpm == le ? above : !above; 00516 }
Get site right of an edge.
@param he A halfedge. @return Returns site right of halfedge he.
Definition at line 574 of file VastDefs.cc.
Referenced by Vast::buildVoronoi().
Site* EdgeList::bottomsite [protected] |
Definition at line 237 of file VastDefs.h.
Referenced by leftreg(), and rightreg().
double EdgeList::deltax [protected] |
Definition at line 234 of file VastDefs.h.
Referenced by ELleftbnd().
Halfedge** EdgeList::ELhash [protected] |
Definition at line 235 of file VastDefs.h.
Referenced by EdgeList(), ELgethash(), ELleftbnd(), initialize(), and reset().
int EdgeList::ELhashsize [protected] |
Definition at line 233 of file VastDefs.h.
Referenced by ELgethash(), ELleftbnd(), HEcreate(), and initialize().
Definition at line 230 of file VastDefs.h.
Referenced by Vast::buildVoronoi(), ELleftbnd(), and initialize().
Definition at line 230 of file VastDefs.h.
Referenced by Vast::buildVoronoi(), ELleftbnd(), and initialize().
int EdgeList::HEcount [protected] |
Definition at line 233 of file VastDefs.h.
Referenced by HEcreate(), initialize(), and reset().
Halfedge** EdgeList::HEmemmap [protected] |
Definition at line 236 of file VastDefs.h.
Referenced by HEcreate(), initialize(), and reset().
int EdgeList::ntry [protected] |
Definition at line 233 of file VastDefs.h.
Referenced by ELleftbnd().
int EdgeList::totalsearch [protected] |
Definition at line 233 of file VastDefs.h.
Referenced by ELleftbnd().
double EdgeList::xmin [protected] |
Definition at line 234 of file VastDefs.h.
Referenced by ELleftbnd().