ExpressionClassifyEngine.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  1. #pragma once
  2. #include "stdafx.h"
  3. #include "ExpressionClassifyEngine.h"
  4. #include "ExpressionParseEngine/LogicExp.h"
  5. #include "XMLSerialization.h"
  6. #include <map>
  7. #include <Element.h>
  8. #include "ExpressionParseEngine/OTSSTDLibFileMgr.h"
  9. #include "COTSUtilityDllFunExport.h"
  10. namespace OTSClassifyEngine
  11. {
  12. using namespace expInterpreter;
  13. bool ExpressionClassifyEngine::Init()
  14. {
  15. CSTDLibFileMgrPtr pLibFileMgr = CSTDLibFileMgrPtr(new CSTDLibFileMgr(m_StrName));
  16. m_std = ParticleSTDPtr(new ParticleSTD());
  17. if (!pLibFileMgr->LoadPartSTD(m_std))
  18. {
  19. return FALSE;
  20. }
  21. pLibFileMgr->LoadMaxEDSRulesData(m_std);
  22. if (!pLibFileMgr->LoadZeroElementRulesData(m_std))
  23. {
  24. //return false;
  25. }
  26. string constantStr = pLibFileMgr->LoadConstantsData();
  27. std::map<std::string, double> m_mapConstants;
  28. m_mapConstants.clear();
  29. std::vector<std::string> strs;
  30. xmls::SplitString(constantStr, strs, ",");
  31. for (std::string s : strs)
  32. {
  33. std::vector<std::string> oneExp;
  34. xmls::SplitString(s, oneExp, "=");
  35. m_mapConstants[oneExp[0]] = std::atof(oneExp[1].c_str());
  36. }
  37. m_std->setConstantsMap(m_mapConstants);
  38. return true;
  39. }
  40. bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPosXrayPtr xray)
  41. {
  42. if (particle != nullptr )//process the particle with the xray data
  43. {
  44. std::map<std::string, CElementChemistryPtr> mapChemistrys;
  45. CElementChemistriesList partEles;
  46. //zero element process,if satisfied the condition than set the particular element percentage to 0.and make it 100% of all the other element percentage.
  47. if (xray != nullptr)
  48. {
  49. auto& originalPartEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
  50. partEles = ZeroElementProcess(particle, xray);//
  51. for (auto ch : partEles)
  52. {
  53. mapChemistrys[ch->GetName().GetBuffer()] = ch;
  54. }
  55. }
  56. PartSTDRuleItemList ruleItems = m_std->GetSTDRuleItems();
  57. std::vector<PartSTDRuleItemPtr> matchedItems;
  58. for (auto itm : ruleItems)
  59. {
  60. //if the element quantity is not match the std item's keyelement num than they are unmatching.
  61. if (partEles.size() < itm->GetKeyElementList().size())
  62. {
  63. continue;
  64. }
  65. auto& mapStdEles = itm->GetMapElements();
  66. bool bMatch = true;
  67. // if the particle does not contain all the key elements of the item than they are unmatching.
  68. for (auto che : mapStdEles)
  69. {
  70. auto chemical = mapChemistrys.find(che.second->GetName().GetBuffer());
  71. if (chemical == mapChemistrys.end())
  72. {
  73. bMatch = false;
  74. break;
  75. }
  76. }
  77. if (!bMatch) continue;
  78. std::string exp = itm->GetExpressionStr();
  79. ProcessAllPropertiesWithParticleData(exp, mapChemistrys, itm, particle);
  80. //calculate the expression which has been processed.
  81. bool rst = CalcuExp(exp);
  82. if (rst)
  83. {
  84. matchedItems.push_back(itm);
  85. }
  86. else
  87. {
  88. continue;
  89. }
  90. }
  91. if (matchedItems.size() > 0)
  92. {
  93. auto matchedItem = matchedItems[0];
  94. for (auto itm : matchedItems)
  95. {
  96. if(itm->GetGrpID() ==0 && matchedItem->GetGrpID()==0)
  97. {
  98. //choose the most detailed one.
  99. if (itm->GetExpressionStr().size() > matchedItem->GetExpressionStr().size())
  100. {
  101. matchedItem = itm;
  102. }
  103. continue;
  104. }
  105. if(itm->GetGrpID()>0 )
  106. {
  107. if(itm->GetGrpID()<matchedItem->GetGrpID())
  108. {
  109. //choose the item with the smallest group id first.
  110. matchedItem = itm;
  111. continue;
  112. }
  113. else if(itm->GetGrpID() == matchedItem->GetGrpID())
  114. {
  115. //choose the most detailed one.
  116. if (itm->GetExpressionStr().size() > matchedItem->GetExpressionStr().size())
  117. {
  118. matchedItem = itm;
  119. }
  120. continue;
  121. }
  122. }
  123. }
  124. particle->SetBasicClassifyId(OTS_PARTICLE_BASIC_CLASSIFY::IDENTIFIED);
  125. particle->SetTypeId(matchedItem->GetID());
  126. particle->SetColor(matchedItem->GetColor());
  127. particle->SetTypeName(matchedItem->GetName());
  128. particle->SetHardness(matchedItem->GetHardness());
  129. particle->SetDensity(matchedItem->GetDensity());
  130. particle->SetConductivity(matchedItem->GetElectrical_conductivity());
  131. particle->SetGroupId(matchedItem->GetGrpID());
  132. particle->SetGroupColor(matchedItem->GetGrpColor());
  133. particle->SetGroupName(matchedItem->GetGrpName());
  134. if (matchedItem->GetIsElementAnalysis() == false)
  135. {
  136. matchedItem->AddXraySpectrum(particle->GetXrayInfo());
  137. }
  138. }
  139. else
  140. {
  141. particle->SetBasicClassifyId(OTS_PARTICLE_BASIC_CLASSIFY::NOT_IDENTIFIED);
  142. particle->SetTypeId((int)OTS_PARTICLE_BASIC_CLASSIFY::NOT_IDENTIFIED);
  143. particle->SetTypeName("Not Identified");
  144. particle->SetColor("#000000");
  145. particle->SetGroupId((int)OTS_PARTICLE_BASIC_CLASSIFY::NOT_IDENTIFIED);
  146. particle->SetGroupName("Not Identified");
  147. particle->SetGroupColor("#000000");
  148. }
  149. return true;
  150. }
  151. else if(particle != nullptr && xray == nullptr)//process particle without xray data
  152. {
  153. PartSTDRuleItemList stdItems = m_std->GetSTDRuleItems();
  154. for (auto itm : stdItems)
  155. {
  156. std::string exp = itm->GetExpressionStr();
  157. //if the rule demand any element infomation then they won't match.
  158. if (itm->GetKeyElementList().size() > 0 || itm->GetSubElementList().size() > 0)
  159. {
  160. continue;
  161. }
  162. ProcessImgPropertiesWithParticleData(exp, itm, particle);
  163. //calculate the expression which has been processed.
  164. bool rst = CalcuExp(exp);
  165. if (rst)
  166. {
  167. //int id = itm->GetID();
  168. particle->SetBasicClassifyId(OTS_PARTICLE_BASIC_CLASSIFY::IDENTIFIED);
  169. particle->SetTypeId(itm->GetID());
  170. particle->SetColor(itm->GetColor());
  171. particle->SetTypeName(itm->GetName());
  172. particle->SetHardness(itm->GetHardness());
  173. particle->SetDensity(itm->GetDensity());
  174. particle->SetConductivity(itm->GetElectrical_conductivity());
  175. particle->SetGroupId(itm->GetGrpID());
  176. particle->SetGroupColor(itm->GetGrpColor());
  177. particle->SetGroupName(itm->GetGrpName());
  178. return true;
  179. }
  180. else
  181. {
  182. continue;
  183. }
  184. }
  185. particle->SetBasicClassifyId(OTS_PARTICLE_BASIC_CLASSIFY::NOT_IDENTIFIED);
  186. particle->SetTypeName("Not Identified");
  187. particle->SetColor("#000000");
  188. particle->SetGroupId((int)OTS_PARTICLE_BASIC_CLASSIFY::NOT_IDENTIFIED);
  189. particle->SetGroupColor("#000000");
  190. particle->SetGroupName("Not Identified");
  191. return true;
  192. }
  193. }
  194. bool ExpressionClassifyEngine::IfNeedMaxEDS(COTSParticlePtr particle, CPosXrayPtr xray, double& MaxEDSTime)
  195. {
  196. if (particle == nullptr || xray == nullptr) return false;
  197. MaxEDSRuleList Rules = m_std->GetMaxEDSRules();
  198. for (auto rule : Rules)
  199. {
  200. std::string exp = rule->m_expressionStr;
  201. auto& partEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
  202. if (partEles.size() < rule->m_elementList.size())
  203. {
  204. continue;// if the size not match then continue.
  205. }
  206. std::map<CString, CElementChemistryPtr> mapChe;
  207. for (auto ch : partEles)
  208. {
  209. mapChe[ch->GetName()] = ch;
  210. }
  211. auto& usingEles = rule->m_elementList;
  212. bool bMatch=true;
  213. for (auto che : usingEles)
  214. {
  215. auto chemical = mapChe.find(che->GetName());
  216. if (chemical == mapChe.end())
  217. {
  218. bMatch = false;
  219. break;
  220. }
  221. }
  222. if (!bMatch) continue;//if cann't find the element in the particle's element,then continue.
  223. // all the rule's using element are contained in the particle then we replace the element with the percentage value
  224. for (std::string s : rule->m_OtherpropertyList)
  225. {
  226. if (s.find("_elem")!=std::string::npos)
  227. {
  228. auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
  229. xmls::ReplaceAll(exp, s, std::to_string(val));
  230. }
  231. if (s.find("Element#")!=std::string::npos)
  232. {
  233. auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
  234. auto& elelist = rule->m_elementList;
  235. elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
  236. xmls::ReplaceAll(exp, s, val.GetBuffer());
  237. }
  238. }
  239. for (auto eleChemistry : rule->m_elementList)
  240. {
  241. auto e = mapChe[eleChemistry->GetName()];
  242. std::string name = eleChemistry->GetName();
  243. xmls::ReplaceAll(exp, name, std::to_string(e->GetPercentage()));
  244. }
  245. for (std::string s : rule->m_ImgPropertyList)
  246. {
  247. auto val = particle->GetImgPropertyValueByName(s.c_str());
  248. xmls::ReplaceAll(exp, s, std::to_string(val));
  249. }
  250. bool rst = CalcuExp(exp);
  251. if (rst)
  252. {
  253. MaxEDSTime = rule->m_MaxEDSTime;
  254. return true;
  255. }
  256. else
  257. {
  258. continue;
  259. }
  260. }
  261. MaxEDSTime = 0;
  262. return false;
  263. }
  264. CString ExpressionClassifyEngine::GetEleNameBySortingPercentage(CString sortingNostr, CPosXrayPtr xrayInfo)
  265. {
  266. std::map<double, CElementChemistryPtr> mapPercent;
  267. std::map<int, CElementChemistryPtr> mapSorted;
  268. auto eles = xrayInfo->GetElementQuantifyData();
  269. for (auto e : eles)
  270. {
  271. mapPercent[e->GetPercentage()] = e;
  272. }
  273. auto itr = --mapPercent.end();
  274. for (int i=0;itr != mapPercent.begin();)
  275. {
  276. mapSorted.insert(std::pair<int, CElementChemistryPtr>(i, itr->second));
  277. itr--;
  278. i++;
  279. }
  280. std::string NoStr = sortingNostr;
  281. std::vector<string> strs;
  282. xmls::SplitString(NoStr, strs, "#");
  283. int No = std::stoi(strs[1]);
  284. if (mapSorted.size() > No)
  285. {
  286. return mapSorted[No]->GetName();
  287. }
  288. else
  289. {
  290. return _T("");
  291. }
  292. }
  293. double ExpressionClassifyEngine::GetMacValue(CString MacStr)
  294. {
  295. auto mapconstant = m_std->GetMapConstants();
  296. if (mapconstant.find(MacStr.GetBuffer()) != mapconstant.end())
  297. {
  298. return mapconstant[MacStr.GetBuffer()];
  299. }
  300. else
  301. {
  302. return 0.0;
  303. }
  304. }
  305. int ExpressionClassifyEngine::GetAtomicNoBySortingPercentage(CString sortingNostr, CPosXrayPtr xrayInfo)
  306. {
  307. std::map<double, CElementChemistryPtr> mapPercent;
  308. std::map<int, CElementChemistryPtr> mapSorted;
  309. auto eles = xrayInfo->GetElementQuantifyData();
  310. if (eles.size() == 0)
  311. {
  312. return 0;
  313. }
  314. for (auto e : eles)
  315. {
  316. mapPercent[e->GetPercentage()] = e;
  317. }
  318. auto itr = --mapPercent.end();
  319. for (int i = 0; itr != mapPercent.begin(); )
  320. {
  321. mapSorted.insert(std::pair<int, CElementChemistryPtr>(i, itr->second));
  322. itr--;
  323. i++;
  324. }
  325. std::string NoStr = sortingNostr;
  326. int No=10;
  327. if (sortingNostr == "first_elem") No = 0;
  328. if (sortingNostr == "second_elem") No = 1;
  329. if (sortingNostr == "third_elem") No = 2;
  330. if (sortingNostr == "fourth_elem") No = 3;
  331. if (sortingNostr == "fifth_elem") No = 4;
  332. if (sortingNostr == "sixth_elem") No = 5;
  333. if (sortingNostr == "seventh_elem") No =6;
  334. if (sortingNostr == "eighth_elem") No = 7;
  335. if (sortingNostr == "ninth_elem") No = 8;
  336. if (sortingNostr == "tenth_elem") No =9;
  337. if (mapSorted.size() > No)
  338. {
  339. std::string elename = mapSorted[No]->GetName();
  340. CElementPtr ele = CElementPtr(new CElement(elename.c_str()));
  341. return ele->GetAtomNum();
  342. }
  343. else
  344. {
  345. return 0;
  346. }
  347. }
  348. CElementChemistriesList ExpressionClassifyEngine::ZeroElementProcess(COTSParticlePtr particle, CPosXrayPtr xray)
  349. {
  350. auto& originalPartEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
  351. CElementChemistriesList partEles;
  352. for (auto che : originalPartEles)
  353. {
  354. auto newChe = CElementChemistryPtr(new CElementChemistry(che.get()));
  355. partEles.push_back(newChe);
  356. }
  357. //make it 100% in total.(so called the "Normalization")
  358. double rawPercentage = 0;
  359. for (auto ele : partEles)
  360. {
  361. rawPercentage += ele->GetPercentage();
  362. }
  363. for (auto ele : partEles)
  364. {
  365. ele->SetPercentage(ele->GetPercentage() / rawPercentage * 100);
  366. }
  367. //zero element process
  368. std::map<CString, CElementChemistryPtr> mapChe;
  369. for (auto ch : partEles)
  370. {
  371. mapChe[ch->GetName()] = ch;
  372. }
  373. ZeroElementRuleList Rules = m_std->GetZeroRules();
  374. for (auto rule : Rules)
  375. {
  376. std::string exp = rule->GetExpressionStr();
  377. if (partEles.size() < rule->GetUsingElementList().size())
  378. {
  379. continue;// if the size not match then continue.
  380. }
  381. auto& usingEles = rule->GetUsingElementList();
  382. bool bMatch = true;
  383. for (auto che : usingEles)
  384. {
  385. auto chemical = mapChe.find(che->GetName());
  386. if (chemical == mapChe.end())
  387. {
  388. bMatch = false;
  389. break;//if cann't find the element in the particle's element,then continue.
  390. }
  391. }
  392. if (bMatch == false) continue;
  393. // all the rule's using elements are contained in the particle then we replace the element with the percentage value
  394. for (std::string s : rule->GetOtherpropertyList())
  395. {
  396. if (s.find("_elem")!=std::string::npos)
  397. {
  398. auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
  399. xmls::ReplaceAll(exp, s, std::to_string(val));
  400. }
  401. if (s.find("Element#")!=std::string::npos)
  402. {
  403. auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
  404. auto elelist = rule->GetUsingElementList();
  405. elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
  406. rule->SetUsingElementList(elelist);
  407. xmls::ReplaceAll(exp, s, val.GetBuffer());
  408. }
  409. }
  410. for (auto eleChemistry : rule->GetUsingElementList())
  411. {
  412. auto e = mapChe.find(eleChemistry->GetName());
  413. if (e != mapChe.end())
  414. {
  415. std::string name = eleChemistry->GetName();
  416. xmls::ReplaceAll(exp, name, std::to_string((*e).second->GetPercentage()));
  417. }
  418. }
  419. for (std::string s : rule->GetImgPropertyList())
  420. {
  421. auto val = particle->GetImgPropertyValueByName(s.c_str());
  422. xmls::ReplaceAll(exp, s, std::to_string(val));
  423. }
  424. for (int i = 0; i < 10; i++)
  425. {
  426. std::string macStr = "MAC#" + std::to_string(i);
  427. if (exp.find(macStr) != std::string::npos)
  428. {
  429. auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
  430. xmls::ReplaceAll(exp, macStr, std::to_string(val));
  431. }
  432. }
  433. bool rst = CalcuExp(exp);
  434. if (rst)
  435. {
  436. auto itr = std::find_if(partEles.begin(), partEles.end(), [rule](CElementChemistryPtr ele) {return ele->GetName() == CString(rule->GetZeroElementName().c_str()); });
  437. if (itr != partEles.end())
  438. {
  439. //partEles.erase(itr);//if satisfied the condition then erase the element(zero the element).
  440. (*itr)->SetPercentage(0);//if satisfied the condition then set element percentage to 0(zero the element).
  441. double sumPercentage=0;
  442. for (auto ele : partEles)
  443. {
  444. sumPercentage += ele->GetPercentage();
  445. }
  446. for (auto ele : partEles)
  447. {
  448. if (sumPercentage != 0)
  449. {
  450. ele->SetPercentage(ele->GetPercentage() / sumPercentage * 100);
  451. }
  452. }
  453. }
  454. }
  455. else
  456. {
  457. continue;
  458. }
  459. }
  460. particle->GetXrayInfo()->SetElementQuantifyData(partEles);//set the particle's xray element quantify data to the new partEles.
  461. return partEles;
  462. }
  463. void ExpressionClassifyEngine::ProcessAllPropertiesWithParticleData(std::string& exp,
  464. std::map<std::string, CElementChemistryPtr>& mapChemistrys,
  465. PartSTDRuleItemPtr itm,
  466. COTSParticlePtr particle
  467. )
  468. {
  469. // process the special property name such as "first_elem" and "Element#1" etc.
  470. auto xray = particle->GetXrayInfo();
  471. for (std::string s : itm->GetUsingOtherpropertyList())
  472. {
  473. if (s.find("_elem") != std::string::npos)
  474. {
  475. auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
  476. xmls::ReplaceAll(exp, s, std::to_string(val));
  477. }
  478. if (s.find("Element#") != std::string::npos)
  479. {
  480. auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
  481. auto elelist = itm->GetKeyElementList();
  482. elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
  483. itm->SetKeyElementList(elelist);
  484. xmls::ReplaceAll(exp, s, val.GetBuffer());
  485. }
  486. }
  487. //process the element property
  488. for (auto eleChemistry : itm->GetAllSortedEleList())
  489. {
  490. auto e = mapChemistrys.find(eleChemistry->GetName().GetBuffer());
  491. if (e != mapChemistrys.end())
  492. {
  493. std::string name = eleChemistry->GetName();
  494. xmls::ReplaceAll(exp, name, std::to_string(e->second->GetPercentage()));
  495. }
  496. else
  497. {
  498. std::string name = eleChemistry->GetName();
  499. xmls::ReplaceAll(exp, name, "0");
  500. }
  501. }
  502. //process the image property
  503. for (std::string s : itm->GetUsingImgPropertyNameList())
  504. {
  505. auto val = particle->GetImgPropertyValueByName(s.c_str());
  506. xmls::ReplaceAll(exp, s, std::to_string(val));
  507. }
  508. //process the "true" keyword.
  509. if (exp.find("true") != std::string::npos)
  510. {
  511. xmls::ReplaceAll(exp, "true", "(1=1)");
  512. }
  513. //process the "false" keyword.
  514. if (exp.find("false") != std::string::npos)
  515. {
  516. xmls::ReplaceAll(exp, "false", "(1=0)");
  517. }
  518. //process the contant value
  519. for (int i = 0; i < 10; i++)
  520. {
  521. std::string macStr = "MAC#" + std::to_string(i);
  522. if (exp.find(macStr) != std::string::npos)
  523. {
  524. auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
  525. xmls::ReplaceAll(exp, macStr, std::to_string(val));
  526. }
  527. }
  528. }
  529. void ExpressionClassifyEngine::ProcessImgPropertiesWithParticleData(std::string& exp, PartSTDRuleItemPtr itm, COTSParticlePtr particle)
  530. {
  531. //process the image property
  532. for (std::string s : itm->GetUsingImgPropertyNameList())
  533. {
  534. auto val = particle->GetImgPropertyValueByName(s.c_str());
  535. xmls::ReplaceAll(exp, s, std::to_string(val));
  536. }
  537. //process the "true" keyword.
  538. if (exp.find("true") != std::string::npos)
  539. {
  540. xmls::ReplaceAll(exp, "true", "(1=1)");
  541. }
  542. //process the "false" keyword.
  543. if (exp.find("false") != std::string::npos)
  544. {
  545. xmls::ReplaceAll(exp, "false", "(1=0)");
  546. }
  547. //process the constant value
  548. for (int i = 0; i < 10; i++)
  549. {
  550. std::string macStr = "MAC#" + std::to_string(i);
  551. if (exp.find(macStr) != std::string::npos)
  552. {
  553. auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
  554. xmls::ReplaceAll(exp, macStr, std::to_string(val));
  555. }
  556. }
  557. }
  558. bool ExpressionClassifyEngine::ZeroElementProcess(COTSParticlePtr particle)
  559. {
  560. auto chems = ZeroElementProcess(particle, particle->GetXrayInfo());
  561. particle->GetXrayInfo()->SetElementQuantifyData(chems);
  562. return true;
  563. }
  564. bool ExpressionClassifyEngine::ClassifyBySpectrum(COTSParticlePtr particle, CPosXrayPtr xray)
  565. {
  566. return false;
  567. }
  568. bool ExpressionClassifyEngine::ClassifyByExpressionTemporarySpectrum(COTSParticlePtr particle, CPosXrayPtr xray)
  569. {
  570. PartSTDRuleItemList ruleItems = m_std->GetSTDRuleItems();
  571. for (auto itm : ruleItems)
  572. {
  573. if (itm->GetIsElementAnalysis() == false)
  574. {
  575. auto sim = itm->CalculateSimilarity(xray);
  576. if (sim > 0.90)
  577. {
  578. particle->SetBasicClassifyId(OTS_PARTICLE_BASIC_CLASSIFY::IDENTIFIED);
  579. particle->SetTypeId(itm->GetID());
  580. particle->SetColor(itm->GetColor());
  581. particle->SetTypeName(itm->GetName());
  582. particle->SetHardness(itm->GetHardness());
  583. particle->SetDensity(itm->GetDensity());
  584. particle->SetConductivity(itm->GetElectrical_conductivity());
  585. particle->SetGroupId(itm->GetGrpID());
  586. particle->SetGroupColor(itm->GetGrpColor());
  587. particle->SetGroupName(itm->GetGrpName());
  588. break;
  589. }
  590. }
  591. }
  592. return true;
  593. }
  594. bool ExpressionClassifyEngine::ClassifyIncA(COTSParticlePtr particle, int SteelTech, CPosXrayPtr xray)
  595. {
  596. return false;
  597. }
  598. OTSClassifyEngine::CLEEnginePtr GetParticleEngine(std::string a_libName)
  599. {
  600. static CLEEnginePtr engine;
  601. static std::string libName="";
  602. if (engine == NULL || libName != a_libName)
  603. {
  604. engine = CLEEnginePtr(new ExpressionClassifyEngine(a_libName));
  605. libName = a_libName;
  606. if (!engine->Init())
  607. {
  608. return NULL;
  609. }
  610. }
  611. return engine;
  612. }
  613. }