2 #ifndef VOROPP_V_CONNECT_HH
3 #define VOROPP_V_CONNECT_HH
4 //To be used with voro++ to get full connectivity information
6 #include "voro++_2d.hh"
17 double minx
,maxx
,miny
,maxy
;
27 //current size of vertl array/2
31 //for all i>=degenerate_vertices, the ith vertex is degenerate
32 int degenerate_vertices
;
33 //current size of ed_to_vert array
37 //maps a generator's id to the place it was recieved in the input file
38 //i.e. if the first particle in the input file has id 20, then mp[20]=0;
40 //vertl[2*i]=x coordinate of ith vertex
42 //vert_to_gen[i]= vector containing list of generators that ith vertex is touching
43 vector
<int> *vert_to_gen
;
44 //vert_to_ed[i]= vector containing list of edges that the i'th vertex is a member of
45 vector
<int> *vert_to_ed
;
46 //vert_on_bd[i].size()==0 if vertex i is not on boundary. if vertex i is on boundary it is a size 2 vector of the generators that define the part of the boundary it is on
47 vector
<int> *vert_on_bd
;
48 //gen_to_vert[i]= list of vertices that ith generatos is touching in cc order
49 vector
<int> *gen_to_vert
;
50 //gen_to_edge[i]= list of edges that the ith generator is touching in cc order (- edge number means ~edge number with reverse orientation
51 vector
<int> *gen_to_ed
;
52 //gen_to_gen_e[i]= list of neighbors of ith generator through edges in cc order
53 vector
<int> *gen_to_gen_e
;
54 //gen_to_gen_v[i]= list of neighbors of ith generator through degenerate vertices in cc order
55 vector
<int> *gen_to_gen_v
;
56 //ed_to_vert[2*i(+1)]=the vertex with the lower(higher) id constituting edge i
58 //ed_to_gen[2*i(+1)]=the generator with the left-hand(right-hand) orientation touching the edge
59 vector
<int> *ed_to_gen
;
60 //ed_on_bd[i].size()==0 if edge i is not on the boundary. if it is, ed_on_bd[i] is a 2 element list of the generators that define that part of the boundary that it is on
61 vector
<int> *ed_on_bd
;
62 //vertex_is_generator[i]=(-1 if ith vertex is not a generator)(j if ith vertex is generator j)
63 int *vertex_is_generator
;
65 int *generator_is_vertex
;
78 //ng initialized during import routine.
83 current_vertices
=init_vertices
;
84 current_edges
=init_vertices
;
85 vertl
=new double[2*current_vertices
];
86 vert_to_gen
= new vector
<int>[current_vertices
];
87 vertex_is_generator
=new int[current_vertices
];
88 for(int i
=0;i
<current_vertices
;i
++) vertex_is_generator
[i
]=-1;
98 delete[] gen_to_gen_e
;
99 delete[] gen_to_gen_v
;
106 void import(FILE *fp
=stdin
);
108 void import(const char* filename
) {
109 FILE *fp
=safe_fopen(filename
, "r");
114 vector
<int> groom_vertexg_help(double x
, double y
,double vx
, double vy
, vector
<int> &g
);
115 vector
<int> groom_vertexg_help2(double x
,double y
,double vx
,double vy
,vector
<int> &g
);
116 inline void groom_vertexg(voronoicell_nonconvex_neighbor_2d
&c
){
117 double x
=vpos
[2*mp
[c
.my_id
]],y
=vpos
[2*mp
[c
.my_id
]+1];
118 for(int i
=0;i
<c
.p
;i
++){
119 c
.vertexg
[i
]=groom_vertexg_help(x
,y
,(c
.pts
[2*i
]*.5)+x
,(c
.pts
[2*i
+1]*.5)+y
,c
.vertexg
[i
]);
122 inline void add_memory_vector(vector
<int>* &old
,int size
){
123 vector
<int> *newv
=new vector
<int>[size
];
124 for(int i
=0;i
<(size
>>1);i
++){
130 inline void add_memory_array(double* &old
,int size
){
131 double *newa
= new double[2*size
];
132 for(int i
=0;i
<(size
);i
++){
138 inline void add_memory_array(int* &old
,int size
){
139 int *newa
=new int[2*size
];
140 for(int i
=0;i
<size
;i
++){
146 inline void add_memory_table(unsigned int* &old
,int size
){
147 unsigned int* newt
=new unsigned int[((size
*size
)/32)+1];
148 for(int i
=0;i
<((((size
>>1)*(size
>>1))/32)+1);i
++){
154 //return true if vector contains the two elements
155 inline bool contains_two(vector
<int> &a
,int b
, int c
){
157 for(int k
=0;k
<a
.size();k
++){
162 }for(int k
=0;k
<a
.size();k
++){
168 if(i
==1 && j
==1) return true;
171 //returns true if a vector contains the element
172 inline bool contains(vector
<int> &a
,int b
){
173 for(int i
=0;i
<a
.size();i
++){
174 if(a
[i
]==b
) return true;
178 //given a three element vector, returns an element != b or c
179 inline int not_these_two(vector
<int> &a
,int b
, int c
){
181 for(int i
=0;i
<a
.size();i
++){
182 if(a
[i
]!=b
&& a
[i
]!=c
){
189 //returns two elements the vectors have in common in g1,g2
190 inline void two_in_common(vector
<int> a
,vector
<int> b
,int &g1
,int &g2
){
192 for(int i
=0;i
<a
.size();i
++){
193 for(int k
=0;k
<b
.size();k
++){
196 else if(a
[i
]==g1
) continue;
202 //if a and b share an element, returns it in g1, if not returns -1
203 inline void one_in_common(vector
<int> a
,vector
<int> b
,int &g1
){
205 for(int i
=0;i
<a
.size();i
++){
206 for(int j
=0;j
<b
.size();j
++){
214 //returns true iff a and b contain the same elements
215 inline bool contain_same_elements(vector
<int> a
,vector
<int> b
){
216 for(int i
=0;i
<a
.size();i
++){
217 if(!contains(b
,a
[i
])) return false;
219 for(int i
=0;i
<b
.size();i
++){
220 if(!contains(a
,b
[i
])) return false;
224 //returns any element in a !=b
225 inline int not_this_one(vector
<int> a
, int b
){
226 for(int i
=0;i
<a
.size();i
++){
227 if(a
[i
]!=b
) return a
[i
];
231 //returns true if the elements of a are a subset of elements of b
232 inline bool subset(vector
<int> a
,vector
<int> b
){
233 for(int i
=0;i
<a
.size();i
++){
234 if(!contains(b
,a
[i
])) return false;
238 inline double cross_product(double x1
,double y1
,double x2
,double y2
){
239 return ((x1
*y2
)-(y1
*x2
));
241 inline double dot_product(double x1
, double y1
, double x2
, double y2
){
242 return ((x1
*x2
)+(y1
*y2
));
244 void arrange_cc_x_to_gen(vector
<int> &list
,double cx
,double cy
);
245 void arrange_cc_gen_to_vert(vector
<int> &list
,double cx
,double cy
);
246 void arrange_cc_gen_to_ed(vector
<int> &list
);
247 void arrange_cc_vert_to_ed(vector
<int> &list
,double cx
,double cy
,int id
);
248 void assemble_vertex();
249 void assemble_gen_ed();
250 void assemble_boundary();
251 void draw_gnu(FILE *fp
=stdout
);
252 inline void draw_gnu(const char *filename
){
253 FILE *fp
=safe_fopen(filename
,"w");
257 void draw_vtg_gnu(FILE *fp
=stdout
);
258 inline void draw_vtg_gnu(const char *filename
){
259 FILE *fp
=safe_fopen(filename
,"w");
263 void draw_gen_gen(FILE *fp
=stdout
);
264 inline void draw_gen_gen(const char *filename
){
265 FILE *fp
=safe_fopen(filename
,"w");
269 void label_vertices(FILE *fp
=stdout
);
270 inline void label_vertices(const char *filename
){
271 FILE *fp
=safe_fopen(filename
,"w");
275 void label_generators(FILE *fp
=stdout
);
276 inline void label_generators(const char *filename
){
277 FILE *fp
=safe_fopen(filename
,"w");
278 label_generators(fp
);
281 void label_edges(FILE *fp
=stdout
);
282 inline void label_edges(const char *filename
){
283 FILE *fp
=safe_fopen(filename
,"w");
287 void label_centroids(FILE *fp
=stdout
);
288 inline void label_centroids(const char *filename
){
289 FILE *fp
=safe_fopen(filename
,"w");
293 void print_gen_to_ed_table(FILE *fp
=stdout
);
294 inline void print_gen_to_ed_table(const char *filename
){
295 FILE *fp
=safe_fopen(filename
,"w");
296 print_gen_to_ed_table(fp
);
299 void print_gen_to_vert_table(FILE *fp
=stdout
);
300 inline void print_gen_to_vert_table(const char *filename
){
301 FILE *fp
=safe_fopen(filename
,"w");
302 print_gen_to_vert_table(fp
);
305 void print_vert_to_gen_table(FILE *fp
=stdout
);
306 inline void print_vert_to_gen_table(const char *filename
){
307 FILE *fp
=safe_fopen(filename
,"w");
308 print_vert_to_gen_table(fp
);
311 void print_ed_to_gen_table(FILE *fp
=stdout
);
312 inline void print_ed_to_gen_table(const char *filename
){
313 FILE *fp
=safe_fopen(filename
,"w");
314 print_ed_to_gen_table(fp
);
317 void print_vert_to_ed_table(FILE *fp
=stdout
);
318 inline void print_vert_to_ed_table(const char *filename
){
319 FILE *fp
=safe_fopen(filename
,"w");
320 print_vert_to_ed_table(fp
);
323 void print_vert_boundary(FILE *fp
=stdout
);
324 inline void print_vert_boundary(const char *filename
){
325 FILE *fp
=safe_fopen(filename
,"w");
326 print_vert_boundary(fp
);
329 void print_ed_boundary(FILE *fp
=stdout
);
330 inline void print_ed_boundary(const char *filename
){
331 FILE *fp
=safe_fopen(filename
,"w");
332 print_ed_boundary(fp
);
335 void add_memory_vertices();
336 void ascii_output(FILE *fp
=stdout
);
337 inline void ascii_output(const char *filename
){
338 FILE *fp
=safe_fopen(filename
,"w");
342 double signed_area(int g
);
343 void centroid(int g
,double &x
,double &y
);
344 void lloyds(double epsilon
);
345 void draw_median_mesh(FILE *fp
=stdout
);
346 inline void draw_median_mesh(const char *filename
){
347 FILE *fp
=safe_fopen(filename
,"w");
348 draw_median_mesh(fp
);
351 void draw_closest_generator(FILE *fp
,double x
,double y
);
352 inline void draw_closest_generator(const char *filename
,double x
,double y
){
353 FILE *fp
=safe_fopen(filename
,"w");
354 draw_closest_generator(fp
,x
,y
);