Chaste Release::3.1
CellsGenerator.hpp
00001 /*
00002 
00003 Copyright (c) 2005-2012, University of Oxford.
00004 All rights reserved.
00005 
00006 University of Oxford means the Chancellor, Masters and Scholars of the
00007 University of Oxford, having an administrative office at Wellington
00008 Square, Oxford OX1 2JD, UK.
00009 
00010 This file is part of Chaste.
00011 
00012 Redistribution and use in source and binary forms, with or without
00013 modification, are permitted provided that the following conditions are met:
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016  * Redistributions in binary form must reproduce the above copyright notice,
00017    this list of conditions and the following disclaimer in the documentation
00018    and/or other materials provided with the distribution.
00019  * Neither the name of the University of Oxford nor the names of its
00020    contributors may be used to endorse or promote products derived from this
00021    software without specific prior written permission.
00022 
00023 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00027 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
00029 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00030 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 
00034 */
00035 
00036 #ifndef CELLSGENERATOR_HPP_
00037 #define CELLSGENERATOR_HPP_
00038 
00039 
00040 #include <vector>
00041 #include "Cell.hpp"
00042 #include "WildTypeCellMutationState.hpp"
00043 #include "RandomNumberGenerator.hpp"
00044 
00050 template<class CELL_CYCLE_MODEL, unsigned DIM>
00051 class CellsGenerator
00052 {
00053 public:
00054 
00066     void GenerateBasic(std::vector<CellPtr>& rCells,
00067                        unsigned numCells,
00068                        const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00069                        CellProliferativeType cellProliferativeType=STEM);
00070 
00080     void GenerateBasicRandom(std::vector<CellPtr>& rCells,
00081                              unsigned numCells,
00082                              CellProliferativeType cellProliferativeType=STEM);
00083 
00091     void GenerateGivenLocationIndices(std::vector<CellPtr>& rCells,
00092                                       const std::vector<unsigned> locationIndices,
00093                                       CellProliferativeType cellProliferativeType=STEM);
00094 };
00095 
00096 template<class CELL_CYCLE_MODEL, unsigned DIM>
00097 void CellsGenerator<CELL_CYCLE_MODEL,DIM>::GenerateBasic(std::vector<CellPtr>& rCells,
00098                                                          unsigned numCells,
00099                                                          const std::vector<unsigned> locationIndices,
00100                                                          CellProliferativeType cellProliferativeType)
00101 {
00102     CellPropertyRegistry::Instance()->Clear();
00103     rCells.clear();
00104     if (!locationIndices.empty())
00105     {
00106         // If location indices is given, then it needs to match the number of output cells
00107         if (numCells != locationIndices.size())
00108         {
00109             EXCEPTION("The size of the locationIndices vector must match the required number of output cells");
00110         }
00111     }
00112     rCells.reserve(numCells);
00113 
00114     // Create cells
00115     for (unsigned i=0; i<numCells; i++)
00116     {
00117         CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00118         p_cell_cycle_model->SetDimension(DIM);
00119 
00120         boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00121         CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00122         p_cell->SetCellProliferativeType(cellProliferativeType);
00123 
00124         double birth_time;
00125         if (!locationIndices.empty())
00126         {
00127             birth_time = 0.0 - locationIndices[i];
00128         }
00129         else
00130         {
00131             birth_time = 0.0 - i;
00132         }
00133 
00134         p_cell->SetBirthTime(birth_time);
00135         rCells.push_back(p_cell);
00136     }
00137 }
00138 
00139 template<class CELL_CYCLE_MODEL, unsigned DIM>
00140 void CellsGenerator<CELL_CYCLE_MODEL,DIM>::GenerateBasicRandom(std::vector<CellPtr>& rCells,
00141                                                                unsigned numCells,
00142                                                                CellProliferativeType cellProliferativeType)
00143 {
00144     CellPropertyRegistry::Instance()->Clear();
00145     rCells.clear();
00146     rCells.reserve(numCells);
00147 
00148     // Create cells
00149     for (unsigned i=0; i<numCells; i++)
00150     {
00151         CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00152         p_cell_cycle_model->SetDimension(DIM);
00153 
00154         boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00155         CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00156         p_cell->SetCellProliferativeType(cellProliferativeType);
00157 
00158         double birth_time = -p_cell_cycle_model->GetAverageStemCellCycleTime()*RandomNumberGenerator::Instance()->ranf();
00159 
00160         if (cellProliferativeType == TRANSIT)
00161         {
00162             birth_time = -p_cell_cycle_model->GetAverageTransitCellCycleTime()*RandomNumberGenerator::Instance()->ranf();
00163         }
00164 
00165         p_cell->SetBirthTime(birth_time);
00166         rCells.push_back(p_cell);
00167     }
00168 }
00169 
00170 template<class CELL_CYCLE_MODEL, unsigned DIM>
00171 void CellsGenerator<CELL_CYCLE_MODEL,DIM>::GenerateGivenLocationIndices(std::vector<CellPtr>& rCells,
00172                                                                         const std::vector<unsigned> locationIndices,
00173                                                                         CellProliferativeType cellProliferativeType)
00174 {
00175     assert(!locationIndices.empty());
00176 
00177     unsigned num_cells = locationIndices.size();
00178 
00179     rCells.clear();
00180     rCells.reserve(num_cells);
00181     CellPropertyRegistry::Instance()->Clear();
00182 
00183     for (unsigned i=0; i<num_cells; i++)
00184     {
00185         CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00186         p_cell_cycle_model->SetDimension(DIM);
00187 
00188         boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00189 
00190         CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00191         p_cell->SetCellProliferativeType(cellProliferativeType);
00192 
00193         double birth_time = 0.0 - locationIndices[i];
00194         p_cell->SetBirthTime(birth_time);
00195         rCells.push_back(p_cell);
00196     }
00197 }
00198 
00199 #endif /* CELLSGENERATOR_HPP_ */