00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef VOROPP_CONTAINER_HH
00011 #define VOROPP_CONTAINER_HH
00012
00013 #include "config.hh"
00014 #include <cstdio>
00015 #include <iostream>
00016 #include <fstream>
00017 #include <cmath>
00018 using namespace std;
00019
00020 class voropp_loop;
00021 class radius_poly;
00022 class wall;
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 template<class r_option>
00033 class container_base {
00034 public:
00035 container_base(fpoint xa,fpoint xb,fpoint ya,fpoint yb,fpoint za,fpoint zb,int xn,int yn,int zn,bool xper,bool yper,bool zper,int memi);
00036 ~container_base();
00037 void draw_particles(const char *filename);
00038 void draw_particles();
00039 void draw_particles(ostream &os);
00040 void draw_particles_pov(const char *filename);
00041 void draw_particles_pov();
00042 void draw_particles_pov(ostream &os);
00043 void import(istream &is);
00044 inline void import();
00045 inline void import(const char *filename);
00046 void region_count();
00047 void clear();
00048 void draw_cells_gnuplot(const char *filename,fpoint xmin,fpoint xmax,fpoint ymin,fpoint ymax,fpoint zmin,fpoint zmax);
00049 inline void draw_cells_gnuplot(const char *filename);
00050 void draw_cells_pov(const char *filename,fpoint xmin,fpoint xmax,fpoint ymin,fpoint ymax,fpoint zmin,fpoint zmax);
00051 inline void draw_cells_pov(const char *filename);
00052 void store_cell_volumes(fpoint *bb);
00053 fpoint packing_fraction(fpoint *bb,fpoint cx,fpoint cy,fpoint cz,fpoint r);
00054 fpoint packing_fraction(fpoint *bb,fpoint xmin,fpoint xmax,fpoint ymin,fpoint ymax,fpoint zmin,fpoint zmax);
00055 fpoint sum_cell_volumes();
00056 void print_facet_information();
00057 void compute_all_cells();
00058 void count_all_faces(ostream &os);
00059 void count_all_faces();
00060 void count_all_faces(const char *filename);
00061 void print_all(ostream &os);
00062 void print_all();
00063 void print_all(const char *filename);
00064 void print_all_neighbor(ostream &os);
00065 void print_all_neighbor();
00066 void print_all_neighbor(const char *filename);
00067 template<class n_option>
00068 inline bool compute_cell_sphere(voronoicell_base<n_option> &c,int i,int j,int k,int ijk,int s);
00069 template<class n_option>
00070 bool compute_cell_sphere(voronoicell_base<n_option> &c,int i,int j,int k,int ijk,int s,fpoint x,fpoint y,fpoint z);
00071 template<class n_option>
00072 inline bool compute_cell(voronoicell_base<n_option> &c,int i,int j,int k,int ijk,int s);
00073 template<class n_option>
00074 bool compute_cell(voronoicell_base<n_option> &c,int i,int j,int k,int ijk,int s,fpoint x,fpoint y,fpoint z);
00075 void put(int n,fpoint x,fpoint y,fpoint z);
00076 void put(int n,fpoint x,fpoint y,fpoint z,fpoint r);
00077 void add_wall(wall &w);
00078 bool point_inside(fpoint x,fpoint y,fpoint z);
00079 bool point_inside_walls(fpoint x,fpoint y,fpoint z);
00080 protected:
00081
00082 const fpoint ax;
00083
00084 const fpoint bx;
00085
00086 const fpoint ay;
00087
00088 const fpoint by;
00089
00090 const fpoint az;
00091
00092 const fpoint bz;
00093
00094
00095 const fpoint xsp;
00096
00097
00098 const fpoint ysp;
00099
00100
00101 const fpoint zsp;
00102
00103 const int nx;
00104
00105 const int ny;
00106
00107 const int nz;
00108
00109
00110
00111 const int nxy;
00112
00113
00114 const int nxyz;
00115
00116 const int hx;
00117
00118 const int hy;
00119
00120 const int hz;
00121
00122
00123
00124 const int hxy;
00125
00126
00127 const int hxyz;
00128
00129
00130 const bool xperiodic;
00131
00132
00133 const bool yperiodic;
00134
00135
00136 const bool zperiodic;
00137
00138
00139 int *co;
00140
00141
00142
00143
00144
00145 int *mem;
00146
00147
00148 int **id;
00149
00150 unsigned int *mask;
00151
00152
00153 int *sl;
00154
00155
00156 unsigned int mv;
00157
00158
00159 int s_start;
00160
00161
00162 int s_end;
00163
00164 int s_size;
00165
00166
00167
00168 fpoint **p;
00169
00170
00171 wall **walls;
00172
00173 int wall_number;
00174
00175 int current_wall_size;
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 r_option radius;
00186
00187
00188
00189
00190
00191
00192 int sz;
00193
00194
00195
00196 fpoint *mrad;
00197
00198 template<class n_option>
00199 inline void print_all(ostream &os,voronoicell_base<n_option> &c);
00200 template<class n_option>
00201 inline bool initialize_voronoicell(voronoicell_base<n_option> &c,fpoint x,fpoint y,fpoint z);
00202 void add_particle_memory(int i);
00203 void add_list_memory();
00204 private:
00205 #include "worklist.hh"
00206 template<class n_option>
00207 inline bool corner_test(voronoicell_base<n_option> &c,fpoint xl,fpoint yl,fpoint zl,fpoint xh,fpoint yh,fpoint zh);
00208 template<class n_option>
00209 inline bool edge_x_test(voronoicell_base<n_option> &c,fpoint x0,fpoint yl,fpoint zl,fpoint x1,fpoint yh,fpoint zh);
00210 template<class n_option>
00211 inline bool edge_y_test(voronoicell_base<n_option> &c,fpoint xl,fpoint y0,fpoint zl,fpoint xh,fpoint y1,fpoint zh);
00212 template<class n_option>
00213 inline bool edge_z_test(voronoicell_base<n_option> &c,fpoint xl,fpoint yl,fpoint z0,fpoint xh,fpoint yh,fpoint z1);
00214 template<class n_option>
00215 inline bool face_x_test(voronoicell_base<n_option> &c,fpoint xl,fpoint y0,fpoint z0,fpoint y1,fpoint z1);
00216 template<class n_option>
00217 inline bool face_y_test(voronoicell_base<n_option> &c,fpoint x0,fpoint yl,fpoint z0,fpoint x1,fpoint z1);
00218 template<class n_option>
00219 inline bool face_z_test(voronoicell_base<n_option> &c,fpoint x0,fpoint y0,fpoint zl,fpoint x1,fpoint y1);
00220 inline void initialize_radii();
00221 inline void compute_minimum(fpoint &minr,fpoint &xlo,fpoint &xhi,fpoint &ylo,fpoint &yhi,fpoint &zlo,fpoint &zhi,int ti,int tj,int tk);
00222 inline bool compute_min_max_radius(int di,int dj,int dk,fpoint fx,fpoint fy,fpoint fz,fpoint gx,fpoint gy,fpoint gz,fpoint& crs,fpoint mrs);
00223 friend class voropp_loop;
00224 friend class radius_poly;
00225 };
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 class radius_mono {
00236 public:
00237
00238
00239
00240 const int mem_size;
00241
00242
00243
00244 radius_mono(container_base<radius_mono> *icc) : mem_size(3), cc(icc) {};
00245 inline void import(istream &is);
00246
00247 inline void store_radius(int i,int j,fpoint r) {};
00248
00249 inline void clear_max() {};
00250
00251 inline void init(int s,int i) {};
00252 inline fpoint volume(int ijk,int s);
00253 inline fpoint cutoff(fpoint lrs);
00254 inline fpoint scale(fpoint rs,int t,int q);
00255
00256 inline void print(ostream &os,int ijk,int q) {};
00257 inline void rad(ostream &os,int l,int c);
00258 private:
00259 container_base<radius_mono> *cc;
00260 };
00261
00262
00263
00264
00265
00266
00267
00268
00269 class radius_poly {
00270 public:
00271
00272
00273
00274 const int mem_size;
00275
00276
00277
00278 radius_poly(container_base<radius_poly> *icc) :
00279 mem_size(4), cc(icc), max_radius(0) {};
00280 inline void import(istream &is);
00281 inline void store_radius(int i,int j,fpoint r);
00282 inline void clear_max();
00283 inline void init(int ijk,int s);
00284 inline fpoint volume(int ijk,int s);
00285 inline fpoint cutoff(fpoint lrs);
00286 inline fpoint scale(fpoint rs,int t,int q);
00287 inline void print(ostream &os,int ijk,int q);
00288 inline void rad(ostream &os,int l,int c);
00289 private:
00290 container_base<radius_poly> *cc;
00291 fpoint max_radius,crad,mul;
00292 };
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 class voropp_loop {
00305 public:
00306 template<class r_option>
00307 voropp_loop(container_base<r_option> *q);
00308 inline int init(fpoint vx,fpoint vy,fpoint vz,fpoint r,fpoint &px,fpoint &py,fpoint &pz);
00309 inline int init(fpoint xmin,fpoint xmax,fpoint ymin,fpoint ymax,fpoint zmin,fpoint zmax,fpoint &px,fpoint &py,fpoint &pz);
00310 inline int inc(fpoint &px,fpoint &py,fpoint &pz);
00311
00312
00313 int ip;
00314
00315
00316 int jp;
00317
00318
00319 int kp;
00320 private:
00321 int i,j,k,ai,bi,aj,bj,ak,bk,s;
00322 int aip,ajp,akp,inc1,inc2;
00323 inline int step_mod(int a,int b);
00324 inline int step_div(int a,int b);
00325 inline int step_int(fpoint a);
00326 fpoint apx,apy,apz;
00327 const fpoint sx,sy,sz,xsp,ysp,zsp,ax,ay,az;
00328 const int nx,ny,nz,nxy,nxyz;
00329 const bool xperiodic,yperiodic,zperiodic;
00330 };
00331
00332
00333
00334
00335
00336
00337 class wall {
00338 public:
00339 virtual ~wall() {};
00340
00341
00342 virtual bool point_inside(fpoint x,fpoint y,fpoint z) = 0;
00343
00344
00345 virtual bool cut_cell(voronoicell_base<neighbor_none> &c,fpoint x,fpoint y,fpoint z) = 0;
00346
00347
00348 virtual bool cut_cell(voronoicell_base<neighbor_track> &c,fpoint x,fpoint y,fpoint z) = 0;
00349 };
00350
00351
00352 typedef container_base<radius_mono> container;
00353
00354
00355 typedef container_base<radius_poly> container_poly;
00356 #endif