| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 | #include "stdafx.h"#include "OTSEDSBase.h"#include "Bruker/OTSBrukerImpl_const.h"namespace OTSController {		// constructor	COTSEDSBase::COTSEDSBase(void)			{	}	// destructor	COTSEDSBase::~COTSEDSBase(void)	{	}		// channel number	DWORD COTSEDSBase::GetNumberOfChannels(void)	{		return (DWORD)EDSConst::XANA_CHANNELS;	}	// data in buffer	DWORD* COTSEDSBase::GetXRayData()	{		return m_nRayData;	}	// collect spectrum from a text file	BOOL COTSEDSBase::CollectASpectrumFromTxtFile(DWORD* a_pCounts, DWORD a_nBufferSize)	{		// input check		ASSERT(a_pCounts);		if (!a_pCounts)		{			LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::CollectASpectrumFromTxtFile: invalid a_pCounts."));			return FALSE;		}		// get simulation spectrum file name		CString strOTSSysDataPath = GetCompanySysDataPathName();		CString strSimSpectrumFilePathName = strOTSSysDataPath + SIMULATION_SPECTRUM_FILENAME;		// check if the file exist 		if (!Exists(strSimSpectrumFilePathName))		{			// simulation spectrum file doesn't exist			LogInfoTrace(__FILE__, __LINE__, _T("COTSEDSBase::CollectASpectrumFromTxtFile: simulation spectrum file doesn't exist."));			return FALSE;		}		// load string lines from the file		std::vector<CString > listLineStr = LoadTextFileToCStingList(strSimSpectrumFilePathName, (int)a_nBufferSize);		// set spectrum data			memset(a_pCounts, 0, sizeof(DWORD) * a_nBufferSize);		for (int i = 0; i < (int)listLineStr.size() && i < (int)a_nBufferSize; ++i)		{			CString strValue = listLineStr[i];			int nValue = 0;			if (StringToInt(strValue, nValue))			{				a_pCounts[i] = (long)nValue;			}		}		// ok, return TRUE		return TRUE;	}	BOOL COTSEDSBase::GetXRayByFeaturesFromMultiPoint(std::vector<CPosXrayPtr>& a_listXRayPoints,		std::vector<std::vector<BrukerSegment>>& a_listFeatures,		const DWORD a_nXRayAQTime)	{		int nPointNum = 0;		for (auto pFeature : a_listFeatures)		{			std::vector<CPosXrayPtr> listXRayPoints;			std::vector<BrukerSegment> listSegment = pFeature;			int nSize = (int)listSegment.size();			if (nSize > 2)			{				for (int i = 0; i < nSize - 2; i = i + 2)				{					BrukerSegment pSegment = listSegment[i];					int nLength = pSegment.XCount;					int nStart = pSegment.XStart;					CPoint pt;					pt.x = nStart;					pt.y = nStart + nLength / 2;					CPosXrayPtr pXray = CPosXrayPtr(new CPosXray());					pXray->SetPosition(pt);					listXRayPoints.push_back(pXray);				}			}			else if(nSize == 0)			{				LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint: there is no points."));				return FALSE;			}			else			{				BrukerSegment pSegment = listSegment[0];				int nLength = pSegment.XCount;				int nStart = pSegment.XStart;				CPoint pt;				pt.x = nStart;				pt.y = nStart + nLength / 2;				CPosXrayPtr pXray = CPosXrayPtr(new CPosXray());				pXray->SetPosition(pt);				listXRayPoints.push_back(pXray);			}			if (!GetXRayByPoints(listXRayPoints, a_nXRayAQTime))			{				LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint: Can't get xray from points."));				return FALSE;			}			int nNum = 0;			DWORD XRayData[GENERALXRAYCHANNELS];			memset(XRayData, 0, sizeof(DWORD) *GENERALXRAYCHANNELS);			for (auto pXRayPoint : listXRayPoints)			{				DWORD* pXRayData;				pXRayData = pXRayPoint->GetXrayData();				for (int m = 0; m < GENERALXRAYCHANNELS; m++)				{					XRayData[m] += pXRayData[m];				}				nNum++;			}			if (nNum == 0)			{				LogErrorTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint:there is no points."));				return FALSE;			}			CElementChemistriesList& listElementQuantifyData = listXRayPoints[0]->GetElementQuantifyData();			LogInfoTrace(__FILE__, __LINE__, _T("GetXRayByFeaturesFromMultiPoint:get element,size is %d."), (int)listElementQuantifyData.size());						if (nNum > 1 )			{				listElementQuantifyData = listXRayPoints[int(nNum/2+0.5)]->GetElementQuantifyData();			}			for (int k = 0; k < GENERALXRAYCHANNELS; k++)			{				XRayData[k] = (int)((double)XRayData[k] / (double)nNum + 0.5);			}			CPosXrayPtr pXrayPoint = CPosXrayPtr(new CPosXray());			a_listXRayPoints[nPointNum]->SetXrayData(XRayData);			a_listXRayPoints[nPointNum]->SetElementQuantifyData(listElementQuantifyData);			nPointNum++;		}		// always return TRUE		return TRUE;	}} // namespace OTSController
 |