CryptProjectionStatistics.cpp
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
00029
00030
00031
00032
00033
00034
00035 #include "CryptProjectionStatistics.hpp"
00036 #include "RandomNumberGenerator.hpp"
00037
00042 bool CellsRadiusComparison(const std::pair<CellPtr, double> lhs, const std::pair<CellPtr, double> rhs)
00043 {
00044 return lhs.second < rhs.second;
00045 }
00046
00047 CryptProjectionStatistics::CryptProjectionStatistics(MeshBasedCellPopulation<2>& rCrypt)
00048 : AbstractCryptStatistics(rCrypt)
00049 {
00050 }
00051
00052 bool CryptProjectionStatistics::CellIsInSection(double angle, const c_vector<double,2>& rCellPosition, double widthOfSection)
00053 {
00054
00055 c_vector<double,2> line_position;
00056 line_position[0] = norm_2(rCellPosition)*cos(angle);
00057 line_position[1] = norm_2(rCellPosition)*sin(angle);
00058
00059 double distance_between_cell_and_line = norm_2(rCellPosition - line_position);
00060
00061 return (distance_between_cell_and_line <= widthOfSection);
00062 }
00063
00064 std::vector<CellPtr> CryptProjectionStatistics::GetCryptSection(double angle)
00065 {
00066 if (angle == DBL_MAX)
00067 {
00068 angle = M_PI - 2*M_PI*RandomNumberGenerator::Instance()->ranf();
00069 }
00070
00071 assert(angle>=-M_PI && angle<=M_PI);
00072
00073 std::list<std::pair<CellPtr, double> > cells_list;
00074
00075
00076
00077 for (AbstractCellPopulation<2>::Iterator cell_iter = mrCrypt.Begin();
00078 cell_iter != mrCrypt.End();
00079 ++cell_iter)
00080 {
00081 if (CellIsInSection(angle, mrCrypt.GetLocationOfCellCentre(*cell_iter)))
00082 {
00083
00084 std::pair<CellPtr, double> pair(*cell_iter, norm_2(mrCrypt.GetLocationOfCellCentre(*cell_iter)));
00085 cells_list.push_back(pair);
00086 }
00087 }
00088
00089
00090 cells_list.sort(CellsRadiusComparison);
00091
00092
00093 std::vector<CellPtr> ordered_cells;
00094 for (std::list<std::pair<CellPtr, double> >::iterator iter = cells_list.begin();
00095 iter != cells_list.end();
00096 ++iter)
00097 {
00098 ordered_cells.push_back(iter->first);
00099 }
00100
00101 return ordered_cells;
00102 }