ExpressionClassifyEngine.cpp 18 KB

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