CryptCellsGenerator.hpp

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

Generated by  doxygen 1.6.2