#include "stdafx.h" #include "CurveCompareEngine.h" #include "OTSSTDLibFileMgr.h" #include "OTSClassifyOnCurveCompEng.h" #include "ParticleEngine/ParticleSTD.h" namespace OTSClassifyEngine { bool CurveCompareEngine::Init() { CSTDLibFileMgrPtr pLibFileMgr = CSTDLibFileMgrPtr(new CSTDLibFileMgr(m_StrName)); if (!pLibFileMgr->Load(myLib)) { return FALSE; } ParticleSTDPtr m_std = ParticleSTDPtr(new ParticleSTD()); if (!pLibFileMgr->LoadPartSTD(m_std)) { return FALSE; } for (int i = 0; i < myLib->GetSTDItemCount(); i++) { auto itm = myLib->GetSTDItem(i); auto expstditm = m_std->GetSTDItemById(itm->GetID()); if (expstditm != nullptr) { itm->SetName(expstditm->GetName().c_str()); DWORD r, g, b; sscanf(expstditm->GetColor().c_str(), "#%2X%2X%2X", &r, &g, &b); COLORREF rgb = RGB(r, g, b); itm->SetColor(rgb); //itm->SetElementsList(expstditm->GetKeyElementList()); itm->SetBSEValue(expstditm->GetBSE()); itm->SetDensity(expstditm->GetDensity()); itm->SetFormula(expstditm->GetFormula().c_str()); } } return TRUE; } bool CurveCompareEngine::Classify(COTSParticlePtr particle, CPosXrayPtr xray) { // similarity double dSim = 0; // classify Particles const std::vector vecIgnoreElementNames; auto stditm = CClassifyOnCurveCompEng::GetCompareSTD(0, vecIgnoreElementNames, xray,myLib, dSim); //if (dSim > 0.05) if (stditm != nullptr) { particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED); particle->SetClassifyId(stditm->GetID()); particle->TypeName(stditm->GetName().GetBuffer()); particle->TypeColor(std::to_string(stditm->GetColor())); }else { particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED); particle->TypeName("Not Identified"); } return true; } bool CurveCompareEngine::Classify(COTSParticlePtr particle, int SteelTech, CPosXrayPtr xray) { throw std::logic_error("The method or operation is not implemented."); } bool CurveCompareEngine::IfNeedMaxEDS(COTSParticlePtr particle, CPosXrayPtr xray, double& MaxEDSTime) { throw std::logic_error("The method or operation is not implemented."); } OTSClassifyEngine::CLEEnginePtr GetCurveCompareEngine(std::string libName) { static CLEEnginePtr engine; if (engine == NULL) { engine = CLEEnginePtr(new CurveCompareEngine(libName)); engine->Init(); } return engine; } }