Chaste Release::3.1
Cell.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef CELL_HPP_
00037 #define CELL_HPP_
00038 
00039 #include <boost/utility.hpp>
00040 #include <boost/shared_ptr.hpp>
00041 #include <boost/enable_shared_from_this.hpp>
00042 
00043 #include "ChasteSerialization.hpp"
00044 #include <boost/serialization/shared_ptr.hpp>
00045 
00046 #include "CellProliferativeTypes.hpp"
00047 #include "AbstractCellMutationState.hpp"
00048 #include "CellLabel.hpp"
00049 #include "CellAncestor.hpp"
00050 #include "CellId.hpp"
00051 #include "CellData.hpp"
00052 
00053 #include "ApoptoticCellProperty.hpp"
00054 #include "AbstractCellCycleModel.hpp"
00055 #include "SimulationTime.hpp"
00056 #include "CellPropertyRegistry.hpp"
00057 #include "CellPropertyCollection.hpp"
00058 #include "SmartPointers.hpp"
00059 
00060 class AbstractCellCycleModel; // Circular definition (cells need to know about cycle models and vice-versa).
00061 
00062 class Cell;
00063 
00065 typedef boost::shared_ptr<Cell> CellPtr;
00066 
00074 class Cell : private boost::noncopyable, public boost::enable_shared_from_this<Cell>
00075 {
00076 private:
00077 
00079     bool mCanDivide;
00080 
00082     friend class boost::serialization::access;
00089     template<class Archive>
00090     void serialize(Archive & archive, const unsigned int version)
00091     {
00092         // These first four are also dealt with by {load,save}_construct_data
00093         archive & mCanDivide;
00094         archive & mCellProliferativeType;
00095         archive & mpCellCycleModel;
00096         archive & mUndergoingApoptosis;
00097         archive & mDeathTime;
00098         archive & mStartOfApoptosisTime;
00099         archive & mApoptosisTime;
00100         archive & mIsDead;
00101         archive & mIsLogged;
00102     }
00103 
00104 protected:
00105 
00107     CellProliferativeType mCellProliferativeType;
00108 
00110     CellPropertyCollection mCellPropertyCollection;
00111 
00113     AbstractCellCycleModel* mpCellCycleModel;
00114 
00116     double mDeathTime;
00117 
00119     double mStartOfApoptosisTime;
00120 
00122     double mApoptosisTime;
00123 
00125     bool mUndergoingApoptosis;
00126 
00131     bool mIsDead;
00132 
00134     bool mIsLogged;
00135 
00136 public:
00137 
00147     Cell(boost::shared_ptr<AbstractCellProperty> pMutationState,
00148                AbstractCellCycleModel* pCellCycleModel,
00149                bool archiving=false,
00150                CellPropertyCollection cellPropertyCollection=CellPropertyCollection());
00151 
00155     ~Cell();
00156 
00160     CellProliferativeType GetCellProliferativeType() const;
00161 
00167     void SetCellProliferativeType(CellProliferativeType cellType);
00168 
00174     void SetBirthTime(double birthTime);
00175 
00181     void SetCellCycleModel(AbstractCellCycleModel* pCellCycleModel);
00182 
00186     AbstractCellCycleModel* GetCellCycleModel() const;
00187 
00191     void InitialiseCellCycleModel();
00192 
00196     double GetAge() const;
00197 
00201     double GetBirthTime() const;
00202 
00206     double GetStartOfApoptosisTime() const;
00207 
00211     double GetApoptosisTime() const;
00212 
00218     void SetApoptosisTime(double apoptosisTime);
00219 
00223     boost::shared_ptr<AbstractCellMutationState> GetMutationState() const;
00224 
00230     boost::shared_ptr<CellData> GetCellData() const;
00231 
00237     void SetMutationState(boost::shared_ptr<AbstractCellProperty> pMutationState);
00238 
00242     CellPropertyCollection& rGetCellPropertyCollection();
00243 
00247     const CellPropertyCollection& rGetCellPropertyCollection() const;
00248 
00257     void AddCellProperty(const boost::shared_ptr<AbstractCellProperty>& rProperty);
00258 
00266     template<typename CLASS>
00267     void RemoveCellProperty()
00268     {
00269         bool cell_has_property = false;
00270 
00271         for (std::set<boost::shared_ptr<AbstractCellProperty> >::iterator property_iter = mCellPropertyCollection.Begin();
00272              property_iter != mCellPropertyCollection.End();
00273              ++property_iter)
00274         {
00275             if ((*property_iter)->IsType<CLASS>())
00276             {
00277                 cell_has_property = true;
00278                 (*property_iter)->DecrementCellCount();
00279                 break;
00280             }
00281         }
00282 
00283         if (cell_has_property)
00284         {
00285             mCellPropertyCollection.RemoveProperty<CLASS>();
00286         }
00287     }
00288 
00293     template<typename CLASS>
00294     bool HasCellProperty() const
00295     {
00296         return mCellPropertyCollection.HasProperty<CLASS>();
00297     }
00298 
00303     bool ReadyToDivide();
00304 
00311     CellPtr Divide();
00312 
00319     void StartApoptosis(bool setDeathTime=true);
00320 
00325     void Kill();
00326 
00330     bool HasApoptosisBegun() const;
00331 
00335     double GetTimeUntilDeath() const;
00336 
00340     bool IsDead();
00341 
00345     void SetLogged();
00346 
00350     bool IsLogged();
00351 
00357     void SetAncestor(boost::shared_ptr<AbstractCellProperty> pCellAncestor);
00358 
00363     unsigned GetAncestor() const;
00364 
00368     unsigned GetCellId() const;
00369 };
00370 
00371 
00372 #include "SerializationExportWrapper.hpp"
00373 CHASTE_CLASS_EXPORT(Cell)
00374 
00375 namespace boost
00376 {
00377 namespace serialization
00378 {
00382 template<class Archive>
00383 inline void save_construct_data(
00384     Archive & ar, const Cell * t, const BOOST_PFTO unsigned int file_version)
00385 {
00386     // Save data required to construct instance
00387     const boost::shared_ptr<AbstractCellMutationState> p_mutation_state = t->GetMutationState();
00388     ar & p_mutation_state;
00389 
00390     const AbstractCellCycleModel* const p_cell_cycle_model = t->GetCellCycleModel();
00391     ar & p_cell_cycle_model;
00392 
00393     const CellPropertyCollection& r_cell_property_collection = t->rGetCellPropertyCollection();
00394     ar & r_cell_property_collection;
00395 }
00396 
00400 template<class Archive>
00401 inline void load_construct_data(
00402     Archive & ar, Cell * t, const unsigned int file_version)
00403 {
00404     // Retrieve data from archive required to construct new instance
00405     boost::shared_ptr<AbstractCellMutationState> p_mutation_state;
00406     ar & p_mutation_state;
00407 
00408     AbstractCellCycleModel* p_cell_cycle_model;
00409     ar & p_cell_cycle_model;
00410 
00411     bool archiving = true;
00412 
00413     CellPropertyCollection cell_property_collection;
00414     ar & cell_property_collection;
00415 
00416     // Invoke inplace constructor to initialize instance
00417     ::new(t)Cell(p_mutation_state, p_cell_cycle_model, archiving, cell_property_collection);
00418 }
00419 }
00420 } // namespace ...
00421 
00422 #endif /*CELL_HPP_*/