Strip extra spaces from code.
[voro++.git] / branches / 2d / src / v_connect.hh
blobbfb2b727c6a3cae6434d278038115c3c40c05613
2 #ifndef VOROPP_V_CONNECT_HH
3 #define VOROPP_V_CONNECT_HH
4 //To be used with voro++ to get full connectivity information
5 using namespace std;
6 #include "voro++_2d.hh"
7 #include <stdio.h>
8 #include <iostream>
9 #include <stdlib.h>
10 #include <vector>
11 namespace voro{
15 class v_connect{
16 public:
17 double minx,maxx,miny,maxy;
18 int nx,ny;
19 vector<int> vid;
20 vector<double> vpos;
21 vector<char> vbd;
22 int bd;
23 //# of generators
24 int ng;
25 //middle generator id
26 int mid;
27 //current size of vertl array/2
28 int current_vertices;
29 //number of vertices
30 int nv;
31 //for all i>=degenerate_vertices, the ith vertex is degenerate
32 int degenerate_vertices;
33 //current size of ed_to_vert array
34 int current_edges;
35 //number of edges
36 int ne;
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;
39 int *mp;
40 //vertl[2*i]=x coordinate of ith vertex
41 double *vertl;
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
57 int *ed_to_vert;
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;
64 //see above
65 int *generator_is_vertex;
74 v_connect(){
75 bd=-1;
76 nv=0;
77 ne=0;
78 //ng initialized during import routine.
79 minx=large_number;
80 maxx=-minx;
81 miny=minx;
82 maxy=maxx;
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;
91 ~v_connect(){
92 delete[] vertl;
93 delete[] vert_to_gen;
94 delete[] vert_to_ed;
95 delete[] vert_on_bd;
96 delete[] gen_to_vert;
97 delete[] gen_to_ed;
98 delete[] gen_to_gen_e;
99 delete[] gen_to_gen_v;
100 delete[] ed_to_vert;
101 delete[] ed_to_gen;
102 delete[] ed_on_bd;
103 delete[] mp;
106 void import(FILE *fp=stdin);
108 void import(const char* filename) {
109 FILE *fp=safe_fopen(filename, "r");
110 import(fp);
111 fclose(fp);
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++){
125 newv[i]=old[i];
127 delete [] old;
128 old=newv;
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++){
133 newa[i]=old[i];
135 delete [] old;
136 old=newa;
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++){
141 newa[i]=old[i];
143 delete [] old;
144 old=newa;
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++){
149 newt[i]=old[i];
151 delete [] old;
152 old=newt;
154 //return true if vector contains the two elements
155 inline bool contains_two(vector<int> &a,int b, int c){
156 int i=0,j=0;
157 for(int k=0;k<a.size();k++){
158 if(a[k]==b){
159 i=1;
160 break;
162 }for(int k=0;k<a.size();k++){
163 if(a[k]==c){
164 j=1;
165 break;
168 if(i==1 && j==1) return true;
169 else return false;
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;
176 return false;
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){
180 int d=-1;
181 for(int i=0;i<a.size();i++){
182 if(a[i]!=b && a[i]!=c){
183 d=a[i];
184 break;
187 return d;
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){
191 g1=g2=-1;
192 for(int i=0;i<a.size();i++){
193 for(int k=0;k<b.size();k++){
194 if(a[i]==b[k]){
195 if(g1==-1) g1=a[i];
196 else if(a[i]==g1) continue;
197 else g2=a[i];
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){
204 g1=-1;
205 for(int i=0;i<a.size();i++){
206 for(int j=0;j<b.size();j++){
207 if(a[i]==b[j]){
208 g1=a[i];
209 return;
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;
222 return true;
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];
229 return -1;
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;
236 return true;
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");
254 draw_gnu(fp);
255 fclose(fp);
257 void draw_vtg_gnu(FILE *fp=stdout);
258 inline void draw_vtg_gnu(const char *filename){
259 FILE *fp=safe_fopen(filename,"w");
260 draw_vtg_gnu(fp);
261 fclose(fp);
263 void draw_gen_gen(FILE *fp=stdout);
264 inline void draw_gen_gen(const char *filename){
265 FILE *fp=safe_fopen(filename,"w");
266 draw_gen_gen(fp);
267 fclose(fp);
269 void label_vertices(FILE *fp=stdout);
270 inline void label_vertices(const char *filename){
271 FILE *fp=safe_fopen(filename,"w");
272 label_vertices(fp);
273 fclose(fp);
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);
279 fclose(fp);
281 void label_edges(FILE *fp=stdout);
282 inline void label_edges(const char *filename){
283 FILE *fp=safe_fopen(filename,"w");
284 label_edges(fp);
285 fclose(fp);
287 void label_centroids(FILE *fp=stdout);
288 inline void label_centroids(const char *filename){
289 FILE *fp=safe_fopen(filename,"w");
290 label_centroids(fp);
291 fclose(fp);
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);
297 fclose(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);
303 fclose(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);
309 fclose(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);
315 fclose(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);
321 fclose(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);
327 fclose(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);
333 fclose(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");
339 ascii_output(fp);
340 fclose(fp);
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);
349 fclose(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);
355 fclose(fp);
361 #endif