PosXray.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. CPosXray::CPosXray(CPosXrayInfo* a_poXrayInfo)
  19. {
  20. // input check
  21. ASSERT(a_poXrayInfo);
  22. if (!a_poXrayInfo)
  23. {
  24. return;
  25. }
  26. CPosXrayInfo::CPosXrayInfo(a_poXrayInfo);
  27. }
  28. // copy constructor
  29. CPosXray::CPosXray(const CPosXray& a_oSource)
  30. {
  31. // can't copy itself
  32. if (&a_oSource == this)
  33. {
  34. return;
  35. }
  36. // copy data over
  37. Duplicate(a_oSource);
  38. }
  39. // copy constructor
  40. CPosXray::CPosXray(CPosXray* a_poSource)
  41. {
  42. // input check
  43. ASSERT(a_poSource);
  44. if (!a_poSource)
  45. {
  46. return;
  47. }
  48. // can't copy itself
  49. if (a_poSource == this)
  50. {
  51. return;
  52. }
  53. // copy data over
  54. Duplicate(*a_poSource);
  55. }
  56. // =operator
  57. CPosXray& CPosXray::operator=(const CPosXray& a_oSource)
  58. {
  59. // copy the class data over
  60. Duplicate(a_oSource);
  61. // return class
  62. return *this;
  63. }
  64. // destructor
  65. CPosXray::~CPosXray()
  66. {
  67. Cleanup();
  68. }
  69. // CPosXray functions
  70. // public
  71. // serialization
  72. void CPosXray::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  73. {
  74. }
  75. // set x-ray data
  76. void CPosXray::SetXrayData(DWORD* a_pnXrayData)
  77. {
  78. // input check
  79. ASSERT(a_pnXrayData);
  80. if (a_pnXrayData)
  81. {
  82. memcpy(m_nXrayData, a_pnXrayData, sizeof(DWORD) * GENERALXRAYCHANNELS);
  83. }
  84. else
  85. {
  86. memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
  87. }
  88. }
  89. // calculate total counts
  90. DWORD CPosXray::GetTotalCount() const
  91. {
  92. const DWORD* pdw = m_nXrayData;
  93. return (DWORD)std::accumulate(pdw, pdw + (DWORD)GENERALXRAYCHANNELS, 0);
  94. }
  95. // calculate highest peek and channel
  96. void CPosXray::GetMaxHeightPosition(long& a_nMaxHeight, long& a_nPosition) const
  97. {
  98. a_nMaxHeight = 0;
  99. a_nPosition = 0;
  100. long nXrayValue = 0;
  101. for (long i = 0; i < GENERALXRAYCHANNELS; ++i)
  102. {
  103. nXrayValue = (long)m_nXrayData[i];
  104. if (a_nMaxHeight < nXrayValue)
  105. {
  106. a_nMaxHeight = nXrayValue;
  107. a_nPosition = i;
  108. }
  109. }
  110. }
  111. // clear data
  112. void CPosXray::ClearXrayData(const long a_nStartPos /*= -1*/)
  113. {
  114. if (a_nStartPos <= 0 || a_nStartPos >= GENERALXRAYCHANNELS)
  115. {
  116. memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
  117. }
  118. else
  119. {
  120. memset(m_nXrayData + a_nStartPos, 0, sizeof(DWORD) * (GENERALXRAYCHANNELS - a_nStartPos));
  121. }
  122. }
  123. void CPosXray::SetXrayDataAtChannel(DWORD a_nXray, const long a_nChannel)
  124. {
  125. m_nXrayData[a_nChannel] = a_nXray;
  126. }
  127. CElementChemistriesList CPosXray::RemoveFe(CElementChemistriesList a_listElementChemistries)
  128. {
  129. CElementChemistriesList listElementChemistry;
  130. CString strFe = _T("Fe");
  131. double dFePercent;
  132. auto itr = std::find_if(a_listElementChemistries.begin(), a_listElementChemistries.end(), [strFe](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strFe) == 0; });
  133. if (itr == a_listElementChemistries.end())
  134. {
  135. //LogErrorTrace(__FILE__, __LINE__, _T("GetElementAreaList: can't find Fe element in Xray."));
  136. return a_listElementChemistries;
  137. }
  138. else
  139. {
  140. CElementChemistryPtr pElementChemistry = *itr;
  141. dFePercent = pElementChemistry->GetPercentage();
  142. a_listElementChemistries.erase(itr);
  143. }
  144. for (auto pElementChemistry : a_listElementChemistries)
  145. {
  146. double dPecent = 100.0 * pElementChemistry->GetPercentage() / (100.0 - dFePercent);
  147. CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get()));
  148. pElementNew->SetPercentage(dPecent);
  149. listElementChemistry.push_back(pElementNew);
  150. }
  151. return listElementChemistry;
  152. }
  153. CElementChemistriesList CPosXray::RemoveC(CElementChemistriesList a_listElementChemistries)
  154. {
  155. CElementChemistriesList listElementChemistry;
  156. CString strFe = _T("C");
  157. double dFePercent;
  158. auto itr = std::find_if(a_listElementChemistries.begin(), a_listElementChemistries.end(), [strFe](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strFe) == 0; });
  159. if (itr == a_listElementChemistries.end())
  160. {
  161. //LogErrorTrace(__FILE__, __LINE__, _T("GetElementAreaList: can't find Fe element in Xray."));
  162. return a_listElementChemistries;
  163. }
  164. else
  165. {
  166. CElementChemistryPtr pElementChemistry = *itr;
  167. dFePercent = pElementChemistry->GetPercentage();
  168. a_listElementChemistries.erase(itr);
  169. }
  170. for (auto pElementChemistry : a_listElementChemistries)
  171. {
  172. double dPecent = 100.0 * pElementChemistry->GetPercentage() / (100.0 - dFePercent);
  173. CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get()));
  174. pElementNew->SetPercentage(dPecent);
  175. listElementChemistry.push_back(pElementNew);
  176. }
  177. return listElementChemistry;
  178. }
  179. // protected
  180. // cleanup
  181. void CPosXray::Cleanup()
  182. {
  183. }
  184. // initialization
  185. void CPosXray::Init()
  186. {
  187. CPosXrayInfo::Init();
  188. // set data to 0
  189. memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
  190. }
  191. // duplication
  192. void CPosXray::Duplicate(const CPosXray& a_oSource)
  193. {
  194. // initial parameters
  195. Init();
  196. CPosXrayInfo::Duplicate(a_oSource);
  197. SetXrayData(a_oSource.GetXrayData());
  198. }
  199. }