CellsGenerator.hpp

00001 /*
00002 
00003 Copyright (c) 2005-2015, 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 #include <vector>
00040 #include "Cell.hpp"
00041 #include "WildTypeCellMutationState.hpp"
00042 #include "StemCellProliferativeType.hpp"
00043 #include "TransitCellProliferativeType.hpp"
00044 #include "RandomNumberGenerator.hpp"
00045 
00051 template<class CELL_CYCLE_MODEL, unsigned DIM>
00052 class CellsGenerator
00053 {
00054 public:
00055 
00067     void GenerateBasic(std::vector<CellPtr>& rCells,
00068                        unsigned numCells,
00069                        const std::vector<unsigned> locationIndices=std::vector<unsigned>(),
00070                        boost::shared_ptr<AbstractCellProperty> pCellProliferativeType=boost::shared_ptr<AbstractCellProperty>());
00071 
00081     void GenerateBasicRandom(std::vector<CellPtr>& rCells,
00082                              unsigned numCells,
00083                              boost::shared_ptr<AbstractCellProperty> pCellProliferativeType=boost::shared_ptr<AbstractCellProperty>());
00084 
00092     void GenerateGivenLocationIndices(std::vector<CellPtr>& rCells,
00093                                       const std::vector<unsigned> locationIndices,
00094                                       boost::shared_ptr<AbstractCellProperty> pCellProliferativeType=boost::shared_ptr<AbstractCellProperty>());
00095 };
00096 
00097 template<class CELL_CYCLE_MODEL, unsigned DIM>
00098 void CellsGenerator<CELL_CYCLE_MODEL,DIM>::GenerateBasic(std::vector<CellPtr>& rCells,
00099                                                          unsigned numCells,
00100                                                          const std::vector<unsigned> locationIndices,
00101                                                          boost::shared_ptr<AbstractCellProperty> pCellProliferativeType)
00102 {
00103     rCells.clear();
00104 
00105     if (!locationIndices.empty())
00106     {
00107         // If location indices is given, then it needs to match the number of output cells
00108         if (numCells != locationIndices.size())
00109         {
00110             EXCEPTION("The size of the locationIndices vector must match the required number of output cells");
00111         }
00112     }
00113     rCells.reserve(numCells);
00114 
00115     // Create cells
00116     for (unsigned i=0; i<numCells; i++)
00117     {
00118         CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00119         p_cell_cycle_model->SetDimension(DIM);
00120 
00121         boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00122         CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00123 
00124         if (!pCellProliferativeType)
00125         {
00126             p_cell->SetCellProliferativeType(CellPropertyRegistry::Instance()->Get<StemCellProliferativeType>());
00127         }
00128         else
00129         {
00130             p_cell->SetCellProliferativeType(pCellProliferativeType);
00131         }
00132 
00133         double birth_time;
00134         if (!locationIndices.empty())
00135         {
00136             birth_time = 0.0 - locationIndices[i];
00137         }
00138         else
00139         {
00140             birth_time = 0.0 - i;
00141         }
00142 
00143         p_cell->SetBirthTime(birth_time);
00144         rCells.push_back(p_cell);
00145     }
00146 }
00147 
00148 template<class CELL_CYCLE_MODEL, unsigned DIM>
00149 void CellsGenerator<CELL_CYCLE_MODEL,DIM>::GenerateBasicRandom(std::vector<CellPtr>& rCells,
00150                                                                unsigned numCells,
00151                                                                boost::shared_ptr<AbstractCellProperty> pCellProliferativeType)
00152 {
00153     rCells.clear();
00154 
00155     rCells.reserve(numCells);
00156 
00157     // Create cells
00158     for (unsigned i=0; i<numCells; i++)
00159     {
00160         CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00161         p_cell_cycle_model->SetDimension(DIM);
00162 
00163         boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00164         CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00165 
00166         if (!pCellProliferativeType)
00167         {
00168             p_cell->SetCellProliferativeType(CellPropertyRegistry::Instance()->Get<StemCellProliferativeType>());
00169         }
00170         else
00171         {
00172             p_cell->SetCellProliferativeType(pCellProliferativeType);
00173         }
00174 
00175         double birth_time = -p_cell_cycle_model->GetAverageStemCellCycleTime()*RandomNumberGenerator::Instance()->ranf();
00176 
00177         if (p_cell->GetCellProliferativeType()->IsType<TransitCellProliferativeType>())
00178         {
00179             birth_time = -p_cell_cycle_model->GetAverageTransitCellCycleTime()*RandomNumberGenerator::Instance()->ranf();
00180         }
00181 
00182         p_cell->SetBirthTime(birth_time);
00183         rCells.push_back(p_cell);
00184     }
00185 }
00186 
00187 template<class CELL_CYCLE_MODEL, unsigned DIM>
00188 void CellsGenerator<CELL_CYCLE_MODEL,DIM>::GenerateGivenLocationIndices(std::vector<CellPtr>& rCells,
00189                                                                         const std::vector<unsigned> locationIndices,
00190                                                                         boost::shared_ptr<AbstractCellProperty> pCellProliferativeType)
00191 {
00192     assert(!locationIndices.empty());
00193 
00194     unsigned num_cells = locationIndices.size();
00195 
00196     rCells.clear();
00197     rCells.reserve(num_cells);
00198     CellPropertyRegistry::Instance()->Clear();
00199 
00200     for (unsigned i=0; i<num_cells; i++)
00201     {
00202         CELL_CYCLE_MODEL* p_cell_cycle_model = new CELL_CYCLE_MODEL;
00203         p_cell_cycle_model->SetDimension(DIM);
00204 
00205         boost::shared_ptr<AbstractCellProperty> p_state(CellPropertyRegistry::Instance()->Get<WildTypeCellMutationState>());
00206 
00207         CellPtr p_cell(new Cell(p_state, p_cell_cycle_model));
00208 
00209         if (!pCellProliferativeType)
00210         {
00211             p_cell->SetCellProliferativeType(CellPropertyRegistry::Instance()->Get<StemCellProliferativeType>());
00212         }
00213         else
00214         {
00215             p_cell->SetCellProliferativeType(pCellProliferativeType);
00216         }
00217 
00218         double birth_time = 0.0 - locationIndices[i];
00219         p_cell->SetBirthTime(birth_time);
00220         rCells.push_back(p_cell);
00221     }
00222 }
00223 
00224 #endif /* CELLSGENERATOR_HPP_ */

Generated by  doxygen 1.6.2