TissueCell.cpp

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

Generated by  doxygen 1.6.2