AbstractTissue.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ABSTRACTTISSUE_HPP_
00029 #define ABSTRACTTISSUE_HPP_
00030
00031 #include "TissueCell.hpp"
00032 #include "OutputFileHandler.hpp"
00033
00034 #include <list>
00035 #include <map>
00036 #include <vector>
00037 #include <boost/shared_ptr.hpp>
00038
00039 #include "ChasteSerialization.hpp"
00040 #include "ClassIsAbstract.hpp"
00041 #include <boost/serialization/vector.hpp>
00042 #include <boost/serialization/list.hpp>
00043 #include <boost/serialization/map.hpp>
00044 #include <boost/serialization/shared_ptr.hpp>
00045
00046 #include "CellMutationStateRegistry.hpp"
00047
00048 #include "WildTypeCellMutationState.hpp"
00049 #include "LabelledCellMutationState.hpp"
00050 #include "ApcOneHitCellMutationState.hpp"
00051 #include "ApcTwoHitCellMutationState.hpp"
00052 #include "BetaCateninOneHitCellMutationState.hpp"
00053
00060 template<unsigned DIM>
00061 class AbstractTissue
00062 {
00063 private:
00065 friend class boost::serialization::access;
00072 template<class Archive>
00073 void serialize(Archive & archive, const unsigned int version)
00074 {
00075 archive & mCells;
00076 archive & mLocationCellMap;
00077 archive & mCellLocationMap;
00078 archive & mCellProliferativeTypeCount;
00079 archive & mCellCyclePhaseCount;
00080 archive & mTissueContainsMesh;
00081 archive & mpMutationStateRegistry;
00082 }
00083
00084 protected:
00085
00087 std::list<TissueCell> mCells;
00088
00090 std::map<unsigned, TissueCell*> mLocationCellMap;
00091
00093 std::map<TissueCell*, unsigned> mCellLocationMap;
00094
00096 std::vector<unsigned> mCellProliferativeTypeCount;
00097
00099 std::vector<unsigned> mCellCyclePhaseCount;
00100
00102 out_stream mpVizNodesFile;
00103
00105 out_stream mpVizCellProliferativeTypesFile;
00106
00108 out_stream mpCellMutationStatesFile;
00109
00111 out_stream mpCellAncestorsFile;
00112
00114 out_stream mpCellProliferativeTypesFile;
00115
00117 out_stream mpCellCyclePhasesFile;
00118
00120 out_stream mpCellVariablesFile;
00121
00123 out_stream mpCellAgesFile;
00124
00126 out_stream mpCellIdFile;
00127
00129 out_stream mpBoundaryNodesFile;
00130
00132 bool mTissueContainsMesh;
00133
00135 boost::shared_ptr<CellMutationStateRegistry> mpMutationStateRegistry;
00136
00140 virtual void Validate()=0;
00141
00142 protected:
00149 AbstractTissue()
00150 {
00151 }
00152
00153 public:
00154
00165 AbstractTissue(std::vector<TissueCell>& rCells,
00166 const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00167
00171 virtual ~AbstractTissue()
00172 {}
00173
00177 void InitialiseCells();
00178
00182 std::list<TissueCell>& rGetCells();
00183
00191 bool HasMesh();
00192
00199 virtual unsigned GetNumNodes()=0;
00200
00208 virtual c_vector<double, DIM> GetLocationOfCellCentre(TissueCell& rCell)=0;
00209
00218 virtual Node<DIM>* GetNode(unsigned index)=0;
00219
00230 virtual unsigned AddNode(Node<DIM>* pNewNode)=0;
00231
00241 virtual void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation)=0;
00242
00254 virtual bool IsCellAssociatedWithADeletedLocation(TissueCell& rCell)=0;
00255
00267 virtual void UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)=0;
00268
00279 virtual double GetDampingConstant(unsigned nodeIndex)=0;
00280
00296 virtual TissueCell* AddCell(TissueCell& rNewCell, const c_vector<double,DIM>& rCellDivisionVector, TissueCell* pParentCell=NULL)=0;
00297
00298 class Iterator;
00299
00308 virtual unsigned RemoveDeadCells()=0;
00309
00316 virtual void Update(bool hasHadBirthsOrDeaths=true)=0;
00317
00328 std::vector<unsigned> GetCellMutationStateCount();
00329
00339 const std::vector<unsigned>& rGetCellProliferativeTypeCount() const;
00340
00351 const std::vector<unsigned>& rGetCellCyclePhaseCount() const;
00352
00356 unsigned GetNumRealCells();
00357
00362 void SetCellAncestorsToLocationIndices();
00363
00367 void WriteCellIdDataToFile();
00368
00375 std::set<unsigned> GetCellAncestors();
00376
00387 TissueCell& rGetCellUsingLocationIndex(unsigned index);
00388
00399 unsigned GetLocationIndexUsingCell(TissueCell& rCell);
00400
00404 boost::shared_ptr<CellMutationStateRegistry> GetMutationRegistry();
00405
00410 void SetDefaultMutationStateOrdering();
00411
00418 virtual void CreateOutputFiles(const std::string& rDirectory,
00419 bool cleanOutputDirectory);
00420
00424 virtual void WriteResultsToFiles();
00425
00429 void WriteTimeAndNodeResultsToFiles();
00430
00434 virtual void GenerateCellResultsAndWriteToFiles()=0;
00435
00443 virtual void GenerateCellResults(unsigned locationIndex,
00444 std::vector<unsigned>& rCellProliferativeTypeCounter,
00445 std::vector<unsigned>& rCellCyclePhaseCounter);
00446
00453 void WriteCellResultsToFiles(std::vector<unsigned>& rCellProliferativeTypeCounter,
00454 std::vector<unsigned>& rCellCyclePhaseCounter);
00455
00459 virtual void CloseOutputFiles();
00460
00467 class Iterator
00468 {
00469 public:
00470
00475 inline TissueCell& operator*();
00476
00480 inline TissueCell* operator->();
00481
00487 inline bool operator!=(const AbstractTissue<DIM>::Iterator& rOther);
00488
00492 inline Iterator& operator++();
00493
00500 Iterator(AbstractTissue& rTissue, std::list<TissueCell>::iterator cellIter);
00501
00505 virtual ~Iterator()
00506 {}
00507
00508 private:
00509
00516 virtual inline bool IsRealCell();
00517
00521 inline bool IsAtEnd();
00522
00524 AbstractTissue& mrTissue;
00525
00527 std::list<TissueCell>::iterator mCellIter;
00528 };
00529
00533 Iterator Begin();
00534
00538 Iterator End();
00539
00540 };
00541
00542 enum cell_colours
00543 {
00544 STEM_COLOUR,
00545 TRANSIT_COLOUR,
00546 DIFFERENTIATED_COLOUR,
00547 EARLY_CANCER_COLOUR,
00548 LATE_CANCER_COLOUR,
00549 LABELLED_COLOUR,
00550 APOPTOSIS_COLOUR,
00551 INVISIBLE_COLOUR,
00552 };
00553
00554 TEMPLATED_CLASS_IS_ABSTRACT_1_UNSIGNED(AbstractTissue);
00555
00557
00559
00560 template<unsigned DIM>
00561 TissueCell& AbstractTissue<DIM>::Iterator::operator*()
00562 {
00563 assert(!IsAtEnd());
00564 return *mCellIter;
00565 }
00566
00567 template<unsigned DIM>
00568 TissueCell* AbstractTissue<DIM>::Iterator::operator->()
00569 {
00570 assert(!IsAtEnd());
00571 return &(*mCellIter);
00572 }
00573
00574 template<unsigned DIM>
00575 bool AbstractTissue<DIM>::Iterator::operator!=(const AbstractTissue<DIM>::Iterator& rOther)
00576 {
00577 return mCellIter != rOther.mCellIter;
00578 }
00579
00580 template<unsigned DIM>
00581 typename AbstractTissue<DIM>::Iterator& AbstractTissue<DIM>::Iterator::operator++()
00582 {
00583 do
00584 {
00585 ++mCellIter;
00586 }
00587 while (!IsAtEnd() && !IsRealCell());
00588
00589 return (*this);
00590 }
00591
00592 template<unsigned DIM>
00593 bool AbstractTissue<DIM>::Iterator::IsRealCell()
00594 {
00595 return !( mrTissue.IsCellAssociatedWithADeletedLocation(*mCellIter) || (*this)->IsDead() );
00596 }
00597
00598 template<unsigned DIM>
00599 bool AbstractTissue<DIM>::Iterator::IsAtEnd()
00600 {
00601 return mCellIter == mrTissue.rGetCells().end();
00602 }
00603
00604 template<unsigned DIM>
00605 AbstractTissue<DIM>::Iterator::Iterator(AbstractTissue& rTissue, std::list<TissueCell>::iterator cellIter)
00606 : mrTissue(rTissue),
00607 mCellIter(cellIter)
00608 {
00609
00610 if (mrTissue.rGetCells().size() == 0)
00611 {
00612 mCellIter = mrTissue.rGetCells().end();
00613 }
00614 else
00615 {
00616
00617 if (mCellIter == mrTissue.rGetCells().begin() && !IsRealCell())
00618 {
00619 ++(*this);
00620 }
00621 }
00622 }
00623
00624 template<unsigned DIM>
00625 typename AbstractTissue<DIM>::Iterator AbstractTissue<DIM>::Begin()
00626 {
00627 return Iterator(*this, this->mCells.begin());
00628 }
00629
00630 template<unsigned DIM>
00631 typename AbstractTissue<DIM>::Iterator AbstractTissue<DIM>::End()
00632 {
00633 return Iterator(*this, this->mCells.end());
00634 }
00635
00636
00637 #endif