OTSEDSBase.cpp 4.3 KB

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