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 #include <CompuCell3D/Potts3D/CellInventory.h>
00026 #include <CompuCell3D/Automaton/Automaton.h>
00027
00028 #include <CompuCell3D/Simulator.h>
00029 #include <CompuCell3D/Potts3D/Cell.h>
00030 #include <CompuCell3D/Potts3D/Potts3D.h>
00031 #include <CompuCell3D/Field3D/Point3D.h>
00032 #include <CompuCell3D/Field3D/Dim3D.h>
00033 #include <CompuCell3D/Field3D/Field3D.h>
00034 #include <CompuCell3D/Field3D/WatchableField3D.h>
00035 using namespace CompuCell3D;
00036
00037
00038 #include <BasicUtils/BasicString.h>
00039 #include <BasicUtils/BasicException.h>
00040 #include <BasicUtils/BasicRandomNumberGenerator.h>
00041
00042 #include <string>
00043 using namespace std;
00044
00045 #define EXP_STL
00046 #include "DictyFieldInitializer.h"
00047
00048 DictyFieldInitializer::DictyFieldInitializer() :
00049 potts(0), gotAmoebaeFieldBorder(false),presporeRatio(0.5), gap(1),width(2),amoebaeFieldBorder(10)
00050 {}
00051
00052
00053 void DictyFieldInitializer::update(CC3DXMLElement *_xmlData, bool _fullInitFlag){
00054
00055 if(_xmlData->findElement("Gap"))
00056 gap=_xmlData->getFirstElement("Gap")->getUInt();
00057
00058 if(_xmlData->findElement("Width"))
00059 width=_xmlData->getFirstElement("Width")->getUInt();
00060
00061 if(_xmlData->findElement("AmoebaeFieldBorder"))
00062 amoebaeFieldBorder=_xmlData->getFirstElement("AmoebaeFieldBorder")->getUInt();
00063
00064 if(_xmlData->findElement("ZonePoint")){
00065 zonePoint.x=_xmlData->getFirstElement("ZonePoint")->getAttributeAsUInt("x");
00066 zonePoint.y=_xmlData->getFirstElement("ZonePoint")->getAttributeAsUInt("y");
00067 zonePoint.z=_xmlData->getFirstElement("ZonePoint")->getAttributeAsUInt("z");
00068 zoneWidth=_xmlData->getFirstElement("ZonePoint")->getUInt();
00069 }
00070
00071 if(_xmlData->findElement("PresporeRatio")){
00072 presporeRatio=_xmlData->getFirstElement("PresporeRatio")->getDouble();
00073 ASSERT_OR_THROW("Ratio must belong to [0,1]!",0<=presporeRatio && presporeRatio<=1.0);
00074 }
00075
00076
00077
00078 }
00079
00080 void DictyFieldInitializer::init(Simulator *simulator, CC3DXMLElement *_xmlData) {
00081
00082 update(_xmlData,true);
00083
00084 potts = simulator->getPotts();
00085 automaton=potts->getAutomaton();
00086 cellField = (WatchableField3D<CellG*> *)potts->getCellFieldG();
00087 ASSERT_OR_THROW("initField() Cell field cannot be null!", cellField);
00088 ASSERT_OR_THROW("Could not find Center of Mass plugin",Simulator::pluginManager.get("CenterOfMass"));
00089
00090 dim = cellField->getDim();
00091
00092 if(!gotAmoebaeFieldBorder){
00093 amoebaeFieldBorder=dim.x;
00094 }
00095
00096
00097 }
00098
00099 void DictyFieldInitializer::start() {
00100
00101
00102
00103
00104 int size = gap + width;
00105
00106
00107
00108
00109
00110
00111
00112
00113 Dim3D itDim;
00114
00115 itDim.x = dim.x / size;
00116 if (dim.x % size) itDim.x += 1;
00117 itDim.y = dim.y / size;
00118 if (dim.y % size) itDim.y += 1;
00119 itDim.z = dim.z / size;
00120 if (dim.z % size) itDim.z += 1;
00121
00122 Point3D pt;
00123 Point3D cellPt;
00124 CellG *cell;
00125
00128 pt.x = 0;
00129 pt.y = 0;
00130 pt.z = 0;
00131
00132 cell = potts->createCellG(pt);
00133 groundCell=cell;
00134 for (cellPt.z = pt.z; cellPt.z <= pt.z + 1*(width+gap)-1 && cellPt.z < dim.z; cellPt.z++)
00135 for (cellPt.y = pt.y; cellPt.y < pt.y + dim.y && cellPt.y < dim.y; cellPt.y++)
00136 for (cellPt.x = pt.x; cellPt.x < pt.x + dim.y && cellPt.x < dim.x; cellPt.x++)
00137 cellField->set(cellPt, cell);
00138
00139
00141 cell = potts->createCellG(pt);
00142 wallCell=cell;
00143 for (cellPt.z = pt.z; cellPt.z < dim.z; cellPt.z++)
00144 for (cellPt.y = pt.y; cellPt.y < dim.y; cellPt.y++)
00145 for (cellPt.x = pt.x; cellPt.x < dim.x; cellPt.x++){
00146
00147 if(
00148 (int)fabs(1.0*cellPt.z-dim.z) % dim.z <=1.0 ||
00149 (int)fabs(1.0*cellPt.y-dim.y) % dim.y <=1.0 ||
00150 (int)fabs(1.0*cellPt.x-dim.x) % dim.x<=1.0
00151 ){
00152
00153 cellField->set(cellPt, cell);
00154 }
00155
00156
00157
00158 }
00159
00160
00161
00163 for (int z = 1; z < 2; z++)
00164 for (int y = 1; y < itDim.y-1; y++)
00165 for (int x = 1; x < itDim.x-1; x++) {
00166
00167 pt.x = x * size;
00168 pt.y = y * size;
00169 pt.z = z * size;
00170
00171
00172
00173 if(pt.x<amoebaeFieldBorder && pt.y<amoebaeFieldBorder ){
00174 cell = potts->createCellG(pt);
00175
00176
00177 for (cellPt.z = pt.z; cellPt.z < pt.z + width && cellPt.z < dim.z; cellPt.z++)
00178 for (cellPt.y = pt.y; cellPt.y < pt.y + width && cellPt.y < dim.y; cellPt.y++)
00179 for (cellPt.x = pt.x; cellPt.x < pt.x + width && cellPt.x < dim.x; cellPt.x++)
00180 cellField->set(cellPt, cell);
00181 }
00182 }
00183
00184
00185
00186 initializeCellTypes();
00187
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220 }
00221
00222
00223 void DictyFieldInitializer::initializeCellTypes(){
00224
00225 BasicRandomNumberGenerator *rand = BasicRandomNumberGenerator::getInstance();
00226 cellInventoryPtr=& potts->getCellInventory();
00227
00229 CellInventory::cellInventoryIterator cInvItr;
00231 Point3D com;
00232 CellG * cell;
00233
00234
00235 float x,y,z;
00236
00237 for(cInvItr=cellInventoryPtr->cellInventoryBegin() ; cInvItr !=cellInventoryPtr->cellInventoryEnd() ;++cInvItr ){
00238
00239 cell=*cInvItr;
00240 if(cell==groundCell)
00241 cell->type=automaton->getTypeId("Ground");
00242 else if(cell==wallCell){
00243 cell->type=automaton->getTypeId("Wall");
00244 }
00245 else{
00246
00247 com.x=cell->xCM/ cell->volume ;
00248 com.y=cell->yCM/ cell->volume;
00249 com.z=cell->zCM/ cell->volume;
00250
00251 cerr<<"belongToZone(com)="<<belongToZone(com)<<" com="<<com<<endl;
00252 if(belongToZone(com)){
00253 cell->type=automaton->getTypeId("Autocycling");
00254 cerr<<"setting autocycling type="<<(int)cell->type<<endl;
00255 }else{
00256 if(rand->getRatio()<presporeRatio){
00257 cell->type=automaton->getTypeId("Prespore");
00258 }else{
00259 cell->type=automaton->getTypeId("Prestalk");
00260 }
00261
00262 }
00263
00264
00265 }
00266
00267
00268 }
00269 }
00270
00272
00273 bool DictyFieldInitializer::belongToZone(Point3D com){
00274
00275 if(
00276 com.x>zonePoint.x && com.x< (zonePoint.x+zoneWidth) &&
00277 com.y>zonePoint.y && com.y< (zonePoint.y+zoneWidth) &&
00278 com.z>zonePoint.z && com.z< (zonePoint.z+zoneWidth)
00279 )
00280 return true;
00281 else
00282 return false;
00283
00284 }
00285
00286
00287
00288 std::string DictyFieldInitializer::toString(){
00289 return "DictyInitializer";
00290 }
00291
00292 std::string DictyFieldInitializer::steerableName(){
00293 return toString();
00294 }
00295