OTSEDSBase.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include "stdafx.h"
  2. #include "OTSEDSBase.h"
  3. #include "Bruker/OTSBrukerImpl_const.h"
  4. //#include "OTSFileSys.h"
  5. //#include "OTSHelper.h"
  6. namespace OTSController {
  7. // constructor
  8. COTSEDSBase::COTSEDSBase(void)
  9. {
  10. }
  11. // destructor
  12. COTSEDSBase::~COTSEDSBase(void)
  13. {
  14. }
  15. // channel number
  16. DWORD COTSEDSBase::GetNumberOfChannels(void)
  17. {
  18. return (DWORD)EDSConst::XANA_CHANNELS;
  19. }
  20. // data in buffer
  21. DWORD* COTSEDSBase::GetXRayData()
  22. {
  23. return m_nRayData;
  24. }
  25. // collect spectrum from a text file
  26. BOOL COTSEDSBase::CollectASpectrumFromTxtFile(DWORD* a_pCounts, DWORD a_nBufferSize)
  27. {
  28. // input check
  29. ASSERT(a_pCounts);
  30. if (!a_pCounts)
  31. {
  32. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::CollectASpectrumFromTxtFile: invalid a_pCounts."));
  33. return FALSE;
  34. }
  35. // get simulation spectrum file name
  36. CString strOTSSysDataPath = GetCompanySysDataPathName();
  37. CString strSimSpectrumFilePathName = strOTSSysDataPath + SIMULATION_SPECTRUM_FILENAME;
  38. // check if the file exist
  39. if (!Exists(strSimSpectrumFilePathName))
  40. {
  41. // simulation spectrum file doesn't exist
  42. LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::CollectASpectrumFromTxtFile: simulation spectrum file doesn't exist."));
  43. return FALSE;
  44. }
  45. // load string lines from the file
  46. std::vector<CString > listLineStr = LoadTextFileToCStingList(strSimSpectrumFilePathName, (int)a_nBufferSize);
  47. // set spectrum data
  48. memset(a_pCounts, 0, sizeof(DWORD) * a_nBufferSize);
  49. for (int i = 0; i < (int)listLineStr.size() && i < (int)a_nBufferSize; ++i)
  50. {
  51. CString strValue = listLineStr[i];
  52. int nValue = 0;
  53. if (StringToInt(strValue, nValue))
  54. {
  55. a_pCounts[i] = (long)nValue;
  56. }
  57. }
  58. // ok, return TRUE
  59. return TRUE;
  60. }
  61. BOOL COTSEDSBase::GetXRayByFeaturesFromMultiPoint(std::vector<CPosXrayPtr>& a_listXRayPoints,
  62. std::vector<std::vector<BrukerSegment>>& a_listFeatures,
  63. const DWORD a_nXRayAQTime)
  64. {
  65. int nPointNum = 0;
  66. for (auto pFeature : a_listFeatures)
  67. {
  68. std::vector<CPosXrayPtr> listXRayPoints;
  69. std::vector<BrukerSegment> listSegment = pFeature;
  70. int nSize = (int)listSegment.size();
  71. if (nSize > 2)
  72. {
  73. for (int i = 0; i < nSize - 2; i = i + 2)
  74. {
  75. BrukerSegment pSegment = listSegment[i];
  76. int nLength = pSegment.XCount;
  77. int nStart = pSegment.XStart;
  78. CPoint pt;
  79. pt.x = nStart;
  80. pt.y = nStart + nLength / 2;
  81. CPosXrayPtr pXray = CPosXrayPtr(new CPosXray());
  82. pXray->SetPosition(pt);
  83. listXRayPoints.push_back(pXray);
  84. }
  85. }
  86. else if(nSize == 0)
  87. {
  88. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint: there is no points."));
  89. return FALSE;
  90. }
  91. else
  92. {
  93. BrukerSegment pSegment = listSegment[0];
  94. int nLength = pSegment.XCount;
  95. int nStart = pSegment.XStart;
  96. CPoint pt;
  97. pt.x = nStart;
  98. pt.y = nStart + nLength / 2;
  99. CPosXrayPtr pXray = CPosXrayPtr(new CPosXray());
  100. pXray->SetPosition(pt);
  101. listXRayPoints.push_back(pXray);
  102. }
  103. if (!GetXRayByPoints(listXRayPoints, a_nXRayAQTime))
  104. {
  105. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint: Can't get xray from points."));
  106. return FALSE;
  107. }
  108. int nNum = 0;
  109. DWORD XRayData[GENERALXRAYCHANNELS];
  110. memset(XRayData, 0, sizeof(DWORD) *GENERALXRAYCHANNELS);
  111. for (auto pXRayPoint : listXRayPoints)
  112. {
  113. DWORD* pXRayData;
  114. pXRayData = pXRayPoint->GetXrayData();
  115. for (int m = 0; m < GENERALXRAYCHANNELS; m++)
  116. {
  117. XRayData[m] += pXRayData[m];
  118. }
  119. nNum++;
  120. }
  121. if (nNum == 0)
  122. {
  123. LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint:there is no points."));
  124. return FALSE;
  125. }
  126. CElementChemistriesList& listElementQuantifyData = listXRayPoints[0]->GetElementQuantifyData();
  127. LogInfoTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint:get element,size is %d."), (int)listElementQuantifyData.size());
  128. if (nNum > 1 )
  129. {
  130. listElementQuantifyData = listXRayPoints[int(nNum/2+0.5)]->GetElementQuantifyData();
  131. }
  132. for (int k = 0; k < GENERALXRAYCHANNELS; k++)
  133. {
  134. XRayData[k] = (int)((double)XRayData[k] / (double)nNum + 0.5);
  135. }
  136. CPosXrayPtr pXrayPoint = CPosXrayPtr(new CPosXray());
  137. a_listXRayPoints[nPointNum]->SetXrayData(XRayData);
  138. a_listXRayPoints[nPointNum]->SetElementQuantifyData(listElementQuantifyData);
  139. nPointNum++;
  140. }
  141. // always return TRUE
  142. return TRUE;
  143. }
  144. } // namespace OTSController