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 unsigned int mv;
00139
00140 int wall_number;
00141
00142 int current_wall_size;
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 r_option radius;
00153
00154
00155
00156
00157
00158
00159 int sz;
00160
00161
00162 int s_start;
00163
00164
00165 int s_end;
00166
00167 int s_size;
00168
00169
00170 int *co;
00171
00172
00173
00174
00175
00176 int *mem;
00177
00178
00179 unsigned int *mask;
00180
00181
00182 int *sl;
00183
00184
00185
00186 fpoint *mrad;
00187
00188
00189 wall **walls;
00190
00191
00192 int **id;
00193
00194
00195
00196 fpoint **p;
00197
00198 template<class n_option>
00199 inline void print_all_internal(voronoicell_base<n_option> &c,ostream &os);
00200 template<class n_option>
00201 void print_all_custom_internal(voronoicell_base<n_option> &c,const char *format,ostream &os);
00202 template<class n_option>
00203 inline bool initialize_voronoicell(voronoicell_base<n_option> &c,fpoint x,fpoint y,fpoint z);
00204 void add_particle_memory(int i);
00205 void add_list_memory();
00206 private:
00207 #include "worklist.hh"
00208 template<class n_option>
00209 inline bool corner_test(voronoicell_base<n_option> &c,fpoint xl,fpoint yl,fpoint zl,fpoint xh,fpoint yh,fpoint zh);
00210 template<class n_option>
00211 inline bool edge_x_test(voronoicell_base<n_option> &c,fpoint x0,fpoint yl,fpoint zl,fpoint x1,fpoint yh,fpoint zh);
00212 template<class n_option>
00213 inline bool edge_y_test(voronoicell_base<n_option> &c,fpoint xl,fpoint y0,fpoint zl,fpoint xh,fpoint y1,fpoint zh);
00214 template<class n_option>
00215 inline bool edge_z_test(voronoicell_base<n_option> &c,fpoint xl,fpoint yl,fpoint z0,fpoint xh,fpoint yh,fpoint z1);
00216 template<class n_option>
00217 inline bool face_x_test(voronoicell_base<n_option> &c,fpoint xl,fpoint y0,fpoint z0,fpoint y1,fpoint z1);
00218 template<class n_option>
00219 inline bool face_y_test(voronoicell_base<n_option> &c,fpoint x0,fpoint yl,fpoint z0,fpoint x1,fpoint z1);
00220 template<class n_option>
00221 inline bool face_z_test(voronoicell_base<n_option> &c,fpoint x0,fpoint y0,fpoint zl,fpoint x1,fpoint y1);
00222 inline void initialize_radii();
00223 inline void compute_minimum(fpoint &minr,fpoint &xlo,fpoint &xhi,fpoint &ylo,fpoint &yhi,fpoint &zlo,fpoint &zhi,int ti,int tj,int tk);
00224 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);
00225 friend class voropp_loop;
00226 friend class radius_poly;
00227 };
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 class radius_mono {
00238 public:
00239
00240
00241
00242 const int mem_size;
00243
00244
00245
00246
00247 radius_mono(container_base<radius_mono> *icc) : mem_size(3), cc(icc) {};
00248 inline void import(istream &is);
00249
00250 inline void store_radius(int i,int j,fpoint r) {};
00251
00252 inline void clear_max() {};
00253
00254 inline void init(int s,int i) {};
00255 inline fpoint volume(int ijk,int s);
00256 inline fpoint cutoff(fpoint lrs);
00257 inline fpoint scale(fpoint rs,int t,int q);
00258
00259 inline void print(ostream &os,int ijk,int q,bool later=true) {};
00260 inline void rad(ostream &os,int l,int c);
00261 private:
00262 container_base<radius_mono> *cc;
00263 };
00264
00265
00266
00267
00268
00269
00270
00271
00272 class radius_poly {
00273 public:
00274
00275
00276
00277 const int mem_size;
00278
00279
00280
00281 radius_poly(container_base<radius_poly> *icc) :
00282 mem_size(4), cc(icc), max_radius(0) {};
00283 inline void import(istream &is);
00284 inline void store_radius(int i,int j,fpoint r);
00285 inline void clear_max();
00286 inline void init(int ijk,int s);
00287 inline fpoint volume(int ijk,int s);
00288 inline fpoint cutoff(fpoint lrs);
00289 inline fpoint scale(fpoint rs,int t,int q);
00290 inline void print(ostream &os,int ijk,int q,bool later=true);
00291 inline void rad(ostream &os,int l,int c);
00292 private:
00293 container_base<radius_poly> *cc;
00294 fpoint max_radius,crad,mul;
00295 };
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307 class voropp_loop {
00308 public:
00309 template<class r_option>
00310 voropp_loop(container_base<r_option> *q);
00311 inline int init(fpoint vx,fpoint vy,fpoint vz,fpoint r,fpoint &px,fpoint &py,fpoint &pz);
00312 inline int init(fpoint xmin,fpoint xmax,fpoint ymin,fpoint ymax,fpoint zmin,fpoint zmax,fpoint &px,fpoint &py,fpoint &pz);
00313 inline int inc(fpoint &px,fpoint &py,fpoint &pz);
00314
00315
00316 int ip;
00317
00318
00319 int jp;
00320
00321
00322 int kp;
00323 private:
00324 int i,j,k,ai,bi,aj,bj,ak,bk,s;
00325 int aip,ajp,akp,inc1,inc2;
00326 inline int step_mod(int a,int b);
00327 inline int step_div(int a,int b);
00328 inline int step_int(fpoint a);
00329 fpoint apx,apy,apz;
00330 const fpoint sx,sy,sz,xsp,ysp,zsp,ax,ay,az;
00331 const int nx,ny,nz,nxy,nxyz;
00332 const bool xperiodic,yperiodic,zperiodic;
00333 };
00334
00335
00336
00337
00338
00339
00340 class wall {
00341 public:
00342 virtual ~wall() {};
00343
00344
00345 virtual bool point_inside(fpoint x,fpoint y,fpoint z) = 0;
00346
00347
00348 virtual bool cut_cell(voronoicell_base<neighbor_none> &c,fpoint x,fpoint y,fpoint z) = 0;
00349
00350
00351 virtual bool cut_cell(voronoicell_base<neighbor_track> &c,fpoint x,fpoint y,fpoint z) = 0;
00352 };
00353
00354
00355 typedef container_base<radius_mono> container;
00356
00357
00358 typedef container_base<radius_poly> container_poly;
00359 #endif