PosXray.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. void CPosXray::SetElementQuantifyData(CElementChemistriesList& a_listElementQuantifyData)
  169. {
  170. m_listElementQuantifyData.clear();
  171. for (auto poElementChemistry : a_listElementQuantifyData)
  172. {
  173. CElementChemistryPtr poElementChemistryNew = poElementChemistry;
  174. m_listElementQuantifyData.push_back(poElementChemistryNew);
  175. }
  176. m_nElementNum = (int)m_listElementQuantifyData.size();
  177. }
  178. void CPosXray::AddElementQuantifyData(CElementChemistryPtr a_ElementQuantifyData)
  179. {
  180. m_listElementQuantifyData.push_back(a_ElementQuantifyData);
  181. m_nElementNum = (int)m_listElementQuantifyData.size();
  182. }
  183. void CPosXray::NormalizeXrayQuantifyData()
  184. {
  185. if (m_listElementQuantifyData.empty())
  186. {
  187. return;
  188. }
  189. double dTotalPercent = 0;
  190. for (auto poElementChemistry : m_listElementQuantifyData)
  191. {
  192. dTotalPercent += poElementChemistry->GetPercentage();
  193. }
  194. if (dTotalPercent > MIN_DOUBLE_VALUE)
  195. {
  196. dTotalPercent /= 100;
  197. for (auto poElementChemistry : m_listElementQuantifyData)
  198. {
  199. poElementChemistry->SetPercentage(poElementChemistry->GetPercentage() / dTotalPercent);
  200. }
  201. }
  202. }
  203. // protected
  204. // cleanup
  205. void CPosXray::Cleanup()
  206. {
  207. }
  208. // initialization
  209. void CPosXray::Init()
  210. {
  211. //CPosXrayInfo::Init();
  212. m_poiPosition = CPoint(0, 0);
  213. m_nIndex = -1;
  214. m_nFieldId = -1;
  215. m_nPartTagId = -1;
  216. m_nFeatureId = -1;
  217. m_listElementQuantifyData.clear();
  218. m_nElementNum = (int)m_listElementQuantifyData.size();
  219. // set data to 0
  220. memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
  221. m_spectrum = new CSpectrumData(0,m_nXrayData);
  222. }
  223. // duplication
  224. void CPosXray::Duplicate(const CPosXray& a_oSource)
  225. {
  226. // initial parameters
  227. Init();
  228. //CPosXrayInfo::Duplicate(a_oSource);
  229. m_poiPosition = a_oSource.m_poiPosition;
  230. m_nIndex = a_oSource.m_nIndex;
  231. m_nFieldId = a_oSource.m_nFieldId;
  232. m_nPartTagId = a_oSource.m_nPartTagId;
  233. m_nFeatureId = a_oSource.m_nFeatureId;
  234. for (auto poElementChemistry : a_oSource.m_listElementQuantifyData)
  235. {
  236. CElementChemistryPtr poElementChemistryNew(new CElementChemistry(poElementChemistry.get()));
  237. m_listElementQuantifyData.push_back(poElementChemistryNew);
  238. }
  239. m_nElementNum = (int)m_listElementQuantifyData.size();
  240. SetXrayData(a_oSource.GetXrayData());
  241. }
  242. }