File indexing completed on 2025-01-18 09:57:16
0001 #ifndef __FASTJET__VORONOI_H__
0002 #define __FASTJET__VORONOI_H__
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 #include "fastjet/LimitedWarning.hh"
0108 #include <vector>
0109 #include <math.h>
0110 #include <stdlib.h>
0111 #include <string.h>
0112
0113 #define DELETED -2
0114 #define le 0
0115 #define re 1
0116
0117 FASTJET_BEGIN_NAMESPACE
0118
0119
0120
0121
0122
0123
0124
0125
0126 class VPoint{
0127 public:
0128
0129 VPoint() : x(0.0), y(0.0) {}
0130
0131
0132 VPoint(double _x, double _y) : x(_x), y(_y) {}
0133
0134
0135 inline VPoint operator + (const VPoint &p) const{
0136 return VPoint(x+p.x, y+p.y);
0137 }
0138
0139
0140 inline VPoint operator - (const VPoint &p) const{
0141 return VPoint(x-p.x, y-p.y);
0142 }
0143
0144
0145 inline VPoint operator * (const double t) const{
0146 return VPoint(x*t, y*t);
0147 }
0148
0149
0150 double x,y;
0151 };
0152
0153
0154
0155 inline double norm(const VPoint p){
0156 return p.x*p.x+p.y*p.y;
0157 }
0158
0159
0160
0161 inline double vector_product(const VPoint &p1, const VPoint &p2){
0162 return p1.x*p2.y-p1.y*p2.x;
0163 }
0164
0165
0166
0167 inline double scalar_product(const VPoint &p1, const VPoint &p2){
0168 return p1.x*p2.x+p1.y*p2.y;
0169 }
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179 class GraphEdge{
0180 public:
0181
0182 double x1,y1,x2,y2;
0183
0184
0185 int point1, point2;
0186
0187
0188 GraphEdge* next;
0189 };
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 class Site{
0200 public:
0201 VPoint coord;
0202 int sitenbr;
0203 int refcnt;
0204 };
0205
0206
0207
0208 class Freenode{
0209 public:
0210 Freenode *nextfree;
0211 };
0212
0213
0214 class FreeNodeArrayList{
0215 public:
0216 Freenode* memory;
0217 FreeNodeArrayList* next;
0218 };
0219
0220
0221 class Freelist{
0222 public:
0223 Freenode *head;
0224 int nodesize;
0225 };
0226
0227 class Edge{
0228 public:
0229 double a,b,c;
0230 Site *ep[2];
0231 Site *reg[2];
0232 int edgenbr;
0233 };
0234
0235
0236 class Halfedge{
0237 public:
0238 Halfedge *ELleft, *ELright;
0239 Edge *ELedge;
0240 int ELrefcnt;
0241 char ELpm;
0242 Site *vertex;
0243 volatile double ystar;
0244 Halfedge *PQnext;
0245 };
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255 class VoronoiDiagramGenerator{
0256 public:
0257 VoronoiDiagramGenerator();
0258 ~VoronoiDiagramGenerator();
0259
0260 bool generateVoronoi(std::vector<VPoint> *_parent_sites,
0261 double minX, double maxX, double minY, double maxY,
0262 double minDist=0);
0263
0264 inline void resetIterator(){
0265 iteratorEdges = allEdges;
0266 }
0267
0268 bool getNext(GraphEdge **e){
0269 if(iteratorEdges == 0)
0270 return false;
0271
0272 *e = iteratorEdges;
0273 iteratorEdges = iteratorEdges->next;
0274 return true;
0275 }
0276
0277 std::vector<VPoint> *parent_sites;
0278 int n_parent_sites;
0279
0280 private:
0281 void cleanup();
0282 void cleanupEdges();
0283 char *getfree(Freelist *fl);
0284 Halfedge *PQfind();
0285 int PQempty();
0286
0287 Halfedge **ELhash;
0288 Halfedge *HEcreate(), *ELleft(), *ELright(), *ELleftbnd();
0289 Halfedge *HEcreate(Edge *e,int pm);
0290
0291 VPoint PQ_min();
0292 Halfedge *PQextractmin();
0293 void freeinit(Freelist *fl,int size);
0294 void makefree(Freenode *curr,Freelist *fl);
0295 void geominit();
0296 void plotinit();
0297
0298
0299 bool voronoi();
0300 void ref(Site *v);
0301 void deref(Site *v);
0302 void endpoint(Edge *e,int lr,Site * s);
0303
0304 void ELdelete(Halfedge *he);
0305 Halfedge *ELleftbnd(VPoint *p);
0306 Halfedge *ELright(Halfedge *he);
0307 void makevertex(Site *v);
0308
0309 void PQinsert(Halfedge *he,Site * v, double offset);
0310 void PQdelete(Halfedge *he);
0311 bool ELinitialize();
0312 void ELinsert(Halfedge *lb, Halfedge *newHe);
0313 Halfedge * ELgethash(int b);
0314 Halfedge *ELleft(Halfedge *he);
0315 Site *leftreg(Halfedge *he);
0316 bool PQinitialize();
0317 int PQbucket(Halfedge *he);
0318 void clip_line(Edge *e);
0319 char *myalloc(unsigned n);
0320 int right_of(Halfedge *el,VPoint *p);
0321
0322 Site *rightreg(Halfedge *he);
0323 Edge *bisect(Site *s1, Site *s2);
0324 double dist(Site *s,Site *t);
0325
0326
0327
0328 Site *intersect(Halfedge *el1, Halfedge *el2 );
0329
0330 Site *nextone();
0331
0332 void pushGraphEdge(double x1, double y1, double x2, double y2,
0333 Site *s1, Site *s2);
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347 Freelist hfl;
0348 Halfedge *ELleftend, *ELrightend;
0349 int ELhashsize;
0350
0351 int sorted, debug;
0352 double xmin, xmax, ymin, ymax, deltax, deltay;
0353
0354 Site *sites;
0355 int nsites;
0356 int siteidx;
0357 int sqrt_nsites;
0358 int nvertices;
0359 Freelist sfl;
0360 Site *bottomsite;
0361
0362 int nedges;
0363 Freelist efl;
0364 int PQhashsize;
0365 Halfedge *PQhash;
0366 int PQcount;
0367 int PQmin;
0368
0369 int ntry, totalsearch;
0370 double pxmin, pxmax, pymin, pymax, cradius;
0371 int total_alloc;
0372
0373 double borderMinX, borderMaxX, borderMinY, borderMaxY;
0374
0375 FreeNodeArrayList* allMemoryList;
0376 FreeNodeArrayList* currentMemoryBlock;
0377
0378 GraphEdge* allEdges;
0379 GraphEdge* iteratorEdges;
0380
0381 double minDistanceBetweenSites;
0382
0383 static LimitedWarning _warning_degeneracy;
0384 };
0385
0386 int scomp(const void *p1,const void *p2);
0387
0388
0389 FASTJET_END_NAMESPACE
0390
0391 #endif