PosXray.cpp 5.3 KB

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