AbstractCellsGenerator.cpp

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 
00029 #include "AbstractCellsGenerator.hpp"
00030 
00032 // Implementation
00034 
00035 template<unsigned DIM>
00036 bool AbstractCellsGenerator<DIM>::CellsCanDifferentiate()
00037 {
00038     return false;
00039 }
00040 
00041 template<unsigned DIM>
00042 void AbstractCellsGenerator<DIM>::GenerateForCrypt(std::vector<TissueCell>& rCells,
00043                                  TetrahedralMesh<2,2>& rMesh,
00044                                  const std::vector<unsigned> locationIndices,
00045                                  bool randomBirthTimes,
00046                                  double y0,
00047                                  double y1,
00048                                  double y2,
00049                                  double y3,
00050                                  bool initialiseCells)
00051 {
00052     #define COVERAGE_IGNORE
00053     assert(DIM==2);
00054     #undef COVERAGE_IGNORE
00055 
00056     RandomNumberGenerator *p_random_num_gen = RandomNumberGenerator::Instance();
00057 
00058     unsigned num_cells = rMesh.GetNumNodes();
00059     if (!locationIndices.empty())
00060     {
00061         num_cells = locationIndices.size();
00062     }
00063 
00064     AbstractCellCycleModel *p_cell_cycle_model = NULL;
00065     double typical_transit_cycle_time;
00066     double typical_stem_cycle_time;
00067 
00068     rCells.clear();
00069     rCells.reserve(num_cells);
00070 
00071     for (unsigned i=0; i<rMesh.GetNumNodes(); i++)
00072     {
00073         CellType cell_type;
00074         unsigned generation;
00075 
00076         double y = 0.0;
00077         if (!locationIndices.empty())
00078         {
00079             if ( std::find(locationIndices.begin(), locationIndices.end(), i) != locationIndices.end() )
00080             {
00081                 y = rMesh.GetNode(i)->GetPoint().rGetLocation()[1];
00082             }
00083         }
00084         else
00085         {
00086             y = rMesh.GetNode(i)->GetPoint().rGetLocation()[1];
00087         }
00088 
00089         p_cell_cycle_model = CreateCellCycleModel();
00090         typical_transit_cycle_time = this->GetTypicalTransitCellCycleTime();
00091         typical_stem_cycle_time = GetTypicalStemCellCycleTime();
00092 
00093         double birth_time = 0.0;
00094         if (randomBirthTimes)
00095         {
00096             birth_time = -p_random_num_gen->ranf();
00097         }
00098 
00099         if (y <= y0)
00100         {
00101             cell_type = STEM;
00102             generation = 0;
00103             birth_time *= typical_stem_cycle_time; // hours
00104         }
00105         else if (y < y1)
00106         {
00107             cell_type = TRANSIT;
00108             generation = 1;
00109             birth_time *= typical_transit_cycle_time; // hours
00110         }
00111         else if (y < y2)
00112         {
00113             cell_type = TRANSIT;
00114             generation = 2;
00115             birth_time *= typical_transit_cycle_time; // hours
00116         }
00117         else if (y < y3)
00118         {
00119             cell_type = TRANSIT;
00120             generation = 3;
00121             birth_time *= typical_transit_cycle_time; // hours
00122         }
00123         else
00124         {
00125             cell_type = CellsCanDifferentiate() ? DIFFERENTIATED : TRANSIT;
00126             generation = 4;
00127             birth_time *= typical_transit_cycle_time; // hours
00128         }
00129 
00130         if (dynamic_cast<AbstractSimpleGenerationBasedCellCycleModel*>(p_cell_cycle_model))
00131         {
00132             static_cast<AbstractSimpleGenerationBasedCellCycleModel*>(p_cell_cycle_model)->SetGeneration(generation);
00133         }
00134 
00135         TissueCell cell(cell_type, HEALTHY, p_cell_cycle_model);
00136         if (initialiseCells)
00137         {
00138             cell.InitialiseCellCycleModel();
00139         }
00140 
00141         cell.SetBirthTime(birth_time);
00142 
00143         if (!locationIndices.empty())
00144         {
00145             if ( std::find(locationIndices.begin(), locationIndices.end(), i) != locationIndices.end() )
00146             {
00147                 rCells.push_back(cell);
00148             }
00149         }
00150         else
00151         {
00152             rCells.push_back(cell);
00153         }
00154     }
00155 }
00156 
00157 template<unsigned DIM>
00158 void AbstractCellsGenerator<DIM>::GenerateBasic(std::vector<TissueCell>& rCells,
00159                                                            const unsigned numCells)
00160 {
00161     rCells.clear();
00162     rCells.reserve(numCells);
00163 
00164     for (unsigned i=0; i<numCells; i++)
00165     {
00166         AbstractCellCycleModel *p_cell_cycle_model = CreateCellCycleModel();
00167         TissueCell cell(STEM, HEALTHY, p_cell_cycle_model);
00168         double birth_time = 0.0 - i;
00169         cell.SetBirthTime(birth_time);
00170         rCells.push_back(cell);
00171     }
00172 }
00173 
00175 // Explicit instantiation
00177 
00178 template class AbstractCellsGenerator<1>;
00179 template class AbstractCellsGenerator<2>;
00180 template class AbstractCellsGenerator<3>;

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