CryptProjectionStatistics.cpp

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 #include "CryptProjectionStatistics.hpp"
00029 #include "RandomNumberGenerator.hpp"
00030 
00035 bool CellsRadiusComparison(const std::pair<CellPtr, double> lhs, const std::pair<CellPtr, double> rhs)
00036 {
00037     return lhs.second < rhs.second;
00038 }
00039 
00040 CryptProjectionStatistics::CryptProjectionStatistics(MeshBasedCellPopulation<2>& rCrypt)
00041     : AbstractCryptStatistics(rCrypt)
00042 {
00043 }
00044 
00045 bool CryptProjectionStatistics::CellIsInSection(double angle, const c_vector<double,2>& rCellPosition, double widthOfSection)
00046 {
00047     // Get corresponding 3D position of closest point on line
00048     c_vector<double,2> line_position;
00049     line_position[0] = norm_2(rCellPosition)*cos(angle);
00050     line_position[1] = norm_2(rCellPosition)*sin(angle);
00051 
00052     double distance_between_cell_and_line = norm_2(rCellPosition - line_position);
00053 
00054     return (distance_between_cell_and_line <= widthOfSection);
00055 }
00056 
00057 std::vector<CellPtr> CryptProjectionStatistics::GetCryptSection(double angle)
00058 {
00059     if (angle == DBL_MAX)
00060     {
00061         angle = M_PI - 2*M_PI*RandomNumberGenerator::Instance()->ranf();
00062     }
00063 
00064     assert(angle>=-M_PI && angle<=M_PI);
00065 
00066     std::list<std::pair<CellPtr, double> > cells_list; // the second entry is the radius (needed for sorting)
00067 
00068 
00069     // Loop over cells and add to the store if they are within a cell's radius of the
00070     // specified line
00071     for (AbstractCellPopulation<2>::Iterator cell_iter = mrCrypt.Begin();
00072          cell_iter != mrCrypt.End();
00073          ++cell_iter)
00074     {
00075 
00076         if (CellIsInSection(angle, mrCrypt.GetLocationOfCellCentre(*cell_iter)))
00077         {
00078             // Set up a pair, equal to (cell,r) and insert
00079             std::pair<CellPtr, double> pair(*cell_iter, norm_2(mrCrypt.GetLocationOfCellCentre(*cell_iter)));
00080             cells_list.push_back(pair);
00081         }
00082     }
00083 
00084     // Sort the list
00085     cells_list.sort(CellsRadiusComparison);
00086 
00087     // Copy to a vector
00088     std::vector<CellPtr> ordered_cells;
00089     for (std::list<std::pair<CellPtr, double> >::iterator iter = cells_list.begin();
00090          iter != cells_list.end();
00091          ++iter)
00092     {
00093         ordered_cells.push_back(iter->first);
00094     }
00095 
00096     return ordered_cells;
00097 }
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3