CurveCompareEngine.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. m_Engine = new CClassifyOnCurveCompEng(0,myLib);
  38. return TRUE;
  39. }
  40. bool CurveCompareEngine::Classify(COTSParticlePtr particle, CPosXrayPtr xray)
  41. {
  42. // similarity
  43. double dSim = 0;
  44. // classify Particles
  45. auto stditm = m_Engine->GetMatchingSTD( xray, dSim);
  46. if (dSim > 0.8)
  47. {
  48. if (stditm != nullptr)
  49. {
  50. particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
  51. particle->SetClassifyId(stditm->GetID());
  52. particle->TypeName(stditm->GetName().GetBuffer());
  53. particle->TypeColor(std::to_string(stditm->GetColor()));
  54. }
  55. else
  56. {
  57. particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
  58. particle->TypeName("Not Identified");
  59. }
  60. }
  61. else
  62. {
  63. particle->SetType(OTS_PARTICLE_TYPE::NOT_IDENTIFIED);
  64. particle->TypeName("Not Identified");
  65. }
  66. return true;
  67. }
  68. bool CurveCompareEngine::Classify(COTSParticlePtr particle, int SteelTech, CPosXrayPtr xray)
  69. {
  70. throw std::logic_error("The method or operation is not implemented.");
  71. }
  72. bool CurveCompareEngine::IfNeedMaxEDS(COTSParticlePtr particle, CPosXrayPtr xray, double& MaxEDSTime)
  73. {
  74. throw std::logic_error("The method or operation is not implemented.");
  75. }
  76. OTSClassifyEngine::CLEEnginePtr GetCurveCompareEngine(std::string libName)
  77. {
  78. static CLEEnginePtr engine;
  79. if (engine == NULL)
  80. {
  81. engine = CLEEnginePtr(new CurveCompareEngine(libName));
  82. engine->Init();
  83. }
  84. return engine;
  85. }
  86. }