00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <cmath>
00036
00037 #ifndef ESBTL_FCC_LATTICE_H
00038 #define ESBTL_FCC_LATTICE_H
00039
00040 namespace ESBTL {
00042 namespace internal_fcc_lattice{
00043 template <class Point_3,class FT,class Output_iterator>
00044 void even_layer(const FT& center_x,const FT& center_y,const FT& layer_z,const FT& unit_move,unsigned size,Output_iterator out){
00045 const FT x_s=center_x - (size-1)*unit_move;
00046 const FT y_s=center_y - (size-1)*unit_move;
00047
00048 for (unsigned i=0;i<size;++i)
00049 for (unsigned j=0;j<size;++j)
00050 *out++=Point_3(x_s+2*i*unit_move,y_s+2*j*unit_move,layer_z);
00051
00052 for (unsigned i=0;i<size-1;++i)
00053 for (unsigned j=0;j<size-1;++j)
00054 *out++=Point_3(x_s+unit_move+2*i*unit_move,y_s+unit_move+2*j*unit_move,layer_z);
00055 }
00056
00057
00058 template <class Point_3,class FT,class Output_iterator>
00059 void odd_layer(const FT& center_x,const FT& center_y,const FT& layer_z,const FT& unit_move,unsigned size,Output_iterator out){
00060 const FT x_s=center_x - (size-1)*unit_move;
00061 const FT y_s=center_y - (size-1)*unit_move;
00062
00063 for (unsigned i=0;i<size;++i)
00064 for (unsigned j=0;j<size-1;++j)
00065 *out++=Point_3(x_s+2*i*unit_move,y_s+unit_move+2*j*unit_move,layer_z);
00066
00067 for (unsigned i=0;i<size-1;++i)
00068 for (unsigned j=0;j<size;++j)
00069 *out++=Point_3(x_s+unit_move+2*i*unit_move,y_s+2*j*unit_move,layer_z);
00070 }
00071
00072 }
00084 template<class Point_3,class Output_iterator>
00085 void fcc_lattice(const Point_3& center, double radius, double min_edge_length,Output_iterator out){
00086 double unit_move=sqrt(2*radius);
00087 unsigned size = static_cast<unsigned>( ceil( min_edge_length/2./unit_move ) )+1;
00088
00089 double z_s=center.z() - (size-1)*unit_move;
00090 for (unsigned i=0;i<size;++i)
00091 internal_fcc_lattice::even_layer<Point_3>(center.x(),center.y(),z_s+2*i*unit_move,unit_move,size,out);
00092 for (unsigned i=0;i<size-1;++i)
00093 internal_fcc_lattice::odd_layer<Point_3>(center.x(),center.y(),z_s+2*i*unit_move+unit_move,unit_move,size,out);
00094 }
00095
00105 template<class Point_3,class Output_iterator>
00106 inline
00107 void fcc_lattice(const std::pair<Point_3,double>& cube, double radius, double expand_value,Output_iterator out){
00108 double edge=cube.second;
00109 Point_3 center(cube.first.x()+edge/2.,cube.first.y()+edge/2.,cube.first.z()+edge/2.);
00110 return fcc_lattice(center,radius,edge+expand_value,out);
00111 }
00112
00113
00114 }
00115
00116 #endif //ESBTL_FCC_LATTICE_H