00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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;
00067
00068
00069
00070
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
00079 std::pair<CellPtr, double> pair(*cell_iter, norm_2(mrCrypt.GetLocationOfCellCentre(*cell_iter)));
00080 cells_list.push_back(pair);
00081 }
00082 }
00083
00084
00085 cells_list.sort(CellsRadiusComparison);
00086
00087
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 }