CurveCompareEngine.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include "stdafx.h"
  2. #include "CurveCompareEngine.h"
  3. #include "OTSSTDLibFileMgr.h"
  4. #include "OTSClassifyOnCurveCompEng.h"
  5. #include "ParticleEngine/ParticleSTD.h"
  6. namespace OTSClassifyEngine
  7. {
  8. bool CurveCompareEngine::Init()
  9. {
  10. CSTDLibFileMgrPtr pLibFileMgr = CSTDLibFileMgrPtr(new CSTDLibFileMgr(m_StrName));
  11. if (!pLibFileMgr->Load(myLib))
  12. {
  13. return FALSE;
  14. }
  15. ParticleSTDPtr m_std = ParticleSTDPtr(new ParticleSTD());
  16. if (!pLibFileMgr->LoadPartSTD(m_std))
  17. {
  18. return FALSE;
  19. }
  20. for (int i = 0; i < myLib->GetSTDItemCount(); i++)
  21. {
  22. auto itm = myLib->GetSTDItem(i);
  23. auto expstditm = m_std->GetSTDItemById(itm->GetID());
  24. if (expstditm != nullptr)
  25. {
  26. itm->SetName(expstditm->GetName().c_str());
  27. DWORD r, g, b;
  28. sscanf(expstditm->GetColor().c_str(), "#%2X%2X%2X", &r, &g, &b);
  29. COLORREF rgb = RGB(r, g, b);
  30. itm->SetColor(rgb);
  31. //itm->SetElementsList(expstditm->GetKeyElementList());
  32. itm->SetBSEValue(expstditm->GetBSE());
  33. itm->SetDensity(expstditm->GetDensity());
  34. itm->SetFormula(expstditm->GetFormula().c_str());
  35. }
  36. }
  37. return TRUE;
  38. }
  39. bool CurveCompareEngine::Classify(COTSParticlePtr particle, CPosXrayPtr xray)
  40. {
  41. // similarity
  42. double dSim = 0;
  43. // classify Particles
  44. const std::vector<CString> vecIgnoreElementNames;
  45. auto stditm = CClassifyOnCurveCompEng::GetCompareSTD(0, vecIgnoreElementNames, xray,myLib, dSim);
  46. //if (dSim > 0.05)
  47. if (stditm != nullptr)
  48. {
  49. particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
  50. particle->SetClassifyId(stditm->GetID());
  51. particle->TypeName(stditm->GetName().GetBuffer());
  52. particle->TypeColor(std::to_string(stditm->GetColor()));
  53. }else
  54. {
  55. particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
  56. particle->TypeName("Not Identified");
  57. }
  58. return true;
  59. }
  60. bool CurveCompareEngine::Classify(COTSParticlePtr particle, int SteelTech, CPosXrayPtr xray)
  61. {
  62. throw std::logic_error("The method or operation is not implemented.");
  63. }
  64. bool CurveCompareEngine::IfNeedMaxEDS(COTSParticlePtr particle, CPosXrayPtr xray, double& MaxEDSTime)
  65. {
  66. throw std::logic_error("The method or operation is not implemented.");
  67. }
  68. OTSClassifyEngine::CLEEnginePtr GetCurveCompareEngine(std::string libName)
  69. {
  70. static CLEEnginePtr engine;
  71. if (engine == NULL)
  72. {
  73. engine = CLEEnginePtr(new CurveCompareEngine(libName));
  74. engine->Init();
  75. }
  76. return engine;
  77. }
  78. }