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 <cstdlib>
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 print_all(ostream &os);
00058 void print_all();
00059 void print_all(const char *filename);
00060 void print_all_neighbor(ostream &os);
00061 void print_all_neighbor();
00062 void print_all_neighbor(const char *filename);
00063 void print_all_custom(const char *format,ostream &os);
00064 void print_all_custom(const char *format);
00065 void print_all_custom(const char *format,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_internal(voronoicell_base<n_option> &c,ostream &os);
00199 template<class n_option>
00200 void print_all_custom_internal(voronoicell_base<n_option> &c,const char *format,ostream &os);
00201 template<class n_option>
00202 inline bool initialize_voronoicell(voronoicell_base<n_option> &c,fpoint x,fpoint y,fpoint z);
00203 void add_particle_memory(int i);
00204 void add_list_memory();
00205 private:
00206 #include "worklist.hh"
00207 template<class n_option>
00208 inline bool corner_test(voronoicell_base<n_option> &c,fpoint xl,fpoint yl,fpoint zl,fpoint xh,fpoint yh,fpoint zh);
00209 template<class n_option>
00210 inline bool edge_x_test(voronoicell_base<n_option> &c,fpoint x0,fpoint yl,fpoint zl,fpoint x1,fpoint yh,fpoint zh);
00211 template<class n_option>
00212 inline bool edge_y_test(voronoicell_base<n_option> &c,fpoint xl,fpoint y0,fpoint zl,fpoint xh,fpoint y1,fpoint zh);
00213 template<class n_option>
00214 inline bool edge_z_test(voronoicell_base<n_option> &c,fpoint xl,fpoint yl,fpoint z0,fpoint xh,fpoint yh,fpoint z1);
00215 template<class n_option>
00216 inline bool face_x_test(voronoicell_base<n_option> &c,fpoint xl,fpoint y0,fpoint z0,fpoint y1,fpoint z1);
00217 template<class n_option>
00218 inline bool face_y_test(voronoicell_base<n_option> &c,fpoint x0,fpoint yl,fpoint z0,fpoint x1,fpoint z1);
00219 template<class n_option>
00220 inline bool face_z_test(voronoicell_base<n_option> &c,fpoint x0,fpoint y0,fpoint zl,fpoint x1,fpoint y1);
00221 inline void initialize_radii();
00222 inline void compute_minimum(fpoint &minr,fpoint &xlo,fpoint &xhi,fpoint &ylo,fpoint &yhi,fpoint &zlo,fpoint &zhi,int ti,int tj,int tk);
00223 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);
00224 friend class voropp_loop;
00225 friend class radius_poly;
00226 };
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236 class radius_mono {
00237 public:
00238
00239
00240
00241 const int mem_size;
00242
00243
00244
00245 radius_mono(container_base<radius_mono> *icc) : mem_size(3), cc(icc) {};
00246 inline void import(istream &is);
00247
00248 inline void store_radius(int i,int j,fpoint r) {};
00249
00250 inline void clear_max() {};
00251
00252 inline void init(int s,int i) {};
00253 inline fpoint volume(int ijk,int s);
00254 inline fpoint cutoff(fpoint lrs);
00255 inline fpoint scale(fpoint rs,int t,int q);
00256
00257 inline void print(ostream &os,int ijk,int q,bool later=true) {};
00258 inline void rad(ostream &os,int l,int c);
00259 private:
00260 container_base<radius_mono> *cc;
00261 };
00262
00263
00264
00265
00266
00267
00268
00269
00270 class radius_poly {
00271 public:
00272
00273
00274
00275 const int mem_size;
00276
00277
00278
00279 radius_poly(container_base<radius_poly> *icc) :
00280 mem_size(4), cc(icc), max_radius(0) {};
00281 inline void import(istream &is);
00282 inline void store_radius(int i,int j,fpoint r);
00283 inline void clear_max();
00284 inline void init(int ijk,int s);
00285 inline fpoint volume(int ijk,int s);
00286 inline fpoint cutoff(fpoint lrs);
00287 inline fpoint scale(fpoint rs,int t,int q);
00288 inline void print(ostream &os,int ijk,int q,bool later=true);
00289 inline void rad(ostream &os,int l,int c);
00290 private:
00291 container_base<radius_poly> *cc;
00292 fpoint max_radius,crad,mul;
00293 };
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305 class voropp_loop {
00306 public:
00307 template<class r_option>
00308 voropp_loop(container_base<r_option> *q);
00309 inline int init(fpoint vx,fpoint vy,fpoint vz,fpoint r,fpoint &px,fpoint &py,fpoint &pz);
00310 inline int init(fpoint xmin,fpoint xmax,fpoint ymin,fpoint ymax,fpoint zmin,fpoint zmax,fpoint &px,fpoint &py,fpoint &pz);
00311 inline int inc(fpoint &px,fpoint &py,fpoint &pz);
00312
00313
00314 int ip;
00315
00316
00317 int jp;
00318
00319
00320 int kp;
00321 private:
00322 int i,j,k,ai,bi,aj,bj,ak,bk,s;
00323 int aip,ajp,akp,inc1,inc2;
00324 inline int step_mod(int a,int b);
00325 inline int step_div(int a,int b);
00326 inline int step_int(fpoint a);
00327 fpoint apx,apy,apz;
00328 const fpoint sx,sy,sz,xsp,ysp,zsp,ax,ay,az;
00329 const int nx,ny,nz,nxy,nxyz;
00330 const bool xperiodic,yperiodic,zperiodic;
00331 };
00332
00333
00334
00335
00336
00337
00338 class wall {
00339 public:
00340 virtual ~wall() {};
00341
00342
00343 virtual bool point_inside(fpoint x,fpoint y,fpoint z) = 0;
00344
00345
00346 virtual bool cut_cell(voronoicell_base<neighbor_none> &c,fpoint x,fpoint y,fpoint z) = 0;
00347
00348
00349 virtual bool cut_cell(voronoicell_base<neighbor_track> &c,fpoint x,fpoint y,fpoint z) = 0;
00350 };
00351
00352
00353 typedef container_base<radius_mono> container;
00354
00355
00356 typedef container_base<radius_poly> container_poly;
00357 #endif