00001 /* 00002 00003 Copyright (C) University of Oxford, 2005-2009 00004 00005 University of Oxford means the Chancellor, Masters and Scholars of the 00006 University of Oxford, having an administrative office at Wellington 00007 Square, Oxford OX1 2JD, UK. 00008 00009 This file is part of Chaste. 00010 00011 Chaste is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU Lesser General Public License as published 00013 by the Free Software Foundation, either version 2.1 of the License, or 00014 (at your option) any later version. 00015 00016 Chaste is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00019 License for more details. The offer of Chaste under the terms of the 00020 License is subject to the License being interpreted in accordance with 00021 English Law and subject to any action against the University of Oxford 00022 being under the jurisdiction of the English Courts. 00023 00024 You should have received a copy of the GNU Lesser General Public License 00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>. 00026 00027 */ 00028 #include "TissueCell.hpp" 00029 00030 00031 TissueCell::TissueCell(CellType cellType, 00032 CellMutationState mutationState, 00033 AbstractCellCycleModel* pCellCycleModel, 00034 bool archiving) 00035 : mpCellCycleModel(pCellCycleModel) 00036 { 00037 if (SimulationTime::Instance()->IsStartTimeSetUp()==false) 00038 { 00039 EXCEPTION("TissueCell is setting up a cell cycle model but SimulationTime has not been set up"); 00040 } 00041 00042 if (pCellCycleModel==NULL) 00043 { 00044 EXCEPTION("Cell cycle model is null"); 00045 } 00046 00047 mCellType = cellType; 00048 mMutationState = mutationState; 00049 mCanDivide = false; 00050 mUndergoingApoptosis = false; 00051 mIsDead = false; 00052 mDeathTime = DBL_MAX; // This has to be initialised for archiving... 00053 mIsLogged = false; 00054 mAncestor = UNSIGNED_UNSET; // Has to be set by a SetAncestor() call (usually from Tissue) 00055 00056 mpCellCycleModel->SetCell(this); 00057 } 00058 00059 00060 void TissueCell::CommonCopy(const TissueCell &otherCell) 00061 { 00062 // Copy private data members 00063 mCanDivide = otherCell.mCanDivide; 00064 00065 // Copy 'easy' protected data members 00066 mCellType = otherCell.mCellType; 00067 mMutationState = otherCell.mMutationState; 00068 mUndergoingApoptosis = otherCell.mUndergoingApoptosis; 00069 mIsDead = otherCell.mIsDead; 00070 mDeathTime = otherCell.mDeathTime; 00071 mIsLogged = otherCell.mIsLogged; 00072 mAncestor = otherCell.mAncestor; 00073 00074 // Copy cell cycle model 00075 // First create a new object 00076 mpCellCycleModel = otherCell.mpCellCycleModel->CreateCellCycleModel(); 00077 // Then copy its state. 00078 // BEWARE: This will only copy base class state!!! 00079 *mpCellCycleModel = *(otherCell.mpCellCycleModel); 00080 // and inform it of the new cell object 00081 mpCellCycleModel->SetCell(this); 00082 } 00083 00084 00085 TissueCell::TissueCell(const TissueCell &otherCell) 00086 { 00087 CommonCopy(otherCell); 00088 } 00089 00090 00091 TissueCell& TissueCell::operator=(const TissueCell &otherCell) 00092 { 00093 // In case this is self-assignment, don't delete the cell cycle model 00094 AbstractCellCycleModel* temp = mpCellCycleModel; 00095 CommonCopy(otherCell); 00096 // ...until after we've copied it. 00097 delete temp; 00098 return *this; 00099 } 00100 00101 00102 TissueCell::~TissueCell() 00103 { 00104 delete mpCellCycleModel; 00105 } 00106 00107 00108 void TissueCell::SetCellCycleModel(AbstractCellCycleModel* pCellCycleModel) 00109 { 00110 if (mpCellCycleModel != pCellCycleModel) 00111 { 00112 delete mpCellCycleModel; 00113 } 00114 mpCellCycleModel = pCellCycleModel; 00115 mpCellCycleModel->SetCell(this); 00116 } 00117 00118 00119 AbstractCellCycleModel* TissueCell::GetCellCycleModel() const 00120 { 00121 return mpCellCycleModel; 00122 } 00123 00124 00125 void TissueCell::InitialiseCellCycleModel() 00126 { 00127 mpCellCycleModel->Initialise(); 00128 } 00129 00130 double TissueCell::GetAge() const 00131 { 00132 return mpCellCycleModel->GetAge(); 00133 } 00134 00135 00136 double TissueCell::GetBirthTime() const 00137 { 00138 return mpCellCycleModel->GetBirthTime(); 00139 } 00140 00141 00142 void TissueCell::SetBirthTime(double birthTime) 00143 { 00144 mpCellCycleModel->SetBirthTime(birthTime); 00145 } 00146 00147 00148 void TissueCell::SetCellType(CellType cellType) 00149 { 00150 mCellType = cellType; 00151 } 00152 00153 00154 CellType TissueCell::GetCellType() const 00155 { 00156 return mCellType; 00157 } 00158 00159 00160 void TissueCell::SetMutationState(CellMutationState mutationState) 00161 { 00162 mMutationState = mutationState; 00163 } 00164 00165 00166 CellMutationState TissueCell::GetMutationState() const 00167 { 00168 return mMutationState; 00169 } 00170 00171 00172 void TissueCell::SetLogged() 00173 { 00174 mIsLogged = true; 00175 } 00176 00177 00178 bool TissueCell::IsLogged() 00179 { 00180 return mIsLogged; 00181 } 00182 00183 00184 void TissueCell::StartApoptosis() 00185 { 00186 assert(!IsDead()); 00187 00188 if (mUndergoingApoptosis) 00189 { 00190 EXCEPTION("StartApoptosis() called when already undergoing apoptosis"); 00191 } 00192 mUndergoingApoptosis = true; 00193 00194 mDeathTime = SimulationTime::Instance()->GetTime() 00195 + CancerParameters::Instance()->GetApoptosisTime(); 00196 } 00197 00198 00199 bool TissueCell::HasApoptosisBegun() const 00200 { 00201 return mUndergoingApoptosis; 00202 } 00203 00204 00205 double TissueCell::TimeUntilDeath() const 00206 { 00207 if (!mUndergoingApoptosis) 00208 { 00209 EXCEPTION("Shouldn't be checking time until apoptosis as it isn't undergoing apoptosis"); 00210 } 00211 00212 return mDeathTime - SimulationTime::Instance()->GetTime(); 00213 } 00214 00215 00216 bool TissueCell::IsDead() const 00217 { 00218 return ( mIsDead || ( (mUndergoingApoptosis) && (SimulationTime::Instance()->GetTime() >= mDeathTime)) ); 00219 } 00220 00221 00222 void TissueCell::Kill() 00223 { 00224 mIsDead = true; 00225 } 00226 00227 00228 void TissueCell::SetAncestor(unsigned ancestorIndex) 00229 { 00230 mAncestor = ancestorIndex; 00231 } 00232 00233 00234 unsigned TissueCell::GetAncestor() const 00235 { 00236 return mAncestor; 00237 } 00238 00239 00240 bool TissueCell::ReadyToDivide() 00241 { 00242 assert(!IsDead()); 00243 if (mUndergoingApoptosis || mCellType==APOPTOTIC) 00244 { 00245 return false; 00246 } 00247 00248 mCanDivide = mpCellCycleModel->ReadyToDivide(); 00249 00250 return mCanDivide; 00251 } 00252 00253 00254 TissueCell TissueCell::Divide() 00255 { 00256 // Check we're allowed to divide 00257 assert(!IsDead()); 00258 assert(mCanDivide); 00259 mCanDivide = false; 00260 00261 // Reset properties of parent cell 00262 mpCellCycleModel->ResetForDivision(); 00263 00264 // Create daughter cell 00265 TissueCell new_cell = TissueCell(mCellType, mMutationState, 00266 mpCellCycleModel->CreateDaughterCellCycleModel()); 00267 00268 // Initialise properties of daughter cell 00269 new_cell.GetCellCycleModel()->InitialiseDaughterCell(); 00270 new_cell.SetAncestor(GetAncestor()); 00271 00272 return new_cell; 00273 }