CryptCellsGenerator.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 CRYPTCELLSGENERATOR_HPP_
00029 #define CRYPTCELLSGENERATOR_HPP_
00030 
00031 #include <boost/mpl/integral_c.hpp>
00032 #include <boost/type_traits/is_same.hpp>
00033 #include <boost/mpl/if.hpp>
00034 
00035 #include "CellsGenerator.hpp"
00036 
00037 #include "CellPropertyRegistry.hpp"
00038 #include "TetrahedralMesh.hpp"
00039 #include "VertexMesh.hpp"
00040 
00041 #include "StochasticDurationGenerationBasedCellCycleModel.hpp"
00042 #include "FixedDurationGenerationBasedCellCycleModel.hpp"
00043 #include "TysonNovakCellCycleModel.hpp"
00044 #include "WntCellCycleModel.hpp"
00045 #include "SimpleWntCellCycleModel.hpp"
00046 #include "StochasticWntCellCycleModel.hpp"
00047 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisOne.hpp"
00048 #include "VanLeeuwen2009WntSwatCellCycleModelHypothesisTwo.hpp"
00049 
00050 
00055 template<class T1, class T2>
00056 bool ClassesAreSame()
00057 {
00058     using namespace boost::mpl;
00059     using namespace boost;
00060     typedef typename if_< is_same<T1, T2>, integral_c<unsigned, 1>, integral_c<unsigned, 0> >::type selector_t;
00061     return  (selector_t()==1);
00062 }
00063 
00064 
00070 template<class CELL_CYCLE_MODEL>
00071 class CryptCellsGenerator : public CellsGenerator<CELL_CYCLE_MODEL,2>
00072 {
00073 public:
00074 
00092     void Generate(std::vector<CellPtr>& rCells,
00093                   AbstractMesh<2,2>* pMesh,
00094                   const std::vector<unsigned> locationIndices,
00095                   bool randomBirthTimes,
00096                   double y0 = 0.3,
00097                   double y1 = 2.0,
00098                   double y2 = 3.0,
00099                   double y3 = 4.0,
00100                   bool initialiseCells = false);
00101 };
00102 
00103 
00104 template<class CELL_CYCLE_MODEL>
00105 void CryptCellsGenerator<CELL_CYCLE_MODEL>::Generate(
00106                                       std::vector<CellPtr>& rCells,
00107                                       AbstractMesh<2,2>* pMesh,
00108                                       const std::vector<unsigned> locationIndices,
00109                                       bool randomBirthTimes,
00110                                       double y0,
00111                                       double y1,
00112                                       double y2,
00113                                       double y3,
00114                                       bool initialiseCells)
00115 {
00116     CellPropertyRegistry::Instance()->Clear();
00117 
00118     RandomNumberGenerator* p_random_num_gen = RandomNumberGenerator::Instance();
00119 
00120     rCells.clear();
00121 
00122     unsigned mesh_size;
00123     if (dynamic_cast<TetrahedralMesh<2,2>*>(pMesh))
00124     {
00125         mesh_size = pMesh->GetNumNodes();
00126         unsigned num_cells = locationIndices.empty() ? pMesh->GetNumNodes() : locationIndices.size();
00127         rCells.reserve(num_cells);
00128     }
00129     else
00130     {
00131         /*
00132          * We cannot directly assert this dynamic cast. This is because the assert macro
00133          * doesn't understand the <2,2> and thinks that it is being passed two arguments.
00134          */
00135         bool is_vertex_mesh = (dynamic_cast<VertexMesh<2,2>*>(pMesh));
00136         if (!is_vertex_mesh)
00137         {
00138             NEVER_REACHED;
00139         }
00140         mesh_size = static_cast<VertexMesh<2,2>*>(pMesh)->GetNumElements();
00141         rCells.reserve(mesh_size);
00142     }
00143 
00144     for (unsigned i=0; i<mesh_size; i++)
00145     {
00146         CellProliferativeType cell_type;
00147         unsigned generation;
00148 
00149         double y = 0.0;
00150 
00151         if (dynamic_cast<TetrahedralMesh<2,2>*>(pMesh))
00152         {
00153             if (locationIndices.empty())
00154             {
00155                 y = pMesh->GetNode(i)->GetPoint().rGetLocation()[1];
00156 
00157             }
00158             else if ( std::find(locationIndices.begin(), locationIndices.end(), i) != locationIndices.end() )
00159             {
00160                 y = pMesh->GetNode(i)->GetPoint().rGetLocation()[1];
00161             }
00162         }
00163         else
00164         {
00165             /*
00166              * We cannot directly assert this dynamic cast. This is because the assert macro
00167              * doesn't understand the <2,2> and thinks that it is being passed two arguments.
00168              */
00169             bool is_vertex_mesh = (dynamic_cast<VertexMesh<2,2>*>(pMesh));
00170             if (!is_vertex_mesh)
00171             {
00172                 NEVER_REACHED;
00173             }
00174             y = dynamic_cast<VertexMesh<2,2>*>(pMesh)->GetCentroidOfElement(i)[1];
00175         }
00176 
00177         CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00178         p_cell_cycle_model->SetDimension(2);
00179 
00180         double typical_transit_cycle_time = p_cell_cycle_model->GetAverageTransitCellCycleTime();
00181         double typical_stem_cycle_time = p_cell_cycle_model->GetAverageStemCellCycleTime();
00182 
00183         double birth_time = 0.0;
00184         if (randomBirthTimes)
00185         {
00186             birth_time = -p_random_num_gen->ranf();
00187         }
00188 
00189         if (y <= y0)
00190         {
00191             cell_type = STEM;
00192             generation = 0;
00193             birth_time *= typical_stem_cycle_time; // hours
00194         }
00195         else if (y < y1)
00196         {
00197             cell_type = TRANSIT;
00198             generation = 1;
00199             birth_time *= typical_transit_cycle_time; // hours
00200         }
00201         else if (y < y2)
00202         {
00203             cell_type = TRANSIT;
00204             generation = 2;
00205             birth_time *= typical_transit_cycle_time; // hours
00206         }
00207         else if (y < y3)
00208         {
00209             cell_type = TRANSIT;
00210             generation = 3;
00211             birth_time *= typical_transit_cycle_time; // hours
00212         }
00213         else
00214         {
00215             cell_type = p_cell_cycle_model->CanCellTerminallyDifferentiate() ? DIFFERENTIATED : TRANSIT;
00216             generation = 4;
00217             birth_time *= typical_transit_cycle_time; // hours
00218         }
00219 
00220         if (dynamic_cast<AbstractSimpleGenerationBasedCellCycleModel*>(p_cell_cycle_model))
00221         {
00222             dynamic_cast<AbstractSimpleGenerationBasedCellCycleModel*>(p_cell_cycle_model)->SetGeneration(generation);
00223         }
00224         p_cell_cycle_model->SetCellProliferativeType(cell_type);
00225 
00226         boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00227 
00228         CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00229 
00230         if (initialiseCells)
00231         {
00232             p_cell->InitialiseCellCycleModel();
00233         }
00234 
00235         p_cell->SetBirthTime(birth_time);
00236 
00237         if (locationIndices.empty())
00238         {
00239             rCells.push_back(p_cell);
00240         }
00241         else if ( std::find(locationIndices.begin(), locationIndices.end(), i) != locationIndices.end() )
00242         {
00243             rCells.push_back(p_cell);
00244         }
00245     }
00246 }
00247 
00248 #endif /* CRYPTCELLSGENERATOR_HPP_ */

Generated on Mon Apr 18 11:35:28 2011 for Chaste by  doxygen 1.5.5