Bugfix in search_for_outside_edge routine.
[voro++.git] / trunk / zeo / v_network.hh
blobd099d16ada027716da5daf295b51cdac67f714e6
1 #ifndef ZEOPP_V_NETWORK_HH
2 #define ZEOPP_V_NETWORK_HH
4 #include <vector>
6 #include "voro++.hh"
7 using namespace voro;
9 const int init_network_edge_memory=4;
10 const int init_network_vertex_memory=64;
11 const int max_network_vertex_memory=65536;
13 struct block {
14 double dis;
15 double e;
16 inline void first(double v,double d) {e=v>0?v:0;dis=d;}
17 inline void add(double v,double d) {
18 if(v<0) e=0;
19 else if(v<e) {e=v;dis=d;}
21 inline void print(FILE *fp) {fprintf(fp," %g %g",e,dis);}
24 class voronoi_network {
25 public:
26 const double bx;
27 const double bxy;
28 const double by;
29 const double bxz;
30 const double byz;
31 const double bz;
32 const int nx;
33 const int ny;
34 const int nz;
35 const int nxyz;
36 const double xsp,ysp,zsp;
37 const double net_tol;
38 double **pts;
39 int **idmem;
40 int *ptsc;
41 int *ptsmem;
42 int **ed;
43 int **ne;
44 block **raded;
45 unsigned int **pered;
46 int edc,edmem;
47 int *nu;
48 int *nec;
49 int *numem;
50 int *reg;
51 int *regp;
52 int *vmap;
53 int map_mem;
54 template<class c_class>
55 voronoi_network(c_class &c,double net_tol_=tolerance);
56 ~voronoi_network();
57 void print_network(FILE *fp=stdout,bool reverse_remove=false);
58 inline void print_network(const char* filename,bool reverse_remove=false) {
59 FILE *fp(safe_fopen(filename,"w"));
60 print_network(fp);
61 fclose(fp);
63 void draw_network(FILE *fp=stdout);
64 inline void draw_network(const char* filename) {
65 FILE *fp(safe_fopen(filename,"w"));
66 draw_network(fp);
67 fclose(fp);
69 template<class v_cell>
70 inline void add_to_network(v_cell &c,int idn,double x,double y,double z,double rad,int *&cmap) {
71 cmap=new int[4*c.p];
72 add_to_network_internal(c,idn,x,y,z,rad,cmap);
74 template<class v_cell>
75 inline void add_to_network_rectangular(v_cell &c,int idn,double x,double y,double z,double rad,int *&cmap) {
76 cmap=new int[4*c.p];
77 add_to_network_rectangular_internal(c,idn,x,y,z,rad,cmap);
79 template<class v_cell>
80 inline void add_to_network(v_cell &c,int idn,double x,double y,double z,double rad) {
81 if(c.p>map_mem) add_mapping_memory(c.p);
82 add_to_network_internal(c,idn,x,y,z,rad,vmap);
84 template<class v_cell>
85 inline void add_to_network_rectangular(v_cell &c,int idn,double x,double y,double z,double rad) {
86 if(c.p>map_mem) add_mapping_memory(c.p);
87 add_to_network_rectangular_internal(c,idn,x,y,z,rad,vmap);
90 void clear_network();
91 private:
92 inline int step_div(int a,int b);
93 inline int step_int(double a);
94 inline void add_neighbor(int k,int idn);
95 void add_particular_vertex_memory(int l);
96 void add_edge_network_memory();
97 void add_network_memory(int l);
98 void add_mapping_memory(int pmem);
99 inline unsigned int pack_periodicity(int i,int j,int k);
100 inline void unpack_periodicity(unsigned int pa,int &i,int &j,int &k);
101 template<class v_cell>
102 void add_edges_to_network(v_cell &c,double x,double y,double z,double rad,int *cmap);
103 int not_already_there(int k,int j,unsigned int cper);
104 bool search_previous(double gx,double gy,double x,double y,double z,int &ijk,int &q,int &ci,int &cj,int &ck);
105 bool safe_search_previous_rect(double x,double y,double z,int &ijk,int &q,int &ci,int &cj,int &ck);
106 bool search_previous_rect(double x,double y,double z,int &ijk,int &q,int &ci,int &cj,int &ck);
107 template<class v_cell>
108 void add_to_network_internal(v_cell &c,int idn,double x,double y,double z,double rad,int *cmap);
109 template<class v_cell>
110 void add_to_network_rectangular_internal(v_cell &c,int idn,double x,double y,double z,double rad,int *cmap);
113 #endif