2 * The author of this software is Steven Fortune. Copyright (c) 1994 by AT&T
\r
4 * Permission to use, copy, modify, and distribute this software for any
\r
5 * purpose without fee is hereby granted, provided that this entire notice
\r
6 * is included in all copies of any software which is or includes a copy
\r
7 * or modification of this software and in all copies of the supporting
\r
8 * documentation for such software.
\r
9 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
\r
10 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
\r
11 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
\r
12 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
\r
16 * This code was originally written by Stephan Fortune in C code. I, Shane O'Sullivan,
\r
17 * have since modified it, encapsulating it in a C++ class and, fixing memory leaks and
\r
18 * adding accessors to the Voronoi Edges.
\r
19 * Permission to use, copy, modify, and distribute this software for any
\r
20 * purpose without fee is hereby granted, provided that this entire notice
\r
21 * is included in all copies of any software which is or includes a copy
\r
22 * or modification of this software and in all copies of the supporting
\r
23 * documentation for such software.
\r
24 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
\r
25 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
\r
26 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
\r
27 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
\r
30 #ifndef VORONOI_DIAGRAM_GENERATOR
\r
31 #define VORONOI_DIAGRAM_GENERATOR
\r
56 struct Freenode *nextfree;
\r
59 struct FreeNodeArrayList
\r
61 struct Freenode* memory;
\r
62 struct FreeNodeArrayList* next;
\r
68 struct Freenode *head;
\r
89 struct PolygonPoint * pointlist;
\r
94 // structure used both for sites and for vertices
\r
98 struct Point coordout;
\r
109 struct Site *ep[2];
\r
110 struct Site *reg[2];
\r
118 struct GraphEdge* next;
\r
126 struct Halfedge *ELleft, *ELright;
\r
127 struct Edge *ELedge;
\r
130 struct Site *vertex;
\r
132 struct Halfedge *PQnext;
\r
138 class VoronoiDiagramGenerator
\r
141 VoronoiDiagramGenerator();
\r
142 ~VoronoiDiagramGenerator();
\r
144 bool generateVoronoi(struct SourcePoint* srcPoints, int numPoints, float minX, float maxX, float minY, float maxY, float minDist=0);
\r
145 void getSitePoints(int sitenbr, int* numpoints, PolygonPoint** pS);
\r
147 void resetIterator()
\r
149 iteratorEdges = allEdges;
\r
152 bool getNext(float& x1, float& y1, float& x2, float& y2)
\r
154 if(iteratorEdges == 0)
\r
157 x1 = iteratorEdges->x1;
\r
158 x2 = iteratorEdges->x2;
\r
159 y1 = iteratorEdges->y1;
\r
160 y2 = iteratorEdges->y2;
\r
162 iteratorEdges = iteratorEdges->next;
\r
170 void cleanupEdges();
\r
171 char *getfree(struct Freelist *fl);
\r
172 struct Halfedge *PQfind();
\r
177 struct Halfedge **ELhash;
\r
178 struct Halfedge *HEcreate(), *ELleft(), *ELright(), *ELleftbnd();
\r
179 struct Halfedge *HEcreate(struct Edge *e,int pm);
\r
182 struct Point PQ_min();
\r
183 struct Halfedge *PQextractmin();
\r
184 void freeinit(struct Freelist *fl,int size);
\r
185 void makefree(struct Freenode *curr,struct Freelist *fl);
\r
188 bool voronoi(int triangulate);
\r
189 void ref(struct Site *v);
\r
190 void deref(struct Site *v);
\r
191 void endpoint(struct Edge *e,int lr,struct Site * s);
\r
192 void endpoint(struct Edge *e1,int lr,struct Site * s, struct Edge *e2, struct Edge *e3);
\r
194 void ELdelete(struct Halfedge *he);
\r
195 struct Halfedge *ELleftbnd(struct Point *p);
\r
196 struct Halfedge *ELright(struct Halfedge *he);
\r
197 void makevertex(struct Site *v);
\r
198 void out_triple(struct Site *s1, struct Site *s2,struct Site * s3);
\r
200 void PQinsert(struct Halfedge *he,struct Site * v, float offset);
\r
201 void PQdelete(struct Halfedge *he);
\r
202 bool ELinitialize();
\r
203 void ELinsert(struct Halfedge *lb, struct Halfedge *newHe);
\r
204 struct Halfedge * ELgethash(int b);
\r
205 struct Halfedge *ELleft(struct Halfedge *he);
\r
206 struct Site *leftreg(struct Halfedge *he);
\r
207 void out_site(struct Site *s);
\r
208 bool PQinitialize();
\r
209 int PQbucket(struct Halfedge *he);
\r
210 void pushpoint(int sitenbr, double x, double y, int boundary);
\r
211 int ccw( Point p0, Point p1, Point p2 );
\r
212 void clip_line(struct Edge *e);
\r
213 char *myalloc(unsigned n);
\r
214 int right_of(struct Halfedge *el,struct Point *p);
\r
216 struct Site *rightreg(struct Halfedge *he);
\r
217 struct Edge *bisect(struct Site *s1,struct Site *s2);
\r
218 float dist(struct Site *s,struct Site *t);
\r
219 struct Site *intersect(struct Halfedge *el1, struct Halfedge *el2, struct Point *p=0);
\r
221 void out_bisector(struct Edge *e);
\r
222 void out_ep(struct Edge *e);
\r
223 void out_vertex(struct Site *v);
\r
224 struct Site *nextone();
\r
226 void pushGraphEdge(float x1, float y1, float x2, float y2);
\r
229 void line(float x1, float y1, float x2, float y2);
\r
230 void circle(float x, float y, float radius);
\r
231 void range(float minX, float minY, float maxX, float maxY);
\r
234 struct Freelist hfl;
\r
235 struct Halfedge *ELleftend, *ELrightend;
\r
238 int triangulate, sorted, plot, debug;
\r
239 float xmin, xmax, ymin, ymax, deltax, deltay;
\r
241 struct Site *sites;
\r
242 struct Polygon *polygons;
\r
243 struct Point corners[4];
\r
248 struct Freelist sfl;
\r
249 struct Site *bottomsite;
\r
252 struct Freelist efl;
\r
254 struct Halfedge *PQhash;
\r
258 int ntry, totalsearch;
\r
259 float pxmin, pxmax, pymin, pymax, cradius;
\r
262 float borderMinX, borderMaxX, borderMinY, borderMaxY;
\r
264 FreeNodeArrayList* allMemoryList;
\r
265 FreeNodeArrayList* currentMemoryBlock;
\r
267 GraphEdge* allEdges;
\r
268 GraphEdge* iteratorEdges;
\r
270 float minDistanceBetweenSites;
\r
274 int scomp(const void *p1,const void *p2);
\r
275 int spcomp(const void *p1,const void *p2);
\r
276 int anglecomp(const void * p1, const void * p2);
\r