PosXrayInfo.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include "stdafx.h"
  2. #include "PosXrayInfo.h"
  3. //ÎļþÃû£ºPosXrayInfo.cpp
  4. //¹¦ÄÜ˵Ã÷£º
  5. namespace OTSDATA {
  6. // CPosXrayInfo
  7. // constructor
  8. CPosXrayInfo::CPosXrayInfo()
  9. {
  10. // initialization
  11. Init();
  12. }
  13. // copy constructor
  14. CPosXrayInfo::CPosXrayInfo(const CPosXrayInfo& a_oSource)
  15. {
  16. // can't copy itself
  17. if (&a_oSource == this)
  18. {
  19. return;
  20. }
  21. // copy data over
  22. Duplicate(a_oSource);
  23. }
  24. // copy constructor
  25. CPosXrayInfo::CPosXrayInfo(CPosXrayInfo* a_poSource)
  26. {
  27. // input check
  28. ASSERT(a_poSource);
  29. if (!a_poSource)
  30. {
  31. return;
  32. }
  33. // can't copy itself
  34. if (a_poSource == this)
  35. {
  36. return;
  37. }
  38. // copy data over
  39. Duplicate(*a_poSource);
  40. }
  41. // =operator
  42. CPosXrayInfo& CPosXrayInfo::operator=(const CPosXrayInfo& a_oSource)
  43. {
  44. // cleanup
  45. Cleanup();
  46. // copy the class data over
  47. Duplicate(a_oSource);
  48. // return class
  49. return *this;
  50. }
  51. // ==operator
  52. BOOL CPosXrayInfo::operator==(const CPosXrayInfo& a_oSource)
  53. {
  54. // size matches?
  55. int nSize = (int)m_listElementQuantifyData.size();
  56. if (nSize != (int)a_oSource.m_listElementQuantifyData.size())
  57. {
  58. return FALSE;
  59. }
  60. // list matches?
  61. for (int i = 0; i < nSize; ++i)
  62. {
  63. if (!(*(m_listElementQuantifyData[i].get()) == *(a_oSource.m_listElementQuantifyData[i].get())))
  64. {
  65. return FALSE;
  66. }
  67. }
  68. // return test result
  69. return m_poiPosition == a_oSource.m_poiPosition &&
  70. m_nIndex == a_oSource.m_nIndex &&
  71. m_nFieldId == a_oSource.m_nFieldId &&
  72. m_nPartTagId == a_oSource.m_nPartTagId &&
  73. m_nFeatureId == a_oSource.m_nFeatureId;
  74. }
  75. // detractor
  76. CPosXrayInfo::~CPosXrayInfo()
  77. {
  78. Cleanup();
  79. }
  80. // CPosXrayInfo member functions
  81. // public
  82. // serialization
  83. void CPosXrayInfo::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode)
  84. {
  85. xmls::xPoint xpoiPosition;
  86. xmls::xLong xnIndex;
  87. xmls::xLong xnFieldId;
  88. xmls::xLong xnPartTagId;
  89. xmls::xLong xnFeatureId;
  90. xmls::Slo slo;
  91. slo.Register("Position",&xpoiPosition);
  92. slo.Register("Index", &xnIndex);
  93. slo.Register("FieldId", &xnFieldId);
  94. slo.Register("PartTagId", &xnPartTagId);
  95. slo.Register("FeatureId", &xnFeatureId);
  96. if (isStoring)
  97. {
  98. xpoiPosition = m_poiPosition;
  99. xnIndex = m_nIndex;
  100. xnFieldId = m_nFieldId;
  101. xnPartTagId = m_nPartTagId;
  102. xnFeatureId = m_nFeatureId;
  103. slo.Serialize(true, classDoc, rootNode);
  104. }
  105. else
  106. {
  107. slo.Serialize(false, classDoc, rootNode);
  108. m_poiPosition = xpoiPosition.value();
  109. m_nIndex = xnIndex.value();
  110. m_nFieldId = xnFieldId.value();
  111. m_nPartTagId = xnPartTagId.value();
  112. m_nFeatureId = xnFeatureId.value();
  113. }
  114. }
  115. // element quantify data
  116. void CPosXrayInfo::SetElementQuantifyData(CElementChemistriesList& a_listElementQuantifyData)
  117. {
  118. m_listElementQuantifyData.clear();
  119. for (auto poElementChemistry : a_listElementQuantifyData)
  120. {
  121. //CElementChemistryPtr poElementChemistryNew(new CElementChemistry(poElementChemistry.get()));
  122. CElementChemistryPtr poElementChemistryNew=poElementChemistry;
  123. m_listElementQuantifyData.push_back(poElementChemistryNew);
  124. }
  125. m_nElementNum = (int)m_listElementQuantifyData.size();
  126. }
  127. void CPosXrayInfo::NormalizeXrayQuantifyData()
  128. {
  129. if (m_listElementQuantifyData.empty())
  130. {
  131. return;
  132. }
  133. double dTotalPercent = 0;
  134. for (auto poElementChemistry : m_listElementQuantifyData)
  135. {
  136. dTotalPercent += poElementChemistry->GetPercentage();
  137. }
  138. if (dTotalPercent > MIN_DOUBLE_VALUE)
  139. {
  140. dTotalPercent /= 100;
  141. for (auto poElementChemistry : m_listElementQuantifyData)
  142. {
  143. poElementChemistry->SetPercentage(poElementChemistry->GetPercentage() /dTotalPercent);
  144. }
  145. }
  146. }
  147. // protected
  148. // cleanup
  149. void CPosXrayInfo::Cleanup()
  150. {
  151. // nothing needs to be done at the moment
  152. m_listElementQuantifyData.clear();
  153. m_nElementNum = (int)m_listElementQuantifyData.size();
  154. }
  155. // initialization
  156. void CPosXrayInfo::Init()
  157. {
  158. m_poiPosition = CPoint(0, 0);
  159. m_nIndex = -1;
  160. m_nFieldId = -1;
  161. m_nPartTagId = -1;
  162. m_nFeatureId = -1;
  163. m_listElementQuantifyData.clear();
  164. m_nElementNum = (int)m_listElementQuantifyData.size();
  165. }
  166. // duplication
  167. void CPosXrayInfo::Duplicate(const CPosXrayInfo& a_oSource)
  168. {
  169. // initialization
  170. Init();
  171. // copy data over
  172. m_poiPosition = a_oSource.m_poiPosition;
  173. m_nIndex = a_oSource.m_nIndex;
  174. m_nFieldId = a_oSource.m_nFieldId;
  175. m_nPartTagId = a_oSource.m_nPartTagId;
  176. m_nFeatureId = a_oSource.m_nFeatureId;
  177. for (auto poElementChemistry : a_oSource.m_listElementQuantifyData)
  178. {
  179. CElementChemistryPtr poElementChemistryNew(new CElementChemistry(poElementChemistry.get()));
  180. m_listElementQuantifyData.push_back(poElementChemistryNew);
  181. }
  182. m_nElementNum = (int)m_listElementQuantifyData.size();
  183. }
  184. }