PosXray.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #include "stdafx.h"
  2. #include "PosXray.h"
  3. namespace OTSDATA {
  4. // CXRayPoint
  5. // constructor
  6. CPosXray::CPosXray()
  7. {
  8. // initialization
  9. Init();
  10. }
  11. CPosXray::CPosXray(const CPoint a_poiPosition)
  12. {
  13. // initialization
  14. Init();
  15. // set position
  16. SetPosition(a_poiPosition);
  17. }
  18. // copy constructor
  19. CPosXray::CPosXray(const CPosXray& a_oSource)
  20. {
  21. // can't copy itself
  22. if (&a_oSource == this)
  23. {
  24. return;
  25. }
  26. // copy data over
  27. Duplicate(a_oSource);
  28. }
  29. // copy constructor
  30. CPosXray::CPosXray(CPosXray* a_poSource)
  31. {
  32. // input check
  33. ASSERT(a_poSource);
  34. if (!a_poSource)
  35. {
  36. return;
  37. }
  38. // can't copy itself
  39. if (a_poSource == this)
  40. {
  41. return;
  42. }
  43. // copy data over
  44. Duplicate(*a_poSource);
  45. }
  46. // =operator
  47. CPosXray& CPosXray::operator=(const CPosXray& a_oSource)
  48. {
  49. // copy the class data over
  50. Duplicate(a_oSource);
  51. // return class
  52. return *this;
  53. }
  54. // destructor
  55. CPosXray::~CPosXray()
  56. {
  57. Cleanup();
  58. }
  59. // set x-ray data
  60. void CPosXray::SetXrayData(DWORD* a_pnXrayData)
  61. {
  62. // input check
  63. ASSERT(a_pnXrayData);
  64. if (a_pnXrayData)
  65. {
  66. memcpy(m_nXrayData, a_pnXrayData, sizeof(DWORD) * GENERALXRAYCHANNELS);
  67. }
  68. else
  69. {
  70. memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
  71. }
  72. m_spectrum->CalVectorNorm();
  73. }
  74. double CPosXray::GetXrayDataVectorNorm()
  75. {
  76. return m_spectrum->GetVectorNorm();
  77. }
  78. // calculate total counts
  79. DWORD CPosXray::GetTotalCount() const
  80. {
  81. const DWORD* pdw = m_nXrayData;
  82. return (DWORD)std::accumulate(pdw, pdw + (DWORD)GENERALXRAYCHANNELS, 0);
  83. }
  84. // calculate highest peek and channel
  85. void CPosXray::GetMaxHeightPosition(long& a_nMaxHeight, long& a_nPosition) const
  86. {
  87. a_nMaxHeight = 0;
  88. a_nPosition = 0;
  89. long nXrayValue = 0;
  90. for (long i = 0; i < GENERALXRAYCHANNELS; ++i)
  91. {
  92. nXrayValue = (long)m_nXrayData[i];
  93. if (a_nMaxHeight < nXrayValue)
  94. {
  95. a_nMaxHeight = nXrayValue;
  96. a_nPosition = i;
  97. }
  98. }
  99. }
  100. // clear data
  101. void CPosXray::ClearXrayData(const long a_nStartPos /*= -1*/)
  102. {
  103. if (a_nStartPos <= 0 || a_nStartPos >= GENERALXRAYCHANNELS)
  104. {
  105. memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
  106. }
  107. else
  108. {
  109. memset(m_nXrayData + a_nStartPos, 0, sizeof(DWORD) * (GENERALXRAYCHANNELS - a_nStartPos));
  110. }
  111. }
  112. void CPosXray::SetXrayDataAtChannel(DWORD a_nXray, const long a_nChannel)
  113. {
  114. m_nXrayData[a_nChannel] = a_nXray;
  115. }
  116. CElementChemistriesList CPosXray::RemoveFe(CElementChemistriesList a_listElementChemistries)
  117. {
  118. CElementChemistriesList listElementChemistry;
  119. CString strFe = _T("Fe");
  120. double dFePercent;
  121. auto itr = std::find_if(a_listElementChemistries.begin(), a_listElementChemistries.end(), [strFe](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strFe) == 0; });
  122. if (itr == a_listElementChemistries.end())
  123. {
  124. //LogErrorTrace(__FILE__, __LINE__, _T("GetElementAreaList: can't find Fe element in Xray."));
  125. return a_listElementChemistries;
  126. }
  127. else
  128. {
  129. CElementChemistryPtr pElementChemistry = *itr;
  130. dFePercent = pElementChemistry->GetPercentage();
  131. a_listElementChemistries.erase(itr);
  132. }
  133. for (auto pElementChemistry : a_listElementChemistries)
  134. {
  135. double dPecent = 100.0 * pElementChemistry->GetPercentage() / (100.0 - dFePercent);
  136. CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get()));
  137. pElementNew->SetPercentage(dPecent);
  138. listElementChemistry.push_back(pElementNew);
  139. }
  140. return listElementChemistry;
  141. }
  142. CElementChemistriesList CPosXray::RemoveC(CElementChemistriesList a_listElementChemistries)
  143. {
  144. CElementChemistriesList listElementChemistry;
  145. CString strFe = _T("C");
  146. double dFePercent;
  147. auto itr = std::find_if(a_listElementChemistries.begin(), a_listElementChemistries.end(), [strFe](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strFe) == 0; });
  148. if (itr == a_listElementChemistries.end())
  149. {
  150. //LogErrorTrace(__FILE__, __LINE__, _T("GetElementAreaList: can't find Fe element in Xray."));
  151. return a_listElementChemistries;
  152. }
  153. else
  154. {
  155. CElementChemistryPtr pElementChemistry = *itr;
  156. dFePercent = pElementChemistry->GetPercentage();
  157. a_listElementChemistries.erase(itr);
  158. }
  159. for (auto pElementChemistry : a_listElementChemistries)
  160. {
  161. double dPecent = 100.0 * pElementChemistry->GetPercentage() / (100.0 - dFePercent);
  162. CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get()));
  163. pElementNew->SetPercentage(dPecent);
  164. listElementChemistry.push_back(pElementNew);
  165. }
  166. return listElementChemistry;
  167. }
  168. CString CPosXray::GetQuantifiedElementsStr()
  169. {
  170. CElementChemistriesList& listElement = GetElementQuantifyData();
  171. int nElementNum = (int)listElement.size();
  172. CString strElementResult = _T("");
  173. for (auto pElement : listElement)
  174. {
  175. CString strResult;
  176. CString strName = pElement->GetName();
  177. double dPercent = pElement->GetPercentage();
  178. strResult.Format(_T("%s: %f\n"), strName, dPercent);
  179. strElementResult += strResult;
  180. }
  181. return strElementResult;
  182. }
  183. void CPosXray::SetElementQuantifyData(CElementChemistriesList& a_listElementQuantifyData)
  184. {
  185. m_listElementQuantifyData.clear();
  186. for (auto poElementChemistry : a_listElementQuantifyData)
  187. {
  188. CElementChemistryPtr poElementChemistryNew = poElementChemistry;
  189. m_listElementQuantifyData.push_back(poElementChemistryNew);
  190. }
  191. m_nElementNum = (int)m_listElementQuantifyData.size();
  192. }
  193. void CPosXray::AddElementQuantifyData(CElementChemistryPtr a_ElementQuantifyData)
  194. {
  195. m_listElementQuantifyData.push_back(a_ElementQuantifyData);
  196. m_nElementNum = (int)m_listElementQuantifyData.size();
  197. }
  198. void CPosXray::NormalizeXrayQuantifyData()
  199. {
  200. if (m_listElementQuantifyData.empty())
  201. {
  202. return;
  203. }
  204. double dTotalPercent = 0;
  205. for (auto poElementChemistry : m_listElementQuantifyData)
  206. {
  207. dTotalPercent += poElementChemistry->GetPercentage();
  208. }
  209. if (dTotalPercent > MIN_DOUBLE_VALUE)
  210. {
  211. dTotalPercent /= 100;
  212. for (auto poElementChemistry : m_listElementQuantifyData)
  213. {
  214. poElementChemistry->SetPercentage(poElementChemistry->GetPercentage() / dTotalPercent);
  215. }
  216. }
  217. }
  218. // protected
  219. // cleanup
  220. void CPosXray::Cleanup()
  221. {
  222. }
  223. // initialization
  224. void CPosXray::Init()
  225. {
  226. //CPosXrayInfo::Init();
  227. m_poiPosition = CPoint(0, 0);
  228. m_nIndex = -1;
  229. m_nFieldId = -1;
  230. m_nPartTagId = -1;
  231. m_nFeatureId = -1;
  232. m_listElementQuantifyData.clear();
  233. m_nElementNum = (int)m_listElementQuantifyData.size();
  234. // set data to 0
  235. memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
  236. m_spectrum = new CSpectrumData(0,m_nXrayData);
  237. }
  238. // duplication
  239. void CPosXray::Duplicate(const CPosXray& a_oSource)
  240. {
  241. // initial parameters
  242. Init();
  243. //CPosXrayInfo::Duplicate(a_oSource);
  244. m_poiPosition = a_oSource.m_poiPosition;
  245. m_nIndex = a_oSource.m_nIndex;
  246. m_nFieldId = a_oSource.m_nFieldId;
  247. m_nPartTagId = a_oSource.m_nPartTagId;
  248. m_nFeatureId = a_oSource.m_nFeatureId;
  249. for (auto poElementChemistry : a_oSource.m_listElementQuantifyData)
  250. {
  251. CElementChemistryPtr poElementChemistryNew(new CElementChemistry(poElementChemistry.get()));
  252. m_listElementQuantifyData.push_back(poElementChemistryNew);
  253. }
  254. m_nElementNum = (int)m_listElementQuantifyData.size();
  255. SetXrayData(a_oSource.GetXrayData());
  256. }
  257. }