2
* The author of this software is Steven Fortune. Copyright (c) 1994 by AT&T
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose without fee is hereby granted, provided that this entire notice
6
* is included in all copies of any software which is or includes a copy
7
* or modification of this software and in all copies of the supporting
8
* documentation for such software.
9
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
10
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
11
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
12
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
16
* This code was originally written by Stephan Fortune in C code. I, Shane O'Sullivan,
17
* have since modified it, encapsulating it in a C++ class and, fixing memory leaks and
18
* adding accessors to the Voronoi Edges.
19
* Permission to use, copy, modify, and distribute this software for any
20
* purpose without fee is hereby granted, provided that this entire notice
21
* is included in all copies of any software which is or includes a copy
22
* or modification of this software and in all copies of the supporting
23
* documentation for such software.
24
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
25
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR AT&T MAKE ANY
26
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
27
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
30
#ifndef VORONOI_DIAGRAM_GENERATOR
31
#define VORONOI_DIAGRAM_GENERATOR
34
#include "numpy/arrayobject.h"
51
#define MAX(x, y) (x > y ? x: y)
56
struct Freenode *nextfree;
59
struct FreeNodeArrayList
61
struct Freenode* memory;
62
struct FreeNodeArrayList* next;
68
struct Freenode *head;
77
// structure used both for sites and for vertices
105
struct EdgeList *next;
111
struct GraphEdge* next;
119
struct Halfedge *ELleft, *ELright;
125
struct Halfedge *PQnext;
131
class VoronoiDiagramGenerator
134
VoronoiDiagramGenerator();
135
~VoronoiDiagramGenerator();
137
bool generateVoronoi(double *xValues, double *yValues, int numPoints, double minX, double maxX, double minY, double maxY, double minDist=0);
141
iteratorEdges = allEdges;
144
bool getNext(double& x1, double& y1, double& x2, double& y2)
146
if(iteratorEdges == 0)
149
x1 = iteratorEdges->x1;
150
x2 = iteratorEdges->x2;
151
y1 = iteratorEdges->y1;
152
y2 = iteratorEdges->y2;
154
iteratorEdges = iteratorEdges->next;
159
void resetEdgeListIter()
161
iterEdgeList = allEdgeList;
164
bool getNextDelaunay(int& ep0, double& ep0x, double& ep0y,
165
int& ep1, double& ep1x, double& ep1y,
166
int& reg0, int& reg1);
168
void getNumbers(int& edges, int& vertices) {
170
vertices = nvertices;
175
void cleanupEdgeList();
177
char *getfree(struct Freelist *fl);
178
struct Halfedge *PQfind();
182
struct Halfedge **ELhash;
183
struct Halfedge *HEcreate(), *ELleft(), *ELright(), *ELleftbnd();
184
struct Halfedge *HEcreate(struct Edge *e,int pm);
187
struct Point PQ_min();
188
struct Halfedge *PQextractmin();
189
void freeinit(struct Freelist *fl,int size);
190
void makefree(struct Freenode *curr,struct Freelist *fl);
193
bool voronoi(int triangulate);
194
void ref(struct Site *v);
195
void deref(struct Site *v);
196
void endpoint(struct Edge *e,int lr,struct Site * s);
198
void ELdelete(struct Halfedge *he);
199
struct Halfedge *ELleftbnd(struct Point *p);
200
struct Halfedge *ELright(struct Halfedge *he);
201
void makevertex(struct Site *v);
202
void out_triple(struct Site *s1, struct Site *s2,struct Site * s3);
204
void PQinsert(struct Halfedge *he,struct Site * v, double offset);
205
void PQdelete(struct Halfedge *he);
207
void ELinsert(struct Halfedge *lb, struct Halfedge *newHe);
208
struct Halfedge *ELgethash(int b);
209
struct Halfedge *ELleft(struct Halfedge *he);
210
struct Site *leftreg(struct Halfedge *he);
211
void out_site(struct Site *s);
213
int PQbucket(struct Halfedge *he);
214
void clip_line(struct Edge *e);
215
char *myalloc(unsigned n);
216
int right_of(struct Halfedge *el,struct Point *p);
218
struct Site *rightreg(struct Halfedge *he);
219
struct Edge *bisect(struct Site *s1, struct Site *s2);
220
double dist(struct Site *s,struct Site *t);
221
struct Site *intersect(struct Halfedge *el1, struct Halfedge *el2, struct Point *p=0);
223
void out_bisector(struct Edge *e);
224
void out_ep(struct Edge *e);
225
void out_vertex(struct Site *v);
226
struct Site *nextone();
228
void pushGraphEdge(double x1, double y1, double x2, double y2);
229
void pushEdgeList(Edge *e);
232
void line(double x1, double y1, double x2, double y2);
233
void circle(double x, double y, double radius);
234
void range(double minX, double minY, double maxX, double maxY);
238
struct Halfedge *ELleftend, *ELrightend;
241
int triangulate, sorted, plot, debug;
242
double xmin, xmax, ymin, ymax, deltax, deltay;
250
struct Site *bottomsite;
255
struct Halfedge *PQhash;
259
int ntry, totalsearch;
260
double pxmin, pxmax, pymin, pymax, cradius;
263
double borderMinX, borderMaxX, borderMinY, borderMaxY;
265
FreeNodeArrayList* allMemoryList;
266
FreeNodeArrayList* currentMemoryBlock;
269
GraphEdge* iteratorEdges;
271
EdgeList* allEdgeList;
272
EdgeList* iterEdgeList;
274
double minDistanceBetweenSites;
278
int scomp(const void *p1, const void *p2);