AbstractCellsGenerator.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 ABSTRACTCELLSGENERATOR_HPP_
00029 #define ABSTRACTCELLSGENERATOR_HPP_
00030 
00031 #include "TetrahedralMesh.hpp"
00032 #include "TissueCell.hpp"
00033 #include "AbstractSimpleGenerationBasedCellCycleModel.hpp"
00034 
00035 
00041 template<unsigned DIM>
00042 class AbstractCellsGenerator
00043 {
00044 public:
00045 
00049     AbstractCellsGenerator()
00050     {}
00051 
00055     virtual AbstractCellCycleModel* CreateCellCycleModel()=0;
00056     
00062     virtual double GetTypicalTransitCellCycleTime()=0;
00063     
00069     virtual double GetTypicalStemCellCycleTime()=0;
00070     
00075     virtual bool CellsCanDifferentiate();
00076 
00080     virtual ~AbstractCellsGenerator()
00081     {}
00082 
00101     virtual void GenerateForCrypt(std::vector<TissueCell>& rCells,
00102                                   TetrahedralMesh<2,2>& rMesh,
00103                                   const std::vector<unsigned> locationIndices,
00104                                   bool randomBirthTimes,
00105                                   double y0 = 0.3,
00106                                   double y1 = 2.0,
00107                                   double y2 = 3.0,
00108                                   double y3 = 4.0,
00109                                   bool initialiseCells = false);
00110 };
00111 
00112 
00113 template<unsigned DIM>
00114 bool AbstractCellsGenerator<DIM>::CellsCanDifferentiate()
00115 {
00116     return false;
00117 }
00118 
00119 template<unsigned DIM>
00120 void AbstractCellsGenerator<DIM>::GenerateForCrypt(std::vector<TissueCell>& rCells,
00121                                  TetrahedralMesh<2,2>& rMesh,
00122                                  const std::vector<unsigned> locationIndices,
00123                                  bool randomBirthTimes,
00124                                  double y0,
00125                                  double y1,
00126                                  double y2,
00127                                  double y3,
00128                                  bool initialiseCells)
00129 {
00130     #define COVERAGE_IGNORE
00131     assert(DIM==2);
00132     #undef COVERAGE_IGNORE
00133     
00134     RandomNumberGenerator* p_random_num_gen = RandomNumberGenerator::Instance();
00135 
00136     unsigned num_cells = rMesh.GetNumNodes();    
00137     if (!locationIndices.empty())
00138     {
00139         num_cells = locationIndices.size();
00140     }
00141 
00142     AbstractCellCycleModel* p_cell_cycle_model = NULL;
00143     double typical_transit_cycle_time;
00144     double typical_stem_cycle_time;
00145 
00146     rCells.clear();
00147     rCells.reserve(num_cells);
00148 
00149     for (unsigned i=0; i<rMesh.GetNumNodes(); i++)
00150     {
00151         CellType cell_type;
00152         unsigned generation;
00153 
00154         double y = 0.0;
00155         if (!locationIndices.empty())
00156         {
00157             if ( std::find(locationIndices.begin(), locationIndices.end(), i) != locationIndices.end() )
00158             {
00159                 y = rMesh.GetNode(i)->GetPoint().rGetLocation()[1];
00160             }
00161         }
00162         else
00163         {
00164             y = rMesh.GetNode(i)->GetPoint().rGetLocation()[1];
00165         }
00166 
00167         p_cell_cycle_model = CreateCellCycleModel();
00168         typical_transit_cycle_time = this->GetTypicalTransitCellCycleTime();
00169         typical_stem_cycle_time = GetTypicalStemCellCycleTime();
00170 
00171         double birth_time = 0.0;
00172         if (randomBirthTimes)
00173         {
00174             birth_time = -p_random_num_gen->ranf();
00175         }
00176 
00177         if (y <= y0)
00178         {
00179             cell_type = STEM;
00180             generation = 0;
00181             birth_time *= typical_stem_cycle_time; // hours
00182         }
00183         else if (y < y1)
00184         {
00185             cell_type = TRANSIT;
00186             generation = 1;
00187             birth_time *= typical_transit_cycle_time; // hours
00188         }
00189         else if (y < y2)
00190         {
00191             cell_type = TRANSIT;
00192             generation = 2;
00193             birth_time *= typical_transit_cycle_time; // hours
00194         }
00195         else if (y < y3)
00196         {
00197             cell_type = TRANSIT;
00198             generation = 3;
00199             birth_time *= typical_transit_cycle_time; // hours
00200         }
00201         else
00202         {
00203             cell_type = CellsCanDifferentiate() ? DIFFERENTIATED : TRANSIT;
00204             generation = 4;
00205             birth_time *= typical_transit_cycle_time; // hours
00206         }
00207 
00208         if (dynamic_cast<AbstractSimpleGenerationBasedCellCycleModel*>(p_cell_cycle_model))
00209         {
00210             static_cast<AbstractSimpleGenerationBasedCellCycleModel*>(p_cell_cycle_model)->SetGeneration(generation);
00211         }
00212 
00213         TissueCell cell(cell_type, HEALTHY, p_cell_cycle_model);
00214         if (initialiseCells)
00215         {
00216             cell.InitialiseCellCycleModel();
00217         }
00218 
00219         cell.SetBirthTime(birth_time);
00220 
00221         if (!locationIndices.empty())
00222         {
00223             if ( std::find(locationIndices.begin(), locationIndices.end(), i) != locationIndices.end() )
00224             {
00225                 rCells.push_back(cell);
00226             }
00227         }
00228         else
00229         {
00230             rCells.push_back(cell);
00231         }
00232     }
00233 }
00234 
00235 #endif /*ABSTRACTCELLSGENERATOR_HPP_*/

Generated on Wed Mar 18 12:51:50 2009 for Chaste by  doxygen 1.5.5