AbstractCellPopulation.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 ABSTRACTCELLPOPULATION_HPP_
00029 #define ABSTRACTCELLPOPULATION_HPP_
00030 
00031 #include "Cell.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 "Node.hpp"
00047 #include "CellPropertyRegistry.hpp"
00048 #include "Identifiable.hpp"
00049 
00050 // Needed here to avoid serialization errors (on Boost<1.37)
00051 #include "WildTypeCellMutationState.hpp"
00052 #include "ApcOneHitCellMutationState.hpp"
00053 #include "ApcTwoHitCellMutationState.hpp"
00054 #include "BetaCateninOneHitCellMutationState.hpp"
00055 #include "ApoptoticCellProperty.hpp"
00056 #include "CellLabel.hpp"
00057 
00064 template<unsigned DIM>
00065 class AbstractCellPopulation : public Identifiable
00066 {
00067 private:
00069     friend class boost::serialization::access;
00076     template<class Archive>
00077     void serialize(Archive & archive, const unsigned int version)
00078     {
00079         archive & mCells;
00080         archive & mLocationCellMap;
00081         archive & mCellLocationMap;
00082         archive & mCellProliferativeTypeCount;
00083         archive & mCellCyclePhaseCount;
00084         archive & mCellPopulationContainsMesh;
00085         archive & mpCellPropertyRegistry;
00086         archive & mDampingConstantNormal;
00087         archive & mDampingConstantMutant;
00088         archive & mOutputCellIdData;
00089         archive & mOutputCellMutationStates;
00090         archive & mOutputCellAncestors;
00091         archive & mOutputCellProliferativeTypes;
00092         archive & mOutputCellVariables;
00093         archive & mOutputCellCyclePhases;
00094         archive & mOutputCellAges;
00095         archive & mOutputCellVolumes;
00096     }
00097 
00098 protected:
00099 
00101     std::list<CellPtr> mCells;
00102 
00104     std::map<unsigned, CellPtr> mLocationCellMap;
00105 
00107     std::map<Cell*, unsigned> mCellLocationMap;
00108 
00110     std::vector<unsigned> mCellProliferativeTypeCount;
00111 
00113     std::vector<unsigned> mCellCyclePhaseCount;
00114 
00116     out_stream mpVizNodesFile;
00117 
00119     out_stream mpVizCellProliferativeTypesFile;
00120 
00122     out_stream mpCellMutationStatesFile;
00123 
00125     out_stream mpVizCellAncestorsFile;
00126 
00128     out_stream mpCellProliferativeTypesFile;
00129 
00131     out_stream mpCellCyclePhasesFile;
00132 
00134     out_stream mpCellVariablesFile;
00135 
00137     out_stream mpCellAgesFile;
00138 
00140     out_stream mpCellIdFile;
00141 
00143     out_stream mpVizBoundaryNodesFile;
00144 
00146     std::string mDirPath;
00147 
00149     out_stream mpVtkMetaFile;
00150 
00152     bool mCellPopulationContainsMesh;
00153 
00155     boost::shared_ptr<CellPropertyRegistry> mpCellPropertyRegistry;
00156 
00163     double mDampingConstantNormal;
00164 
00168     double mDampingConstantMutant;
00169 
00171     bool mOutputCellIdData;
00172 
00174     bool mOutputCellMutationStates;
00175 
00177     bool mOutputCellAncestors;
00178 
00180     bool mOutputCellProliferativeTypes;
00181 
00183     bool mOutputCellVariables;
00184 
00186     bool mOutputCellCyclePhases;
00187 
00189     bool mOutputCellAges;
00190 
00192     bool mOutputCellVolumes;
00193 
00200     virtual void Validate()=0;
00201 
00208     virtual void WriteVtkResultsToFile()=0;
00209 
00215     AbstractCellPopulation()
00216     {
00217     }
00218 
00219 public:
00220 
00231     AbstractCellPopulation(std::vector<CellPtr>& rCells,
00232                            const std::vector<unsigned> locationIndices=std::vector<unsigned>());
00233 
00237     virtual ~AbstractCellPopulation();
00238 
00242     void InitialiseCells();
00243 
00247     std::list<CellPtr>& rGetCells();
00248 
00252     bool IsMeshBasedCellPopulation();
00253 
00260     virtual unsigned GetNumNodes()=0;
00261 
00271     virtual c_vector<double, DIM> GetLocationOfCellCentre(CellPtr pCell)=0;
00272 
00282     virtual Node<DIM>* GetNode(unsigned index)=0;
00283 
00293     virtual unsigned AddNode(Node<DIM>* pNewNode)=0;
00294 
00304     virtual void SetNode(unsigned nodeIndex, ChastePoint<DIM>& rNewLocation)=0;
00305 
00316     virtual bool IsCellAssociatedWithADeletedLocation(CellPtr pCell)=0;
00317 
00329     virtual void UpdateNodeLocations(const std::vector< c_vector<double, DIM> >& rNodeForces, double dt)=0;
00330 
00340     virtual double GetDampingConstant(unsigned nodeIndex)=0;
00341 
00357     virtual CellPtr AddCell(CellPtr pNewCell, const c_vector<double,DIM>& rCellDivisionVector, CellPtr pParentCell=CellPtr())=0;
00358 
00359     class Iterator; // Forward declaration; see below
00360 
00369     virtual unsigned RemoveDeadCells()=0;
00370 
00377     virtual void Update(bool hasHadBirthsOrDeaths=true)=0;
00378 
00388     std::vector<unsigned> GetCellMutationStateCount();
00389 
00398      const std::vector<unsigned>& rGetCellProliferativeTypeCount() const;
00399 
00410     const std::vector<unsigned>& rGetCellCyclePhaseCount() const;
00411 
00415     unsigned GetNumRealCells();
00416 
00421     void SetCellAncestorsToLocationIndices();
00422 
00426     void WriteCellIdDataToFile();
00427 
00434     std::set<unsigned> GetCellAncestors();
00435 
00446     CellPtr GetCellUsingLocationIndex(unsigned index);
00447 
00458     unsigned GetLocationIndexUsingCell(CellPtr pCell);
00459 
00463     boost::shared_ptr<CellPropertyRegistry> GetCellPropertyRegistry();
00464 
00469     void SetDefaultMutationStateOrdering();
00470 
00479     virtual double GetWidth(const unsigned& rDimension)=0;
00480 
00487     virtual void CreateOutputFiles(const std::string& rDirectory,
00488                                    bool cleanOutputDirectory);
00489 
00493     virtual void WriteResultsToFiles();
00494 
00498     virtual void WriteTimeAndNodeResultsToFiles();
00499 
00503     virtual void GenerateCellResultsAndWriteToFiles()=0;
00504 
00512     virtual void GenerateCellResults(unsigned locationIndex,
00513                              std::vector<unsigned>& rCellProliferativeTypeCounter,
00514                              std::vector<unsigned>& rCellCyclePhaseCounter);
00515 
00522     void WriteCellResultsToFiles(std::vector<unsigned>& rCellProliferativeTypeCounter,
00523                                  std::vector<unsigned>& rCellCyclePhaseCounter);
00524 
00528     virtual void CloseOutputFiles();
00529 
00535     void OutputCellPopulationInfo(out_stream& rParamsFile);
00536 
00545     virtual void OutputCellPopulationParameters(out_stream& rParamsFile)=0;
00546 
00550     double GetDampingConstantNormal();
00554     double GetDampingConstantMutant();
00555 
00559     bool GetOutputCellIdData();
00560 
00564     bool GetOutputCellMutationStates();
00565 
00569     bool GetOutputCellAncestors();
00570 
00574     bool GetOutputCellProliferativeTypes();
00575 
00579     bool GetOutputCellVariables();
00580 
00584     bool GetOutputCellCyclePhases();
00585 
00589     bool GetOutputCellAges();
00590 
00594     bool GetOutputCellVolumes();
00595 
00601     void SetDampingConstantNormal(double dampingConstantNormal);
00602 
00608     void SetDampingConstantMutant(double dampingConstantMutant);
00609 
00615     void SetOutputCellIdData(bool outputCellIdData);
00616 
00622     void SetOutputCellMutationStates(bool outputCellMutationStates);
00623 
00629     void SetOutputCellAncestors(bool outputCellAncestors);
00630 
00636     void SetOutputCellProliferativeTypes(bool outputCellProliferativeTypes);
00637 
00643     void SetOutputCellVariables(bool outputCellVariables);
00644 
00650     void SetOutputCellCyclePhases(bool outputCellCyclePhases);
00651 
00657     void SetOutputCellAges(bool outputCellAges);
00658 
00664     virtual void SetOutputCellVolumes(bool outputCellVolumes);
00665 
00672     class Iterator
00673     {
00674     public:
00675 
00679         inline CellPtr operator*();
00680 
00685         inline CellPtr operator->();
00686 
00692         inline bool operator!=(const AbstractCellPopulation<DIM>::Iterator& rOther);
00693 
00697         inline Iterator& operator++();
00698 
00705         Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter);
00706 
00710         virtual ~Iterator()
00711         {}
00712 
00713     private:
00714 
00721         virtual inline bool IsRealCell();
00722 
00726         inline bool IsAtEnd();
00727 
00729         AbstractCellPopulation& mrCellPopulation;
00730 
00732         std::list<CellPtr>::iterator mCellIter;
00733     };
00734 
00738     Iterator Begin();
00739 
00743     Iterator End();
00744 
00745 };
00746 
00747 enum cell_colours
00748 {
00749     STEM_COLOUR, // 0
00750     TRANSIT_COLOUR, // 1
00751     DIFFERENTIATED_COLOUR, // 2
00752     EARLY_CANCER_COLOUR, // 3
00753     LATE_CANCER_COLOUR, // 4
00754     LABELLED_COLOUR, // 5
00755     APOPTOSIS_COLOUR, // 6
00756     INVISIBLE_COLOUR // visualizer treats '7' as invisible
00757 };
00758 
00759 TEMPLATED_CLASS_IS_ABSTRACT_1_UNSIGNED(AbstractCellPopulation)
00760 
00761 
00762 //         Iterator class implementation - most methods are inlined         //
00764 
00765 template<unsigned DIM>
00766 CellPtr AbstractCellPopulation<DIM>::Iterator::operator*()
00767 {
00768     assert(!IsAtEnd());
00769     return *mCellIter;
00770 }
00771 
00772 template<unsigned DIM>
00773 CellPtr AbstractCellPopulation<DIM>::Iterator::operator->()
00774 {
00775     assert(!IsAtEnd());
00776     return *mCellIter;
00777 }
00778 
00779 template<unsigned DIM>
00780 bool AbstractCellPopulation<DIM>::Iterator::operator!=(const AbstractCellPopulation<DIM>::Iterator& rOther)
00781 {
00782     return mCellIter != rOther.mCellIter;
00783 }
00784 
00785 template<unsigned DIM>
00786 typename AbstractCellPopulation<DIM>::Iterator& AbstractCellPopulation<DIM>::Iterator::operator++()
00787 {
00788     do
00789     {
00790         ++mCellIter;
00791     }
00792     while (!IsAtEnd() && !IsRealCell());
00793 
00794     return (*this);
00795 }
00796 
00797 template<unsigned DIM>
00798 bool AbstractCellPopulation<DIM>::Iterator::IsRealCell()
00799 {
00800     return !( mrCellPopulation.IsCellAssociatedWithADeletedLocation(*mCellIter) || (*this)->IsDead() );
00801 }
00802 
00803 template<unsigned DIM>
00804 bool AbstractCellPopulation<DIM>::Iterator::IsAtEnd()
00805 {
00806     return mCellIter == mrCellPopulation.rGetCells().end();
00807 }
00808 
00809 template<unsigned DIM>
00810 AbstractCellPopulation<DIM>::Iterator::Iterator(AbstractCellPopulation& rCellPopulation, std::list<CellPtr>::iterator cellIter)
00811     : mrCellPopulation(rCellPopulation),
00812       mCellIter(cellIter)
00813 {
00814     // The cell population can now return empty if it only has ghost nodes
00815     if (mrCellPopulation.rGetCells().empty())
00816     {
00817         mCellIter = mrCellPopulation.rGetCells().end();
00818     }
00819     else
00820     {
00821         // Make sure we start at a real cell
00822         if (mCellIter == mrCellPopulation.rGetCells().begin() && !IsRealCell())
00823         {
00824             ++(*this);
00825         }
00826     }
00827 }
00828 
00829 template<unsigned DIM>
00830 typename AbstractCellPopulation<DIM>::Iterator AbstractCellPopulation<DIM>::Begin()
00831 {
00832     return Iterator(*this, this->mCells.begin());
00833 }
00834 
00835 template<unsigned DIM>
00836 typename AbstractCellPopulation<DIM>::Iterator AbstractCellPopulation<DIM>::End()
00837 {
00838     return Iterator(*this, this->mCells.end());
00839 }
00840 
00841 
00842 #endif /*ABSTRACTCELLPOPULATION_HPP_*/

Generated on Tue May 31 14:31:40 2011 for Chaste by  doxygen 1.5.5