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