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