GBParticle.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "GBParticle.h"
  4. namespace OTSGBCalculate
  5. {
  6. using namespace std;
  7. using namespace OTSDATA;
  8. GB_CHEMICAL_TYPE GBParticle::IdentifyPartChemicalType(COTSParticlePtr Particle)
  9. {
  10. const CString STR_Al = _T("Al");
  11. const CString STR_SI = _T("Si");
  12. const CString STR_O = _T("O");
  13. const CString STR_SUL = _T("S");
  14. const CString STR_N = _T("N");
  15. const CString STR_Mn = _T("Mn");
  16. const CString STR_Fe = _T("Fe");
  17. const CString STR_C = _T("C");
  18. const double MIN_ELEMENT_SUM = 0.02;
  19. const double RICH_ELEMENT_SUM = 5;
  20. if (Particle->GetXrayInfo() == NULL)
  21. {
  22. return GB_CHEMICAL_TYPE::INVALID;
  23. }
  24. auto chamicalList = Particle->GetXrayInfo()->GetElementQuantifyData();
  25. double dOWeight = 0;
  26. double dSWeight = 0;
  27. double dNWeight = 0;
  28. double dSiWeight = 0;
  29. double dAlWeight = 0;
  30. double dMnWeight = 0;
  31. double dFeWeight = 0;
  32. double dCWeight = 0;
  33. for (auto pElChem : chamicalList)
  34. {
  35. if (pElChem->GetName().CompareNoCase(STR_O) == 0)
  36. {
  37. dOWeight = pElChem->GetPercentage();
  38. }
  39. else if (pElChem->GetName().CompareNoCase(STR_SUL) == 0)
  40. {
  41. dSWeight = pElChem->GetPercentage();
  42. }
  43. else if (pElChem->GetName().CompareNoCase(STR_N) == 0)
  44. {
  45. dNWeight = pElChem->GetPercentage();
  46. }
  47. else if (pElChem->GetName().CompareNoCase(STR_SI) == 0)
  48. {
  49. dSiWeight = pElChem->GetPercentage();
  50. }
  51. else if (pElChem->GetName().CompareNoCase(STR_Al) == 0)
  52. {
  53. dAlWeight = pElChem->GetPercentage();
  54. }
  55. else if (pElChem->GetName().CompareNoCase(STR_Mn) == 0)
  56. {
  57. dMnWeight = pElChem->GetPercentage();
  58. }
  59. else if (pElChem->GetName().CompareNoCase(STR_Fe) == 0)
  60. {
  61. dFeWeight = pElChem->GetPercentage();
  62. }
  63. else if (pElChem->GetName().CompareNoCase(STR_C) == 0)
  64. {
  65. dCWeight = pElChem->GetPercentage();
  66. }
  67. }
  68. if (dSWeight >= MIN_ELEMENT_SUM && dMnWeight > MIN_ELEMENT_SUM)
  69. {
  70. return GB_CHEMICAL_TYPE::CHE_S;
  71. }
  72. else if (dSWeight >= MIN_ELEMENT_SUM && dOWeight < MIN_ELEMENT_SUM)//
  73. {
  74. return GB_CHEMICAL_TYPE::CHE_S;
  75. }
  76. else if (dOWeight >= MIN_ELEMENT_SUM && dAlWeight >= MIN_ELEMENT_SUM)
  77. {
  78. return GB_CHEMICAL_TYPE::CHE_Al;
  79. }
  80. else if (dOWeight >= MIN_ELEMENT_SUM && dSiWeight >= MIN_ELEMENT_SUM)
  81. {
  82. return GB_CHEMICAL_TYPE::CHE_Si;
  83. }
  84. else if (dOWeight >= RICH_ELEMENT_SUM)
  85. {
  86. return GB_CHEMICAL_TYPE::CHE_O;
  87. }
  88. else
  89. {
  90. return GB_CHEMICAL_TYPE::INVALID;
  91. }
  92. }
  93. int GBParticle::GetFieldId()
  94. {
  95. COTSParticlePtr Particle = myOTSParts[0];
  96. for (auto p : myOTSParts)//get the longest particle
  97. {
  98. if (p->GetDMax() > Particle->GetDMax())
  99. {
  100. Particle = p;
  101. }
  102. }
  103. return Particle->GetFieldId();
  104. }
  105. CString GBParticle::GetParticleId()
  106. {
  107. COTSParticlePtr Particle = myOTSParts[0];
  108. CString partsid="";
  109. for (auto p : myOTSParts)
  110. {
  111. CString partid;
  112. partid.Format(_T("%d:%d "), p->GetFieldId(), p->GetParticleId());
  113. partsid += partid;
  114. }
  115. partsid.TrimRight();
  116. return partsid;
  117. }
  118. GB_WIDTH_TYPE GBParticle::CaculateLevelWidth( GB_CLASSIFY_TYPE a_nLevel)
  119. {
  120. COTSParticlePtr Particle= myOTSParts[0];
  121. for (auto p : myOTSParts)//get the longest particle
  122. {
  123. if (p->GetDMax() > Particle->GetDMax())
  124. {
  125. Particle = p;
  126. }
  127. }
  128. double dWidth = (double)Particle->GetDMin();
  129. double dMin = 2, dMax = 0;
  130. switch ((int)a_nLevel)
  131. {
  132. case (int)GB_CLASSIFY_TYPE::A_TYPE:
  133. dMax = 4;
  134. break;
  135. case (int)GB_CLASSIFY_TYPE::B_TYPE:
  136. dMax = 9;
  137. break;
  138. case (int)GB_CLASSIFY_TYPE::C_TYPE:
  139. dMax = 5;
  140. break;
  141. case (int)GB_CLASSIFY_TYPE::D_TYPE:
  142. dMax = 8;
  143. break;
  144. }
  145. //if (dWidth < dMin)
  146. //{
  147. // return GB_WIDTH_TYPE::INVALID;//СÓÚ2um²»¿¼ÂÇ
  148. //}
  149. /*else*/
  150. if (dWidth >= 0 && dWidth <= dMax)
  151. {
  152. return GB_WIDTH_TYPE::THIN;
  153. }
  154. switch ((int)a_nLevel)
  155. {
  156. case (int)GB_CLASSIFY_TYPE::A_TYPE:
  157. dMin = 4;
  158. dMax = 12;
  159. break;
  160. case (int)GB_CLASSIFY_TYPE::B_TYPE:
  161. dMin = 9;
  162. dMax = 15;
  163. break;
  164. case (int)GB_CLASSIFY_TYPE::C_TYPE:
  165. dMin = 5;
  166. dMax = 12;
  167. break;
  168. case (int)GB_CLASSIFY_TYPE::D_TYPE:
  169. dMin = 8;
  170. dMax = 13;
  171. break;
  172. }
  173. if (dWidth > dMin && dWidth <= dMax)
  174. {
  175. return GB_WIDTH_TYPE::WIDE;
  176. }
  177. switch ((int)a_nLevel)
  178. {
  179. case (int)GB_CLASSIFY_TYPE::A_TYPE:
  180. dMin = 12;
  181. break;
  182. case (int)GB_CLASSIFY_TYPE::B_TYPE:
  183. dMin = 15;
  184. break;
  185. case (int)GB_CLASSIFY_TYPE::C_TYPE:
  186. dMin = 12;
  187. break;
  188. case (int)GB_CLASSIFY_TYPE::D_TYPE:
  189. dMin = 13;
  190. break;
  191. }
  192. if (dWidth > dMin)
  193. {
  194. return GB_WIDTH_TYPE::SUPER;
  195. }
  196. return GB_WIDTH_TYPE::INVALID;
  197. }
  198. double GBParticle::GetDMax()
  199. {
  200. auto compare = [](const COTSParticlePtr& a, const COTSParticlePtr& b)
  201. {
  202. return a->GetOTSRect().GetTopLeft().y> b->GetOTSRect().GetTopLeft().y;
  203. };
  204. std::sort(myOTSParts.begin(), myOTSParts.end(), compare);
  205. double dmax=0;
  206. auto p = myOTSParts.begin();
  207. while (p != myOTSParts.end())
  208. {
  209. dmax += (*p)->GetDMax();
  210. auto cur = p;
  211. auto next = ++p;
  212. if (next!= myOTSParts.end())
  213. {
  214. auto distance= (*cur)->GetOTSRect().GetBottomRight().y - (*next)->GetOTSRect().GetTopLeft().y;
  215. if (distance > 0)
  216. {
  217. dmax += distance;
  218. }
  219. }
  220. }
  221. return dmax;
  222. }
  223. double GBParticle::GetFeretDiameter()
  224. {
  225. double dferet=0;
  226. for (auto p : myOTSParts)
  227. {
  228. dferet += p->GetFeretDiameter();
  229. }
  230. return dferet;
  231. }
  232. double GBParticle::GetActualArea()
  233. {
  234. double area = 0;
  235. for (auto p : myOTSParts)
  236. {
  237. area += p->GetActualArea();
  238. }
  239. return area;
  240. }
  241. }