#include "stdafx.h" #include "PosXray.h" namespace OTSDATA { // CXRayPoint // constructor CPosXray::CPosXray() { // initialization Init(); } CPosXray::CPosXray(const CPoint a_poiPosition) { // initialization Init(); // set position SetPosition(a_poiPosition); } CPosXray::CPosXray(CPosXrayInfo* a_poXrayInfo) { // input check ASSERT(a_poXrayInfo); if (!a_poXrayInfo) { return; } CPosXrayInfo::Duplicate(a_poXrayInfo);//CPosXrayInfo::CPosXrayInfo(a_poXrayInfo);这种写法vs2017可以工作,2019不行 memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS); } // copy constructor CPosXray::CPosXray(const CPosXray& a_oSource) { // can't copy itself if (&a_oSource == this) { return; } // copy data over Duplicate(a_oSource); } // copy constructor CPosXray::CPosXray(CPosXray* a_poSource) { // input check ASSERT(a_poSource); if (!a_poSource) { return; } // can't copy itself if (a_poSource == this) { return; } // copy data over Duplicate(*a_poSource); } // =operator CPosXray& CPosXray::operator=(const CPosXray& a_oSource) { // copy the class data over Duplicate(a_oSource); // return class return *this; } // destructor CPosXray::~CPosXray() { Cleanup(); } // CPosXray functions // public // serialization /*void CPosXray::Serialize(bool isStoring, tinyxml2::XMLDocument * classDoc, tinyxml2::XMLElement * rootNode) { }*/ // set x-ray data void CPosXray::SetXrayData(DWORD* a_pnXrayData) { // input check ASSERT(a_pnXrayData); if (a_pnXrayData) { memcpy(m_nXrayData, a_pnXrayData, sizeof(DWORD) * GENERALXRAYCHANNELS); } else { memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS); } } // calculate total counts DWORD CPosXray::GetTotalCount() const { const DWORD* pdw = m_nXrayData; return (DWORD)std::accumulate(pdw, pdw + (DWORD)GENERALXRAYCHANNELS, 0); } // calculate highest peek and channel void CPosXray::GetMaxHeightPosition(long& a_nMaxHeight, long& a_nPosition) const { a_nMaxHeight = 0; a_nPosition = 0; long nXrayValue = 0; for (long i = 0; i < GENERALXRAYCHANNELS; ++i) { nXrayValue = (long)m_nXrayData[i]; if (a_nMaxHeight < nXrayValue) { a_nMaxHeight = nXrayValue; a_nPosition = i; } } } // clear data void CPosXray::ClearXrayData(const long a_nStartPos /*= -1*/) { if (a_nStartPos <= 0 || a_nStartPos >= GENERALXRAYCHANNELS) { memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS); } else { memset(m_nXrayData + a_nStartPos, 0, sizeof(DWORD) * (GENERALXRAYCHANNELS - a_nStartPos)); } } void CPosXray::SetXrayDataAtChannel(DWORD a_nXray, const long a_nChannel) { m_nXrayData[a_nChannel] = a_nXray; } CElementChemistriesList CPosXray::RemoveFe(CElementChemistriesList a_listElementChemistries) { CElementChemistriesList listElementChemistry; CString strFe = _T("Fe"); double dFePercent; auto itr = std::find_if(a_listElementChemistries.begin(), a_listElementChemistries.end(), [strFe](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strFe) == 0; }); if (itr == a_listElementChemistries.end()) { //LogErrorTrace(__FILE__, __LINE__, _T("GetElementAreaList: can't find Fe element in Xray.")); return a_listElementChemistries; } else { CElementChemistryPtr pElementChemistry = *itr; dFePercent = pElementChemistry->GetPercentage(); a_listElementChemistries.erase(itr); } for (auto pElementChemistry : a_listElementChemistries) { double dPecent = 100.0 * pElementChemistry->GetPercentage() / (100.0 - dFePercent); CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get())); pElementNew->SetPercentage(dPecent); listElementChemistry.push_back(pElementNew); } return listElementChemistry; } CElementChemistriesList CPosXray::RemoveC(CElementChemistriesList a_listElementChemistries) { CElementChemistriesList listElementChemistry; CString strFe = _T("C"); double dFePercent; auto itr = std::find_if(a_listElementChemistries.begin(), a_listElementChemistries.end(), [strFe](CElementChemistryPtr p) { return p->GetName().CompareNoCase(strFe) == 0; }); if (itr == a_listElementChemistries.end()) { //LogErrorTrace(__FILE__, __LINE__, _T("GetElementAreaList: can't find Fe element in Xray.")); return a_listElementChemistries; } else { CElementChemistryPtr pElementChemistry = *itr; dFePercent = pElementChemistry->GetPercentage(); a_listElementChemistries.erase(itr); } for (auto pElementChemistry : a_listElementChemistries) { double dPecent = 100.0 * pElementChemistry->GetPercentage() / (100.0 - dFePercent); CElementChemistryPtr pElementNew = CElementChemistryPtr(new CElementChemistry(*pElementChemistry.get())); pElementNew->SetPercentage(dPecent); listElementChemistry.push_back(pElementNew); } return listElementChemistry; } // protected // cleanup void CPosXray::Cleanup() { } // initialization void CPosXray::Init() { CPosXrayInfo::Init(); // set data to 0 memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS); } // duplication void CPosXray::Duplicate(const CPosXray& a_oSource) { // initial parameters Init(); CPosXrayInfo::Duplicate(a_oSource); SetXrayData(a_oSource.GetXrayData()); } }