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
00036 #include <climits>
00037 #include <boost/serialization/access.hpp>
00038 #include <boost/serialization/is_abstract.hpp>
00039 #include <boost/serialization/list.hpp>
00040 #include <boost/serialization/map.hpp>
00041
00042
00049 template<unsigned DIM>
00050 class AbstractTissue
00051 {
00052 protected:
00053
00055 std::list<TissueCell> mCells;
00056
00058 std::map<unsigned, TissueCell*> mLocationCellMap;
00059
00061 std::map<TissueCell*, unsigned> mCellLocationMap;
00062
00064 c_vector<unsigned, NUM_CELL_MUTATION_STATES> mCellMutationStateCount;
00065
00067 c_vector<unsigned, NUM_CELL_TYPES> mCellTypeCount;
00068
00070 c_vector<unsigned, 5> mCellCyclePhaseCount;
00071
00073 out_stream mpVizNodesFile;
00074
00076 out_stream mpVizCellTypesFile;
00077
00079 out_stream mpCellMutationStatesFile;
00080
00082 out_stream mpCellAncestorsFile;
00083
00085 out_stream mpCellTypesFile;
00086
00088 out_stream mpCellCyclePhasesFile;
00089
00091 out_stream mpCellVariablesFile;
00092
00094 bool mTissueContainsMesh;
00095
00097 friend class boost::serialization::access;
00104 template<class Archive>
00105 void serialize(Archive & archive, const unsigned int version)
00106 {
00107 archive & mCells;
00108 archive & mLocationCellMap;
00109 archive & mCellLocationMap;
00110 archive & mTissueContainsMesh;
00111 }
00112
00116 virtual void Validate()=0;
00117
00118 public:
00119
00126 AbstractTissue(const std::vector<TissueCell>& rCells,
00127 const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00128
00133 AbstractTissue()
00134 {}
00135
00139 virtual ~AbstractTissue()
00140 {}
00141
00145 void InitialiseCells();
00146
00150 std::list<TissueCell>& rGetCells();
00151
00155 bool HasMesh();
00156
00163 virtual unsigned GetNumNodes()=0;
00164
00172 virtual c_vector<double, DIM> GetLocationOfCellCentre(TissueCell* pCell)=0;
00173
00182 virtual Node<DIM>* GetNode(unsigned index)=0;
00183
00194 virtual unsigned AddNode(Node<DIM> *pNewNode)=0;
00195
00205 virtual void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation)=0;
00206
00217 virtual bool IsCellAssociatedWithADeletedNode(TissueCell& rCell)=0;
00218
00230 virtual void UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)=0;
00231
00242 virtual double GetDampingConstant(unsigned nodeIndex)=0;
00243
00256 virtual TissueCell* AddCell(TissueCell& rNewCell, c_vector<double,DIM> newLocation, TissueCell* pParentCell=NULL)=0;
00257
00258 class Iterator;
00259
00268 virtual unsigned RemoveDeadCells()=0;
00269
00274 virtual void Update()=0;
00275
00286 c_vector<unsigned, NUM_CELL_MUTATION_STATES> GetCellMutationStateCount();
00287
00297 c_vector<unsigned, NUM_CELL_TYPES> GetCellTypeCount();
00298
00309 c_vector<unsigned, 5> GetCellCyclePhaseCount();
00310
00319 virtual bool IsGhostNode(unsigned index);
00320
00324 unsigned GetNumRealCells();
00325
00330 void SetCellAncestorsToNodeIndices();
00331
00338 std::set<unsigned> GetCellAncestors();
00339
00350 TissueCell& rGetCellUsingLocationIndex(unsigned index);
00351
00362 unsigned GetLocationIndexUsingCell(TissueCell* pCell);
00363
00372 virtual void WriteMeshToFile(const std::string &rArchiveDirectory, const std::string &rMeshFileName);
00373
00385 virtual void CreateOutputFiles(const std::string &rDirectory,
00386 bool rCleanOutputDirectory,
00387 bool outputCellMutationStates,
00388 bool outputCellTypes,
00389 bool outputCellVariables,
00390 bool outputCellCyclePhases,
00391 bool outputCellAncestors);
00392
00402 virtual void WriteResultsToFiles(bool outputCellMutationStates,
00403 bool outputCellTypes,
00404 bool outputCellVariables,
00405 bool outputCellCyclePhases,
00406 bool outputCellAncestors)=0;
00407
00420 void WriteTimeAndNodeResultsToFiles(bool outputCellMutationStates,
00421 bool outputCellTypes,
00422 bool outputCellVariables,
00423 bool outputCellCyclePhases,
00424 bool outputCellAncestors,
00425 std::vector<unsigned>& rCellTypeCounter,
00426 std::vector<unsigned>& rCellMutationStateCounter,
00427 std::vector<unsigned>& rCellCyclePhaseCounter);
00428
00442 void GenerateCellResults(unsigned locationIndex,
00443 bool outputCellMutationStates,
00444 bool outputCellTypes,
00445 bool outputCellVariables,
00446 bool outputCellCyclePhases,
00447 bool outputCellAncestors,
00448 std::vector<unsigned>& rCellTypeCounter,
00449 std::vector<unsigned>& rCellMutationStateCounter,
00450 std::vector<unsigned>& rCellCyclePhaseCounter);
00451
00464 void WriteCellResultsToFiles(bool outputCellMutationStates,
00465 bool outputCellTypes,
00466 bool outputCellVariables,
00467 bool outputCellCyclePhases,
00468 bool outputCellAncestors,
00469 std::vector<unsigned>& rCellTypeCounter,
00470 std::vector<unsigned>& rCellMutationStateCounter,
00471 std::vector<unsigned>& rCellCyclePhaseCounter);
00472
00482 virtual void CloseOutputFiles(bool outputCellMutationStates,
00483 bool outputCellTypes,
00484 bool outputCellVariables,
00485 bool outputCellCyclePhases,
00486 bool outputCellAncestors);
00487
00494 class Iterator
00495 {
00496 public:
00497
00502 inline TissueCell& operator*();
00503
00507 inline TissueCell* operator->();
00508
00514 inline bool operator!=(const Iterator& other);
00515
00519 inline Iterator& operator++();
00520
00527 Iterator(AbstractTissue& rTissue, std::list<TissueCell>::iterator cellIter);
00528
00532 virtual ~Iterator()
00533 {}
00534
00535 private:
00536
00543 virtual inline bool IsRealCell();
00544
00548 inline bool IsAtEnd();
00549
00551 AbstractTissue& mrTissue;
00552
00554 std::list<TissueCell>::iterator mCellIter;
00555 };
00556
00560 Iterator Begin();
00561
00565 Iterator End();
00566
00567 };
00568
00569 enum cell_colours
00570 {
00571 STEM_COLOUR,
00572 TRANSIT_COLOUR,
00573 DIFFERENTIATED_COLOUR,
00574 EARLY_CANCER_COLOUR,
00575 LATE_CANCER_COLOUR,
00576 LABELLED_COLOUR,
00577 APOPTOSIS_COLOUR,
00578 INVISIBLE_COLOUR,
00579 };
00580
00581
00582 namespace boost {
00583 namespace serialization {
00589 template<unsigned DIM>
00590 struct is_abstract<AbstractTissue<DIM> > {
00591 typedef mpl::bool_<true> type;
00592 BOOST_STATIC_CONSTANT(bool, value=true);
00593 };
00594 }}
00595
00597
00599
00600 template<unsigned DIM>
00601 TissueCell& AbstractTissue<DIM>::Iterator::operator*()
00602 {
00603 assert(!IsAtEnd());
00604 return *mCellIter;
00605 }
00606
00607 template<unsigned DIM>
00608 TissueCell* AbstractTissue<DIM>::Iterator::operator->()
00609 {
00610 assert(!IsAtEnd());
00611 return &(*mCellIter);
00612 }
00613
00614 template<unsigned DIM>
00615 bool AbstractTissue<DIM>::Iterator::operator!=(const AbstractTissue<DIM>::Iterator& other)
00616 {
00617 return mCellIter != other.mCellIter;
00618 }
00619
00620 template<unsigned DIM>
00621 typename AbstractTissue<DIM>::Iterator& AbstractTissue<DIM>::Iterator::operator++()
00622 {
00623 do
00624 {
00625 ++mCellIter;
00626 }
00627 while (!IsAtEnd() && !IsRealCell());
00628
00629 return (*this);
00630 }
00631
00632 template<unsigned DIM>
00633 bool AbstractTissue<DIM>::Iterator::IsRealCell()
00634 {
00635 return !( mrTissue.IsCellAssociatedWithADeletedNode(*mCellIter) || (*this)->IsDead() );
00636 }
00637
00638 template<unsigned DIM>
00639 bool AbstractTissue<DIM>::Iterator::IsAtEnd()
00640 {
00641 return mCellIter == mrTissue.rGetCells().end();
00642 }
00643
00644 template<unsigned DIM>
00645 AbstractTissue<DIM>::Iterator::Iterator(AbstractTissue& rTissue, std::list<TissueCell>::iterator cellIter)
00646 : mrTissue(rTissue),
00647 mCellIter(cellIter)
00648 {
00649
00650 if (mrTissue.rGetCells().size() == 0)
00651 {
00652 mCellIter = mrTissue.rGetCells().end();
00653 }
00654 else
00655 {
00656
00657 if (mCellIter == mrTissue.rGetCells().begin() && !IsRealCell())
00658 {
00659 ++(*this);
00660 }
00661 }
00662 }
00663
00664 template<unsigned DIM>
00665 typename AbstractTissue<DIM>::Iterator AbstractTissue<DIM>::Begin()
00666 {
00667 return Iterator(*this, this->mCells.begin());
00668 }
00669
00670 template<unsigned DIM>
00671 typename AbstractTissue<DIM>::Iterator AbstractTissue<DIM>::End()
00672 {
00673 return Iterator(*this, this->mCells.end());
00674 }
00675
00676
00677 #endif