00001 #include "AdjacentNeighbor.h"
00002 #include <algorithm>
00003 #include <iostream>
00004 #include <cmath>
00005
00006 using namespace CompuCell3D;
00007 using namespace std;
00008
00010 AdjacentNeighbor::AdjacentNeighbor(const Dim3D & _dim):
00011 periodicX(false),
00012 periodicY(false),
00013 periodicZ(false)
00014
00015
00016
00017
00018 {
00020 initialize(_dim);
00021 }
00023 void AdjacentNeighbor::initialize(const Dim3D & _dim){
00024
00025 depth=1;
00026 fieldDim=_dim;
00027 field3DIndex=Field3DIndex(_dim);
00028
00029 adjNeighborOffsetsInner.assign((2*depth+1)*(2*depth+1)*(2*depth+1)-1,Point3D(0,0,0));
00030
00031
00032 adjFace2FaceNeighborOffsetsInner.assign(6,Point3D(0,0,0) );
00033
00034
00035 adjNeighborOffsets.assign((2*depth+1)*(2*depth+1)*(2*depth+1)-1,0);
00036 adjFace2FaceNeighborOffsets.assign(6,0 );
00037
00038 long index;
00039 long counter=0;
00040 Point3D self(0,0,0);
00041 for(short x = -depth ; x<=depth ; ++x)
00042 for(short y = -depth ; y<=depth; ++y)
00043 for(short z = -depth ; z<=depth ; ++z){
00044 Point3D pt(x,y,z);
00045 index=field3DIndex.index(pt);
00046 if(! (self==pt) ){
00047 adjNeighborOffsetsInner[counter]=pt;
00048 adjNeighborOffsets[counter]=index;
00049 ++counter;
00050 }
00051
00052
00053
00054
00055
00056
00057
00058 }
00059
00061 counter=0;
00062 for(short x = -1 ; x<=1 ; ++x)
00063 for(short y = -1 ; y<=1; ++y)
00064 for(short z = -1 ; z<=1 ; ++z){
00065 Point3D pt(x,y,z);
00066
00067 index=field3DIndex.index(pt);
00068
00069 if(!(self==pt) && !(distance(x,y,z)>1.0)){
00070 adjFace2FaceNeighborOffsetsInner[counter]=pt;
00071 adjFace2FaceNeighborOffsets[counter]=index;
00072 ++counter;
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 }
00084
00085 adjNeighborOffsetsBoundary.assign( adjNeighborOffsetsInner.begin() , adjNeighborOffsetsInner.end() );
00086 adjFace2FaceNeighborOffsetsBoundary.assign( adjFace2FaceNeighborOffsetsInner.begin() , adjFace2FaceNeighborOffsetsInner.end() );
00087
00088
00089
00090
00091
00092 }
00093
00094
00096 double AdjacentNeighbor::distance(double x, double y, double z){
00097 return sqrt (x*x+y*y+z*z);
00098
00099 }
00101 void AdjacentNeighbor::setPeriodicX(){
00102 if(periodicX)
00103 return;
00104
00105 periodicX=true;
00106 short maxXPlus=fieldDim.x-1;
00107 short maxXMinus=-(fieldDim.x-1);
00108 Point3D self(0,0,0);
00109 for(short y = -1 ; y<=1; ++y)
00110 for(short z = -1 ; z<=1 ; ++z){
00111 Point3D ptPlus(maxXPlus,y,z);
00112 Point3D ptMinus(maxXMinus,y,z);
00113 if(!(ptPlus==self)){
00114 adjNeighborOffsetsBoundary.push_back(ptPlus);
00115 }
00116 if(!(ptMinus==self)){
00117 adjNeighborOffsetsBoundary.push_back(ptMinus);
00118 }
00119
00120 }
00121
00123 Point3D ptPlus(maxXPlus,0,0);
00124 Point3D ptMinus(maxXMinus,0,0);
00125 adjFace2FaceNeighborOffsetsBoundary.push_back(ptPlus);
00126 adjFace2FaceNeighborOffsetsBoundary.push_back(ptMinus);
00127
00128
00129
00130
00131 }
00133 void AdjacentNeighbor::setPeriodicY(){
00134
00135 if(periodicY)
00136 return;
00137
00138 periodicY=true;
00139 short maxYPlus=fieldDim.y-1;
00140 short maxYMinus=-(fieldDim.y-1);
00141 Point3D self(0,0,0);
00142 for(short x = -1 ; x<=1; ++x)
00143 for(short z = -1 ; z<=1 ; ++z){
00144 Point3D ptPlus(x,maxYPlus,z);
00145 Point3D ptMinus(x,maxYMinus,z);
00146 if(!(ptPlus==self)){
00147 adjNeighborOffsetsBoundary.push_back(ptPlus);
00148 }
00149 if(!(ptMinus==self)){
00150 adjNeighborOffsetsBoundary.push_back(ptMinus);
00151 }
00152
00153 }
00154
00155 Point3D ptPlus(0,maxYPlus,0);
00156 Point3D ptMinus(0,maxYMinus,0);
00157 adjFace2FaceNeighborOffsetsBoundary.push_back(ptPlus);
00158 adjFace2FaceNeighborOffsetsBoundary.push_back(ptMinus);
00159
00160
00161
00162
00163
00164 }
00166 void AdjacentNeighbor::setPeriodicZ(){
00167 if(periodicZ)
00168 return;
00169
00170 periodicZ=true;
00171
00172 short maxZPlus=fieldDim.z-1;
00173 short maxZMinus=-(fieldDim.z-1);
00174 Point3D self(0,0,0);
00175 for(short x = -1 ; x<=1; ++x)
00176 for(short y = -1 ; y<=1 ; ++y){
00177 Point3D ptPlus(x,y,maxZPlus);
00178 Point3D ptMinus(x,y,maxZMinus);
00179 if(!(ptPlus==self)){
00180 adjNeighborOffsetsBoundary.push_back(ptPlus);
00181 }
00182 if(!(ptMinus==self)){
00183 adjNeighborOffsetsBoundary.push_back(ptMinus);
00184 }
00185
00186 }
00187 cerr<<"adjNeighborOffsetsBoundary.size()="<<adjNeighborOffsetsBoundary.size()<<endl;
00188 Point3D ptPlus(0,0,maxZPlus);
00189 Point3D ptMinus(0,0,maxZMinus);
00190 adjFace2FaceNeighborOffsetsBoundary.push_back(ptPlus);
00191 adjFace2FaceNeighborOffsetsBoundary.push_back(ptMinus);
00192
00193
00194
00195
00196
00197 }
00199 AdjacentNeighbor::~AdjacentNeighbor()
00200 {
00201 }
00202
00203