|
|
@@ -42,20 +42,10 @@ bool ExpressionClassifyEngine::Init()
|
|
|
bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPosXrayPtr xray)
|
|
|
{
|
|
|
|
|
|
- if (particle != nullptr && xray != nullptr)
|
|
|
+ if (particle != nullptr && xray != nullptr)//process the particle with the xray data
|
|
|
{
|
|
|
auto& originalPartEles = xray->GetElementQuantifyData();//find all the elements containing in the particle xray.
|
|
|
- //以下为调试用代码段(在log中打出颗粒元素),不要删除----------
|
|
|
- /*std::string allele=std::to_string(particle->GetTagId()) + " ";
|
|
|
- for (auto che : originalPartEles)
|
|
|
- {
|
|
|
- allele += che->GetName().GetBuffer() ;
|
|
|
- allele += ":";
|
|
|
- allele += std::to_string(che->GetPercentage()).c_str();
|
|
|
- allele += " ";
|
|
|
- }
|
|
|
- LogTrace(__FILE__, __LINE__, allele.c_str());*/
|
|
|
- //-----------------------------
|
|
|
+
|
|
|
//zero element process,if satisfied the condition than set the particular element percentage to 0.and make it 100% of all the element percentage.
|
|
|
|
|
|
auto partEles = ZeroElementProcess(particle, xray);//
|
|
|
@@ -67,15 +57,11 @@ bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPos
|
|
|
mapChemistrys[ch->GetName().GetBuffer()] = ch;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
PartSTDRuleItemList ruleItems = m_std->GetSTDRuleItems();
|
|
|
- //以下为调试用代码段(在log中打出颗粒元素),不要删除----------
|
|
|
- /*CString stdnum = _T("STDNum ")+ CString(std::to_string(stdItems.size()).c_str());
|
|
|
- LogTrace(__FILE__, __LINE__, stdnum);*/
|
|
|
+
|
|
|
for (auto itm : ruleItems)
|
|
|
{
|
|
|
- std::string exp = itm->GetExpressionStr();
|
|
|
- //LogTrace(__FILE__, __LINE__, exp.c_str());
|
|
|
+
|
|
|
//if the element quantity is not match the std item's keyelement num than they are unmatching.
|
|
|
if (partEles.size() < itm->GetKeyElementList().size())
|
|
|
{
|
|
|
@@ -100,87 +86,16 @@ bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPos
|
|
|
|
|
|
if (!bMatch) continue;
|
|
|
|
|
|
- // process the special property name such as "first_elem" and "Element#1" etc.
|
|
|
- for (std::string s : itm->GetUsingOtherpropertyList())
|
|
|
- {
|
|
|
-
|
|
|
- if (s.find("_elem") != std::string::npos)
|
|
|
- {
|
|
|
- auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
|
|
|
-
|
|
|
- xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
- }
|
|
|
-
|
|
|
- if (s.find("Element#") != std::string::npos)
|
|
|
- {
|
|
|
- auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
|
|
|
- auto elelist = itm->GetKeyElementList();
|
|
|
- elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
|
|
|
- itm->SetKeyElementList(elelist);
|
|
|
- xmls::ReplaceAll(exp, s, val.GetBuffer());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for (auto eleChemistry : itm->GetAllSortedEleList())
|
|
|
- {
|
|
|
- auto e = mapChemistrys.find(eleChemistry->GetName().GetBuffer());
|
|
|
-
|
|
|
- if (e != mapChemistrys.end())
|
|
|
- {
|
|
|
- std::string name = eleChemistry->GetName();
|
|
|
-
|
|
|
- xmls::ReplaceAll(exp, name, std::to_string(e->second->GetPercentage()));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- std::string name = eleChemistry->GetName();
|
|
|
-
|
|
|
- xmls::ReplaceAll(exp, name, "0");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //process the image property
|
|
|
- for (std::string s : itm->GetUsingImgPropertyNameList())
|
|
|
- {
|
|
|
- auto val = particle->GetImgPropertyValueByName(s.c_str());
|
|
|
- xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
- }
|
|
|
- //process the "true" keyword.
|
|
|
- if (exp.find("true") != std::string::npos)
|
|
|
- {
|
|
|
- xmls::ReplaceAll(exp, "true", "(1=1)");
|
|
|
- }
|
|
|
- //process the "false" keyword.
|
|
|
- if (exp.find("false") != std::string::npos)
|
|
|
- {
|
|
|
- xmls::ReplaceAll(exp, "false", "(1=0)");
|
|
|
- }
|
|
|
- for (int i = 0; i < 10; i++)
|
|
|
- {
|
|
|
- std::string macStr = "MAC#" + std::to_string(i);
|
|
|
- if (exp.find(macStr) != std::string::npos)
|
|
|
- {
|
|
|
- auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
|
|
|
- xmls::ReplaceAll(exp, macStr, std::to_string(val));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ std::string exp = itm->GetExpressionStr();
|
|
|
|
|
|
+
|
|
|
+ ProcessAllPropertiesWithParticleData(exp, mapChemistrys, itm, particle);
|
|
|
|
|
|
//calculate the expression which has been processed.
|
|
|
|
|
|
bool rst = CalcuExp(exp);
|
|
|
|
|
|
- //以下为调试用代码段(在log中打出颗粒元素),不要删除----------
|
|
|
- /*LogTrace(__FILE__, __LINE__, exp.c_str());
|
|
|
- if (rst)
|
|
|
- {
|
|
|
- LogTrace(__FILE__, __LINE__, CString("true"));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogTrace(__FILE__, __LINE__, CString("false"));
|
|
|
- }*/
|
|
|
+
|
|
|
|
|
|
if (rst)
|
|
|
{
|
|
|
@@ -196,6 +111,14 @@ bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPos
|
|
|
particle->SetGroupId(itm->GetGrpID());
|
|
|
particle->SetGroupColor(itm->GetGrpColor());
|
|
|
particle->SetGroupName(itm->GetGrpName());
|
|
|
+
|
|
|
+ //if this item is a spectrum compared item then we should memory these spectrum to be used when doing spectrum compare.
|
|
|
+
|
|
|
+ if (itm->GetIsElementAnalysis() == false)
|
|
|
+ {
|
|
|
+
|
|
|
+ itm->AddXraySpectrum(particle->GetXrayInfo());
|
|
|
+ }
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
@@ -211,45 +134,20 @@ bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPos
|
|
|
particle->SetGroupColor("#000000");
|
|
|
return true;
|
|
|
}
|
|
|
- else if(particle != nullptr && xray == nullptr)
|
|
|
+ else if(particle != nullptr && xray == nullptr)//process particle without xray data
|
|
|
{
|
|
|
PartSTDRuleItemList stdItems = m_std->GetSTDRuleItems();
|
|
|
|
|
|
for (auto itm : stdItems)
|
|
|
{
|
|
|
std::string exp = itm->GetExpressionStr();
|
|
|
-
|
|
|
+ //if the rule demand any element infomation then they won't match.
|
|
|
if (itm->GetKeyElementList().size() > 0 || itm->GetSubElementList().size() > 0)
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- //process the image property
|
|
|
- for (std::string s : itm->GetUsingImgPropertyNameList())
|
|
|
- {
|
|
|
- auto val = particle->GetImgPropertyValueByName(s.c_str());
|
|
|
- xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
- }
|
|
|
- //process the "true" keyword.
|
|
|
- if (exp.find("true") != std::string::npos)
|
|
|
- {
|
|
|
- xmls::ReplaceAll(exp, "true", "(1=1)");
|
|
|
- }
|
|
|
- //process the "false" keyword.
|
|
|
- if (exp.find("false") != std::string::npos)
|
|
|
- {
|
|
|
- xmls::ReplaceAll(exp, "false", "(1=0)");
|
|
|
- }
|
|
|
- for (int i = 0; i < 10; i++)
|
|
|
- {
|
|
|
- std::string macStr = "MAC#" + std::to_string(i);
|
|
|
- if (exp.find(macStr) != std::string::npos)
|
|
|
- {
|
|
|
- auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
|
|
|
- xmls::ReplaceAll(exp, macStr, std::to_string(val));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ ProcessImgPropertiesWithParticleData(exp, itm, particle);
|
|
|
|
|
|
|
|
|
//calculate the expression which has been processed.
|
|
|
@@ -270,10 +168,7 @@ bool ExpressionClassifyEngine::ClassifyExpression(COTSParticlePtr particle, CPos
|
|
|
particle->SetGroupColor(itm->GetGrpColor());
|
|
|
particle->SetGroupName(itm->GetGrpName());
|
|
|
|
|
|
- if (itm->GetIsElementAnalysis() == false)
|
|
|
- {
|
|
|
- itm->AddXraySpectrum(particle->GetXrayInfo());
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
@@ -489,7 +384,7 @@ CElementChemistriesList ExpressionClassifyEngine::ZeroElementProcess(COTSParticl
|
|
|
auto newChe = CElementChemistryPtr(new CElementChemistry(che.get()));
|
|
|
partEles.push_back(newChe);
|
|
|
}
|
|
|
- //make it 100% in total.
|
|
|
+ //make it 100% in total.(so called the "Normalization")
|
|
|
double rawPercentage = 0;
|
|
|
for (auto ele : partEles)
|
|
|
{
|
|
|
@@ -590,7 +485,7 @@ CElementChemistriesList ExpressionClassifyEngine::ZeroElementProcess(COTSParticl
|
|
|
if (itr != partEles.end())
|
|
|
{
|
|
|
//partEles.erase(itr);//if satisfied the condition then erase the element(zero the element).
|
|
|
- (*itr)->SetPercentage(0);//if satisfied the condition then set element percenttage to 0(zero the element).
|
|
|
+ (*itr)->SetPercentage(0);//if satisfied the condition then set element percentage to 0(zero the element).
|
|
|
double sumPercentage=0;
|
|
|
for (auto ele : partEles)
|
|
|
{
|
|
|
@@ -615,6 +510,112 @@ CElementChemistriesList ExpressionClassifyEngine::ZeroElementProcess(COTSParticl
|
|
|
|
|
|
}
|
|
|
|
|
|
+void ExpressionClassifyEngine::ProcessAllPropertiesWithParticleData(std::string& exp,
|
|
|
+ std::map<std::string, CElementChemistryPtr>& mapChemistrys,
|
|
|
+ PartSTDRuleItemPtr itm,
|
|
|
+ COTSParticlePtr particle
|
|
|
+ )
|
|
|
+{
|
|
|
+ // process the special property name such as "first_elem" and "Element#1" etc.
|
|
|
+ auto xray = particle->GetXrayInfo();
|
|
|
+ for (std::string s : itm->GetUsingOtherpropertyList())
|
|
|
+ {
|
|
|
+
|
|
|
+ if (s.find("_elem") != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetAtomicNoBySortingPercentage(s.c_str(), xray);
|
|
|
+
|
|
|
+ xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (s.find("Element#") != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetEleNameBySortingPercentage(s.c_str(), xray);//find the "Element#1" and replace it with the real element name.
|
|
|
+ auto elelist = itm->GetKeyElementList();
|
|
|
+ elelist.push_back(CElementPtr(new CElement(val)));// then replace it in the next step.
|
|
|
+ itm->SetKeyElementList(elelist);
|
|
|
+ xmls::ReplaceAll(exp, s, val.GetBuffer());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //process the element property
|
|
|
+ for (auto eleChemistry : itm->GetAllSortedEleList())
|
|
|
+ {
|
|
|
+ auto e = mapChemistrys.find(eleChemistry->GetName().GetBuffer());
|
|
|
+
|
|
|
+ if (e != mapChemistrys.end())
|
|
|
+ {
|
|
|
+ std::string name = eleChemistry->GetName();
|
|
|
+
|
|
|
+ xmls::ReplaceAll(exp, name, std::to_string(e->second->GetPercentage()));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::string name = eleChemistry->GetName();
|
|
|
+
|
|
|
+ xmls::ReplaceAll(exp, name, "0");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //process the image property
|
|
|
+ for (std::string s : itm->GetUsingImgPropertyNameList())
|
|
|
+ {
|
|
|
+ auto val = particle->GetImgPropertyValueByName(s.c_str());
|
|
|
+ xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
+ }
|
|
|
+ //process the "true" keyword.
|
|
|
+ if (exp.find("true") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "true", "(1=1)");
|
|
|
+ }
|
|
|
+ //process the "false" keyword.
|
|
|
+ if (exp.find("false") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "false", "(1=0)");
|
|
|
+ }
|
|
|
+ //process the contant value
|
|
|
+ for (int i = 0; i < 10; i++)
|
|
|
+ {
|
|
|
+ std::string macStr = "MAC#" + std::to_string(i);
|
|
|
+ if (exp.find(macStr) != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
|
|
|
+ xmls::ReplaceAll(exp, macStr, std::to_string(val));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void ExpressionClassifyEngine::ProcessImgPropertiesWithParticleData(std::string& exp, PartSTDRuleItemPtr itm, COTSParticlePtr particle)
|
|
|
+{
|
|
|
+ //process the image property
|
|
|
+ for (std::string s : itm->GetUsingImgPropertyNameList())
|
|
|
+ {
|
|
|
+ auto val = particle->GetImgPropertyValueByName(s.c_str());
|
|
|
+ xmls::ReplaceAll(exp, s, std::to_string(val));
|
|
|
+ }
|
|
|
+ //process the "true" keyword.
|
|
|
+ if (exp.find("true") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "true", "(1=1)");
|
|
|
+ }
|
|
|
+ //process the "false" keyword.
|
|
|
+ if (exp.find("false") != std::string::npos)
|
|
|
+ {
|
|
|
+ xmls::ReplaceAll(exp, "false", "(1=0)");
|
|
|
+ }
|
|
|
+ //process the constant value
|
|
|
+ for (int i = 0; i < 10; i++)
|
|
|
+ {
|
|
|
+ std::string macStr = "MAC#" + std::to_string(i);
|
|
|
+ if (exp.find(macStr) != std::string::npos)
|
|
|
+ {
|
|
|
+ auto val = GetMacValue(macStr.c_str());//find the "Mac#1" and replace it with the real element name.
|
|
|
+ xmls::ReplaceAll(exp, macStr, std::to_string(val));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
bool ExpressionClassifyEngine::ClassifyBySpectrum(COTSParticlePtr particle, CPosXrayPtr xray)
|
|
|
{
|
|
|
return false;
|
|
|
@@ -631,7 +632,8 @@ bool ExpressionClassifyEngine::ClassifyByExpressionTemporarySpectrum(COTSParticl
|
|
|
{
|
|
|
if (itm->GetIsElementAnalysis() == false)
|
|
|
{
|
|
|
- if (itm->CalculateSimilarity(xray) > 0.90)
|
|
|
+ auto sim = itm->CalculateSimilarity(xray);
|
|
|
+ if (sim > 0.90)
|
|
|
{
|
|
|
particle->SetType(OTS_PARTICLE_TYPE::IDENTIFIED);
|
|
|
particle->SetClassifyId(itm->GetID());
|