#include <Edgelist.h>
Maintains the edges found while building the voronoi diagram.
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::EdgeList | ( | ) |
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.
Referenced by NeighborsList::buildVoronoi().
00032 { 00033 int i; 00034 00035 HEcount = 0; 00036 ELhashsize = 2 * sqrt_nsites; 00037 00038 HEmemmap = new Halfedge*[ELhashsize]; 00039 00040 ELhash = new Halfedge*[ELhashsize]; 00041 for(i=0; i<ELhashsize; i++) ELhash[i] = NULL; 00042 ELleftend = HEcreate(NULL, 0); 00043 ELrightend = HEcreate(NULL, 0); 00044 ELleftend->ELleft = NULL; 00045 ELleftend->ELright = ELrightend; 00046 ELrightend->ELleft = ELleftend; 00047 ELrightend->ELright = NULL; 00048 ELhash[0] = ELleftend; 00049 ELhash[ELhashsize-1] = ELrightend; 00050 this->xmin = xmin; 00051 this->deltax = deltax; 00052 this->bottomsite = bottomsite; 00053 }
void EdgeList::reset | ( | ) |
Resets the list for further use.
Referenced by NeighborsList::buildVoronoi().
00056 { 00057 delete[] ELhash; 00058 // free all allocated memory 00059 for(int i=0; i<HEcount; i++) delete HEmemmap[i]; 00060 delete[] HEmemmap; 00061 }
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.
Referenced by NeighborsList::buildVoronoi(), and initialize().
00064 { 00065 Halfedge *answer = new Halfedge; 00066 answer->ELedge = e; 00067 answer->ELpm = pm; 00068 00069 HEmemmap[HEcount++] = answer; 00070 if(HEcount%ELhashsize == 0) { 00071 Halfedge **Temp = new Halfedge*[HEcount + ELhashsize]; 00072 for(int i=0; i<HEcount; i++) Temp[i] = HEmemmap[i]; 00073 delete[] HEmemmap; 00074 HEmemmap = Temp; 00075 } 00076 return answer; 00077 }
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.
Referenced by NeighborsList::buildVoronoi().
00080 { 00081 new_he->ELleft = lb; 00082 new_he->ELright = lb->ELright; 00083 (lb->ELright)->ELleft = new_he; 00084 lb->ELright = new_he; 00085 }
Halfedge * EdgeList::ELgethash | ( | int | b | ) |
Get an entry from the list by number.
@param b An integer. @return Returns halfedge number b.
Referenced by ELleftbnd().
00089 { 00090 Halfedge *he; 00091 00092 if(b < 0 || b >= ELhashsize) return NULL; 00093 he = ELhash[b]; 00094 if(he == NULL || he->ELedge != (Edge*)DELETED) return he; 00095 00096 /* Hash table points to deleted half edge. */ 00097 ELhash[b] = NULL; 00098 return NULL; 00099 }
Get an entry from the list by point.
@param p A pointer to a point. @return Returns halfedge nearest to p.
Referenced by NeighborsList::buildVoronoi().
00145 { 00146 int i, bucket; 00147 Halfedge *he; 00148 00149 /* Use hash table to get close to desired halfedge */ 00150 bucket = (int)((p->x - xmin) / deltax) * ELhashsize; 00151 if(bucket < 0) bucket =0; 00152 if(bucket >= ELhashsize) bucket = ELhashsize - 1; 00153 he = ELgethash(bucket); 00154 if(he == NULL) { 00155 for(i=1; 1; i++) { 00156 if((he = ELgethash(bucket-i)) != NULL) break; 00157 if((he = ELgethash(bucket+i)) != NULL) break; 00158 } 00159 totalsearch++; 00160 } 00161 ntry++; 00162 /* Now search linear list of halfedges for the corect one */ 00163 if(he == ELleftend || (he != ELrightend && right_of(he, p))) { 00164 do {he = he->ELright;} while(he != ELrightend && right_of(he, p)); 00165 he = he->ELleft; 00166 } 00167 else do {he = he->ELleft;} while(he != ELleftend && !right_of(he, p)); 00168 00169 /* Update hash table and reference counts */ 00170 if(bucket > 0 && bucket < ELhashsize-1) { 00171 ELhash[bucket] = he; 00172 } 00173 return he; 00174 }
void EdgeList::ELdelete | ( | Halfedge * | he | ) |
Get right neighbor of an edge.
@param he A halfedge. @return Returns right neighbor of halfedge he.
Referenced by NeighborsList::buildVoronoi(), and ELdelete().
00184 { 00185 return he->ELright; 00186 }
Get left neighbor of an edge.
@param he A halfedge. @return Returns left neighbor of halfedge he.
Referenced by NeighborsList::buildVoronoi(), and ELinsert().
00189 { 00190 return he->ELleft; 00191 }
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.
Referenced by ELleftbnd().
00103 { 00104 Edge *e; 00105 Site *topsite; 00106 int right_of_site, above, fast; 00107 double dxp, dyp, dxs, t1, t2, t3, yl; 00108 00109 e = el->ELedge; 00110 topsite = e->reg[1]; 00111 right_of_site = p->x > topsite->coord.x; 00112 if(right_of_site && el->ELpm == le) return 1; 00113 if(!right_of_site && el->ELpm == re) return 0; 00114 00115 if(e->a == 1.0) { 00116 dyp = p->y - topsite->coord.y; 00117 dxp = p->x - topsite->coord.x; 00118 fast = 0; 00119 if((!right_of_site & e->b < 0.0) | (right_of_site & e->b >= 0.0)) { 00120 above = dyp >= e->b * dxp; 00121 fast = above; 00122 } 00123 else { 00124 above = p->x + p->y * e->b > e->c; 00125 if(e->b < 0.0) above = !above; 00126 if(!above) fast = 1; 00127 } 00128 if(!fast) { 00129 dxs = topsite->coord.x - (e->reg[0])->coord.x; 00130 above = e->b * (dxp*dxp - dyp*dyp) < dxs * dyp * (1.0 + 2.0*dxp/dxs + e->b*e->b); 00131 if(e->b < 0.0) above = !above; 00132 } 00133 } 00134 else { 00135 yl = e->c - e->a * p->x; 00136 t1 = p->y - yl; 00137 t2 = p->x - topsite->coord.x; 00138 t3 = yl - topsite->coord.y; 00139 above = t1*t1 > t2*t2 + t3*t3; 00140 } 00141 return el->ELpm == le ? above : !above; 00142 }
Referenced by NeighborsList::buildVoronoi(), ELleftbnd(), and initialize().
Referenced by NeighborsList::buildVoronoi(), ELleftbnd(), and initialize().
int EdgeList::ELhashsize [protected] |
Referenced by ELgethash(), ELleftbnd(), HEcreate(), and initialize().
int EdgeList::totalsearch [protected] |
Referenced by ELleftbnd().
int EdgeList::ntry [protected] |
Referenced by ELleftbnd().
int EdgeList::HEcount [protected] |
Referenced by HEcreate(), initialize(), and reset().
double EdgeList::xmin [protected] |
Referenced by ELleftbnd().
double EdgeList::deltax [protected] |
Referenced by ELleftbnd().
Halfedge** EdgeList::ELhash [protected] |
Referenced by EdgeList(), ELgethash(), ELleftbnd(), initialize(), and reset().
Halfedge** EdgeList::HEmemmap [protected] |
Referenced by HEcreate(), initialize(), and reset().
Site* EdgeList::bottomsite [protected] |
Referenced by leftreg(), and rightreg().