TissueCell.cpp

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 unsigned TissueCell::mMaxCellId = 0;
00031 
00032 
00033 TissueCell::TissueCell(CellType cellType,
00034                        CellMutationState mutationState,
00035                        AbstractCellCycleModel* pCellCycleModel,
00036                        bool archiving)
00037     : mCanDivide(false),
00038       mCellType(cellType),
00039       mMutationState(mutationState),
00040       mpCellCycleModel(pCellCycleModel),
00041       mAncestor(UNSIGNED_UNSET), // Has to be set by a SetAncestor() call (usually from Tissue)
00042       mDeathTime(DBL_MAX), // This has to be initialised for archiving,
00043       mStartOfApoptosisTime(DBL_MAX),
00044       mUndergoingApoptosis(false),
00045       mIsDead(false),
00046       mIsLogged(false)
00047 {
00048     if (SimulationTime::Instance()->IsStartTimeSetUp()==false)
00049     {
00050         EXCEPTION("TissueCell is setting up a cell cycle model but SimulationTime has not been set up");
00051     }
00052 
00053     if (pCellCycleModel==NULL)
00054     {
00055         EXCEPTION("Cell cycle model is null");
00056     }
00057 
00058     mpCellCycleModel->SetCell(this);
00059 
00060     // Set Cell identifier
00061     mCellId = ++ mMaxCellId -1;
00062 }
00063 
00064 
00065 void TissueCell::CommonCopy(const TissueCell& rOtherCell)
00066 {
00067     // Copy private data members
00068     mCanDivide = rOtherCell.mCanDivide;
00069 
00070     // Copy 'easy' protected data members
00071     mCellType = rOtherCell.mCellType;
00072     mMutationState = rOtherCell.mMutationState;
00073     mUndergoingApoptosis = rOtherCell.mUndergoingApoptosis;
00074     mIsDead = rOtherCell.mIsDead;
00075     mDeathTime = rOtherCell.mDeathTime;
00076     mStartOfApoptosisTime = rOtherCell.mStartOfApoptosisTime;
00077     mIsLogged = rOtherCell.mIsLogged;
00078     mAncestor = rOtherCell.mAncestor;
00079     mCellId = rOtherCell.mCellId;
00080 
00081     // Copy cell cycle model
00082     // Create a new object of the correct child type and copy its state
00083     mpCellCycleModel = rOtherCell.mpCellCycleModel->CreateCellCycleModel();
00084     // and inform it of the new cell object
00085     mpCellCycleModel->SetCell(this);
00086 }
00087 
00088 
00089 TissueCell::TissueCell(const TissueCell& rOtherCell)
00090 {
00091     CommonCopy(rOtherCell);
00092 }
00093 
00094 
00095 TissueCell& TissueCell::operator=(const TissueCell& rOtherCell)
00096 {
00097     // In case this is self-assignment, don't delete the cell cycle model
00098     AbstractCellCycleModel *p_temp_model = mpCellCycleModel;
00099     CommonCopy(rOtherCell);
00100     // ...until after we've copied it.
00101     delete p_temp_model;
00102     return *this;
00103 }
00104 
00105 
00106 TissueCell::~TissueCell()
00107 {
00108     delete mpCellCycleModel;
00109 }
00110 
00111 
00112 void TissueCell::SetCellCycleModel(AbstractCellCycleModel* pCellCycleModel)
00113 {
00114     if (mpCellCycleModel != pCellCycleModel)
00115     {
00116         delete mpCellCycleModel;
00117     }
00118     mpCellCycleModel = pCellCycleModel;
00119     mpCellCycleModel->SetCell(this);
00120 }
00121 
00122 
00123 AbstractCellCycleModel* TissueCell::GetCellCycleModel() const
00124 {
00125     return mpCellCycleModel;
00126 }
00127 
00128 
00129 void TissueCell::InitialiseCellCycleModel()
00130 {
00131     mpCellCycleModel->Initialise();
00132 }
00133 
00134 
00135 double TissueCell::GetAge() const
00136 {
00137     return mpCellCycleModel->GetAge();
00138 }
00139 
00140 
00141 double TissueCell::GetBirthTime() const
00142 {
00143     return mpCellCycleModel->GetBirthTime();
00144 }
00145 
00146 
00147 void TissueCell::SetBirthTime(double birthTime)
00148 {
00149     mpCellCycleModel->SetBirthTime(birthTime);
00150 }
00151 
00152 
00153 void TissueCell::SetCellType(CellType cellType)
00154 {
00155     mCellType = cellType;
00156 }
00157 
00158 
00159 CellType TissueCell::GetCellType() const
00160 {
00161     return mCellType;
00162 }
00163 
00164 
00165 void TissueCell::SetMutationState(CellMutationState mutationState)
00166 {
00167     mMutationState = mutationState;
00168 }
00169 
00170 
00171 CellMutationState TissueCell::GetMutationState() const
00172 {
00173     return mMutationState;
00174 }
00175 
00176 
00177 void TissueCell::SetLogged()
00178 {
00179     mIsLogged = true;
00180 }
00181 
00182 
00183 bool TissueCell::IsLogged()
00184 {
00185     return mIsLogged;
00186 }
00187 
00188 
00189 void TissueCell::StartApoptosis(bool setDeathTime)
00190 {
00191     assert(!IsDead());
00192 
00193     if (mUndergoingApoptosis)
00194     {
00195         EXCEPTION("StartApoptosis() called when already undergoing apoptosis");
00196     }
00197     mUndergoingApoptosis = true;
00198     mStartOfApoptosisTime = SimulationTime::Instance()->GetTime();
00199     if (setDeathTime)
00200     {
00201         mDeathTime = mStartOfApoptosisTime + TissueConfig::Instance()->GetApoptosisTime();
00202     }
00203     else
00204     {
00205         mDeathTime = DBL_MAX;
00206     }
00207 
00208     mCellType = APOPTOTIC;
00209 }
00210 
00211 
00212 bool TissueCell::HasApoptosisBegun() const
00213 {
00214     return mUndergoingApoptosis;
00215 }
00216 
00217 double TissueCell::GetStartOfApoptosisTime() const
00218 {
00219     return mStartOfApoptosisTime;
00220 }
00221 
00222 double TissueCell::TimeUntilDeath() const
00223 {
00224     if (!mUndergoingApoptosis || mDeathTime==DBL_MAX)
00225     {
00226         EXCEPTION("Shouldn't be checking time until apoptosis as it isn't set");
00227     }
00228 
00229     return mDeathTime - SimulationTime::Instance()->GetTime();
00230 }
00231 
00232 
00233 bool TissueCell::IsDead()
00234 {
00235     if (mUndergoingApoptosis)
00236     {
00237         if (SimulationTime::Instance()->GetTime() >= mDeathTime)
00238         {
00239             this->Kill();
00240         }
00241     }
00242     return mIsDead;
00243 }
00244 
00245 
00246 void TissueCell::Kill()
00247 {
00248     mIsDead = true;
00249 }
00250 
00251 void TissueCell::SetAncestor(unsigned ancestorIndex)
00252 {
00253     mAncestor = ancestorIndex;
00254 }
00255 
00256 unsigned TissueCell::GetAncestor() const
00257 {
00258     return mAncestor;
00259 }
00260 
00261 unsigned TissueCell::GetCellId() const
00262 {
00263     return mCellId;
00264 }
00265 
00266 void TissueCell::ResetMaxCellId()
00267 {
00268     mMaxCellId = 0;
00269 }
00270 
00271 bool TissueCell::ReadyToDivide()
00272 {
00273     assert(!IsDead());
00274     if (mUndergoingApoptosis || mCellType==APOPTOTIC)
00275     {
00276         return false;
00277     }
00278 
00279     mCanDivide = mpCellCycleModel->ReadyToDivide();
00280 
00281     return mCanDivide;
00282 }
00283 
00284 
00285 TissueCell TissueCell::Divide()
00286 {
00287     // Check we're allowed to divide
00288     assert(!IsDead());
00289     assert(mCanDivide);
00290     mCanDivide = false;
00291 
00292     // Reset properties of parent cell
00293     mpCellCycleModel->ResetForDivision();
00294 
00295     // Create daughter cell
00296     TissueCell new_cell = TissueCell(mCellType, mMutationState,
00297                                      mpCellCycleModel->CreateCellCycleModel());
00298 
00299     // Initialise properties of daughter cell
00300     new_cell.GetCellCycleModel()->InitialiseDaughterCell();
00301     new_cell.SetAncestor(GetAncestor());
00302 
00303     return new_cell;
00304 }

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5