00001 /************************************************************************* 00002 * CompuCell - A software framework for multimodel simulations of * 00003 * biocomplexity problems Copyright (C) 2003 University of Notre Dame, * 00004 * Indiana * 00005 * * 00006 * This program is free software; IF YOU AGREE TO CITE USE OF CompuCell * 00007 * IN ALL RELATED RESEARCH PUBLICATIONS according to the terms of the * 00008 * CompuCell GNU General Public License RIDER you can redistribute it * 00009 * and/or modify it under the terms of the GNU General Public License as * 00010 * published by the Free Software Foundation; either version 2 of the * 00011 * License, or (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, but * 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program; if not, write to the Free Software * 00020 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00021 *************************************************************************/ 00022 00023 00024 #include <map> 00025 #include <vector> 00026 #include <CompuCell3D/Automaton/CellType.h> 00027 using namespace CompuCell3D; 00028 00029 #include <CompuCell3D/Simulator.h> 00030 #include <CompuCell3D/Potts3D/Potts3D.h> 00031 00032 //#include <XMLCereal/XMLPullParser.h> 00033 //#include <XMLCereal/XMLSerializer.h> 00034 00035 #include <BasicUtils/BasicString.h> 00036 #include <BasicUtils/BasicException.h> 00037 00038 #include <XMLUtils/CC3DXMLElement.h> 00039 00040 #include <iostream> 00041 using namespace std; 00042 00043 #define EXP_STL 00044 #include "CellTypePlugin.h" 00045 //#include "CellTypeParseData.h" 00046 00047 00048 00049 std::string CellTypePlugin::toString(){ 00050 return "CellType"; 00051 } 00052 00053 std::string CellTypePlugin::steerableName(){ 00054 return toString(); 00055 } 00056 00057 CellTypePlugin::CellTypePlugin() {classType = new CellType();} 00058 00059 CellTypePlugin::~CellTypePlugin() { 00060 if (classType){ 00061 delete classType; 00062 classType=0; 00063 } 00064 } 00065 00066 void CellTypePlugin::init(Simulator *simulator, CC3DXMLElement *_xmlData){ 00067 00068 potts = simulator->getPotts(); 00069 potts->registerCellGChangeWatcher(this); 00070 potts->registerAutomaton(this); 00071 update(_xmlData); 00072 simulator->registerSteerableObject((SteerableObject*)this); 00073 00074 } 00075 00076 void CellTypePlugin::update(CC3DXMLElement *_xmlData, bool _fullInitFlag){ 00077 00078 typeNameMap.clear(); 00079 nameTypeMap.clear(); 00080 vector<unsigned char> frozenTypeVec; 00081 CC3DXMLElementList cellTypeVec=_xmlData->getElements("CellType"); 00082 00083 for (int i = 0 ; i<cellTypeVec.size(); ++i){ 00084 typeNameMap[cellTypeVec[i]->getAttributeAsByte("TypeId")]=cellTypeVec[i]->getAttribute("TypeName"); 00085 nameTypeMap[cellTypeVec[i]->getAttribute("TypeName")]=cellTypeVec[i]->getAttributeAsByte("TypeId"); 00086 00087 if(cellTypeVec[i]->findAttribute("Freeze")) 00088 frozenTypeVec.push_back(cellTypeVec[i]->getAttributeAsByte("TypeId")); 00089 } 00090 00091 potts->setFrozenTypeVector(frozenTypeVec); 00092 00093 00094 } 00095 00096 void CellTypePlugin::init(Simulator *simulator, ParseData * _pd) { 00097 //cerr<<"CELL TYPE THIS IS _pd="<<_pd<<endl; 00098 // potts = simulator->getPotts(); 00099 // potts->registerCellGChangeWatcher(this); 00100 // potts->registerAutomaton(this); 00101 // update(_pd); 00102 // simulator->registerSteerableObject((SteerableObject*)this); 00103 00104 } 00105 00106 void CellTypePlugin::update(ParseData *_pd, bool _fullInitFlag){ 00107 00108 // if(_pd){ 00109 // typeNameMap.clear(); 00110 // nameTypeMap.clear(); 00111 // CellTypeParseData * cpdPtr=(CellTypeParseData *)_pd; 00112 // vector<unsigned char> frozenTypeVec; 00114 // for(int i = 0 ; i < cpdPtr->cellTypeTuppleVec.size() ; ++i){ 00115 // typeNameMap[cpdPtr->cellTypeTuppleVec[i].typeId]=cpdPtr->cellTypeTuppleVec[i].typeName; 00116 // nameTypeMap[cpdPtr->cellTypeTuppleVec[i].typeName]=cpdPtr->cellTypeTuppleVec[i].typeId; 00117 // if(cpdPtr->cellTypeTuppleVec[i].freeze){ 00118 // frozenTypeVec.push_back(cpdPtr->cellTypeTuppleVec[i].typeId); 00119 // } 00120 // } 00121 // potts->setFrozenTypeVector(frozenTypeVec); 00122 // } 00123 00124 } 00125 00126 00127 00128 unsigned char CellTypePlugin::getCellType(const CellG *cell) const { 00129 00130 if(!cell) return 0; 00131 00132 return cell->type; 00133 00134 } 00135 00136 00137 string CellTypePlugin::getTypeName(const char type) const { 00138 00139 00140 std::map<unsigned char,std::string>::const_iterator typeNameMapItr=typeNameMap.find((const unsigned char)type); 00141 00142 00143 if(typeNameMapItr!=typeNameMap.end()){ 00144 return typeNameMapItr->second; 00145 }else{ 00146 THROW(string("getTypeName: Unknown cell type ") + BasicString(type) + "!"); 00147 } 00148 00149 00150 } 00151 00152 unsigned char CellTypePlugin::getTypeId(const string typeName) const { 00153 00154 00155 std::map<std::string,unsigned char>::const_iterator nameTypeMapItr=nameTypeMap.find(typeName); 00156 00157 00158 if(nameTypeMapItr!=nameTypeMap.end()){ 00159 return nameTypeMapItr->second; 00160 }else{ 00161 THROW(string("getTypeName: Unknown cell type ") + typeName + "!"); 00162 } 00163 00164 } 00165 00166 00167 00168 //void CellTypePlugin::readXML(XMLPullParser &in) { 00169 // 00170 // pd=&cpd; 00171 // in.skip(TEXT); 00172 // 00173 // while (in.check(START_ELEMENT)) { 00174 // if (in.getName() == "CellType") { 00175 // CellTypeTupple cellTypeTupple; 00176 // cellTypeTupple.typeName = in.getAttribute("TypeName").value; 00177 // cellTypeTupple.typeId = BasicString::parseUByte(in.getAttribute("TypeId").value); 00178 // cerr<<"typeName="<<cellTypeTupple.typeName<<endl; 00179 // cerr<<"typeId="<<(short)cellTypeTupple.typeId<<endl; 00180 // 00181 // ///deciding whether to freeze or not 00182 // int attrNum=in.findAttribute("Freeze"); 00183 // if(attrNum != -1){ 00184 // cellTypeTupple.freeze=true; 00185 // } 00186 // in.matchSimple(); 00187 // cpd.cellTypeTuppleVec.push_back(cellTypeTupple); 00188 // } 00189 // else { 00190 // throw BasicException(string("Unexpected element '") + in.getName() + 00191 // "'!", in.getLocation()); 00192 // } 00193 // 00194 // in.skip(TEXT); 00195 // } 00196 // 00197 // 00198 //} 00199 // 00200 //void CellTypePlugin::writeXML(XMLSerializer &out) { 00201 //} 00202 //
1.5.6