PosXrayInfo.cpp 4.6 KB

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