CryptStatistics.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 "CryptStatistics.hpp"
00036 #include "RandomNumberGenerator.hpp"
00037
00042 bool CellsHeightComparison(const std::pair<CellPtr, double> lhs, const std::pair<CellPtr, double> rhs)
00043 {
00044 return lhs.second < rhs.second;
00045 }
00046
00047 CryptStatistics::CryptStatistics(MeshBasedCellPopulation<2>& rCrypt)
00048 : AbstractCryptStatistics(rCrypt)
00049 {
00050 }
00051
00052 std::vector<CellPtr> CryptStatistics::GetCryptSection(double yTop, double xBottom, double xTop, bool periodic)
00053 {
00054 double crypt_width = mrCrypt.rGetMesh().GetWidth(0);
00055
00056
00057 if (xBottom == DBL_MAX)
00058 {
00059 xBottom = RandomNumberGenerator::Instance()->ranf()*crypt_width;
00060 }
00061
00062 if (xTop == DBL_MAX)
00063 {
00064 xTop = RandomNumberGenerator::Instance()->ranf()*crypt_width;
00065 }
00066
00067 assert(yTop>0.0);
00068 std::list<std::pair<CellPtr, double> > cells_list;
00069
00070 if (fabs(xTop-xBottom)<0.5*crypt_width)
00071 {
00072
00073 periodic = false;
00074 }
00075
00076
00077 for (AbstractCellPopulation<2>::Iterator cell_iter = mrCrypt.Begin();
00078 cell_iter != mrCrypt.End();
00079 ++cell_iter)
00080 {
00081 if (periodic)
00082 {
00083 if (CellIsInSectionPeriodic(xBottom, xTop, yTop, mrCrypt.GetLocationOfCellCentre(*cell_iter)))
00084 {
00085
00086 std::pair<CellPtr, double> pair(*cell_iter, mrCrypt.GetLocationOfCellCentre(*cell_iter)[1]);
00087 cells_list.push_back(pair);
00088 }
00089 }
00090 else
00091 {
00092 if (CellIsInSection(xBottom, xTop, yTop, mrCrypt.GetLocationOfCellCentre(*cell_iter)))
00093 {
00094
00095 std::pair<CellPtr, double> pair(*cell_iter, mrCrypt.GetLocationOfCellCentre(*cell_iter)[1]);
00096 cells_list.push_back(pair);
00097 }
00098 }
00099 }
00100
00101
00102 cells_list.sort(CellsHeightComparison);
00103
00104
00105 std::vector<CellPtr> ordered_cells;
00106 for (std::list<std::pair<CellPtr, double> >::iterator iter = cells_list.begin();
00107 iter!=cells_list.end();
00108 ++iter)
00109 {
00110 ordered_cells.push_back(iter->first);
00111 }
00112
00113 return ordered_cells;
00114 }
00115
00116 std::vector<CellPtr> CryptStatistics::GetCryptSectionPeriodic(double yTop, double xBottom, double xTop)
00117 {
00118 return GetCryptSection(yTop, xBottom, xTop, true);
00119 }
00120 bool CryptStatistics::CellIsInSection(double xBottom, double xTop, double yTop, const c_vector<double,2>& rCellPosition, double widthOfSection)
00121 {
00122 c_vector<double,2> intercept;
00123
00124 if (xBottom == xTop)
00125 {
00126 intercept[0] = xTop;
00127 intercept[1] = rCellPosition[1];
00128 }
00129 else
00130 {
00131 double m = (yTop)/(xTop-xBottom);
00132
00133 intercept[0] = (m*m*xBottom + rCellPosition[0] + m*rCellPosition[1])/(1+m*m);
00134 intercept[1] = m*(intercept[0] - xBottom);
00135 }
00136
00137 c_vector<double,2> vec_from_A_to_B = mrCrypt.rGetMesh().GetVectorFromAtoB(intercept, rCellPosition);
00138 double dist = norm_2(vec_from_A_to_B);
00139
00140 return (dist <= widthOfSection);
00141 }
00142
00143 bool CryptStatistics::CellIsInSectionPeriodic(double xBottom, double xTop, double yTop, const c_vector<double,2>& rCellPosition, double widthOfSection)
00144 {
00145 bool is_in_section = false;
00146
00147 c_vector<double,2> intercept;
00148 double crypt_width = mrCrypt.rGetMesh().GetWidth(0u);
00149
00150 double m;
00151 double offset;
00152
00153 if (xBottom < xTop)
00154 {
00155 offset = -crypt_width;
00156 }
00157 else
00158 {
00159 offset = crypt_width;
00160 }
00161
00162 m = (yTop)/(xTop-xBottom+offset);
00163
00164
00165 intercept[0] = (m*m*xBottom + rCellPosition[0] + m*rCellPosition[1])/(1+m*m);
00166 intercept[1] = m*(intercept[0] - xBottom);
00167
00168 c_vector<double,2> vec_from_A_to_B = mrCrypt.rGetMesh().GetVectorFromAtoB(intercept, rCellPosition);
00169 double dist = norm_2(vec_from_A_to_B);
00170
00171 if (dist < widthOfSection)
00172 {
00173 is_in_section = true;
00174 }
00175
00176
00177 intercept[0] = (m*m*(xBottom-offset) + rCellPosition[0] + m*rCellPosition[1])/(1+m*m);
00178 intercept[1] = m*(intercept[0] - (xBottom-offset));
00179
00180 vec_from_A_to_B = mrCrypt.rGetMesh().GetVectorFromAtoB(intercept, rCellPosition);
00181 dist = norm_2(vec_from_A_to_B);
00182
00183 if (dist < widthOfSection)
00184 {
00185 is_in_section = true;
00186 }
00187
00188 return is_in_section;
00189 }