123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- #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);
- }
- // 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();
- }
- // 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);
- }
- m_spectrum->CalVectorNorm();
- }
- double CPosXray::GetXrayDataVectorNorm()
- {
- return m_spectrum->GetVectorNorm();
- }
- // 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;
- }
- CString CPosXray::GetQuantifiedElementsStr()
- {
- CElementChemistriesList& listElement = GetElementQuantifyData();
- int nElementNum = (int)listElement.size();
- CString strElementResult = _T("");
- for (auto pElement : listElement)
- {
- CString strResult;
- CString strName = pElement->GetName();
- double dPercent = pElement->GetPercentage();
- strResult.Format(_T("%s: %f\n"), strName, dPercent);
- strElementResult += strResult;
- }
- return strElementResult;
- }
- void CPosXray::SetElementQuantifyData(CElementChemistriesList& a_listElementQuantifyData)
- {
- m_listElementQuantifyData.clear();
- for (auto poElementChemistry : a_listElementQuantifyData)
- {
- CElementChemistryPtr poElementChemistryNew = poElementChemistry;
- m_listElementQuantifyData.push_back(poElementChemistryNew);
- }
- m_nElementNum = (int)m_listElementQuantifyData.size();
- }
- void CPosXray::AddElementQuantifyData(CElementChemistryPtr a_ElementQuantifyData)
- {
-
- m_listElementQuantifyData.push_back(a_ElementQuantifyData);
-
- m_nElementNum = (int)m_listElementQuantifyData.size();
- }
- void CPosXray::NormalizeXrayQuantifyData()
- {
- if (m_listElementQuantifyData.empty())
- {
- return;
- }
- double dTotalPercent = 0;
- for (auto poElementChemistry : m_listElementQuantifyData)
- {
- dTotalPercent += poElementChemistry->GetPercentage();
- }
- if (dTotalPercent > MIN_DOUBLE_VALUE)
- {
- dTotalPercent /= 100;
- for (auto poElementChemistry : m_listElementQuantifyData)
- {
- poElementChemistry->SetPercentage(poElementChemistry->GetPercentage() / dTotalPercent);
- }
- }
- }
- // protected
- // cleanup
- void CPosXray::Cleanup()
- {
- }
- // initialization
- void CPosXray::Init()
- {
- //CPosXrayInfo::Init();
- m_poiPosition = CPoint(0, 0);
- m_nIndex = -1;
- m_nFieldId = -1;
- m_nPartTagId = -1;
- m_nFeatureId = -1;
- m_listElementQuantifyData.clear();
- m_nElementNum = (int)m_listElementQuantifyData.size();
- // set data to 0
- memset(m_nXrayData, 0, sizeof(DWORD) * GENERALXRAYCHANNELS);
- m_spectrum = new CSpectrumData(0,m_nXrayData);
- }
- // duplication
- void CPosXray::Duplicate(const CPosXray& a_oSource)
- {
- // initial parameters
- Init();
- //CPosXrayInfo::Duplicate(a_oSource);
- m_poiPosition = a_oSource.m_poiPosition;
- m_nIndex = a_oSource.m_nIndex;
- m_nFieldId = a_oSource.m_nFieldId;
- m_nPartTagId = a_oSource.m_nPartTagId;
- m_nFeatureId = a_oSource.m_nFeatureId;
- for (auto poElementChemistry : a_oSource.m_listElementQuantifyData)
- {
- CElementChemistryPtr poElementChemistryNew(new CElementChemistry(poElementChemistry.get()));
- m_listElementQuantifyData.push_back(poElementChemistryNew);
- }
- m_nElementNum = (int)m_listElementQuantifyData.size();
- SetXrayData(a_oSource.GetXrayData());
- }
- }
|