AbstractTissue.hpp

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 #ifndef ABSTRACTTISSUE_HPP_
00029 #define ABSTRACTTISSUE_HPP_
00030 
00031 #include "TissueCell.hpp"
00032 #include "OutputFileHandler.hpp"
00033 
00034 #include <list>
00035 
00036 #include <climits> // work around boost bug
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 private:
00054     friend class boost::serialization::access;
00061     template<class Archive>
00062     void serialize(Archive & archive, const unsigned int version)
00063     {
00064         archive & mCells;
00065         archive & mLocationCellMap;
00066         archive & mCellLocationMap;
00067         archive & mTissueContainsMesh;
00068     }
00069 
00070 protected:
00071 
00073     std::list<TissueCell> mCells;
00074 
00076     std::map<unsigned, TissueCell*> mLocationCellMap;
00077 
00079     std::map<TissueCell*, unsigned> mCellLocationMap;
00080 
00082     c_vector<unsigned, NUM_CELL_MUTATION_STATES> mCellMutationStateCount;
00083 
00085     c_vector<unsigned, NUM_CELL_TYPES> mCellTypeCount;
00086 
00088     c_vector<unsigned, 5> mCellCyclePhaseCount;
00089 
00091     out_stream mpVizNodesFile;
00092 
00094     out_stream mpVizCellTypesFile;
00095 
00097     out_stream mpCellMutationStatesFile;
00098 
00100     out_stream mpCellAncestorsFile;
00101 
00103     out_stream mpCellTypesFile;
00104 
00106     out_stream mpCellCyclePhasesFile;
00107 
00109     out_stream mpCellVariablesFile;
00110 
00112     out_stream mpCellAgesFile;
00113 
00115     out_stream mpCellIdFile;
00116 
00118     bool mTissueContainsMesh;
00119 
00123     virtual void Validate()=0;
00124 
00125 public:
00126 
00133     AbstractTissue(const std::vector<TissueCell>& rCells,
00134                    const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00135 
00140     AbstractTissue()
00141     {}
00142 
00146     virtual ~AbstractTissue()
00147     {}
00148 
00152     void InitialiseCells();
00153 
00157     std::list<TissueCell>& rGetCells();
00158 
00162     bool HasMesh();
00163 
00170     virtual unsigned GetNumNodes()=0;
00171 
00179     virtual c_vector<double, DIM> GetLocationOfCellCentre(TissueCell* pCell)=0;
00180 
00189     virtual Node<DIM>* GetNode(unsigned index)=0;
00190 
00201     virtual unsigned AddNode(Node<DIM>* pNewNode)=0;
00202 
00212     virtual void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation)=0;
00213 
00224     virtual bool IsCellAssociatedWithADeletedNode(TissueCell& rCell)=0;
00225 
00237     virtual void UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)=0;
00238 
00249     virtual double GetDampingConstant(unsigned nodeIndex)=0;
00250 
00263     virtual TissueCell* AddCell(TissueCell& rNewCell, c_vector<double,DIM> newLocation, TissueCell* pParentCell=NULL)=0;
00264 
00265     class Iterator; // Forward declaration; see below
00266 
00275     virtual unsigned RemoveDeadCells()=0;
00276 
00283     virtual void Update(bool hasHadBirthsOrDeaths=true)=0;
00284 
00295     c_vector<unsigned, NUM_CELL_MUTATION_STATES> GetCellMutationStateCount();
00296 
00306     c_vector<unsigned, NUM_CELL_TYPES> GetCellTypeCount();
00307 
00318     c_vector<unsigned, 5> GetCellCyclePhaseCount();
00319 
00328     virtual bool IsGhostNode(unsigned index);
00329 
00333     unsigned GetNumRealCells();
00334 
00339     void SetCellAncestorsToNodeIndices();
00340 
00344     void WriteCellIdDataToFile();
00345 
00352     std::set<unsigned> GetCellAncestors();
00353 
00364     TissueCell& rGetCellUsingLocationIndex(unsigned index);
00365 
00376     unsigned GetLocationIndexUsingCell(TissueCell* pCell);
00377 
00384     virtual void CreateOutputFiles(const std::string& rDirectory,
00385                                    bool cleanOutputDirectory);
00386 
00390     virtual void WriteResultsToFiles();
00391 
00399     void WriteTimeAndNodeResultsToFiles(std::vector<unsigned>& rCellTypeCounter,
00400                                         std::vector<unsigned>& rCellMutationStateCounter,
00401                                         std::vector<unsigned>& rCellCyclePhaseCounter);
00402 
00410     virtual void GenerateCellResultsAndWriteToFiles(std::vector<unsigned>& rCellTypeCounter,
00411                                                     std::vector<unsigned>& rCellMutationStateCounter,
00412                                                     std::vector<unsigned>& rCellCyclePhaseCounter);
00413 
00422     void GenerateCellResults(unsigned locationIndex,
00423                              std::vector<unsigned>& rCellTypeCounter,
00424                              std::vector<unsigned>& rCellMutationStateCounter,
00425                              std::vector<unsigned>& rCellCyclePhaseCounter);
00426 
00434     void WriteCellResultsToFiles(std::vector<unsigned>& rCellTypeCounter,
00435                                  std::vector<unsigned>& rCellMutationStateCounter,
00436                                  std::vector<unsigned>& rCellCyclePhaseCounter);
00437 
00441     virtual void CloseOutputFiles();
00442 
00449     class Iterator
00450     {
00451     public:
00452 
00457         inline TissueCell& operator*();
00458 
00462         inline TissueCell* operator->();
00463 
00469         inline bool operator!=(const AbstractTissue<DIM>::Iterator& rOther);
00470 
00474         inline Iterator& operator++();
00475 
00482         Iterator(AbstractTissue& rTissue, std::list<TissueCell>::iterator cellIter);
00483 
00487         virtual ~Iterator()
00488         {}
00489 
00490     private:
00491 
00498         virtual inline bool IsRealCell();
00499 
00503         inline bool IsAtEnd();
00504 
00506         AbstractTissue& mrTissue;
00507 
00509         std::list<TissueCell>::iterator mCellIter;
00510     };
00511 
00515     Iterator Begin();
00516 
00520     Iterator End();
00521 
00522 };
00523 
00524 enum cell_colours
00525 {
00526     STEM_COLOUR, // 0
00527     TRANSIT_COLOUR, // 1
00528     DIFFERENTIATED_COLOUR, // 2
00529     EARLY_CANCER_COLOUR, // 3
00530     LATE_CANCER_COLOUR, // 4
00531     LABELLED_COLOUR, // 5
00532     APOPTOSIS_COLOUR, // 6
00533     INVISIBLE_COLOUR, // visualizer treats '7' as invisible
00534 };
00535 
00536 namespace boost
00537 {
00538 namespace serialization
00539 {
00545 template<unsigned DIM>
00546 struct is_abstract<AbstractTissue<DIM> >
00547 {
00549     typedef mpl::bool_<true> type;
00551     BOOST_STATIC_CONSTANT(bool, value=true);
00552 };
00553 }
00554 }
00555 
00557 //         Iterator class implementation - most methods are inlined         //
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.IsCellAssociatedWithADeletedNode(*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     // The tissue can now return empty if it only has ghost nodes
00610     if (mrTissue.rGetCells().size() == 0)
00611     {
00612         mCellIter = mrTissue.rGetCells().end();
00613     }
00614     else
00615     {
00616         // Make sure we start at a real cell
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 /*ABSTRACTTISSUE_HPP_*/

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